2022-04-20 07:31:49 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2017-03-06 19:31:46 -05:00
|
|
|
/* FreeRTOS timer tests
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "unity.h"
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "freertos/timers.h"
|
2022-05-20 06:16:47 -04:00
|
|
|
#include "test_utils.h"
|
2017-03-06 19:31:46 -05:00
|
|
|
|
|
|
|
static void timer_callback(TimerHandle_t timer)
|
|
|
|
{
|
|
|
|
volatile int *count;
|
|
|
|
count = (volatile int *)pvTimerGetTimerID( timer );
|
|
|
|
(*count)++;
|
|
|
|
printf("Callback timer %p count %p = %d\n", timer, count, *count);
|
|
|
|
}
|
|
|
|
|
2022-05-20 06:16:47 -04:00
|
|
|
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
|
|
//IDF-5140
|
2017-03-06 19:31:46 -05:00
|
|
|
TEST_CASE("Oneshot FreeRTOS timers", "[freertos]")
|
|
|
|
{
|
|
|
|
volatile int count = 0;
|
|
|
|
TimerHandle_t oneshot = xTimerCreate("oneshot", 100 / portTICK_PERIOD_MS, pdFALSE,
|
|
|
|
(void *)&count, timer_callback);
|
|
|
|
TEST_ASSERT(oneshot);
|
|
|
|
TEST_ASSERT_EQUAL(pdFALSE, xTimerIsTimerActive(oneshot));
|
|
|
|
TEST_ASSERT_EQUAL(0, count);
|
|
|
|
|
|
|
|
TEST_ASSERT( xTimerStart(oneshot, 1) );
|
|
|
|
vTaskDelay(2); /* give the timer task a chance to process the message */
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL(pdTRUE, xTimerIsTimerActive(oneshot));
|
|
|
|
TEST_ASSERT_EQUAL(0, count);
|
|
|
|
|
|
|
|
vTaskDelay(250 / portTICK_PERIOD_MS); // 2.5 timer periods
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL(1, count);
|
|
|
|
TEST_ASSERT_EQUAL(pdFALSE, xTimerIsTimerActive(oneshot));
|
|
|
|
|
|
|
|
TEST_ASSERT( xTimerDelete(oneshot, 1) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE("Recurring FreeRTOS timers", "[freertos]")
|
|
|
|
{
|
|
|
|
volatile int count = 0;
|
|
|
|
TimerHandle_t recurring = xTimerCreate("oneshot", 100 / portTICK_PERIOD_MS, pdTRUE,
|
|
|
|
(void *)&count, timer_callback);
|
|
|
|
TEST_ASSERT(recurring);
|
|
|
|
TEST_ASSERT_EQUAL(pdFALSE, xTimerIsTimerActive(recurring));
|
|
|
|
TEST_ASSERT_EQUAL(0, count);
|
|
|
|
|
|
|
|
TEST_ASSERT( xTimerStart(recurring, 1) );
|
|
|
|
|
|
|
|
vTaskDelay(2); // let timer task process the queue
|
|
|
|
TEST_ASSERT_EQUAL(pdTRUE, xTimerIsTimerActive(recurring));
|
|
|
|
TEST_ASSERT_EQUAL(0, count);
|
|
|
|
|
|
|
|
vTaskDelay(250 / portTICK_PERIOD_MS); // 2.5 timer periods
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL(2, count);
|
|
|
|
TEST_ASSERT_EQUAL(pdTRUE, xTimerIsTimerActive(recurring));
|
|
|
|
|
|
|
|
TEST_ASSERT( xTimerStop(recurring, 1) );
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL(2, count);
|
|
|
|
|
|
|
|
vTaskDelay(100 / portTICK_PERIOD_MS); // One more timer period
|
|
|
|
TEST_ASSERT_EQUAL(2, count); // hasn't gone up
|
|
|
|
TEST_ASSERT_EQUAL(pdFALSE, xTimerIsTimerActive(recurring));
|
|
|
|
|
|
|
|
TEST_ASSERT( xTimerDelete(recurring, 1) );
|
|
|
|
}
|
2022-05-20 06:16:47 -04:00
|
|
|
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
2020-04-23 15:34:13 -04:00
|
|
|
|
|
|
|
TEST_CASE("Static timer creation", "[freertos]")
|
|
|
|
{
|
|
|
|
StaticTimer_t static_timer;
|
|
|
|
TimerHandle_t created_timer;
|
|
|
|
volatile int count = 0;
|
|
|
|
|
2020-11-10 02:40:01 -05:00
|
|
|
created_timer = xTimerCreateStatic("oneshot", 100 / portTICK_PERIOD_MS,
|
2020-04-23 15:34:13 -04:00
|
|
|
pdTRUE,
|
2020-11-10 02:40:01 -05:00
|
|
|
(void *)&count,
|
|
|
|
timer_callback,
|
2020-04-23 15:34:13 -04:00
|
|
|
&static_timer);
|
2020-11-10 02:40:01 -05:00
|
|
|
|
2020-04-23 15:34:13 -04:00
|
|
|
TEST_ASSERT_NOT_NULL(created_timer);
|
|
|
|
}
|