FreeRTOS Coding Procedure
FreeRTOS Coding Procedure
Task creation
• Step 1: Define thread handle and functions
TaskHandle_t led_on, led_off;
// Define the functions later
static void led_on_function(void* params);
static void led_off_function(void* params);
portYIELD_FROM_ISR(pxHigherPriorityTaskWoken);
printf("Button pressed!\n");
}
// ...
}
• Inside led_function():
myhandle = xSemaphoreCreateMutex();
vSemaphoreCreateBinary( myhandle );
• Step 3: Create tasks if mutex is successfully created.
if(myhandle != NULL)
{
status = xTaskCreate(task_1, "Task 1", 200,NULL,2,&t1);
configASSERT(status == pdPASS);
vTaskStartScheduler();
}
• Inside the tasks:
// ...
vTaskStartScheduler();
}
• Step 4: Give semaphores
xSemaphoreGive(mycountsem);
xSemaphoreGive(mycountsem);
xSemaphoreGive(mycountsem);
xSemaphoreGive(mycountsem);
vTaskStartScheduler();
}
• Inside writing task: