Serial.begin(112500);
queue = xQueueCreate( queueSize, sizeof( int ) );
if(queue == NULL){
Serial.println("Error creating the queue");
}
xTaskCreate(
producerTask, /* Task function. */
"Producer", /* String with name of task. */
10000, /* Stack size in words. */
NULL, /* Parameter passed as input of the task */
10, /* Priority of the task. */
NULL); /* Task handle. */
xTaskCreate(
consumerTask, /* Task function. */
"Consumer", /* String with name of task. */
10000, /* Stack size in words. */
NULL, /* Parameter passed as input of the task */
10, /* Priority of the task. */
NULL); /* Task handle. */
producingTime = endProducing - startProducing;
Serial.println(producingTime);
consumingTime = endConsuming - startConsuming;
Serial.println(consumingTime);
void producerTask( void * parameter )
{
startProducing = millis();
for( int i = 0;i<queueSize;i++ ){
xQueueSend(queue, &i, portMAX_DELAY);
}
endProducing = millis();
vTaskDelete( NULL );
}
void consumerTask( void * parameter)
{
startConsuming = millis();
int element;
for( int i = 0;i<queueSize;i++ ){
xQueueReceive(queue, &element, portMAX_DELAY);
}
endConsuming = millis();
vTaskDelete( NULL );
}
QueueHandle_t queue;
int queueSize = 10000;
unsigned long startProducing, endProducing, startConsuming, endConsuming, producingTime, consumingTime;
void setup() {
Serial.begin(112500);
queue = xQueueCreate( queueSize, sizeof( int ) );
if(queue == NULL){
Serial.println("Error creating the queue");
}
xTaskCreate(
producerTask, /* Task function. */
"Producer", /* String with name of task. */
10000, /* Stack size in words. */
NULL, /* Parameter passed as input of the task */
10, /* Priority of the task. */
NULL); /* Task handle. */
xTaskCreate(
consumerTask, /* Task function. */
"Consumer", /* String with name of task. */
10000, /* Stack size in words. */
NULL, /* Parameter passed as input of the task */
10, /* Priority of the task. */
NULL); /* Task handle. */
producingTime = endProducing - startProducing;
Serial.print("Producing time: ");
Serial.println(producingTime);
consumingTime = endConsuming - startConsuming;
Serial.print("Consuming time: ");
Serial.println(consumingTime);
}
void loop() {
delay(100000);
}
void producerTask( void * parameter )
{
startProducing = millis();
for( int i = 0;i<queueSize;i++ ){
xQueueSend(queue, &i, portMAX_DELAY);
}
endProducing = millis();
vTaskDelete( NULL );
}
void consumerTask( void * parameter)
{
startConsuming = millis();
int element;
for( int i = 0; i<queueSize; i++ ){
xQueueReceive(queue, &element, portMAX_DELAY);
}
endConsuming = millis();
vTaskDelete( NULL );
}
Figure 1 – Output of the FreeRTOS queues performance analysis program.