Skip to content

Commit 8c915e1

Browse files
committed
[bsp][etherkit] fix bug and optimize timer irq callback, enable high optimization.
[kernel] add UP scheduler critical switch flag.
1 parent 32e93ad commit 8c915e1

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

bsp/renesas/libraries/HAL_Drivers/config/rzt/timer_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern "C"
1919
{
2020
#endif
2121

22-
#define PLCKD_PRESCALER_MAX_SELECT 8
22+
#define PLCKD_PRESCALER_MAX_SELECT 9
2323

2424
/* RSK-RZN2L: Frequency ratio: PCLKA:PCLKD = 1:N (N = 1/2/4/8/16/32/64) */
2525
#define PLCKD_PRESCALER_400M (BSP_PRV_PCLKGPTL_FREQ_400_MHZ)

bsp/renesas/libraries/HAL_Drivers/drv_hwtimer.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const rt_uint32_t PLCKD_FREQ_PRESCALER[PLCKD_PRESCALER_MAX_SELECT] =
3838
PLCKD_PRESCALER_3_75M,
3939
PLCKD_PRESCALER_1_875M,
4040
#elif defined(SOC_SERIES_R9A07G0)
41+
PLCKD_PRESCALER_400M,
42+
PLCKD_PRESCALER_200M,
4143
PLCKD_PRESCALER_100M,
4244
PLCKD_PRESCALER_50M,
4345
PLCKD_PRESCALER_25M,
@@ -184,8 +186,10 @@ static void timer_one_shot_check(void)
184186
#ifdef BSP_USING_TIM0
185187
void timer0_callback(timer_callback_args_t *p_args)
186188
{
189+
#if !defined(SOC_SERIES_R9A07G0)
187190
/* enter interrupt */
188191
rt_interrupt_enter();
192+
#endif
189193

190194
if (TIMER_EVENT_CYCLE_END == p_args->event)
191195
{
@@ -194,16 +198,20 @@ void timer0_callback(timer_callback_args_t *p_args)
194198
timer_one_shot_check();
195199
}
196200

201+
#if !defined(SOC_SERIES_R9A07G0)
197202
/* leave interrupt */
198203
rt_interrupt_leave();
204+
#endif
199205
}
200206
#endif
201207

202208
#ifdef BSP_USING_TIM1
203209
void timer1_callback(timer_callback_args_t *p_args)
204210
{
211+
#if !defined(SOC_SERIES_R9A07G0)
205212
/* enter interrupt */
206213
rt_interrupt_enter();
214+
#endif
207215

208216
if (TIMER_EVENT_CYCLE_END == p_args->event)
209217
{
@@ -212,8 +220,10 @@ void timer1_callback(timer_callback_args_t *p_args)
212220
timer_one_shot_check();
213221
}
214222

223+
#if !defined(SOC_SERIES_R9A07G0)
215224
/* leave interrupt */
216225
rt_interrupt_leave();
226+
#endif
217227
}
218228
#endif
219229

bsp/renesas/rzn2l_etherkit/rzn/fsp/src/bsp/cmsis/Device/RENESAS/Source/system.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ void bsp_loader_bss_init (void)
577577
void bsp_copy_multibyte (uintptr_t * src, uintptr_t * dst, uintptr_t bytesize)
578578
{
579579
uintptr_t i;
580-
uintptr_t cnt;
580+
volatile uintptr_t cnt;
581581

582582
uintptr_t src_mod;
583583
uint8_t * src_single_byte;
@@ -630,7 +630,7 @@ void bsp_copy_multibyte (uintptr_t * src, uintptr_t * dst, uintptr_t bytesize)
630630
void bsp_bss_init_multibyte (uintptr_t * src, uintptr_t bytesize)
631631
{
632632
uintptr_t i;
633-
uintptr_t cnt;
633+
volatile uintptr_t cnt;
634634
uintptr_t zero = 0;
635635

636636
uintptr_t src_mod;

src/cpu_up.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void rt_spin_lock(struct rt_spinlock *lock)
4040

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

7374
/**
7475
* @brief This function will unlock the spinlock and then restore current cpu interrupt status, will unlock the thread scheduler.
76+
* If the scheduling function is called before unlocking, it will be scheduled in this function.
7577
*
7678
* @param lock is a pointer to the spinlock.
7779
*

src/scheduler_up.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to scheduler.c
3131
* 2023-03-27 rose_man Split into scheduler upc and scheduler_mp.c
3232
* 2023-10-17 ChuShicheng Modify the timing of clearing RT_THREAD_STAT_YIELD flag bits
33+
* 2025-08-04 Pillar Add rt_scheduler_critical_switch_flag
3334
*/
3435

3536
#define __RT_IPC_SOURCE__
@@ -51,6 +52,15 @@ extern volatile rt_atomic_t rt_interrupt_nest;
5152
static rt_int16_t rt_scheduler_lock_nest;
5253
rt_uint8_t rt_current_priority;
5354

55+
/*
56+
* scheduler critical switch flag macros
57+
*/
58+
#define CRITICAL_SWITCH_FLAG_UNINIT -1
59+
#define CRITICAL_SWITCH_FLAG_IDLE 0
60+
#define CRITICAL_SWITCH_FLAG_PENDING 1
61+
62+
static rt_int8_t rt_scheduler_critical_switch_flag = CRITICAL_SWITCH_FLAG_UNINIT;
63+
5464
#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
5565
static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to);
5666
static void (*rt_scheduler_switch_hook)(struct rt_thread *tid);
@@ -235,6 +245,7 @@ void rt_system_scheduler_start(void)
235245
to_thread = _scheduler_get_highest_priority_thread(&highest_ready_priority);
236246

237247
rt_cpu_self()->current_thread = to_thread;
248+
rt_scheduler_critical_switch_flag = CRITICAL_SWITCH_FLAG_IDLE;
238249

239250
rt_sched_remove_thread(to_thread);
240251
RT_SCHED_CTX(to_thread).stat = RT_THREAD_RUNNING;
@@ -387,6 +398,10 @@ void rt_schedule(void)
387398
}
388399
}
389400
}
401+
else
402+
{
403+
rt_scheduler_critical_switch_flag = CRITICAL_SWITCH_FLAG_PENDING;
404+
}
390405

391406
/* enable interrupt */
392407
rt_hw_interrupt_enable(level);
@@ -604,6 +619,7 @@ void rt_exit_critical_safe(rt_base_t critical_level)
604619

605620
/**
606621
* @brief Safely exit critical section (non-debug version)
622+
* If the scheduling function is called before exiting, it will be scheduled in this function.
607623
*
608624
* @param critical_level The expected critical level (unused in non-debug build)
609625
*
@@ -657,6 +673,7 @@ RTM_EXPORT(rt_enter_critical);
657673

658674
/**
659675
* @brief Exit critical section and unlock scheduler
676+
* If the scheduling function is called before exiting, it will be scheduled in this function.
660677
*
661678
* @details This function:
662679
* - Decrements the scheduler lock nesting count
@@ -685,9 +702,10 @@ void rt_exit_critical(void)
685702
/* enable interrupt */
686703
rt_hw_interrupt_enable(level);
687704

688-
if (rt_current_thread)
705+
if (rt_scheduler_critical_switch_flag == CRITICAL_SWITCH_FLAG_PENDING)
689706
{
690-
/* if scheduler is started, do a schedule */
707+
rt_scheduler_critical_switch_flag = CRITICAL_SWITCH_FLAG_IDLE;
708+
/* if scheduler is started and needs to be scheduled, do a schedule */
691709
rt_schedule();
692710
}
693711
}

0 commit comments

Comments
 (0)