#include "FreeRTOS.h" #include "task.h" #include "semphr.h" xSemaphoreHandle xBinarySemaphore; void vHandlerTask(void *p) { for( ;; ) { xSemaphoreTake(xBinarySemaphore, portMAX_DELAY ); printf("Handler task - Processing event.\n"); } } void vPeriodicTask(void *p) { for( ;; ) { vTaskDelay( 500 / portTICK_RATE_MS ); printf("Perodic task - About to generate an interrupt.\n"); vPortGenerateSimulatedInterrupt(3); printf("Periodic task - Interrupt generated.\n\n\n"); } } uint32_t ExampleISR(void) { portBASE_TYPE xHigherPriorityTaskWoken=0; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken ); if(xHigherPriorityTaskWoken) { return pdTRUE; } else return pdFALSE; } int Example5( void ) { xBinarySemaphore=xSemaphoreCreateBinary(); vPortSetInterruptHandler(3,ExampleISR); xTaskCreate( vHandlerTask,"Handler", 1000, NULL,3 , NULL ); xTaskCreate( vPeriodicTask,"Periodic", 1000, NULL, 1, NULL ); vTaskStartScheduler(); for( ;; ); return 0; }