Hi, I ran into some problem when trying to understand how are tasks in FreeRTOS working. Expected result for given code was:
-only red LED ON → only green LED ON → only blue LED ON → and so on
but after first loop, which was ok instead of green LED switching on after red, there is blue LED (idle task) for a while before that. I wanted to paste link to yt video showing that, but I can’t. There is code:
#include "led.h"
#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MKV58F24.h"
#include "fsl_debug_console.h"
#include "FreeRTOS.h"
#include "task.h"
#define my_task_PRIORITY (configMAX_PRIORITIES - 1)
static void prvSetupHardware(void);
static void vHelloTask(void *pvParameters);
static void vLEDTask(void *pvParameters);
void vApplicationIdleHook(void);
int main(void) {
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
BOARD_InitDebugConsole();
prvSetupHardware();
if (xTaskCreate(vLEDTask, "LED_RED", configMINIMAL_STACK_SIZE + 10, "r", 3, NULL) != pdPASS)
{
PRINTF("Task creation failed!.\r\n");
while (1) ;
}
if (xTaskCreate(vLEDTask, "LED_GREEN", configMINIMAL_STACK_SIZE + 10, "g", 2, NULL) != pdPASS)
{
PRINTF("Task creation failed!.\r\n");
while (1) ;
}
vTaskStartScheduler();
while(1) {
}
return 0 ;
}
static void prvSetupHardware(void)
{
initLed('b');
initLed('g');
initLed('r');
}
static void vLEDTask(void *pvParameters)
{
char color = *((char*)pvParameters);
for (;;) {
onLed(color);
for(int i=8000000;i>0;i--);
vTaskDelay( 4000 / portTICK_RATE_MS );
}
vTaskDelete(NULL);
}
void vApplicationTickHook(void)
{
offLed('r');
offLed('g');
offLed('b');
}
void vApplicationIdleHook(void)
{
onLed('b');
}