Skip to content

xSemaphoreGiveFromISR replacing timerflags or tasks which need to wait on interrupts #63

Description

@TZlindra
#define BUFFER_SIZE 16
uint16_t bufferA[BUFFER_SIZE];
uint16_t bufferB[BUFFER_SIZE];
uint16_t *isrBuffer = bufferA;
uint16_t *taskBuffer = bufferB;
SemaphoreHandle_t bufferReadySem;

// ISR
void ADC_IRQHandler(void)
{
    static uint8_t index = 0;
    isrBuffer[index++] = ReadADC();

    if(index >= BUFFER_SIZE)
    {
        index = 0;

        // Swap buffers safely
        uint16_t *temp = taskBuffer;
        taskBuffer = isrBuffer;
        isrBuffer = temp;

        // Signal task that new buffer is ready
        BaseType_t xHigherPriorityTaskWoken = pdFALSE;
        xSemaphoreGiveFromISR(bufferReadySem, &xHigherPriorityTaskWoken);
        portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
    }
}

// Task
void DataProcessingTask(void *pvParameters)
{
    for(;;)
    {
        xSemaphoreTake(bufferReadySem, portMAX_DELAY);
        ProcessData(taskBuffer, BUFFER_SIZE);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions