/* 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)
{
BaseType_t xReturned;
TickType_t nowTick;
TaskHandle_t xHandle1 = NULL;
uart_set_baud(0, 115200);
nowTick = xTaskGetTickCount();
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);
xReturned = xTaskCreate(taskEntry,
"myTask1", 256, NULL, 2, &xHandle1);
if( xReturned != pdPASS ) {
printf("xTaskCreate
fail\n");
}
eTaskState taskState;
UBaseType_t taskCount;
for(int i=0;i<10;i++) {
taskState = eTaskGetState(
xHandle1 );
taskCount =
uxTaskGetNumberOfTasks();
nowTick =
xTaskGetTickCount();
printf("[%s:%d]
taskState=%d
taskCount=%d\n",pcTaskGetName(0),nowTick,taskState,(int)taskCount);
// delay 10mSec
vTaskDelay(10 /
portTICK_PERIOD_MS);
}
}
|