]>
git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/rtos/rtos/Thread.cpp
1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2012 ARM Limited
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #include "mbed_error.h"
28 Thread::Thread(void (*task
)(void const *argument
), void *argument
,
29 osPriority priority
, uint32_t stack_size
, unsigned char *stack_pointer
) {
31 _thread_def
.pthread
= task
;
32 _thread_def
.tpriority
= priority
;
33 _thread_def
.stacksize
= stack_size
;
34 #ifndef __MBED_CMSIS_RTOS_CA9
35 if (stack_pointer
!= NULL
) {
36 _thread_def
.stack_pointer
= (uint32_t*)stack_pointer
;
37 _dynamic_stack
= false;
39 _thread_def
.stack_pointer
= new uint32_t[stack_size
/sizeof(uint32_t)];
40 if (_thread_def
.stack_pointer
== NULL
)
41 error("Error allocating the stack memory\n");
42 _dynamic_stack
= true;
46 _tid
= osThreadCreate(&_thread_def
, argument
);
49 osStatus
Thread::terminate() {
50 return osThreadTerminate(_tid
);
53 osStatus
Thread::set_priority(osPriority priority
) {
54 return osThreadSetPriority(_tid
, priority
);
57 osPriority
Thread::get_priority() {
58 return osThreadGetPriority(_tid
);
61 int32_t Thread::signal_set(int32_t signals
) {
62 return osSignalSet(_tid
, signals
);
65 Thread::State
Thread::get_state() {
66 #ifndef __MBED_CMSIS_RTOS_CA9
67 return ((State
)_thread_def
.tcb
.state
);
70 status
= osThreadGetState(_tid
);
71 return ((State
)status
);
75 osEvent
Thread::signal_wait(int32_t signals
, uint32_t millisec
) {
76 return osSignalWait(signals
, millisec
);
79 osStatus
Thread::wait(uint32_t millisec
) {
80 return osDelay(millisec
);
83 osStatus
Thread::yield() {
84 return osThreadYield();
87 osThreadId
Thread::gettid() {
88 return osThreadGetId();
93 #ifndef __MBED_CMSIS_RTOS_CA9
95 delete[] (_thread_def
.stack_pointer
);