Merge branch 'bugfix/freertos_eventgroup_isr_test' into 'master'
freertos/Fix Event Group ISR test case See merge request !1733
This commit is contained in:
commit
f61dcf4d1a
1 changed files with 44 additions and 31 deletions
|
@ -127,28 +127,37 @@ TEST_CASE("FreeRTOS Event Group Sync", "[freertos]")
|
|||
|
||||
//Use a timer to trigger an ISr
|
||||
#define TIMER_DIVIDER 10000
|
||||
#define TIMER_COUNT 1000
|
||||
#define TIMER_COUNT 100
|
||||
#define TIMER_NUMBER 0
|
||||
#define SET_BITS 0xAA
|
||||
#define CLEAR_BITS 0x55
|
||||
#define BITS 0xAA
|
||||
|
||||
static bool event_grp_cleared = false;
|
||||
static timer_isr_handle_t isr_handle;
|
||||
static bool test_set_bits;
|
||||
static bool test_clear_bits;
|
||||
|
||||
static void IRAM_ATTR event_group_isr()
|
||||
{
|
||||
portBASE_TYPE task_woken = pdFALSE;
|
||||
TIMERG0.int_clr_timers.t0 = 1;
|
||||
TIMERG0.hw_timer[xPortGetCoreID()].config.alarm_en = 1;
|
||||
if(!event_grp_cleared){
|
||||
xEventGroupClearBitsFromISR(eg, CLEAR_BITS);
|
||||
event_grp_cleared = true;
|
||||
}else{
|
||||
xEventGroupSetBitsFromISR(eg, SET_BITS, NULL);
|
||||
|
||||
if(test_set_bits){
|
||||
xEventGroupSetBitsFromISR(eg, BITS, &task_woken);
|
||||
timer_pause(TIMER_GROUP_0, TIMER_NUMBER);
|
||||
test_set_bits = false;
|
||||
} else if (test_clear_bits){
|
||||
xEventGroupClearBitsFromISR(eg, BITS);
|
||||
xSemaphoreGiveFromISR(done_sem, &task_woken);
|
||||
timer_pause(TIMER_GROUP_0, TIMER_NUMBER);
|
||||
test_clear_bits = false;
|
||||
}
|
||||
//Switch context if necessary
|
||||
if(task_woken == pdTRUE){
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void test_event_group_trace_facility(void* arg)
|
||||
static void setup_timer()
|
||||
{
|
||||
//Setup timer for ISR
|
||||
int timer_group = TIMER_GROUP_0;
|
||||
|
@ -166,37 +175,41 @@ static void test_event_group_trace_facility(void* arg)
|
|||
timer_set_alarm_value(timer_group, timer_idx, TIMER_COUNT); //Set alarm value
|
||||
timer_enable_intr(timer_group, timer_idx); //Enable timer interrupt
|
||||
timer_set_auto_reload(timer_group, timer_idx, 1); //Auto Reload
|
||||
timer_isr_register(timer_group, timer_idx, event_group_isr, NULL, ESP_INTR_FLAG_IRAM, NULL); //Set ISR handler
|
||||
|
||||
//Start timer to trigger isr
|
||||
timer_start(TIMER_GROUP_0, TIMER_NUMBER);
|
||||
TEST_ASSERT(xEventGroupWaitBits(eg, SET_BITS, pdFALSE, pdTRUE, portMAX_DELAY));
|
||||
//Check clear was successful
|
||||
TEST_ASSERT((xEventGroupGetBits(eg) & CLEAR_BITS) == 0);
|
||||
|
||||
//Give semaphore to signal done
|
||||
xSemaphoreGive(done_sem);
|
||||
vTaskDelete(NULL);
|
||||
timer_isr_register(timer_group, timer_idx, event_group_isr, NULL, ESP_INTR_FLAG_IRAM, &isr_handle); //Set ISR handler
|
||||
}
|
||||
|
||||
static void cleanup_timer()
|
||||
{
|
||||
timer_disable_intr(TIMER_GROUP_0, TIMER_NUMBER);
|
||||
esp_intr_free(isr_handle);
|
||||
}
|
||||
|
||||
TEST_CASE("FreeRTOS Event Group ISR", "[freertos]")
|
||||
{
|
||||
|
||||
done_sem = xSemaphoreCreateBinary();
|
||||
eg = xEventGroupCreate();
|
||||
xEventGroupSetBits(eg, CLEAR_BITS); //Set bits to be cleared by ISR
|
||||
test_set_bits = false;
|
||||
test_clear_bits = false;
|
||||
setup_timer(); //Init timer to trigger ISR
|
||||
|
||||
xTaskCreatePinnedToCore(test_event_group_trace_facility, "Testing Task", 4096, NULL, configMAX_PRIORITIES - 1, NULL, 0);
|
||||
//Test set bits
|
||||
test_set_bits = true;
|
||||
timer_start(TIMER_GROUP_0, TIMER_NUMBER);
|
||||
TEST_ASSERT_EQUAL(BITS, xEventGroupWaitBits(eg, BITS, pdFALSE, pdTRUE, portMAX_DELAY)); //Let ISR set event group bits
|
||||
|
||||
//Test clear bits
|
||||
xEventGroupSetBits(eg, BITS); //Set bits to be cleared
|
||||
test_clear_bits = true;
|
||||
timer_start(TIMER_GROUP_0, TIMER_NUMBER);
|
||||
xSemaphoreTake(done_sem, portMAX_DELAY); //Wait for ISR to clear bits
|
||||
vTaskDelay(10); //Event group clear bits runs via daemon task, delay so daemon can run
|
||||
TEST_ASSERT_EQUAL(0, xEventGroupGetBits(eg)); //Check bits are cleared
|
||||
|
||||
//Wait until task and isr have finished testing
|
||||
xSemaphoreTake(done_sem, portMAX_DELAY);
|
||||
//Clean up
|
||||
vSemaphoreDelete(done_sem);
|
||||
cleanup_timer();
|
||||
vEventGroupDelete(eg);
|
||||
|
||||
vTaskDelay(10); //Give time for idle task to clear up delted tasks
|
||||
|
||||
vSemaphoreDelete(done_sem);
|
||||
vTaskDelay(10); //Give time for idle task to clear up deleted tasks
|
||||
}
|
||||
|
||||
#endif //CONFIG_FREERTOS_USE_TRACE_FACILITY
|
||||
|
|
Loading…
Reference in a new issue