按照以前的方法开打FREE RTOS的例程。
则可以看出这个例程跑两个线程:
一个LED闪,一个打印当前运行的线程。
其中,定义两个线程的堆栈如下:
#define TASK_MONITOR_STACK_SIZE (2048/sizeof(portSTACK_TYPE))
#define TASK_MONITOR_STACK_PRIORITY (tskIDLE_PRIORITY)
#define TASK_LED_STACK_SIZE (1024/sizeof(portSTACK_TYPE))
#define TASK_LED_STACK_PRIORITY (tskIDLE_PRIORITY)
定义两个线程如下:
**
* \brief This task, when activated, send every ten seconds on debug UART
* the whole report of free heap and total tasks status
*/
static void task_monitor(void *pvParameters)
{
static portCHAR szList[256];
UNUSED(pvParameters);
for (;;) {
printf("--- task ## %u", (unsigned int)uxTaskGetNumberOfTasks());
vTaskList((signed portCHAR *)szList);
printf(szList);
vTaskDelay(1000);
}
}
/**
* \brief This task, when activated, make LED blink at a fixed rate
*/
static void task_led(void *pvParameters)
{
UNUSED(pvParameters);
for (;;) {
#if SAM4CM
LED_Toggle(LED4);
#else
LED_Toggle(LED0);
#endif
vTaskDelay(1000);
}
}
建立两个线程及开始运行如下:
/* Create task to monitor processor activity */
if (xTaskCreate(task_monitor, "Monitor", TASK_MONITOR_STACK_SIZE, NULL,
TASK_MONITOR_STACK_PRIORITY, NULL) != pdPASS) {
printf("Failed to create Monitor task\r\n");
}
/* Create task to make led blink */
if (xTaskCreate(task_led, "Led", TASK_LED_STACK_SIZE, NULL,
TASK_LED_STACK_PRIORITY, NULL) != pdPASS) {
printf("Failed to create test led task\r\n");
}
/* Start the scheduler. */
vTaskStartScheduler();
运行结果:
灯一闪一闪并在闪的同时打印出如下信息:
|