Resuming task from interrupt

The following example shows how to resume a suspended task, to immediately notify the interrupt occurrence.

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


HANDLE TaskHandle;


void InterruptHandler(void)
{
  /* Resume task after receiving interrupt */
  osResumeTask(TaskHandle);
}


ERROR MainTask(PVOID Arg)
{
  TIME TaskStart;

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

  /* Task startup time */
  TaskStart = arGetTickCount();

  /* Infinite loop (catch all interrupts) */
  while(1)
  {
    /* Suspend current task and wait for interrupt */
    osSuspendTask(TaskHandle);

    /* Task has been resumed by interrupt handler */
    printf("Interrupt after %i msec.\n",
      (arGetTickCount() - TaskStart) * 1000 / AR_TICKS_PER_SECOND);
  }
}


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

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

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

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

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