2022-08-15 04:20:27 -05:00
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
* RL-ARM - RTX
|
|
|
|
*----------------------------------------------------------------------------
|
|
|
|
* Name: RT_SYSTEM.C
|
|
|
|
* Purpose: System Task Manager
|
|
|
|
* Rev.: V4.60
|
|
|
|
*----------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
|
|
|
|
* All rights reserved.
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* - Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* - Neither the name of ARM nor the names of its contributors may be used
|
|
|
|
* to endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "rt_System.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "RTX_Conf.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "rt_Event.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "rt_HAL_CM.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "rt_List.h"
|
|
|
|
#include "rt_Mailbox.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "rt_Robin.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "rt_Semaphore.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "rt_Task.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "rt_Time.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "rt_TypeDef.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#include "hal_sleep.h"
|
|
|
|
#include "hal_timer.h"
|
|
|
|
#include "hal_trace.h"
|
|
|
|
|
|
|
|
extern void sysTimerTick(void);
|
|
|
|
extern uint32_t rt_timer_delay_count(void);
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
* Global Variables
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
int os_tick_irqn;
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
* Local Variables
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static volatile BIT os_lock;
|
|
|
|
static volatile BIT os_psh_flag;
|
2023-02-01 14:52:54 -06:00
|
|
|
static U8 pend_flags;
|
|
|
|
static U32 systick_lock_tick;
|
|
|
|
static U32 systick_lock_ts;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
* Global Functions
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
#if defined(__CC_ARM)
|
|
|
|
__asm void $$RTX$$version(void) {
|
|
|
|
/* Export a version number symbol for a version control. */
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
EXPORT __RL_RTX_VER
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
__RL_RTX_VER EQU 0x450
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*--------------------------- rt_suspend ------------------------------------*/
|
2023-02-01 14:52:54 -06:00
|
|
|
U32 rt_suspend(void) {
|
2022-08-15 04:20:27 -05:00
|
|
|
/* Suspend OS scheduler */
|
|
|
|
U32 delta = 0xFFFF;
|
|
|
|
U32 start_tick;
|
|
|
|
|
|
|
|
__disable_irq();
|
|
|
|
start_tick = NVIC_ST_CURRENT;
|
|
|
|
rt_tsk_lock();
|
|
|
|
systick_lock_tick = NVIC_ST_CURRENT;
|
|
|
|
systick_lock_ts = hal_sys_timer_get();
|
2023-02-01 14:52:54 -06:00
|
|
|
if (start_tick != 0 &&
|
|
|
|
(systick_lock_tick == 0 || start_tick < systick_lock_tick)) {
|
2022-08-15 04:20:27 -05:00
|
|
|
#if defined(DEBUG_SLEEP) && (DEBUG_SLEEP >= 1)
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(6, "[%u/0x%X][%2u/%u] rt_suspend corner case: %02u -> %02u",
|
|
|
|
TICKS_TO_MS(hal_sys_timer_get()), hal_sys_timer_get(),
|
|
|
|
NVIC_ST_CURRENT, os_time, start_tick, systick_lock_tick);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
pend_flags |= 1;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
if (pend_flags) {
|
|
|
|
delta = 0;
|
|
|
|
}
|
|
|
|
__enable_irq();
|
|
|
|
|
|
|
|
if (delta == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (os_dly.p_dlnk) {
|
|
|
|
delta = os_dly.delta_time;
|
|
|
|
}
|
|
|
|
#ifdef __CMSIS_RTOS
|
|
|
|
{
|
|
|
|
uint32_t tcnt = rt_timer_delay_count();
|
|
|
|
if (tcnt && tcnt < delta) {
|
|
|
|
delta = tcnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (os_tmr.next) {
|
2023-02-01 14:52:54 -06:00
|
|
|
if (os_tmr.tcnt < delta)
|
|
|
|
delta = os_tmr.tcnt;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*--------------------------- rt_resume -------------------------------------*/
|
2023-02-01 14:52:54 -06:00
|
|
|
void rt_resume(U32 sleep_time) {
|
2022-08-15 04:20:27 -05:00
|
|
|
/* Resume OS scheduler after suspend */
|
2023-02-01 14:52:54 -06:00
|
|
|
// P_TCB next;
|
|
|
|
U32 delta;
|
|
|
|
U32 resume_ts;
|
|
|
|
U32 unlock_ts;
|
|
|
|
U32 systick_remain;
|
|
|
|
U32 sleep_ticks;
|
|
|
|
U8 tick_running = 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
const U32 reload = (NVIC_ST_RELOAD + 1);
|
|
|
|
|
|
|
|
__disable_irq();
|
|
|
|
resume_ts = hal_sys_timer_get();
|
|
|
|
__enable_irq();
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
sleep_ticks = (resume_ts - systick_lock_ts) *
|
|
|
|
(OS_CLOCK_NOMINAL / CONFIG_SYSTICK_HZ_NOMINAL);
|
2022-08-15 04:20:27 -05:00
|
|
|
if (systick_lock_tick == 0) {
|
|
|
|
sleep_time = sleep_ticks / reload;
|
|
|
|
systick_remain = reload - sleep_ticks % reload;
|
|
|
|
} else if (sleep_ticks >= systick_lock_tick) {
|
|
|
|
delta = sleep_ticks - systick_lock_tick;
|
|
|
|
sleep_time = delta / reload + 1;
|
|
|
|
systick_remain = reload - delta % reload;
|
|
|
|
} else {
|
|
|
|
sleep_time = 0;
|
|
|
|
systick_remain = systick_lock_tick - sleep_ticks;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sleep_time == 0) {
|
|
|
|
tick_running = 1;
|
|
|
|
goto _task_unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Task switching is allowed in SVC/PENDSV/SYSTICK handlers only
|
|
|
|
#if 0
|
|
|
|
os_tsk.run->state = READY;
|
|
|
|
rt_put_rdy_first (os_tsk.run);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_inc_sleep_time:
|
|
|
|
|
|
|
|
os_robin.task = NULL;
|
|
|
|
|
|
|
|
if (sleep_time) {
|
|
|
|
/* Update delays. */
|
|
|
|
if (os_dly.p_dlnk) {
|
|
|
|
delta = sleep_time;
|
|
|
|
if (delta >= os_dly.delta_time) {
|
2023-02-01 14:52:54 -06:00
|
|
|
delta -= os_dly.delta_time;
|
2022-08-15 04:20:27 -05:00
|
|
|
os_time += os_dly.delta_time;
|
|
|
|
os_dly.delta_time = 1;
|
|
|
|
while (os_dly.p_dlnk) {
|
|
|
|
rt_dec_dly();
|
2023-02-01 14:52:54 -06:00
|
|
|
if (delta == 0)
|
|
|
|
break;
|
2022-08-15 04:20:27 -05:00
|
|
|
delta--;
|
|
|
|
os_time++;
|
|
|
|
}
|
|
|
|
while (delta) {
|
|
|
|
delta--;
|
|
|
|
os_time++;
|
|
|
|
}
|
|
|
|
rt_psh_req();
|
|
|
|
} else {
|
2023-02-01 14:52:54 -06:00
|
|
|
os_time += delta;
|
2022-08-15 04:20:27 -05:00
|
|
|
os_dly.delta_time -= delta;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
os_time += sleep_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_idle_TCB.rtime += sleep_time;
|
|
|
|
#ifdef __CMSIS_RTOS
|
|
|
|
delta = sleep_time;
|
|
|
|
while (delta && rt_timer_delay_count()) {
|
|
|
|
sysTimerTick();
|
|
|
|
delta--;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Check the user timers. */
|
|
|
|
if (os_tmr.next) {
|
|
|
|
delta = sleep_time;
|
|
|
|
if (delta >= os_tmr.tcnt) {
|
2023-02-01 14:52:54 -06:00
|
|
|
delta -= os_tmr.tcnt;
|
2022-08-15 04:20:27 -05:00
|
|
|
os_tmr.tcnt = 1;
|
|
|
|
while (os_tmr.next) {
|
|
|
|
rt_tmr_tick();
|
2023-02-01 14:52:54 -06:00
|
|
|
if (delta == 0)
|
|
|
|
break;
|
2022-08-15 04:20:27 -05:00
|
|
|
delta--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
os_tmr.tcnt -= delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} // sleep_time
|
|
|
|
|
|
|
|
// Task switching is allowed in SVC/PENDSV/SYSTICK handlers only
|
|
|
|
#if 0
|
|
|
|
/* Switch back to highest ready task */
|
|
|
|
next = rt_get_first (&os_rdy);
|
|
|
|
rt_switch_req (next);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(DEBUG_SLEEP) && (DEBUG_SLEEP >= 1)
|
|
|
|
if (sleep_time > 0) {
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(7,
|
|
|
|
"[%u/0x%X][%2u/%u] rt_resume: sleep_ticks=%u sleep_time=%u "
|
|
|
|
"systick_remain=%u",
|
|
|
|
TICKS_TO_MS(hal_sys_timer_get()), hal_sys_timer_get(),
|
|
|
|
NVIC_ST_CURRENT, os_time, sleep_ticks, sleep_time, systick_remain);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_task_unlock:
|
|
|
|
|
|
|
|
sleep_time = 0;
|
|
|
|
|
|
|
|
__disable_irq();
|
|
|
|
// Handle corner case: systick counter wraps inside rt_resume()
|
|
|
|
unlock_ts = hal_sys_timer_get();
|
|
|
|
sleep_ticks = (unlock_ts - resume_ts) * 2;
|
|
|
|
// systick_remain value range: [1, reload]
|
|
|
|
if (sleep_ticks >= systick_remain) {
|
|
|
|
#if defined(DEBUG_SLEEP) && (DEBUG_SLEEP >= 1)
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(6,
|
|
|
|
"[%u/0x%X][%2u/%u] rt_resume corner case: sleep_ticks=%u "
|
|
|
|
"systick_remain=%u",
|
|
|
|
TICKS_TO_MS(hal_sys_timer_get()), hal_sys_timer_get(),
|
|
|
|
NVIC_ST_CURRENT, os_time, sleep_ticks, systick_remain);
|
2022-08-15 04:20:27 -05:00
|
|
|
// Update timestamp since traces also consume time
|
|
|
|
unlock_ts = hal_sys_timer_get();
|
2023-02-01 14:52:54 -06:00
|
|
|
sleep_ticks = (unlock_ts - resume_ts) *
|
|
|
|
(OS_CLOCK_NOMINAL / CONFIG_SYSTICK_HZ_NOMINAL);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
delta = sleep_ticks - systick_remain;
|
|
|
|
sleep_time = delta / reload + 1;
|
|
|
|
systick_remain = reload - delta % reload;
|
|
|
|
resume_ts = unlock_ts;
|
|
|
|
} else {
|
|
|
|
if (tick_running == 0) {
|
|
|
|
systick_remain -= sleep_ticks;
|
|
|
|
// Adjust systick_remain value range to [0, reload - 1]
|
|
|
|
if (systick_remain == reload) {
|
|
|
|
systick_remain = 0;
|
|
|
|
}
|
|
|
|
if (systick_remain) {
|
2023-02-01 14:52:54 -06:00
|
|
|
NVIC_ST_RELOAD = systick_remain;
|
2022-08-15 04:20:27 -05:00
|
|
|
NVIC_ST_CURRENT = 0;
|
2023-02-01 14:52:54 -06:00
|
|
|
while (NVIC_ST_CURRENT == 0)
|
|
|
|
;
|
|
|
|
NVIC_ST_RELOAD = reload - 1;
|
2022-08-15 04:20:27 -05:00
|
|
|
} else {
|
|
|
|
NVIC_ST_CURRENT = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rt_tsk_unlock();
|
|
|
|
}
|
|
|
|
__enable_irq();
|
|
|
|
|
|
|
|
if (sleep_time) {
|
|
|
|
goto _inc_sleep_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*--------------------------- rt_tsk_lock -----------------------------------*/
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void rt_tsk_lock(void) {
|
2022-08-15 04:20:27 -05:00
|
|
|
/* Prevent task switching by locking out scheduler */
|
|
|
|
if (os_tick_irqn < 0) {
|
|
|
|
OS_LOCK();
|
|
|
|
os_lock = __TRUE;
|
2023-02-01 14:52:54 -06:00
|
|
|
OS_UNPEND(&pend_flags);
|
2022-08-15 04:20:27 -05:00
|
|
|
} else {
|
|
|
|
OS_X_LOCK(os_tick_irqn);
|
|
|
|
os_lock = __TRUE;
|
2023-02-01 14:52:54 -06:00
|
|
|
OS_X_UNPEND(&pend_flags);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*--------------------------- rt_tsk_unlock ---------------------------------*/
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void rt_tsk_unlock(void) {
|
2022-08-15 04:20:27 -05:00
|
|
|
/* Unlock scheduler and re-enable task switching */
|
|
|
|
if (os_tick_irqn < 0) {
|
|
|
|
OS_UNLOCK();
|
|
|
|
os_lock = __FALSE;
|
2023-02-01 14:52:54 -06:00
|
|
|
OS_PEND(pend_flags, os_psh_flag);
|
2022-08-15 04:20:27 -05:00
|
|
|
os_psh_flag = __FALSE;
|
|
|
|
} else {
|
|
|
|
OS_X_UNLOCK(os_tick_irqn);
|
|
|
|
os_lock = __FALSE;
|
2023-02-01 14:52:54 -06:00
|
|
|
OS_X_PEND(pend_flags, os_psh_flag);
|
2022-08-15 04:20:27 -05:00
|
|
|
os_psh_flag = __FALSE;
|
|
|
|
}
|
|
|
|
// Allow cpu sleep
|
|
|
|
hal_cpu_wake_unlock(HAL_CPU_WAKE_LOCK_USER_RTOS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*--------------------------- rt_psh_req ------------------------------------*/
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void rt_psh_req(void) {
|
2022-08-15 04:20:27 -05:00
|
|
|
/* Initiate a post service handling request if required. */
|
|
|
|
if (os_lock == __FALSE) {
|
2023-02-01 14:52:54 -06:00
|
|
|
OS_PEND_IRQ();
|
|
|
|
} else {
|
2022-08-15 04:20:27 -05:00
|
|
|
os_psh_flag = __TRUE;
|
2023-02-01 14:52:54 -06:00
|
|
|
// Prohibit cpu sleep when an OS service request is enqueued during os lock
|
|
|
|
// (rt_suspend)
|
2022-08-15 04:20:27 -05:00
|
|
|
hal_cpu_wake_lock(HAL_CPU_WAKE_LOCK_USER_RTOS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*--------------------------- rt_pop_req ------------------------------------*/
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void rt_pop_req(void) {
|
2022-08-15 04:20:27 -05:00
|
|
|
/* Process an ISR post service requests. */
|
|
|
|
struct OS_XCB *p_CB;
|
|
|
|
P_TCB next;
|
2023-02-01 14:52:54 -06:00
|
|
|
U32 idx;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
os_tsk.run->state = READY;
|
|
|
|
if (os_tsk.run == &os_idle_TCB) {
|
2023-02-01 14:52:54 -06:00
|
|
|
rt_put_rdy_last(os_tsk.run);
|
2022-08-15 04:20:27 -05:00
|
|
|
} else {
|
2023-02-01 14:52:54 -06:00
|
|
|
rt_put_rdy_first(os_tsk.run);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
idx = os_psq->last;
|
|
|
|
while (os_psq->count) {
|
|
|
|
p_CB = os_psq->q[idx].id;
|
|
|
|
if (p_CB->cb_type == TCB) {
|
|
|
|
/* Is of TCB type */
|
2023-02-01 14:52:54 -06:00
|
|
|
rt_evt_psh((P_TCB)p_CB, (U16)os_psq->q[idx].arg);
|
|
|
|
} else if (p_CB->cb_type == MCB) {
|
2022-08-15 04:20:27 -05:00
|
|
|
/* Is of MCB type */
|
2023-02-01 14:52:54 -06:00
|
|
|
rt_mbx_psh((P_MCB)p_CB, (void *)os_psq->q[idx].arg);
|
|
|
|
} else {
|
2022-08-15 04:20:27 -05:00
|
|
|
/* Must be of SCB type */
|
2023-02-01 14:52:54 -06:00
|
|
|
rt_sem_psh((P_SCB)p_CB);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
2023-02-01 14:52:54 -06:00
|
|
|
if (++idx == os_psq->size)
|
|
|
|
idx = 0;
|
|
|
|
rt_dec(&os_psq->count);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
os_psq->last = idx;
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
next = rt_get_first(&os_rdy);
|
|
|
|
rt_switch_req(next);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*--------------------------- os_tick_init ----------------------------------*/
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
__weak int os_tick_init(void) {
|
2022-08-15 04:20:27 -05:00
|
|
|
/* Initialize SysTick timer as system tick timer. */
|
2023-02-01 14:52:54 -06:00
|
|
|
rt_systick_init();
|
|
|
|
return (-1); /* Return IRQ number of SysTick timer */
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*--------------------------- os_tick_irqack --------------------------------*/
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
__weak void os_tick_irqack(void) { /* Acknowledge timer interrupt. */
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*--------------------------- rt_systick ------------------------------------*/
|
2023-02-01 14:52:54 -06:00
|
|
|
void rt_systick(void) {
|
2022-08-15 04:20:27 -05:00
|
|
|
/* Check for system clock update, suspend running task. */
|
|
|
|
P_TCB next;
|
|
|
|
|
|
|
|
#if __RTX_CPU_STATISTICS__
|
|
|
|
os_tsk.run->rtime += 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
os_tsk.run->state = READY;
|
2023-02-01 14:52:54 -06:00
|
|
|
rt_put_rdy_first(os_tsk.run);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
/* Check Round Robin timeout. */
|
2023-02-01 14:52:54 -06:00
|
|
|
rt_chk_robin();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
/* Update delays. */
|
|
|
|
os_time++;
|
2023-02-01 14:52:54 -06:00
|
|
|
rt_dec_dly();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
/* Check the user timers. */
|
|
|
|
#ifdef __CMSIS_RTOS
|
|
|
|
sysTimerTick();
|
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
rt_tmr_tick();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Switch back to highest ready task */
|
2023-02-01 14:52:54 -06:00
|
|
|
next = rt_get_first(&os_rdy);
|
|
|
|
rt_switch_req(next);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*--------------------------- rt_stk_check ----------------------------------*/
|
2023-02-01 14:52:54 -06:00
|
|
|
__weak void rt_stk_check(void) {
|
|
|
|
/* Check for stack overflow. */
|
|
|
|
if (os_tsk.run->task_id == 0x01) {
|
|
|
|
// TODO: For the main thread the check should be done against the main heap
|
|
|
|
// pointer
|
|
|
|
} else {
|
|
|
|
if ((os_tsk.run->tsk_stack < (U32)os_tsk.run->stack) ||
|
|
|
|
(os_tsk.run->stack[0] != MAGIC_WORD)) {
|
|
|
|
os_error(OS_ERR_STK_OVF);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
2023-02-01 14:52:54 -06:00
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
* end of file
|
|
|
|
*---------------------------------------------------------------------------*/
|