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