Modified to run on Renesas GR Peach board

Dependencies:   EthernetInterface HTTP-Server Webpage mbed-rpc mbed-src

Fork of HTTPServer_echoback by Takuya Urakawa

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Thread.cpp Source File

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 #ifndef __MBED_CMSIS_RTOS_CA9
00035     if (stack_pointer != NULL) {
00036         _thread_def.stack_pointer = (uint32_t*)stack_pointer;
00037         _dynamic_stack = false;
00038     } else {
00039         _thread_def.stack_pointer = new uint32_t[stack_size/sizeof(uint32_t)];
00040         if (_thread_def.stack_pointer == NULL)
00041             error("Error allocating the stack memory\n");
00042         _dynamic_stack = true;
00043     }
00044 #endif
00045 #endif
00046     _tid = osThreadCreate(&_thread_def, argument);
00047 }
00048 
00049 osStatus Thread::terminate() {
00050     return osThreadTerminate(_tid);
00051 }
00052 
00053 osStatus Thread::set_priority(osPriority priority) {
00054     return osThreadSetPriority(_tid, priority);
00055 }
00056 
00057 osPriority Thread::get_priority() {
00058     return osThreadGetPriority(_tid);
00059 }
00060 
00061 int32_t Thread::signal_set(int32_t signals) {
00062     return osSignalSet(_tid, signals);
00063 }
00064 
00065 Thread::State Thread::get_state() {
00066 #ifndef __MBED_CMSIS_RTOS_CA9
00067     return ((State)_thread_def.tcb.state);
00068 #else
00069     uint8_t status;
00070     status = osThreadGetState(_tid);
00071     return ((State)status);
00072 #endif
00073 }
00074 
00075 osEvent Thread::signal_wait(int32_t signals, uint32_t millisec) {
00076     return osSignalWait(signals, millisec);
00077 }
00078 
00079 osStatus Thread::wait(uint32_t millisec) {
00080     return osDelay(millisec);
00081 }
00082 
00083 osStatus Thread::yield() {
00084     return osThreadYield();
00085 }
00086 
00087 osThreadId Thread::gettid() {
00088     return osThreadGetId();
00089 }
00090 
00091 Thread::~Thread() {
00092     terminate();
00093 #ifndef __MBED_CMSIS_RTOS_CA9
00094     if (_dynamic_stack) {
00095         delete[] (_thread_def.stack_pointer);
00096     }
00097 #endif
00098 }
00099 
00100 }