STM Imu acquisition setup using ethernet
Dependencies: F7_Ethernet mbed HTS221 LPS22HB LSM303AGR LSM6DSL
Fork of Nucleo_F746ZG_Ethernet by
mbed-rtos/rtos/Thread.cpp@9:45a96c88754d, 2018-10-15 (annotated)
- Committer:
- nirnakern
- Date:
- Mon Oct 15 14:41:19 2018 +0000
- Revision:
- 9:45a96c88754d
- Parent:
- 0:f9b6112278fe
First Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DieterGraef | 0:f9b6112278fe | 1 | /* mbed Microcontroller Library |
DieterGraef | 0:f9b6112278fe | 2 | * Copyright (c) 2006-2012 ARM Limited |
DieterGraef | 0:f9b6112278fe | 3 | * |
DieterGraef | 0:f9b6112278fe | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
DieterGraef | 0:f9b6112278fe | 5 | * of this software and associated documentation files (the "Software"), to deal |
DieterGraef | 0:f9b6112278fe | 6 | * in the Software without restriction, including without limitation the rights |
DieterGraef | 0:f9b6112278fe | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
DieterGraef | 0:f9b6112278fe | 8 | * copies of the Software, and to permit persons to whom the Software is |
DieterGraef | 0:f9b6112278fe | 9 | * furnished to do so, subject to the following conditions: |
DieterGraef | 0:f9b6112278fe | 10 | * |
DieterGraef | 0:f9b6112278fe | 11 | * The above copyright notice and this permission notice shall be included in |
DieterGraef | 0:f9b6112278fe | 12 | * all copies or substantial portions of the Software. |
DieterGraef | 0:f9b6112278fe | 13 | * |
DieterGraef | 0:f9b6112278fe | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
DieterGraef | 0:f9b6112278fe | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
DieterGraef | 0:f9b6112278fe | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
DieterGraef | 0:f9b6112278fe | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
DieterGraef | 0:f9b6112278fe | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
DieterGraef | 0:f9b6112278fe | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
DieterGraef | 0:f9b6112278fe | 20 | * SOFTWARE. |
DieterGraef | 0:f9b6112278fe | 21 | */ |
DieterGraef | 0:f9b6112278fe | 22 | #include "Thread.h" |
DieterGraef | 0:f9b6112278fe | 23 | |
DieterGraef | 0:f9b6112278fe | 24 | #include "mbed_error.h" |
DieterGraef | 0:f9b6112278fe | 25 | #include "rtos_idle.h" |
DieterGraef | 0:f9b6112278fe | 26 | |
DieterGraef | 0:f9b6112278fe | 27 | // rt_tid2ptcb is an internal function which we exposed to get TCB for thread id |
DieterGraef | 0:f9b6112278fe | 28 | #undef NULL //Workaround for conflicting macros in rt_TypeDef.h and stdio.h |
DieterGraef | 0:f9b6112278fe | 29 | #include "rt_TypeDef.h" |
DieterGraef | 0:f9b6112278fe | 30 | |
DieterGraef | 0:f9b6112278fe | 31 | extern "C" P_TCB rt_tid2ptcb(osThreadId thread_id); |
DieterGraef | 0:f9b6112278fe | 32 | |
DieterGraef | 0:f9b6112278fe | 33 | namespace rtos { |
DieterGraef | 0:f9b6112278fe | 34 | |
DieterGraef | 0:f9b6112278fe | 35 | Thread::Thread(void (*task)(void const *argument), void *argument, |
DieterGraef | 0:f9b6112278fe | 36 | osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) { |
DieterGraef | 0:f9b6112278fe | 37 | #if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM) |
DieterGraef | 0:f9b6112278fe | 38 | _thread_def.pthread = task; |
DieterGraef | 0:f9b6112278fe | 39 | _thread_def.tpriority = priority; |
DieterGraef | 0:f9b6112278fe | 40 | _thread_def.stacksize = stack_size; |
DieterGraef | 0:f9b6112278fe | 41 | if (stack_pointer != NULL) { |
DieterGraef | 0:f9b6112278fe | 42 | _thread_def.stack_pointer = (uint32_t*)stack_pointer; |
DieterGraef | 0:f9b6112278fe | 43 | _dynamic_stack = false; |
DieterGraef | 0:f9b6112278fe | 44 | } else { |
DieterGraef | 0:f9b6112278fe | 45 | _thread_def.stack_pointer = new uint32_t[stack_size/sizeof(uint32_t)]; |
DieterGraef | 0:f9b6112278fe | 46 | if (_thread_def.stack_pointer == NULL) |
DieterGraef | 0:f9b6112278fe | 47 | error("Error allocating the stack memory\n"); |
DieterGraef | 0:f9b6112278fe | 48 | _dynamic_stack = true; |
DieterGraef | 0:f9b6112278fe | 49 | } |
DieterGraef | 0:f9b6112278fe | 50 | |
DieterGraef | 0:f9b6112278fe | 51 | //Fill the stack with a magic word for maximum usage checking |
DieterGraef | 0:f9b6112278fe | 52 | for (uint32_t i = 0; i < (stack_size / sizeof(uint32_t)); i++) { |
DieterGraef | 0:f9b6112278fe | 53 | _thread_def.stack_pointer[i] = 0xE25A2EA5; |
DieterGraef | 0:f9b6112278fe | 54 | } |
DieterGraef | 0:f9b6112278fe | 55 | #endif |
DieterGraef | 0:f9b6112278fe | 56 | _tid = osThreadCreate(&_thread_def, argument); |
DieterGraef | 0:f9b6112278fe | 57 | } |
DieterGraef | 0:f9b6112278fe | 58 | |
DieterGraef | 0:f9b6112278fe | 59 | osStatus Thread::terminate() { |
DieterGraef | 0:f9b6112278fe | 60 | return osThreadTerminate(_tid); |
DieterGraef | 0:f9b6112278fe | 61 | } |
DieterGraef | 0:f9b6112278fe | 62 | |
DieterGraef | 0:f9b6112278fe | 63 | osStatus Thread::set_priority(osPriority priority) { |
DieterGraef | 0:f9b6112278fe | 64 | return osThreadSetPriority(_tid, priority); |
DieterGraef | 0:f9b6112278fe | 65 | } |
DieterGraef | 0:f9b6112278fe | 66 | |
DieterGraef | 0:f9b6112278fe | 67 | osPriority Thread::get_priority() { |
DieterGraef | 0:f9b6112278fe | 68 | return osThreadGetPriority(_tid); |
DieterGraef | 0:f9b6112278fe | 69 | } |
DieterGraef | 0:f9b6112278fe | 70 | |
DieterGraef | 0:f9b6112278fe | 71 | int32_t Thread::signal_set(int32_t signals) { |
DieterGraef | 0:f9b6112278fe | 72 | return osSignalSet(_tid, signals); |
DieterGraef | 0:f9b6112278fe | 73 | } |
DieterGraef | 0:f9b6112278fe | 74 | |
DieterGraef | 0:f9b6112278fe | 75 | int32_t Thread::signal_clr(int32_t signals) { |
DieterGraef | 0:f9b6112278fe | 76 | return osSignalClear(_tid, signals); |
DieterGraef | 0:f9b6112278fe | 77 | } |
DieterGraef | 0:f9b6112278fe | 78 | |
DieterGraef | 0:f9b6112278fe | 79 | Thread::State Thread::get_state() { |
DieterGraef | 0:f9b6112278fe | 80 | #if !defined(__MBED_CMSIS_RTOS_CA9) && !defined(__MBED_CMSIS_RTOS_CM) |
DieterGraef | 0:f9b6112278fe | 81 | #ifdef CMSIS_OS_RTX |
DieterGraef | 0:f9b6112278fe | 82 | return ((State)_thread_def.tcb.state); |
DieterGraef | 0:f9b6112278fe | 83 | #endif |
DieterGraef | 0:f9b6112278fe | 84 | #else |
DieterGraef | 0:f9b6112278fe | 85 | uint8_t status; |
DieterGraef | 0:f9b6112278fe | 86 | status = osThreadGetState(_tid); |
DieterGraef | 0:f9b6112278fe | 87 | return ((State)status); |
DieterGraef | 0:f9b6112278fe | 88 | #endif |
DieterGraef | 0:f9b6112278fe | 89 | } |
DieterGraef | 0:f9b6112278fe | 90 | |
DieterGraef | 0:f9b6112278fe | 91 | uint32_t Thread::stack_size() { |
DieterGraef | 0:f9b6112278fe | 92 | #ifndef __MBED_CMSIS_RTOS_CA9 |
DieterGraef | 0:f9b6112278fe | 93 | #if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM) |
DieterGraef | 0:f9b6112278fe | 94 | return _thread_def.tcb.priv_stack; |
DieterGraef | 0:f9b6112278fe | 95 | #else |
DieterGraef | 0:f9b6112278fe | 96 | P_TCB tcb = rt_tid2ptcb(_tid); |
DieterGraef | 0:f9b6112278fe | 97 | return tcb->priv_stack; |
DieterGraef | 0:f9b6112278fe | 98 | #endif |
DieterGraef | 0:f9b6112278fe | 99 | #else |
DieterGraef | 0:f9b6112278fe | 100 | return 0; |
DieterGraef | 0:f9b6112278fe | 101 | #endif |
DieterGraef | 0:f9b6112278fe | 102 | } |
DieterGraef | 0:f9b6112278fe | 103 | |
DieterGraef | 0:f9b6112278fe | 104 | uint32_t Thread::free_stack() { |
DieterGraef | 0:f9b6112278fe | 105 | #ifndef __MBED_CMSIS_RTOS_CA9 |
DieterGraef | 0:f9b6112278fe | 106 | #if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM) |
DieterGraef | 0:f9b6112278fe | 107 | uint32_t bottom = (uint32_t)_thread_def.tcb.stack; |
DieterGraef | 0:f9b6112278fe | 108 | return _thread_def.tcb.tsk_stack - bottom; |
DieterGraef | 0:f9b6112278fe | 109 | #else |
DieterGraef | 0:f9b6112278fe | 110 | P_TCB tcb = rt_tid2ptcb(_tid); |
DieterGraef | 0:f9b6112278fe | 111 | uint32_t bottom = (uint32_t)tcb->stack; |
DieterGraef | 0:f9b6112278fe | 112 | return tcb->tsk_stack - bottom; |
DieterGraef | 0:f9b6112278fe | 113 | #endif |
DieterGraef | 0:f9b6112278fe | 114 | #else |
DieterGraef | 0:f9b6112278fe | 115 | return 0; |
DieterGraef | 0:f9b6112278fe | 116 | #endif |
DieterGraef | 0:f9b6112278fe | 117 | } |
DieterGraef | 0:f9b6112278fe | 118 | |
DieterGraef | 0:f9b6112278fe | 119 | uint32_t Thread::used_stack() { |
DieterGraef | 0:f9b6112278fe | 120 | #ifndef __MBED_CMSIS_RTOS_CA9 |
DieterGraef | 0:f9b6112278fe | 121 | #if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM) |
DieterGraef | 0:f9b6112278fe | 122 | uint32_t top = (uint32_t)_thread_def.tcb.stack + _thread_def.tcb.priv_stack; |
DieterGraef | 0:f9b6112278fe | 123 | return top - _thread_def.tcb.tsk_stack; |
DieterGraef | 0:f9b6112278fe | 124 | #else |
DieterGraef | 0:f9b6112278fe | 125 | P_TCB tcb = rt_tid2ptcb(_tid); |
DieterGraef | 0:f9b6112278fe | 126 | uint32_t top = (uint32_t)tcb->stack + tcb->priv_stack; |
DieterGraef | 0:f9b6112278fe | 127 | return top - tcb->tsk_stack; |
DieterGraef | 0:f9b6112278fe | 128 | #endif |
DieterGraef | 0:f9b6112278fe | 129 | #else |
DieterGraef | 0:f9b6112278fe | 130 | return 0; |
DieterGraef | 0:f9b6112278fe | 131 | #endif |
DieterGraef | 0:f9b6112278fe | 132 | } |
DieterGraef | 0:f9b6112278fe | 133 | |
DieterGraef | 0:f9b6112278fe | 134 | uint32_t Thread::max_stack() { |
DieterGraef | 0:f9b6112278fe | 135 | #ifndef __MBED_CMSIS_RTOS_CA9 |
DieterGraef | 0:f9b6112278fe | 136 | #if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM) |
DieterGraef | 0:f9b6112278fe | 137 | uint32_t high_mark = 0; |
DieterGraef | 0:f9b6112278fe | 138 | while (_thread_def.tcb.stack[high_mark] == 0xE25A2EA5) |
DieterGraef | 0:f9b6112278fe | 139 | high_mark++; |
DieterGraef | 0:f9b6112278fe | 140 | return _thread_def.tcb.priv_stack - (high_mark * 4); |
DieterGraef | 0:f9b6112278fe | 141 | #else |
DieterGraef | 0:f9b6112278fe | 142 | P_TCB tcb = rt_tid2ptcb(_tid); |
DieterGraef | 0:f9b6112278fe | 143 | uint32_t high_mark = 0; |
DieterGraef | 0:f9b6112278fe | 144 | while (tcb->stack[high_mark] == 0xE25A2EA5) |
DieterGraef | 0:f9b6112278fe | 145 | high_mark++; |
DieterGraef | 0:f9b6112278fe | 146 | return tcb->priv_stack - (high_mark * 4); |
DieterGraef | 0:f9b6112278fe | 147 | #endif |
DieterGraef | 0:f9b6112278fe | 148 | #else |
DieterGraef | 0:f9b6112278fe | 149 | return 0; |
DieterGraef | 0:f9b6112278fe | 150 | #endif |
DieterGraef | 0:f9b6112278fe | 151 | } |
DieterGraef | 0:f9b6112278fe | 152 | |
DieterGraef | 0:f9b6112278fe | 153 | osEvent Thread::signal_wait(int32_t signals, uint32_t millisec) { |
DieterGraef | 0:f9b6112278fe | 154 | return osSignalWait(signals, millisec); |
DieterGraef | 0:f9b6112278fe | 155 | } |
DieterGraef | 0:f9b6112278fe | 156 | |
DieterGraef | 0:f9b6112278fe | 157 | osStatus Thread::wait(uint32_t millisec) { |
DieterGraef | 0:f9b6112278fe | 158 | return osDelay(millisec); |
DieterGraef | 0:f9b6112278fe | 159 | } |
DieterGraef | 0:f9b6112278fe | 160 | |
DieterGraef | 0:f9b6112278fe | 161 | osStatus Thread::yield() { |
DieterGraef | 0:f9b6112278fe | 162 | return osThreadYield(); |
DieterGraef | 0:f9b6112278fe | 163 | } |
DieterGraef | 0:f9b6112278fe | 164 | |
DieterGraef | 0:f9b6112278fe | 165 | osThreadId Thread::gettid() { |
DieterGraef | 0:f9b6112278fe | 166 | return osThreadGetId(); |
DieterGraef | 0:f9b6112278fe | 167 | } |
DieterGraef | 0:f9b6112278fe | 168 | |
DieterGraef | 0:f9b6112278fe | 169 | void Thread::attach_idle_hook(void (*fptr)(void)) { |
DieterGraef | 0:f9b6112278fe | 170 | rtos_attach_idle_hook(fptr); |
DieterGraef | 0:f9b6112278fe | 171 | } |
DieterGraef | 0:f9b6112278fe | 172 | |
DieterGraef | 0:f9b6112278fe | 173 | Thread::~Thread() { |
DieterGraef | 0:f9b6112278fe | 174 | terminate(); |
DieterGraef | 0:f9b6112278fe | 175 | #ifdef __MBED_CMSIS_RTOS_CM |
DieterGraef | 0:f9b6112278fe | 176 | if (_dynamic_stack) { |
DieterGraef | 0:f9b6112278fe | 177 | delete[] (_thread_def.stack_pointer); |
DieterGraef | 0:f9b6112278fe | 178 | } |
DieterGraef | 0:f9b6112278fe | 179 | #endif |
DieterGraef | 0:f9b6112278fe | 180 | } |
DieterGraef | 0:f9b6112278fe | 181 | |
DieterGraef | 0:f9b6112278fe | 182 | } |