This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/CC2642R: Seconds_getTime() call in UART Rx Callback

Part Number: CC2642R

Tool/software: TI C/C++ Compiler

Dear All
I'm using the CC2642R with UART, I need to measure accurately when the UART Rx data arrive.
I tried to call Seconds_getTime() in the UART Rx callback but it seems to cause problems, the timestamp I obtain from Seconds_getTime in release mode does not seem correct.
When I try to debug with printf() the timestamp I obtain, the execution hangs.

I suspect this function cannot be called from the interrupt, is there a way to solve this ?

My code is as follow :

void MidiUART_readCallBack(UART_Handle handle, void *ptr, size_t size)
{
    if(size > 0)
    {
        Seconds_Time ts; Seconds_getTime(&ts);
        uint32_t currentTimeStamp = ((ts.secs & 15) * 1000) + (ts.nsecs / 1000000);
        uint32_t timePassedSinceLatestRxMidi = currentTimeStamp - latestRxMidiTimeStampReceived;

        //Display_printf(dispHandle, currentLogLine++, 0, "ts %u", currentTimeStamp);

        latestRxMidiTimeStampReceived = currentTimeStamp;

        .......

        Semaphore_post(hSemaphoreMidiRx);

        // Trigger next RX Midi read
        UART_read(uartMidi, &lowLevelRxBuff[0], LOW_LEVEL_MIDI_BUFF_SIZE);
}


void midiRxTask(UArg a0, UArg a1)
{
    Semaphore_Params sParams;
    Semaphore_Params_init(&sParams);
    sParams.mode = Semaphore_Mode_COUNTING; // Semaphore_Mode_BINARY;
    Semaphore_construct(&semaphoreMidiRx, 0, &sParams);
    hSemaphoreMidiRx = Semaphore_handle(&semaphoreMidiRx);

    // trigger first read
    UART_read(uartMidi, &lowLevelRxBuff[0], LOW_LEVEL_MIDI_BUFF_SIZE );

    while(1)
    {
        // Wait until something was received
        Semaphore_pend(hSemaphoreMidiRx, BIOS_WAIT_FOREVER);

        ......

    }
}

I'm using UART PARTIAL READ.

Thanks for any tip
Jerome

  • Hi Jerome,

    You are correct in that function calls and lengthy calculations should not be performed inside a callback, please only raise a flag or set an event before posting the semaphore and exiting the callback.  You can then process the required information immediately after the semaphore pend instruction.

    Regards,
    Ryan