• AVR Freaks

AnsweredHot!How to create separate events for read and write in USART dynamic driver?

Author
carmix
New Member
  • Total Posts : 30
  • Reward points : 0
  • Joined: 2013/07/23 13:32:56
  • Location: 0
  • Status: offline
2015/03/12 00:16:08 (permalink)
0

How to create separate events for read and write in USART dynamic driver?

I have an application in which I need to receive and write data simultaneously (like in Full Duplex). So in order:
I create an Usart Handle:
app.usartHandle = DRV_USART_Open(DRV_USART_INDEX_2,(DRV_IO_INTENT_READWRITE | DRV_IO_INTENT_NONBLOCKING));
Then I set up a BufferEventHandler:
DRV_USART_BufferEventHandlerSet( app.usartHandle,
                                         APP_BufferEventHandler,
                             NULL );
Then I start a BufferAddRead and a BufferAddWrite:
 
DRV_USART_BufferAddRead( app.usartHandle,
    &(app.usartBufferHandle),
            app.buffer,RDBUFFER_SIZE);

    DRV_USART_BufferAddWrite( app.usartHandle,
                                          &(app.usartBufferHandle),
                                          &wrbuffer, WRBUFFER_SIZE);
 
Now, the question is when I got an Event_Complete in the APP_BufferEventHandler, how to distinguish between a Read complete event and a Write complete event???
 
Carmix
#1
REALPIC
Junior Member
  • Total Posts : 45
  • Reward points : 0
  • Status: offline
Re: How to create separate events for read and write in USART dynamic driver? 2015/03/12 05:15:16 (permalink) ☼ Best Answerby carmix 2015/03/13 02:27:11
3 (1)
Hi carmix,
 
For your case, its better to crate two buffer handles, one for read and  other for write.
Once the buffer event is triggered, there you can distinguish read/write completion based on the buffer handles "hBufferEvent" which is been passed to the event handler :
 
void APP_BufferEventHandler(DRV_USART_BUFFER_EVENT buffEvent,
                            DRV_USART_BUFFER_HANDLE hBufferEvent,
                            uintptr_t context )
 
Please refer Harmony USART demo application for more information :
C:\Microchip\harmony\v1_03\apps\driver\usart\usart_echo

Thanks
REALPIC
#2
l1800turbo
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2015/04/30 00:20:43
  • Location: 0
  • Status: offline
Re: How to create separate events for read and write in USART dynamic driver? 2015/05/07 10:25:04 (permalink)
0
Hello,
 
I have a similar problem, but I don't know which information I should take out of the "usart_echo" demo.
The demo uses to different context vars, but only one buffer handler. In the manual I see that it identifies the corresponding read or write buffer, but I see no way of actually identifying it when I'm at the bufferEvent.
 
Can you show a small example of it?
 
EDIT:
If found an example in the bluetooth examples:
/**********************************************************
 * Application USART buffer Event handler.
 * This function is called back by the USART driver when
 * a USART data buffer TX/RX completes.
 ***********************************************************/
void APP_USARTBufferEventHandler(DRV_USART_BUFFER_EVENT event,
        DRV_USART_BUFFER_HANDLE handle, uintptr_t context )
{
    switch(event)
    {
        case DRV_USART_BUFFER_EVENT_COMPLETE:
        {
            if(handle == appData.usartClient.writeBufHandle)
            {
                bttask_setSignal(BTTASK_SIG_TX);
            }
            if(handle == appData.usartClient.readBufHandle)
            {
                bttask_setSignal(BTTASK_SIG_RX);
            }
        }
        break;
        case DRV_USART_BUFFER_EVENT_ERROR:
        {
        } break;

        case DRV_USART_BUFFER_EVENT_ABORT:
        {
        } break;

    }
}

 
One thing is still unclear:
I want to get answers for AT commands from a modem. I use some buffer size and start a 'DRV_USART_BufferAddRead' to collect data. The answers finish with '\r\n'. How do I get to know when this happens and I can parse this line instead of waiting until the buffer is full?
 
Thanks
post edited by l1800turbo - 2015/05/07 11:09:27
#3
epareja
Super Member
  • Total Posts : 380
  • Reward points : 0
  • Joined: 2003/11/07 12:53:08
  • Location: Colombia
  • Status: offline
Re: How to create separate events for read and write in USART dynamic driver? 2020/02/27 07:29:19 (permalink)
0
l1800turbo
 
One thing is still unclear:
I want to get answers for AT commands from a modem. I use some buffer size and start a 'DRV_USART_BufferAddRead' to collect data. The answers finish with '\r\n'. How do I get to know when this happens and I can parse this line instead of waiting until the buffer is full?
 
Thanks




Hello, after 5 years of your question.... I have the same doubt. When receiving a variable length data, how the event handler of the receive buffer is triggered? 


Ernesto Pareja J
www.dcctrains.netne.net

#4
Jump to:
© 2020 APG vNext Commercial Version 4.5