This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

blinky_rtc_freertos task switching not working when nrf_drv_rtc_init is disable

HW: nrf52840

SW: nRF5_SDK_15.2.0_9412b96

source code: blinky_rtc_freertos example

Q1:

I read freeRTOS xtaskcreate operation on the web, it seem that I just need to call xtaskcreate function and link to a function and it should able to switching between multiple task with the right priority been set. But I notice when RTC function in the blinky_rtc_freertos example is removed the task will stop switching.

Expected xtaskcreate coding that is not working.

/**
 * @brief Reference to LED0 toggling FreeRTOS task.
 */
static TaskHandle_t  m_led_toggle_task_handle;

/**
 * @brief Reference to LED0 toggling FreeRTOS task.
 */
static TaskHandle_t  m_led_toggle_task_handle2;

static void led_toggle_task_function (void * pvParameter)
{
    ret_code_t err_code;

    UNUSED_PARAMETER(pvParameter);
    while (true)
    {
        bsp_board_led_invert(BSP_BOARD_LED_0);

        /* Wait for the event from the RTC */
        UNUSED_RETURN_VALUE(xSemaphoreTake(m_led_semaphore, portMAX_DELAY));
    }

    /* Tasks must be implemented to never return... */
}

static void led_toggle_task_function2 (void * pvParameter)
{
    UNUSED_PARAMETER(pvParameter);
    while (true)
    {
        bsp_board_led_invert(BSP_BOARD_LED_2);

        /* Wait for the event from the RTC */
        UNUSED_RETURN_VALUE(xSemaphoreTake(m_led_semaphore, portMAX_DELAY));
    }

    /* Tasks must be implemented to never return... */
}

int main(void)
{
    m_led_semaphore = xSemaphoreCreateBinary();
    ASSERT(NULL != m_led_semaphore);
    /* Create task for LED0 blinking with priority set to 2 */
    UNUSED_VARIABLE(xTaskCreate(led_toggle_task_function, "LED0", configMINIMAL_STACK_SIZE + 200, NULL, 2, &m_led_toggle_task_handle));

   /* Create task for LED0 blinking with priority set to 2 */
    UNUSED_VARIABLE(xTaskCreate(led_toggle_task_function2, "LED1", configMINIMAL_STACK_SIZE + 200, NULL, 3, &m_led_toggle_task_handle2));
}

Q2:

I still not very clear with how softdevices <> FreeRTOS interact and how do RTC vs systick and how RTC or systick can influence the task scheduling. As I know RTC can still operate when the device in deep sleep which I can use RTC interrupt to wake the device from Tickless idle mode but I not sure how nordic softdevices + FreeRTOS works.

Related