I am trying to learn how to use FreeRTOS , and i encountered some difficulties ; I creat 2 task in my code , one task is led flash and printf “hello world” ; the other is key detect , it is used to detect whether the key is pressed , if the key is pressed , this task will delete the led task; but i find that , if these two task have same priority ,when delete the led task , the program will get stuck , it will trigger configAssert() in heap_4.c , the iamge bellow show the poisition .
but if they have different priority , the program will run normally ; So I’m curious why this happens ; my code is simple , please help me , thanks !
#define START_TASK_PRIO 1
#define START_STK_SIZE 128
TaskHandle_t StartTask_Handler;
void start_task(void *pvParameters);
#define LED0_TASK_PRIO 2
#define LED0_STK_SIZE 50
TaskHandle_t LED0Task_Handler;
void led0_task(void *p_arg);
#define KEY_TASK_PRIO 2
#define KEY_STK_SIZE 50
TaskHandle_t KEY0Task_Handler;
void key0_task(void *p_arg);
int main(void)
{
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
uart_init(115200);
LED_Init();
KEY_Init();
xTaskCreate( (TaskFunction_t) start_task,
(const char * ) "start_task",
(uint16_t) START_STK_SIZE,
(void*) NULL,
( UBaseType_t )START_TASK_PRIO,
(TaskHandle_t*)&StartTask_Handler );
vTaskStartScheduler();
}
void start_task(void *pvParameters )
{
taskENTER_CRITICAL();
xTaskCreate((TaskFunction_t) key0_task,
(const char * ) "key0_task",
(uint16_t) KEY_STK_SIZE,
(void*) NULL,
(UBaseType_t) KEY_TASK_PRIO ,
(TaskHandle_t*)&KEY0Task_Handler
);
xTaskCreate ((TaskFunction_t) led0_task,
(const char * ) "led0_task",
(uint16_t) LED0_STK_SIZE,
(void*) NULL,
( UBaseType_t )LED0_TASK_PRIO,
(TaskHandle_t*)&LED0Task_Handler );
vTaskDelete(StartTask_Handler);
taskEXIT_CRITICAL();
}
void led0_task(void *p_arg)
{
while(1)
{
LED0 = ~LED0;
vTaskDelay(1000);
printf("hello World ");
}
}
void key0_task(void *p_arg)
{
u8 keyValue;
while(1)
{
keyValue = KEY_Scan(0);
if(keyValue == KEY0_PRES)
{
printf("Delete LE0_TASK!");
vTaskDelete(LED0Task_Handler);
}
vTaskDelay(10);
LED1 = ~ LED1;
}
}