• AVR Freaks

Hot!USART Harmony 3 removed functionalities from Harmony 2?

Author
lcitos
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2019/07/01 10:58:01
  • Location: 0
  • Status: offline
2019/08/22 06:23:00 (permalink)
0

USART Harmony 3 removed functionalities from Harmony 2?

Hi!
 
I'm implementing a UART code and notice that there are some functions that exist on Harmony 2 but not in Harmony 3 like these:
  • DRV_USART_ByteTransmitCallbackSet( DRV_USART_INDEX_0, USART_4_TransmitEventHandler );
  • DRV_USART_ByteReceiveCallbackSet( DRV_USART_INDEX_0, USART_4_ReceiveEventHandler );
  • DRV_USART_ByteErrorCallbackSet( DRV_USART_INDEX_0, USART_4_ErrorEventHandler );
Harmony 3 framework only implemented a single callback for received/transmited buffer with DRV_USART_BufferEventHandlerSet. This means I can't send and receive at the same time with async functions.
 
With harmony 3 a few problems arrise between DRV_USART_WriteBufferAdd and DRV_USART_ReadBufferAdd , for example:
  • while sending some data through DRV_USART_WriteBufferAdd how can I know if there's something to read meanwhile?
  • If I call DRV_USART_ReadBufferAdd (expecting to receive something in the future) then I can't call DRV_USART_WriteBufferAdd while not really receiving data.
 
So, how I can maintain a proper sending/receive task if harmony does not exposes more functionalities ?
 
#1

1 Reply Related Threads

    vgandhi
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2016/10/24 21:28:35
    • Location: 0
    • Status: offline
    Re: USART Harmony 3 removed functionalities from Harmony 2? 2019/08/28 21:44:11 (permalink)
    0
    You can submit a UART read and write requests simultaneously, even with a single callback. When the UART read or write request is complete, the UART driver will call the registered callback passing the buffer handle as one of the arguments to the callback function. To figure out whether the callback is called for a read or a write, the application can compare the buffer handle received in the callback with the buffer handle that was saved when submitting the UART read/write request. 
    For example:


    static void APP_USARTBufferEventHandler(
        DRV_USART_BUFFER_EVENT bufferEvent,
        DRV_USART_BUFFER_HANDLE bufferHandle,
        uintptr_t context
    )
    {
        switch(bufferEvent)
        {
            case DRV_USART_BUFFER_EVENT_COMPLETE:
                if (bufferHandle == appData.writeBufferHandle)
                {
                    // This means the USART write request corresponding to
                    // the appData.writeBufferHandle is complete.
                }
                else if (bufferHandle == appData.readBufferHandle)
                {
                    // This means the USART read request corresponding to
                    // the appData.readBufferHandle is complete.
                }
                appData.transferStatus = true;

                break;

            case DRV_USART_BUFFER_EVENT_ERROR:
                appData.state = APP_STATE_ERROR;
                break;

            default:
                break;
        }
    }

    // Register an event handler
    DRV_USART_BufferEventHandlerSet(appData.usartHandle, APP_USARTBufferEventHandler, 0);

    // Submit a USART write request
    DRV_USART_WriteBufferAdd(appData.usartHandle, (void*)messageBuffer, strlen(messageBuffer), &appData.writeBufferHandle);
    if (appData.writeBufferHandle == DRV_USART_BUFFER_HANDLE_INVALID)
    {
        //Handle error here
    }

    // Submit a USART read request
    DRV_USART_ReadBufferAdd(appData.usartHandle, appData.readBuffer, APP_DATA_SIZE, &appData.readBufferHandle);
    if (appData.readBufferHandle == DRV_USART_BUFFER_HANDLE_INVALID)
    {
        //Handle error here
    }

    post edited by vgandhi - 2019/08/28 21:46:30
    #2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5