Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard. Patched to work with NUCLEO L152 board
Fork of mbed-rtos by
Thread.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2012 ARM Limited 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00020 * SOFTWARE. 00021 */ 00022 #include "Thread.h" 00023 00024 #include "mbed_error.h" 00025 00026 namespace rtos { 00027 00028 Thread::Thread(void (*task)(void const *argument), void *argument, 00029 osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) { 00030 #ifdef CMSIS_OS_RTX 00031 _thread_def.pthread = task; 00032 _thread_def.tpriority = priority; 00033 _thread_def.stacksize = stack_size; 00034 if (stack_pointer != NULL) { 00035 _thread_def.stack_pointer = stack_pointer; 00036 _dynamic_stack = false; 00037 } else { 00038 _thread_def.stack_pointer = new unsigned char[stack_size]; 00039 if (_thread_def.stack_pointer == NULL) 00040 error("Error allocating the stack memory\n"); 00041 _dynamic_stack = true; 00042 } 00043 #endif 00044 _tid = osThreadCreate(&_thread_def, argument); 00045 } 00046 00047 osStatus Thread::terminate() { 00048 return osThreadTerminate(_tid); 00049 } 00050 00051 osStatus Thread::set_priority(osPriority priority) { 00052 return osThreadSetPriority(_tid, priority); 00053 } 00054 00055 osPriority Thread::get_priority() { 00056 return osThreadGetPriority(_tid); 00057 } 00058 00059 int32_t Thread::signal_set(int32_t signals) { 00060 return osSignalSet(_tid, signals); 00061 } 00062 00063 Thread::State Thread::get_state() { 00064 return ((State)_thread_def.tcb.state); 00065 } 00066 00067 osEvent Thread::signal_wait(int32_t signals, uint32_t millisec) { 00068 return osSignalWait(signals, millisec); 00069 } 00070 00071 osStatus Thread::wait(uint32_t millisec) { 00072 return osDelay(millisec); 00073 } 00074 00075 osStatus Thread::yield() { 00076 return osThreadYield(); 00077 } 00078 00079 osThreadId Thread::gettid() { 00080 return osThreadGetId(); 00081 } 00082 00083 Thread::~Thread() { 00084 terminate(); 00085 if (_dynamic_stack) { 00086 delete[] (_thread_def.stack_pointer); 00087 } 00088 } 00089 00090 }
Generated on Thu Jul 14 2022 02:41:33 by 1.7.2