/* The example of esp-free-rtos
*
* This sample code is in the public domain.
*
* You have to add this in FreeRTOSConfig.h.
* #define
configUSE_QUEUE_SETS 1
*/
#include <stdlib.h>
#include <string.h>
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "esp8266.h"
QueueHandle_t xQueue;
/* Define the lengths of the queues that will be added to
the queue set. */
#define QUEUE_LENGTH 10
/* Define the size of the item to be held by queue 1 and
queue 2 respectively.
The values used here are just for demonstration purposes.
*/
#define ITEM_SIZE_QUEUE sizeof( uint32_t )
// Send Queue
void task1(void *pvParameters)
{
uint32_t count = 0;
TickType_t nowTick;
nowTick = xTaskGetTickCount();
printf("[%s:%d]
Start\n",pcTaskGetName(0),nowTick);
for(int i=0;i<10;i++) {
#if 0
xQueueSend(xQueue,
&count, 0);
#endif
#if 1
xQueueSendToBack(xQueue,
&count, 0);
#endif
#if 0
xQueueSendToFront(xQueue,
&count, 0);
#endif
count++;
}
while(1) {
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}
void task2(void *pvParameters)
{
TickType_t nowTick;
uint32_t count;
nowTick = xTaskGetTickCount();
printf("[%s:%d]
Start\n",pcTaskGetName(0),nowTick);
while(1) {
nowTick =
xTaskGetTickCount();
if(xQueueReceive(xQueue,
&count, 0)) {
printf("[%s:%d]
count=%u\n",pcTaskGetName(0),nowTick,count);
} else {
printf("[%s:%d] No msg\n",pcTaskGetName(0),nowTick);
break;
}
}
while(1) {
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}
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 the queues and semaphores
that will be contained in the set. */
xQueue = xQueueCreate( QUEUE_LENGTH,
ITEM_SIZE_QUEUE );
/* Check everything was created. */
configASSERT( xQueue );
xTaskCreate(task1, "task1", 256, NULL,
2, NULL);
xTaskCreate(task2, "task2", 256, NULL,
2, NULL);
}
|