/* The example of esp-free-rtos
*
* This sample code is in the public domain.
*/
#include <stdlib.h>
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "esp8266.h"
//時間稼ぎ
void ConsumptionTick(int delay) {
TickType_t startTick;
TickType_t endTick;
TickType_t nowTick;
startTick = xTaskGetTickCount();
endTick = startTick + delay;
//printf("startTick=%d
endTick=%d\n",startTick,endTick);
while(1) {
nowTick =
xTaskGetTickCount();
if (nowTick > endTick)
break;
}
}
// Task Body
void taskEntry(void *pvParameters)
{
UBaseType_t prio;
TickType_t nowTick;
prio = uxTaskPriorityGet( NULL );
nowTick = xTaskGetTickCount();
printf("[%s:%d] start
Priority=%d\n",pcTaskGetName(0),nowTick,(int)prio);
ConsumptionTick(200);
nowTick = xTaskGetTickCount();
printf("[%s:%d]
end\n",pcTaskGetName(0),nowTick);
vTaskDelete( NULL );
}
void user_init(void)
{
UBaseType_t prio;
TickType_t nowTick;
BaseType_t xReturned;
TaskHandle_t xHandle1 = NULL;
TaskHandle_t xHandle2 = NULL;
uart_set_baud(0, 115200);
prio = uxTaskPriorityGet( NULL );
nowTick = xTaskGetTickCount();
printf("[%s:%d] start
Priority=%d\n",pcTaskGetName(0),nowTick,(int)prio);
printf("[%s:%d] SDK
version:%s\n",pcTaskGetName(0),nowTick,sdk_system_get_sdk_version());
printf("[%s:%d]
portTICK_PERIOD_MS=%d[ms]\n",pcTaskGetName(0),nowTick,portTICK_PERIOD_MS);
printf("[%s:%d]
configMAX_PRIORITIES=%d\n",pcTaskGetName(0),nowTick,configMAX_PRIORITIES);
#if 1
// myTask1を優先度=2で起動
// myTask2を優先度=2で起動
xReturned = xTaskCreate(taskEntry,
"myTask1", 256, NULL, 2, &xHandle1);
if( xReturned == pdPASS ) {
nowTick =
xTaskGetTickCount();
printf("[%s:%d] myTask1
xTaskCreate success\n",pcTaskGetName(0),nowTick);
}
xReturned = xTaskCreate(taskEntry,
"myTask2", 256, NULL, 2, &xHandle2);
if( xReturned == pdPASS ) {
nowTick =
xTaskGetTickCount();
printf("[%s:%d] myTask2
xTaskCreate success\n",pcTaskGetName(0),nowTick);
}
#endif
#if 0
// myTask1を優先度=2で起動
// myTask2を優先度=4で起動
xReturned = xTaskCreate(taskEntry,
"myTask1", 256, NULL, 2, &xHandle1);
if( xReturned == pdPASS ) {
nowTick =
xTaskGetTickCount();
printf("[%s:%d] myTask1
xTaskCreate success\n",pcTaskGetName(0),nowTick);
}
xReturned = xTaskCreate(taskEntry,
"myTask2", 256, NULL, 4, &xHandle2);
if( xReturned == pdPASS ) {
nowTick =
xTaskGetTickCount();
printf("[%s:%d] myTask2
xTaskCreate success\n",pcTaskGetName(0),nowTick);
}
#endif
#if 0
// myTask1を優先度=2で起動
// 自分自身をDelay
// myTask2を優先度=4で起動
xReturned = xTaskCreate(taskEntry,
"myTask1", 256, NULL, 2, &xHandle1);
if( xReturned == pdPASS ) {
nowTick =
xTaskGetTickCount();
printf("[%s:%d] myTask1
xTaskCreate success\n",pcTaskGetName(0),nowTick);
}
// delay 10mSec
vTaskDelay(10 / portTICK_PERIOD_MS);
xReturned = xTaskCreate(taskEntry,
"myTask2", 256, NULL, 4, &xHandle2);
if( xReturned == pdPASS ) {
nowTick =
xTaskGetTickCount();
printf("[%s:%d] myTask2
xTaskCreate success\n",pcTaskGetName(0),nowTick);
}
#endif
}
|