/* 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 "semphr.h"
#include "esp8266.h"
SemaphoreHandle_t xSemaphore;
//時間稼ぎ
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;
}
}
void task1(void *pvParameters)
{
UBaseType_t prio;
TickType_t nowTick;
nowTick = xTaskGetTickCount();
prio = uxTaskPriorityGet( NULL );
printf("[%s:%d] Start
Priority=%d\n",pcTaskGetName(0),nowTick,(int)prio);
xSemaphoreTake(xSemaphore, portMAX_DELAY);
printf("[%s:%d] Take\n",pcTaskGetName(0),nowTick);
ConsumptionTick(1000);
prio = uxTaskPriorityGet( NULL );
xSemaphoreGive(xSemaphore);
nowTick = xTaskGetTickCount();
printf("[%s:%d] Give Semaphore
Priority=%d\n",pcTaskGetName(0),nowTick,(int)prio);
while(1) {
vTaskDelay(100);
}
}
void task2(void *pvParameters)
{
UBaseType_t prio;
TickType_t nowTick;
nowTick = xTaskGetTickCount();
prio = uxTaskPriorityGet( NULL );
printf("[%s:%d] Start
Priority=%d\n",pcTaskGetName(0),nowTick,(int)prio);
ConsumptionTick(200);
nowTick = xTaskGetTickCount();
printf("[%s:%d] Waiting
Mutex\n",pcTaskGetName(0),nowTick);
xSemaphoreTake(xSemaphore, portMAX_DELAY);
nowTick = xTaskGetTickCount();
printf("[%s:%d] Take
Semaphore\n",pcTaskGetName(0),nowTick);
while(1) {
vTaskDelay(100);
}
}
void task3(void *pvParameters)
{
UBaseType_t prio;
TickType_t nowTick;
nowTick = xTaskGetTickCount();
prio = uxTaskPriorityGet( NULL );
printf("[%s:%d] Start
Priority=%d\n",pcTaskGetName(0),nowTick,(int)prio);
ConsumptionTick(200);
nowTick = xTaskGetTickCount();
printf("[%s:%d] Waiting
Mutex\n",pcTaskGetName(0),nowTick);
xSemaphoreTake(xSemaphore, portMAX_DELAY);
nowTick = xTaskGetTickCount();
printf("[%s:%d] Take
Semaphore\n",pcTaskGetName(0),nowTick);
while(1) {
vTaskDelay(100);
}
}
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));
/* Create Mutex */
xSemaphore = xSemaphoreCreateMutex();
/* Check everything was created. */
configASSERT( xSemaphore );
/* Get current value */
UBaseType_t value;
value = uxSemaphoreGetCount( xSemaphore );
printf("Semaphore value=%d\n",(int)value);
#if 1
xTaskCreate(task1, "task1", 256, NULL, 2, NULL);
vTaskDelay(10);
xTaskCreate(task2, "task2", 256, NULL, 2, NULL);
vTaskDelay(210);
xTaskCreate(task3, "task3", 256, NULL, 2, NULL);
#endif
#if 0
xTaskCreate(task1, "task1", 256, NULL, 2, NULL);
vTaskDelay(10);
xTaskCreate(task2, "task2", 256, NULL, 3, NULL);
vTaskDelay(210);
xTaskCreate(task3, "task3", 256, NULL, 4, NULL);
#endif
}
|