rtos sd encoder systems

Dependencies:   mbed

Committer:
eembed
Date:
Thu Aug 01 08:00:33 2019 +0000
Revision:
0:5459cdde6298
first commit

Who changed what in which revision?

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