Passing TaskHandle_t references to other classes from Main

Hi,

I have a range of classes which make use of DMA transfers. I have a single DMA interrupt handler in my main.c file, which passes Task Notifications to the relevant task for processing. Each of these tasks is in an external class, with each of the external classes being initialised from main.c from the vApplicationDaemonTaskStartupHook() function.

I’m unsure how to create each of the TaskHandle_t references in main.c, and pass them to each of the external classes, such that I can use the reference in the main.c interrupt handler and receive the notification in the external class.

Below is the general approach:

main.c:

TaskHandle_t classATaskHandle;

void MainInterrupt(void)
{
    BaseType_t higherPriorityTaskWoken = pdFALSE;

    If (someCondition) {
    
        xTaskNotifyIndexedFromISR(classATaskHandle, 0x00, 0x01, eSetBits, &higherPriorityTaskWoken);
    }

    portYIELD_FROM_ISR(higherPriorityTaskWoken);
}

void vApplicationDaemonTaskStartupHook(void)
{
    initialiseClassA(CLASS_A_STACK_SIZE, CLASS_A_PRIORITY, classATaskHandle);
}

ClassA.c:

void initialiseClassA(uint16_t stackSize, BaseType_t priority, TaskHandle_t taskHandle)
{
    //Initialise the class here...
    classAStackSize = stackSize;

    xTaskCreate(ClassA, "ClassAProcessing", classAStackSize, NULL, priority + 1, &taskHandle);
}

The above is obviously a very simplified, condensed illustration, but hopefully it demonstrates what I’m trying to achieve. Establishing a TaskHandle_t in main, which can be used to send Task Notifications from the main.c interrupt handler to each of the classes initialised from main.c.

Any guidance would be greatly appreciated as always!

If vApplicationDaemonTaskStartupHook() is also in main.c, can initialiseClassA() return the handle?

1 Like

Ah very good point, yes the startup hook is also in main.c. I’ll give that a go now, thanks Richard!

Thanks again Richard, that works perfectly.