Clone of mbed rtos 2 for easy accessibility.
Fork of mbed-rtos by
rtx/TARGET_CORTEX_M/rt_System.c@123:58563e6cba1e, 2016-11-14 (annotated)
- Committer:
- c1728p9
- Date:
- Mon Nov 14 17:14:42 2016 -0600
- Revision:
- 123:58563e6cba1e
- Parent:
- 120:4dc938e301cc
Configure RTOS to behave as it did before 5.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 49:77c8e4604045 | 1 | /*---------------------------------------------------------------------------- |
mbed_official | 112:53ace74b190c | 2 | * CMSIS-RTOS - RTX |
mbed_official | 49:77c8e4604045 | 3 | *---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 4 | * Name: RT_SYSTEM.C |
mbed_official | 49:77c8e4604045 | 5 | * Purpose: System Task Manager |
mbed_official | 112:53ace74b190c | 6 | * Rev.: V4.80 |
mbed_official | 49:77c8e4604045 | 7 | *---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 8 | * |
mbed_official | 112:53ace74b190c | 9 | * Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH |
mbed_official | 49:77c8e4604045 | 10 | * All rights reserved. |
mbed_official | 49:77c8e4604045 | 11 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 49:77c8e4604045 | 12 | * modification, are permitted provided that the following conditions are met: |
mbed_official | 49:77c8e4604045 | 13 | * - Redistributions of source code must retain the above copyright |
mbed_official | 49:77c8e4604045 | 14 | * notice, this list of conditions and the following disclaimer. |
mbed_official | 49:77c8e4604045 | 15 | * - Redistributions in binary form must reproduce the above copyright |
mbed_official | 49:77c8e4604045 | 16 | * notice, this list of conditions and the following disclaimer in the |
mbed_official | 49:77c8e4604045 | 17 | * documentation and/or other materials provided with the distribution. |
mbed_official | 49:77c8e4604045 | 18 | * - Neither the name of ARM nor the names of its contributors may be used |
mbed_official | 49:77c8e4604045 | 19 | * to endorse or promote products derived from this software without |
mbed_official | 49:77c8e4604045 | 20 | * specific prior written permission. |
mbed_official | 49:77c8e4604045 | 21 | * |
mbed_official | 49:77c8e4604045 | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 49:77c8e4604045 | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 49:77c8e4604045 | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
mbed_official | 49:77c8e4604045 | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
mbed_official | 49:77c8e4604045 | 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
mbed_official | 49:77c8e4604045 | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
mbed_official | 49:77c8e4604045 | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
mbed_official | 49:77c8e4604045 | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
mbed_official | 49:77c8e4604045 | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
mbed_official | 49:77c8e4604045 | 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
mbed_official | 49:77c8e4604045 | 32 | * POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 49:77c8e4604045 | 33 | *---------------------------------------------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 34 | |
mbed_official | 49:77c8e4604045 | 35 | #include "rt_TypeDef.h" |
mbed_official | 112:53ace74b190c | 36 | #include "RTX_Config.h" |
mbed_official | 49:77c8e4604045 | 37 | #include "rt_Task.h" |
mbed_official | 49:77c8e4604045 | 38 | #include "rt_System.h" |
mbed_official | 49:77c8e4604045 | 39 | #include "rt_Event.h" |
mbed_official | 49:77c8e4604045 | 40 | #include "rt_List.h" |
mbed_official | 49:77c8e4604045 | 41 | #include "rt_Mailbox.h" |
mbed_official | 49:77c8e4604045 | 42 | #include "rt_Semaphore.h" |
mbed_official | 49:77c8e4604045 | 43 | #include "rt_Time.h" |
mbed_official | 112:53ace74b190c | 44 | #include "rt_Timer.h" |
mbed_official | 49:77c8e4604045 | 45 | #include "rt_Robin.h" |
mbed_official | 49:77c8e4604045 | 46 | #include "rt_HAL_CM.h" |
mbed_official | 49:77c8e4604045 | 47 | |
mbed_official | 49:77c8e4604045 | 48 | /*---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 49 | * Global Variables |
mbed_official | 49:77c8e4604045 | 50 | *---------------------------------------------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 51 | |
mbed_official | 112:53ace74b190c | 52 | S32 os_tick_irqn; |
mbed_official | 49:77c8e4604045 | 53 | |
mbed_official | 49:77c8e4604045 | 54 | /*---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 55 | * Local Variables |
mbed_official | 49:77c8e4604045 | 56 | *---------------------------------------------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 57 | |
mbed_official | 49:77c8e4604045 | 58 | static volatile BIT os_lock; |
mbed_official | 49:77c8e4604045 | 59 | static volatile BIT os_psh_flag; |
mbed_official | 49:77c8e4604045 | 60 | static U8 pend_flags; |
mbed_official | 49:77c8e4604045 | 61 | |
mbed_official | 49:77c8e4604045 | 62 | /*---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 63 | * Global Functions |
mbed_official | 49:77c8e4604045 | 64 | *---------------------------------------------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 65 | |
mbed_official | 112:53ace74b190c | 66 | #define RL_RTX_VER 0x480 |
mbed_official | 112:53ace74b190c | 67 | |
mbed_official | 49:77c8e4604045 | 68 | #if defined (__CC_ARM) |
mbed_official | 49:77c8e4604045 | 69 | __asm void $$RTX$$version (void) { |
mbed_official | 49:77c8e4604045 | 70 | /* Export a version number symbol for a version control. */ |
mbed_official | 49:77c8e4604045 | 71 | |
mbed_official | 49:77c8e4604045 | 72 | EXPORT __RL_RTX_VER |
mbed_official | 49:77c8e4604045 | 73 | |
mbed_official | 112:53ace74b190c | 74 | __RL_RTX_VER EQU RL_RTX_VER |
mbed_official | 49:77c8e4604045 | 75 | } |
mbed_official | 49:77c8e4604045 | 76 | #endif |
mbed_official | 49:77c8e4604045 | 77 | |
mbed_official | 49:77c8e4604045 | 78 | |
mbed_official | 49:77c8e4604045 | 79 | /*--------------------------- rt_suspend ------------------------------------*/ |
mbed_official | 112:53ace74b190c | 80 | |
mbed_official | 112:53ace74b190c | 81 | extern U32 sysUserTimerWakeupTime(void); |
mbed_official | 112:53ace74b190c | 82 | |
mbed_official | 49:77c8e4604045 | 83 | U32 rt_suspend (void) { |
mbed_official | 49:77c8e4604045 | 84 | /* Suspend OS scheduler */ |
mbed_official | 112:53ace74b190c | 85 | U32 delta = 0xFFFFU; |
mbed_official | 112:53ace74b190c | 86 | #ifdef __CMSIS_RTOS |
mbed_official | 112:53ace74b190c | 87 | U32 sleep; |
mbed_official | 112:53ace74b190c | 88 | #endif |
mbed_official | 49:77c8e4604045 | 89 | |
mbed_official | 49:77c8e4604045 | 90 | rt_tsk_lock(); |
mbed_official | 112:53ace74b190c | 91 | |
mbed_official | 49:77c8e4604045 | 92 | if (os_dly.p_dlnk) { |
mbed_official | 49:77c8e4604045 | 93 | delta = os_dly.delta_time; |
mbed_official | 49:77c8e4604045 | 94 | } |
mbed_official | 112:53ace74b190c | 95 | #ifdef __CMSIS_RTOS |
mbed_official | 112:53ace74b190c | 96 | sleep = sysUserTimerWakeupTime(); |
mbed_official | 112:53ace74b190c | 97 | if (sleep < delta) { delta = sleep; } |
mbed_official | 112:53ace74b190c | 98 | #else |
mbed_official | 49:77c8e4604045 | 99 | if (os_tmr.next) { |
mbed_official | 49:77c8e4604045 | 100 | if (os_tmr.tcnt < delta) delta = os_tmr.tcnt; |
mbed_official | 49:77c8e4604045 | 101 | } |
mbed_official | 49:77c8e4604045 | 102 | #endif |
mbed_official | 49:77c8e4604045 | 103 | |
mbed_official | 49:77c8e4604045 | 104 | return (delta); |
mbed_official | 49:77c8e4604045 | 105 | } |
mbed_official | 49:77c8e4604045 | 106 | |
mbed_official | 49:77c8e4604045 | 107 | |
mbed_official | 49:77c8e4604045 | 108 | /*--------------------------- rt_resume -------------------------------------*/ |
mbed_official | 112:53ace74b190c | 109 | |
mbed_official | 112:53ace74b190c | 110 | extern void sysUserTimerUpdate (U32 sleep_time); |
mbed_official | 112:53ace74b190c | 111 | |
mbed_official | 49:77c8e4604045 | 112 | void rt_resume (U32 sleep_time) { |
mbed_official | 49:77c8e4604045 | 113 | /* Resume OS scheduler after suspend */ |
mbed_official | 49:77c8e4604045 | 114 | P_TCB next; |
mbed_official | 49:77c8e4604045 | 115 | U32 delta; |
mbed_official | 49:77c8e4604045 | 116 | |
mbed_official | 49:77c8e4604045 | 117 | os_tsk.run->state = READY; |
mbed_official | 49:77c8e4604045 | 118 | rt_put_rdy_first (os_tsk.run); |
mbed_official | 49:77c8e4604045 | 119 | |
mbed_official | 49:77c8e4604045 | 120 | os_robin.task = NULL; |
mbed_official | 49:77c8e4604045 | 121 | |
mbed_official | 49:77c8e4604045 | 122 | /* Update delays. */ |
mbed_official | 49:77c8e4604045 | 123 | if (os_dly.p_dlnk) { |
mbed_official | 49:77c8e4604045 | 124 | delta = sleep_time; |
mbed_official | 49:77c8e4604045 | 125 | if (delta >= os_dly.delta_time) { |
mbed_official | 49:77c8e4604045 | 126 | delta -= os_dly.delta_time; |
mbed_official | 49:77c8e4604045 | 127 | os_time += os_dly.delta_time; |
mbed_official | 112:53ace74b190c | 128 | os_dly.delta_time = 1U; |
mbed_official | 49:77c8e4604045 | 129 | while (os_dly.p_dlnk) { |
mbed_official | 49:77c8e4604045 | 130 | rt_dec_dly(); |
mbed_official | 112:53ace74b190c | 131 | if (delta == 0U) { break; } |
mbed_official | 49:77c8e4604045 | 132 | delta--; |
mbed_official | 49:77c8e4604045 | 133 | os_time++; |
mbed_official | 49:77c8e4604045 | 134 | } |
mbed_official | 49:77c8e4604045 | 135 | } else { |
mbed_official | 112:53ace74b190c | 136 | os_time += delta; |
mbed_official | 112:53ace74b190c | 137 | os_dly.delta_time -= (U16)delta; |
mbed_official | 49:77c8e4604045 | 138 | } |
mbed_official | 49:77c8e4604045 | 139 | } else { |
mbed_official | 49:77c8e4604045 | 140 | os_time += sleep_time; |
mbed_official | 49:77c8e4604045 | 141 | } |
mbed_official | 49:77c8e4604045 | 142 | |
mbed_official | 49:77c8e4604045 | 143 | /* Check the user timers. */ |
mbed_official | 112:53ace74b190c | 144 | #ifdef __CMSIS_RTOS |
mbed_official | 112:53ace74b190c | 145 | sysUserTimerUpdate(sleep_time); |
mbed_official | 112:53ace74b190c | 146 | #else |
mbed_official | 49:77c8e4604045 | 147 | if (os_tmr.next) { |
mbed_official | 49:77c8e4604045 | 148 | delta = sleep_time; |
mbed_official | 49:77c8e4604045 | 149 | if (delta >= os_tmr.tcnt) { |
mbed_official | 49:77c8e4604045 | 150 | delta -= os_tmr.tcnt; |
mbed_official | 112:53ace74b190c | 151 | os_tmr.tcnt = 1U; |
mbed_official | 49:77c8e4604045 | 152 | while (os_tmr.next) { |
mbed_official | 49:77c8e4604045 | 153 | rt_tmr_tick(); |
mbed_official | 112:53ace74b190c | 154 | if (delta == 0U) { break; } |
mbed_official | 49:77c8e4604045 | 155 | delta--; |
mbed_official | 49:77c8e4604045 | 156 | } |
mbed_official | 49:77c8e4604045 | 157 | } else { |
mbed_official | 49:77c8e4604045 | 158 | os_tmr.tcnt -= delta; |
mbed_official | 49:77c8e4604045 | 159 | } |
mbed_official | 49:77c8e4604045 | 160 | } |
mbed_official | 49:77c8e4604045 | 161 | #endif |
mbed_official | 49:77c8e4604045 | 162 | |
mbed_official | 49:77c8e4604045 | 163 | /* Switch back to highest ready task */ |
mbed_official | 49:77c8e4604045 | 164 | next = rt_get_first (&os_rdy); |
mbed_official | 49:77c8e4604045 | 165 | rt_switch_req (next); |
mbed_official | 49:77c8e4604045 | 166 | |
mbed_official | 49:77c8e4604045 | 167 | rt_tsk_unlock(); |
mbed_official | 49:77c8e4604045 | 168 | } |
mbed_official | 49:77c8e4604045 | 169 | |
mbed_official | 49:77c8e4604045 | 170 | |
mbed_official | 49:77c8e4604045 | 171 | /*--------------------------- rt_tsk_lock -----------------------------------*/ |
mbed_official | 49:77c8e4604045 | 172 | |
mbed_official | 49:77c8e4604045 | 173 | void rt_tsk_lock (void) { |
mbed_official | 49:77c8e4604045 | 174 | /* Prevent task switching by locking out scheduler */ |
mbed_official | 49:77c8e4604045 | 175 | if (os_tick_irqn < 0) { |
mbed_official | 49:77c8e4604045 | 176 | OS_LOCK(); |
mbed_official | 49:77c8e4604045 | 177 | os_lock = __TRUE; |
mbed_official | 112:53ace74b190c | 178 | OS_UNPEND(pend_flags); |
mbed_official | 49:77c8e4604045 | 179 | } else { |
mbed_official | 112:53ace74b190c | 180 | OS_X_LOCK((U32)os_tick_irqn); |
mbed_official | 49:77c8e4604045 | 181 | os_lock = __TRUE; |
mbed_official | 112:53ace74b190c | 182 | OS_X_UNPEND(pend_flags); |
mbed_official | 49:77c8e4604045 | 183 | } |
mbed_official | 49:77c8e4604045 | 184 | } |
mbed_official | 49:77c8e4604045 | 185 | |
mbed_official | 49:77c8e4604045 | 186 | |
mbed_official | 49:77c8e4604045 | 187 | /*--------------------------- rt_tsk_unlock ---------------------------------*/ |
mbed_official | 49:77c8e4604045 | 188 | |
mbed_official | 49:77c8e4604045 | 189 | void rt_tsk_unlock (void) { |
mbed_official | 49:77c8e4604045 | 190 | /* Unlock scheduler and re-enable task switching */ |
mbed_official | 49:77c8e4604045 | 191 | if (os_tick_irqn < 0) { |
mbed_official | 49:77c8e4604045 | 192 | OS_UNLOCK(); |
mbed_official | 49:77c8e4604045 | 193 | os_lock = __FALSE; |
mbed_official | 112:53ace74b190c | 194 | OS_PEND(pend_flags, os_psh_flag); |
mbed_official | 49:77c8e4604045 | 195 | os_psh_flag = __FALSE; |
mbed_official | 49:77c8e4604045 | 196 | } else { |
mbed_official | 112:53ace74b190c | 197 | OS_X_UNLOCK((U32)os_tick_irqn); |
mbed_official | 49:77c8e4604045 | 198 | os_lock = __FALSE; |
mbed_official | 112:53ace74b190c | 199 | OS_X_PEND(pend_flags, os_psh_flag); |
mbed_official | 49:77c8e4604045 | 200 | os_psh_flag = __FALSE; |
mbed_official | 49:77c8e4604045 | 201 | } |
mbed_official | 49:77c8e4604045 | 202 | } |
mbed_official | 49:77c8e4604045 | 203 | |
mbed_official | 49:77c8e4604045 | 204 | |
mbed_official | 49:77c8e4604045 | 205 | /*--------------------------- rt_psh_req ------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 206 | |
mbed_official | 49:77c8e4604045 | 207 | void rt_psh_req (void) { |
mbed_official | 49:77c8e4604045 | 208 | /* Initiate a post service handling request if required. */ |
mbed_official | 49:77c8e4604045 | 209 | if (os_lock == __FALSE) { |
mbed_official | 112:53ace74b190c | 210 | OS_PEND_IRQ(); |
mbed_official | 49:77c8e4604045 | 211 | } |
mbed_official | 49:77c8e4604045 | 212 | else { |
mbed_official | 49:77c8e4604045 | 213 | os_psh_flag = __TRUE; |
mbed_official | 49:77c8e4604045 | 214 | } |
mbed_official | 49:77c8e4604045 | 215 | } |
mbed_official | 49:77c8e4604045 | 216 | |
mbed_official | 49:77c8e4604045 | 217 | |
mbed_official | 49:77c8e4604045 | 218 | /*--------------------------- rt_pop_req ------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 219 | |
mbed_official | 49:77c8e4604045 | 220 | void rt_pop_req (void) { |
mbed_official | 49:77c8e4604045 | 221 | /* Process an ISR post service requests. */ |
mbed_official | 49:77c8e4604045 | 222 | struct OS_XCB *p_CB; |
mbed_official | 49:77c8e4604045 | 223 | P_TCB next; |
mbed_official | 49:77c8e4604045 | 224 | U32 idx; |
mbed_official | 49:77c8e4604045 | 225 | |
mbed_official | 49:77c8e4604045 | 226 | os_tsk.run->state = READY; |
mbed_official | 49:77c8e4604045 | 227 | rt_put_rdy_first (os_tsk.run); |
mbed_official | 49:77c8e4604045 | 228 | |
mbed_official | 49:77c8e4604045 | 229 | idx = os_psq->last; |
mbed_official | 49:77c8e4604045 | 230 | while (os_psq->count) { |
mbed_official | 49:77c8e4604045 | 231 | p_CB = os_psq->q[idx].id; |
mbed_official | 49:77c8e4604045 | 232 | if (p_CB->cb_type == TCB) { |
mbed_official | 49:77c8e4604045 | 233 | /* Is of TCB type */ |
mbed_official | 49:77c8e4604045 | 234 | rt_evt_psh ((P_TCB)p_CB, (U16)os_psq->q[idx].arg); |
mbed_official | 49:77c8e4604045 | 235 | } |
mbed_official | 49:77c8e4604045 | 236 | else if (p_CB->cb_type == MCB) { |
mbed_official | 49:77c8e4604045 | 237 | /* Is of MCB type */ |
mbed_official | 49:77c8e4604045 | 238 | rt_mbx_psh ((P_MCB)p_CB, (void *)os_psq->q[idx].arg); |
mbed_official | 49:77c8e4604045 | 239 | } |
mbed_official | 49:77c8e4604045 | 240 | else { |
mbed_official | 49:77c8e4604045 | 241 | /* Must be of SCB type */ |
mbed_official | 49:77c8e4604045 | 242 | rt_sem_psh ((P_SCB)p_CB); |
mbed_official | 49:77c8e4604045 | 243 | } |
mbed_official | 112:53ace74b190c | 244 | if (++idx == os_psq->size) { idx = 0U; } |
mbed_official | 49:77c8e4604045 | 245 | rt_dec (&os_psq->count); |
mbed_official | 49:77c8e4604045 | 246 | } |
mbed_official | 112:53ace74b190c | 247 | os_psq->last = (U8)idx; |
mbed_official | 49:77c8e4604045 | 248 | |
mbed_official | 49:77c8e4604045 | 249 | next = rt_get_first (&os_rdy); |
mbed_official | 49:77c8e4604045 | 250 | rt_switch_req (next); |
mbed_official | 49:77c8e4604045 | 251 | } |
mbed_official | 49:77c8e4604045 | 252 | |
mbed_official | 49:77c8e4604045 | 253 | |
mbed_official | 49:77c8e4604045 | 254 | /*--------------------------- os_tick_init ----------------------------------*/ |
mbed_official | 49:77c8e4604045 | 255 | |
mbed_official | 112:53ace74b190c | 256 | __weak S32 os_tick_init (void) { |
mbed_official | 49:77c8e4604045 | 257 | /* Initialize SysTick timer as system tick timer. */ |
mbed_official | 112:53ace74b190c | 258 | rt_systick_init(); |
mbed_official | 49:77c8e4604045 | 259 | return (-1); /* Return IRQ number of SysTick timer */ |
mbed_official | 49:77c8e4604045 | 260 | } |
mbed_official | 49:77c8e4604045 | 261 | |
mbed_official | 112:53ace74b190c | 262 | /*--------------------------- os_tick_val -----------------------------------*/ |
mbed_official | 112:53ace74b190c | 263 | |
mbed_official | 112:53ace74b190c | 264 | __weak U32 os_tick_val (void) { |
mbed_official | 112:53ace74b190c | 265 | /* Get SysTick timer current value (0 .. OS_TRV). */ |
mbed_official | 112:53ace74b190c | 266 | return rt_systick_val(); |
mbed_official | 112:53ace74b190c | 267 | } |
mbed_official | 112:53ace74b190c | 268 | |
mbed_official | 112:53ace74b190c | 269 | /*--------------------------- os_tick_ovf -----------------------------------*/ |
mbed_official | 112:53ace74b190c | 270 | |
mbed_official | 112:53ace74b190c | 271 | __weak U32 os_tick_ovf (void) { |
mbed_official | 112:53ace74b190c | 272 | /* Get SysTick timer overflow flag */ |
mbed_official | 112:53ace74b190c | 273 | return rt_systick_ovf(); |
mbed_official | 112:53ace74b190c | 274 | } |
mbed_official | 49:77c8e4604045 | 275 | |
mbed_official | 49:77c8e4604045 | 276 | /*--------------------------- os_tick_irqack --------------------------------*/ |
mbed_official | 49:77c8e4604045 | 277 | |
mbed_official | 49:77c8e4604045 | 278 | __weak void os_tick_irqack (void) { |
mbed_official | 49:77c8e4604045 | 279 | /* Acknowledge timer interrupt. */ |
mbed_official | 49:77c8e4604045 | 280 | } |
mbed_official | 49:77c8e4604045 | 281 | |
mbed_official | 49:77c8e4604045 | 282 | |
mbed_official | 49:77c8e4604045 | 283 | /*--------------------------- rt_systick ------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 284 | |
mbed_official | 49:77c8e4604045 | 285 | extern void sysTimerTick(void); |
mbed_official | 49:77c8e4604045 | 286 | |
mbed_official | 49:77c8e4604045 | 287 | void rt_systick (void) { |
mbed_official | 49:77c8e4604045 | 288 | /* Check for system clock update, suspend running task. */ |
mbed_official | 49:77c8e4604045 | 289 | P_TCB next; |
mbed_official | 49:77c8e4604045 | 290 | |
mbed_official | 49:77c8e4604045 | 291 | os_tsk.run->state = READY; |
mbed_official | 49:77c8e4604045 | 292 | rt_put_rdy_first (os_tsk.run); |
mbed_official | 49:77c8e4604045 | 293 | |
mbed_official | 49:77c8e4604045 | 294 | /* Check Round Robin timeout. */ |
mbed_official | 49:77c8e4604045 | 295 | rt_chk_robin (); |
mbed_official | 49:77c8e4604045 | 296 | |
mbed_official | 49:77c8e4604045 | 297 | /* Update delays. */ |
mbed_official | 49:77c8e4604045 | 298 | os_time++; |
mbed_official | 49:77c8e4604045 | 299 | rt_dec_dly (); |
mbed_official | 49:77c8e4604045 | 300 | |
mbed_official | 49:77c8e4604045 | 301 | /* Check the user timers. */ |
mbed_official | 49:77c8e4604045 | 302 | #ifdef __CMSIS_RTOS |
mbed_official | 49:77c8e4604045 | 303 | sysTimerTick(); |
mbed_official | 49:77c8e4604045 | 304 | #else |
mbed_official | 49:77c8e4604045 | 305 | rt_tmr_tick (); |
mbed_official | 49:77c8e4604045 | 306 | #endif |
mbed_official | 49:77c8e4604045 | 307 | |
mbed_official | 49:77c8e4604045 | 308 | /* Switch back to highest ready task */ |
mbed_official | 49:77c8e4604045 | 309 | next = rt_get_first (&os_rdy); |
mbed_official | 49:77c8e4604045 | 310 | rt_switch_req (next); |
mbed_official | 49:77c8e4604045 | 311 | } |
mbed_official | 49:77c8e4604045 | 312 | |
mbed_official | 49:77c8e4604045 | 313 | /*--------------------------- rt_stk_check ----------------------------------*/ |
mbed_official | 112:53ace74b190c | 314 | |
mbed_official | 49:77c8e4604045 | 315 | __weak void rt_stk_check (void) { |
c1728p9 | 123:58563e6cba1e | 316 | #ifdef __MBED_CMSIS_RTOS_CM |
c1728p9 | 123:58563e6cba1e | 317 | /* Check for stack overflow. */ |
c1728p9 | 123:58563e6cba1e | 318 | if (os_tsk.run->task_id == MAIN_THREAD_ID) { |
c1728p9 | 123:58563e6cba1e | 319 | // TODO: For the main thread the check should be done against the main heap pointer |
c1728p9 | 123:58563e6cba1e | 320 | } else { |
c1728p9 | 123:58563e6cba1e | 321 | if ((os_tsk.run->tsk_stack < (U32)os_tsk.run->stack) || |
c1728p9 | 123:58563e6cba1e | 322 | (os_tsk.run->stack[0] != MAGIC_WORD)) { |
c1728p9 | 123:58563e6cba1e | 323 | os_error (OS_ERR_STK_OVF); |
c1728p9 | 123:58563e6cba1e | 324 | } |
c1728p9 | 123:58563e6cba1e | 325 | } |
c1728p9 | 123:58563e6cba1e | 326 | #else |
mbed_official | 112:53ace74b190c | 327 | if ((os_tsk.run->tsk_stack < (U32)os_tsk.run->stack) || |
mbed_official | 112:53ace74b190c | 328 | (os_tsk.run->stack[0] != MAGIC_WORD)) { |
mbed_official | 112:53ace74b190c | 329 | os_error (OS_ERR_STK_OVF); |
mbed_official | 112:53ace74b190c | 330 | } |
c1728p9 | 123:58563e6cba1e | 331 | #endif |
mbed_official | 49:77c8e4604045 | 332 | } |
mbed_official | 49:77c8e4604045 | 333 | |
mbed_official | 49:77c8e4604045 | 334 | /*---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 335 | * end of file |
mbed_official | 49:77c8e4604045 | 336 | *---------------------------------------------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 337 |