Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern "C"
{
#endif

#define PLCKD_PRESCALER_MAX_SELECT 8
#define PLCKD_PRESCALER_MAX_SELECT 9

/* RSK-RZN2L: Frequency ratio: PCLKA:PCLKD = 1:N (N = 1/2/4/8/16/32/64) */
#define PLCKD_PRESCALER_400M (BSP_PRV_PCLKGPTL_FREQ_400_MHZ)
Expand Down
2 changes: 2 additions & 0 deletions bsp/renesas/libraries/HAL_Drivers/drv_hwtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const rt_uint32_t PLCKD_FREQ_PRESCALER[PLCKD_PRESCALER_MAX_SELECT] =
PLCKD_PRESCALER_3_75M,
PLCKD_PRESCALER_1_875M,
#elif defined(SOC_SERIES_R9A07G0)
PLCKD_PRESCALER_400M,
PLCKD_PRESCALER_200M,
PLCKD_PRESCALER_100M,
PLCKD_PRESCALER_50M,
PLCKD_PRESCALER_25M,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ void bsp_loader_bss_init (void)
void bsp_copy_multibyte (uintptr_t * src, uintptr_t * dst, uintptr_t bytesize)
{
uintptr_t i;
uintptr_t cnt;
volatile uintptr_t cnt;

uintptr_t src_mod;
uint8_t * src_single_byte;
Expand Down Expand Up @@ -630,7 +630,7 @@ void bsp_copy_multibyte (uintptr_t * src, uintptr_t * dst, uintptr_t bytesize)
void bsp_bss_init_multibyte (uintptr_t * src, uintptr_t bytesize)
{
uintptr_t i;
uintptr_t cnt;
volatile uintptr_t cnt;
uintptr_t zero = 0;

uintptr_t src_mod;
Expand Down
2 changes: 2 additions & 0 deletions src/cpu_up.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void rt_spin_lock(struct rt_spinlock *lock)

/**
* @brief This function will unlock the spinlock, will unlock the thread scheduler.
* If the scheduling function is called before unlocking, it will be scheduled in this function.
*
* @param lock is a pointer to the spinlock.
*/
Expand Down Expand Up @@ -72,6 +73,7 @@ rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)

/**
* @brief This function will unlock the spinlock and then restore current cpu interrupt status, will unlock the thread scheduler.
* If the scheduling function is called before unlocking, it will be scheduled in this function.
*
* @param lock is a pointer to the spinlock.
*
Expand Down
20 changes: 18 additions & 2 deletions src/scheduler_up.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to scheduler.c
* 2023-03-27 rose_man Split into scheduler upc and scheduler_mp.c
* 2023-10-17 ChuShicheng Modify the timing of clearing RT_THREAD_STAT_YIELD flag bits
* 2025-08-04 Pillar Add rt_scheduler_critical_switch_flag
*/

#define __RT_IPC_SOURCE__
Expand All @@ -51,6 +52,11 @@ extern volatile rt_atomic_t rt_interrupt_nest;
static rt_int16_t rt_scheduler_lock_nest;
rt_uint8_t rt_current_priority;

static rt_int8_t rt_scheduler_critical_switch_flag;
#define IS_CRITICAL_SWITCH_PEND() (rt_scheduler_critical_switch_flag == 1)
#define SET_CRITICAL_SWITCH_FLAG() (rt_scheduler_critical_switch_flag = 1)
#define CLR_CRITICAL_SWITCH_FLAG() (rt_scheduler_critical_switch_flag = 0)

#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to);
static void (*rt_scheduler_switch_hook)(struct rt_thread *tid);
Expand Down Expand Up @@ -236,6 +242,9 @@ void rt_system_scheduler_start(void)

rt_cpu_self()->current_thread = to_thread;

/* flush critical switch flag */
CLR_CRITICAL_SWITCH_FLAG();

rt_sched_remove_thread(to_thread);
RT_SCHED_CTX(to_thread).stat = RT_THREAD_RUNNING;

Expand Down Expand Up @@ -387,6 +396,10 @@ void rt_schedule(void)
}
}
}
else
{
SET_CRITICAL_SWITCH_FLAG();
}

/* enable interrupt */
rt_hw_interrupt_enable(level);
Expand Down Expand Up @@ -604,6 +617,7 @@ void rt_exit_critical_safe(rt_base_t critical_level)

/**
* @brief Safely exit critical section (non-debug version)
* If the scheduling function is called before exiting, it will be scheduled in this function.
*
* @param critical_level The expected critical level (unused in non-debug build)
*
Expand Down Expand Up @@ -657,6 +671,7 @@ RTM_EXPORT(rt_enter_critical);

/**
* @brief Exit critical section and unlock scheduler
* If the scheduling function is called before exiting, it will be scheduled in this function.
*
* @details This function:
* - Decrements the scheduler lock nesting count
Expand Down Expand Up @@ -685,9 +700,10 @@ void rt_exit_critical(void)
/* enable interrupt */
rt_hw_interrupt_enable(level);

if (rt_current_thread)
if (IS_CRITICAL_SWITCH_PEND())
{
/* if scheduler is started, do a schedule */
CLR_CRITICAL_SWITCH_FLAG();
/* if scheduler is started and needs to be scheduled, do a schedule */
rt_schedule();
}
}
Expand Down