Using a queue

The following example shows how to use a queue to notify a task to process the received interrupts in order to the interrupt occurrence.

#include <stdio.h>
#include "OS_API.h"


HANDLE QueueHandle;


void InterruptHandler(int VectID)
{
  /* Send the vector ID to the processing task. The vector IDs are queued in
     order to occurrence time */
  if(osQueuePost(QueueHandle, &VectID))
  {
    /* Failure: queue is full */
    /* ... */
  }
}


ERROR MainTask(PVOID Arg)
{
  int VectID;

  /* Mark parameter as unused */
  AR_UNUSED_PARAM(Arg);

  /* Infinite loop */
  while(1)
  {
    /* Receive the vector ID */
    osQueuePend(QueueHandle, &VectID);

    /* Process the interrupt */
    printf("Processing the %i interrupt.\n", VectID);
    switch(VectID)
    {
      case 0:
        /* ... */
        break;

      case 1:
        /* ... */
        break;

      case 2:
        /* ... */
        break;

      /* ... */
    }
  }
}


int main(void)
{
  /* Initialization */
  arInit();
  stInit();
  osInit();

  /* Create queue with buffer for 32 messages */
  QueueHandle = osCreateQueue(NULL,
    OS_IPC_WAIT_IF_EMPTY | OS_IPC_DIRECT_READ_WRITE, 32, sizeof(int));

  /* Create main task */
  osCreateTask(MainTask, NULL, 0, 0, FALSE);

  /* Setup the interrupt handler */
  /* ... */

  /* Start the operating system */
  osStart();

  /* Deinitialization */
  osDeinit();
  arDeinit();
  return 0;
}
SpaceShadow documentation