martedì 5 marzo 2019

Queue con FreeRTOS su Arduino Uno

Le Queue, code, di FreeRTOs sono metodi per scambiare dati tra due task. In questo esempio una coda monodirezionale (un task invia dati e l'altro li riceve)


-----------------------------------------------------------------
#include <Arduino_FreeRTOS.h>
#include <queue.h>  

QueueHandle_t coda;
int codasize = 10;

void sender( void *pvParameters );
void receiver( void *pvParameters );

void setup() {

  Serial.begin(9600);
  coda = xQueueCreate(codasize,sizeof(int));
  
  if ( coda == NULL )   {
     Serial.println("Errore nella creazione");
  }

  xTaskCreate(sender,(const portCHAR *)"Sender",128,NULL,3,NULL);
  xTaskCreate(receiver,(const portCHAR *)"Receiver",128,NULL,2,NULL);

}

void loop()
{
}



void sender( void *pvParameters __attribute__((unused)) )  // This is a Task.
{
  for (;;)
  {
    for (int t=0;t<5;t++){
      xQueueSend(coda,&t,portMAX_DELAY);
    }
    vTaskDelay( 1000 / portTICK_PERIOD_MS );

  }
}


void receiver( void *pvParameters __attribute__((unused)) )  
{
  int elemento;
  for (;;)
  {
    for (int t=0;t<codasize;t++){
      xQueueReceive(coda,&elemento,portMAX_DELAY);
      Serial.print(elemento);
      Serial.print("|");
    }
    Serial.println();

    vTaskDelay( 1000 / portTICK_PERIOD_MS );
  }
}

Nessun commento:

Posta un commento

Unmixing iperspettrale di campioni di terreno naturale

Aggiornamento Ho trovato che USGS Spectral library mette a disposizione anche degli spettri Fieldspec (2151 bande da 350 a 2500 nm) di campi...