/* 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 task(void *pvParameters)
{
TickType_t nowTick;
TickType_t xLastWakeTime;
nowTick = xTaskGetTickCount();
printf("[%s:%d]
start\n",pcTaskGetName(0),nowTick);
// Initialise the xLastWakeTime
variable with the current time.
xLastWakeTime = xTaskGetTickCount();
for(int i=0;i<10;i++) {
// Wait for the next cycle.
vTaskDelayUntil(
&xLastWakeTime, 100 );
nowTick =
xTaskGetTickCount();
printf("[%s:%d] wakeup from
vTaskDelayUntil\n",pcTaskGetName(0),nowTick);
ConsumptionTick(10);
}
for(int i=0;i<10;i++) {
// Wait for the next cycle.
vTaskDelay( 100 );
nowTick =
xTaskGetTickCount();
printf("[%s:%d] wakeup from
vTaskDelay\n",pcTaskGetName(0),nowTick);
ConsumptionTick(10);
}
vTaskDelete( NULL );
}
void user_init(void)
{
uart_set_baud(0, 115200);
printf("SDK version:%s\n",
sdk_system_get_sdk_version());
printf("pcTaskGetName=%s\n",pcTaskGetName(0));
xTaskCreate(task, "task", 256, NULL, 2,
NULL);
}
|