Using an auto-reset event

The following example demonstrates how to utilize an auto-reset event object to signal the occurrence of an interrupt to a waiting task.

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


HANDLE EventHandle;


void InterruptHandler(void)
{
  /* Notify task */
  osSetEvent(EventHandle);
}


ERROR MainTask(PVOID Arg)
{
  /* Mark parameter as unused */
  AR_UNUSED_PARAM(Arg);

  /* Infinite loop */
  while(1)
  {
    /* Wait for interrupt occurrence */
    osWaitForObject(EventHandle, OS_INFINITE);
    printf("Interrupt has been received.\n");
  }
}


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

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

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

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

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