local fork

Dependents:   Encrypted

Fork of mbed-rtos by mbed official

Committer:
ashleymills
Date:
Fri Apr 26 16:49:39 2013 +0000
Revision:
11:2162c1c1f255
Parent:
8:88a1a9c26ae3
tiny change due to resolution of error.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 11:2162c1c1f255 1 /* mbed Microcontroller Library
ashleymills 11:2162c1c1f255 2 * Copyright (c) 2006-2012 ARM Limited
ashleymills 11:2162c1c1f255 3 *
ashleymills 11:2162c1c1f255 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
ashleymills 11:2162c1c1f255 5 * of this software and associated documentation files (the "Software"), to deal
ashleymills 11:2162c1c1f255 6 * in the Software without restriction, including without limitation the rights
ashleymills 11:2162c1c1f255 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ashleymills 11:2162c1c1f255 8 * copies of the Software, and to permit persons to whom the Software is
ashleymills 11:2162c1c1f255 9 * furnished to do so, subject to the following conditions:
ashleymills 11:2162c1c1f255 10 *
ashleymills 11:2162c1c1f255 11 * The above copyright notice and this permission notice shall be included in
ashleymills 11:2162c1c1f255 12 * all copies or substantial portions of the Software.
ashleymills 11:2162c1c1f255 13 *
ashleymills 11:2162c1c1f255 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ashleymills 11:2162c1c1f255 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ashleymills 11:2162c1c1f255 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ashleymills 11:2162c1c1f255 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ashleymills 11:2162c1c1f255 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ashleymills 11:2162c1c1f255 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
ashleymills 11:2162c1c1f255 20 * SOFTWARE.
ashleymills 11:2162c1c1f255 21 */
ashleymills 11:2162c1c1f255 22 #include "Thread.h"
ashleymills 11:2162c1c1f255 23
ashleymills 11:2162c1c1f255 24 #include "capi/error.h"
ashleymills 11:2162c1c1f255 25
ashleymills 11:2162c1c1f255 26 namespace rtos {
ashleymills 11:2162c1c1f255 27
ashleymills 11:2162c1c1f255 28 Thread::Thread(void (*task)(void const *argument), void *argument,
ashleymills 11:2162c1c1f255 29 osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) {
ashleymills 11:2162c1c1f255 30 #ifdef CMSIS_OS_RTX
ashleymills 11:2162c1c1f255 31 _thread_def.pthread = task;
ashleymills 11:2162c1c1f255 32 _thread_def.tpriority = priority;
ashleymills 11:2162c1c1f255 33 _thread_def.stacksize = stack_size;
ashleymills 11:2162c1c1f255 34 if (stack_pointer != NULL) {
ashleymills 11:2162c1c1f255 35 _thread_def.stack_pointer = stack_pointer;
ashleymills 11:2162c1c1f255 36 _dynamic_stack = false;
ashleymills 11:2162c1c1f255 37 } else {
ashleymills 11:2162c1c1f255 38 _thread_def.stack_pointer = new unsigned char[stack_size];
ashleymills 11:2162c1c1f255 39 if (_thread_def.stack_pointer == NULL)
ashleymills 11:2162c1c1f255 40 error("Error allocating the stack memory");
ashleymills 11:2162c1c1f255 41 _dynamic_stack = true;
ashleymills 11:2162c1c1f255 42 }
ashleymills 11:2162c1c1f255 43 #endif
ashleymills 11:2162c1c1f255 44 _tid = osThreadCreate(&_thread_def, argument);
ashleymills 11:2162c1c1f255 45 }
ashleymills 11:2162c1c1f255 46
ashleymills 11:2162c1c1f255 47 osStatus Thread::terminate() {
ashleymills 11:2162c1c1f255 48 return osThreadTerminate(_tid);
ashleymills 11:2162c1c1f255 49 }
ashleymills 11:2162c1c1f255 50
ashleymills 11:2162c1c1f255 51 osStatus Thread::set_priority(osPriority priority) {
ashleymills 11:2162c1c1f255 52 return osThreadSetPriority(_tid, priority);
ashleymills 11:2162c1c1f255 53 }
ashleymills 11:2162c1c1f255 54
ashleymills 11:2162c1c1f255 55 osPriority Thread::get_priority() {
ashleymills 11:2162c1c1f255 56 return osThreadGetPriority(_tid);
ashleymills 11:2162c1c1f255 57 }
ashleymills 11:2162c1c1f255 58
ashleymills 11:2162c1c1f255 59 int32_t Thread::signal_set(int32_t signals) {
ashleymills 11:2162c1c1f255 60 return osSignalSet(_tid, signals);
ashleymills 11:2162c1c1f255 61 }
ashleymills 11:2162c1c1f255 62
ashleymills 11:2162c1c1f255 63 Thread::State Thread::get_state() {
ashleymills 11:2162c1c1f255 64 return ((State)_thread_def.tcb.state);
ashleymills 11:2162c1c1f255 65 }
ashleymills 11:2162c1c1f255 66
ashleymills 11:2162c1c1f255 67 osEvent Thread::signal_wait(int32_t signals, uint32_t millisec) {
ashleymills 11:2162c1c1f255 68 return osSignalWait(signals, millisec);
ashleymills 11:2162c1c1f255 69 }
ashleymills 11:2162c1c1f255 70
ashleymills 11:2162c1c1f255 71 osStatus Thread::wait(uint32_t millisec) {
ashleymills 11:2162c1c1f255 72 return osDelay(millisec);
ashleymills 11:2162c1c1f255 73 }
ashleymills 11:2162c1c1f255 74
ashleymills 11:2162c1c1f255 75 osStatus Thread::yield() {
ashleymills 11:2162c1c1f255 76 return osThreadYield();
ashleymills 11:2162c1c1f255 77 }
ashleymills 11:2162c1c1f255 78
ashleymills 11:2162c1c1f255 79 osThreadId Thread::gettid() {
ashleymills 11:2162c1c1f255 80 return osThreadGetId();
ashleymills 11:2162c1c1f255 81 }
ashleymills 11:2162c1c1f255 82
ashleymills 11:2162c1c1f255 83 Thread::~Thread() {
ashleymills 11:2162c1c1f255 84 terminate();
ashleymills 11:2162c1c1f255 85 if (_dynamic_stack) {
ashleymills 11:2162c1c1f255 86 delete[] (_thread_def.stack_pointer);
ashleymills 11:2162c1c1f255 87 }
ashleymills 11:2162c1c1f255 88 }
ashleymills 11:2162c1c1f255 89
ashleymills 11:2162c1c1f255 90 }