include <stdio.h>
include <windows.h>
/* Kernel includes. */include “FreeRTOS.h”
include “task.h”
static HANDLE gThread;define INTERRUPT_ID 0x11
TaskHandle_t gFreeRtosTaksHandler; uint32_t myISR(void) {BaseType_t xHigherPriorityTaskWoken = pdFALSE;
/* Unblock the handling task so the task can perform any processing
necessitated by the interrupt. xHandlingTask is the task's handle, which was
obtained when the task was created. vTaskNotifyGiveFromISR() also increments
the receiving task's notification value. */
vTaskNotifyGiveFromISR(gFreeRtosTaksHandler, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
DWORD WINAPI someThread(void* data) {
DWORD dwError;
if (!SetThreadPriority(GetCurrentThread(), THREADPRIORITYTIMECRITICAL))
{
dwError = GetLastError();
printf(“error (%d)n”, dwError);
return -1;
}
Sleep(1000);
while (1) {
myISR(); // a direct call of the myISR does not lead to an task notification
//vPortGenerateSimulatedInterrupt(INTERRUPTID); // this is working
Sleep(1000);
}
return 0;
}
void freeRtosTask(void *pvParameters)
{const TickType_t xBlockTime = 5000000; uint32_t ulNotifiedValue;
for (;; )
{
ulNotifiedValue = ulTaskNotifyTake(pdTRUE,
xBlockTime);
// HERE's the problem: I am NOT receiving any notification when myISR is directly called
printf("Hallon");
}
}
int main(void)
{
gThread = CreateThread(NULL, 0, someThread, NULL, 0, NULL);
xTaskCreate(freeRtosTask, /* The function that implements the task. /
“foo”, / The text name assigned to the task – for debug only as it is not used by the kernel. /
configMINIMAL_STACK_SIZE, / The size of the stack to allocate to the task. /
NULL, / The parameter passed to the task – not used in this simple case. /
tskIDLE_PRIORITY + 5,/ The priority assigned to the task. /
&gFreeRtosTaksHandler); / The task handle is not required, so NULL is passed. */
vPortSetInterruptHandler(INTERRUPT_ID, myISR);
vTaskStartScheduler();
for (;; );
}
~~~
When I am using in the “someThread” function the vPortGenerateSimulatedInterrupt call, the notification is received. But when I do a direct call of my ISR in the “someThread” function the notification is not received.
I did not yet dive in the debugging but I’d like to have some feedback about this concept from the community. IMHO the direct call is closer to the real use case when working on an microcontroller but I am not sure about that nor do I know if my code can work.
Any hints and comments are very appreciated.
Thanks
Matthias