Skip to content

Commit

Permalink
Fix RP2040 IntQueue test
Browse files Browse the repository at this point in the history
* Add critical section protection in timer ISR

Note that the following PR is still required to prevent race condition
chinglee-iot/FreeRTOS-Kernel#62
  • Loading branch information
chinglee-iot committed Feb 9, 2023
1 parent 1bf0f01 commit 2b3002e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pico_add_extra_outputs(main_full_smp)

# Use USB uart
pico_enable_stdio_usb(main_full_smp 1)
pico_enable_stdio_uart(main_full_smp 0)
pico_enable_stdio_uart(main_full_smp 1)

add_executable(main_blinky_smp
main.c
Expand All @@ -70,4 +70,4 @@ pico_add_extra_outputs(main_blinky_smp)

# Use USB uart
pico_enable_stdio_usb(main_blinky_smp 1)
pico_enable_stdio_uart(main_blinky_smp 0)
pico_enable_stdio_uart(main_blinky_smp 1)
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ to exclude the API function. */

/* SMP Related config. */
#define configUSE_MINIMAL_IDLE_HOOK 0
#define portCRITICAL_NESTING_IN_TCB 1
#define portSUPPORT_SMP 1

#endif /* FREERTOS_CONFIG_H */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,35 @@ possible on Cortex-M devices. */

void prvAlarm0Callback( uint timer )
{
UBaseType_t uxSavedInterruptState;
BaseType_t xHigherPriorityTaskWoken;

configASSERT(timer == 0);
BaseType_t xHigherPriorityTaskWoken = xFirstTimerHandler();
hardware_alarm_set_target(0, make_timeout_time_us( FIRST_TIMER_PERIOD_US) );

uxSavedInterruptState = taskENTER_CRITICAL_FROM_ISR();
{
xHigherPriorityTaskWoken = xFirstTimerHandler();
hardware_alarm_set_target(0, make_timeout_time_us( FIRST_TIMER_PERIOD_US) );
}
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptState );

portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
}

void prvAlarm1Callback( uint timer )
{
UBaseType_t uxSavedInterruptState;
BaseType_t xHigherPriorityTaskWoken;

configASSERT(timer == 1);
BaseType_t xHigherPriorityTaskWoken = xSecondTimerHandler();
hardware_alarm_set_target(1, make_timeout_time_us( SECOND_TIMER_PERIOD_US) );

uxSavedInterruptState = taskENTER_CRITICAL_FROM_ISR();
{
xHigherPriorityTaskWoken = xSecondTimerHandler();
hardware_alarm_set_target(1, make_timeout_time_us( SECOND_TIMER_PERIOD_US) );
}
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptState );

portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,30 @@

#define mainRUN_ON_CORE 0


/* These tests should work in all modes */
#define mainENABLE_COUNTING_SEMAPHORE 1
#define mainENABLE_DEATH 1

/* TODO: This still seems flaky on SMP */
#if ( portSUPPORT_SMP == 0)
#define mainENABLE_INTERRUPT_QUEUE 1
#endif
#define mainENABLE_INTERRUPT_QUEUE 1
#define mainENABLE_MATH 1
#define mainENABLE_QUEUE_OVERWRITE 1
#define mainENABLE_REG_TEST 1
#define mainENABLE_SEMAPHORE 1
#define mainENABLE_TASK_NOTIFY 1

#if configNUMBER_OF_CORES != 2 || configRUN_MULTIPLE_PRIORITIES == 0

/* These tests assume that a higher priority task will block a lower priority tax from running */
#define mainENABLE_BLOCK_TIME 1
#define mainENABLE_BLOCKING_QUEUE 1
#define mainENABLE_GENERIC_QUEUE 1
#define mainENABLE_INTERRUPT_SEMAPHORE 1
#define mainENABLE_EVENT_GROUP 1
#define mainENABLE_RECURSIVE_MUTEX 1
#define mainENABLE_TIMER_DEMO 1
#if ( configNUMBER_OF_CORES == 1 ) || ( configRUN_MULTIPLE_PRIORITIES == 0 )
/* These tests assume that a higher priority task will block a lower priority tax from running */
#define mainENABLE_BLOCK_TIME 1
#define mainENABLE_BLOCKING_QUEUE 1
#define mainENABLE_GENERIC_QUEUE 1
#define mainENABLE_INTERRUPT_SEMAPHORE 1
#define mainENABLE_EVENT_GROUP 1
#define mainENABLE_RECURSIVE_MUTEX 1
#define mainENABLE_TIMER_DEMO 1
#endif

#if configNUMBER_OF_CORES != 2
/* This test just expects two tasks not to run concurrently */
#define mainENABLE_DYNAMIC_PRIORITY 1
#if ( configNUMBER_OF_CORES == 1 )
/* This test just expects two tasks not to run concurrently */
#define mainENABLE_DYNAMIC_PRIORITY 1
#endif

#endif /* MAIN_H */
2 changes: 1 addition & 1 deletion FreeRTOS/Source
Submodule Source updated 1 files
+235 −258 tasks.c

0 comments on commit 2b3002e

Please sign in to comment.