#include "freertos/FreeRTOS.h"
#include "Arduino.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 )
void Task1(void *pvParameters) {
TickType_t nowTick;
UBaseType_t prio =
uxTaskPriorityGet(NULL);
nowTick = xTaskGetTickCount();
printf("[%s:%d] Start
prio=%d\n",pcTaskGetTaskName(NULL),nowTick,prio);
for(uint32_t
count=0;count<10;count++) {
xQueueSend(xQueue,
&count, 0);
nowTick =
xTaskGetTickCount();
printf("[%s:%d]
xQueueSend\n",pcTaskGetTaskName(NULL),nowTick);
}
while(1) {
vTaskDelay(10 /
portTICK_PERIOD_MS);
}
}
void Task2(void *pvParameters) {
TickType_t nowTick;
UBaseType_t prio =
uxTaskPriorityGet(NULL);
uint32_t count;
nowTick = xTaskGetTickCount();
printf("[%s:%d] Start
prio=%d\n",pcTaskGetTaskName(NULL),nowTick,prio);
while(1) {
if(xQueueReceive(xQueue,
&count, portMAX_DELAY)) {
nowTick =
xTaskGetTickCount();
printf("[%s:%d]
xQueueReceive
count=%u\n",pcTaskGetTaskName(NULL),nowTick,count);
}
}
}
void setup()
{
TickType_t nowTick;
vTaskDelay(2000/portTICK_PERIOD_MS);
UBaseType_t prio =
uxTaskPriorityGet(NULL);
nowTick = xTaskGetTickCount();
printf("[%s:%d] Start
prio=%d\n",pcTaskGetTaskName(NULL),nowTick,prio);
printf("[%s:%d]
portTICK_PERIOD_MS=%d\n",pcTaskGetTaskName(NULL),nowTick,portTICK_PERIOD_MS);
/* 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", 4096, NULL,
1, NULL);
xTaskCreate(Task2, "Task2", 4096, NULL,
1, NULL);
/* stop main task */
nowTick = xTaskGetTickCount();
printf("[%s:%d] End
prio=%d\n",pcTaskGetTaskName(NULL),nowTick,prio);
vTaskDelete( NULL );
}
void loop() { // Never run
printf("[%s:%d]
loop\n",pcTaskGetTaskName(NULL),xTaskGetTickCount());
}
|