I would like to use the Harmony USART driver on a PIC32MX695F512H using interrupts and with buffer support. After setting the appropriate settings in the MPLAB Harmony Configurator, the system has generated the ISR for me (system_interrupt.c
):
void __ISR(_UART_2_VECTOR, ipl1AUTO) _IntHandlerDrvUsartInstance0(void) {
DRV_USART_TasksTransmit(sysObj.drvUsart0);
DRV_USART_TasksReceive(sysObj.drvUsart0);
DRV_USART_TasksError(sysObj.drvUsart0);
}
Since this is a generated file, I assume I'm not supposed to edit it. But if this is the ISR, how can I make sure my code will be executed on an RX interrupt. I want to receive the received data in a function that I am supposed to edit.
As I understand it, that is what the buffer event handler is for. So I can do the following (this code is highly simplified):
void APP_BufferEventHandler(DRV_USART_BUFFER_EVENT bufferEvent,
DRV_USART_BUFFER_HANDLE bufferHandle, uintptr_t context) {
switch (bufferEvent) {
case DRV_USART_BUFFER_EVENT_COMPLETE:
// @todo
break;
case DRV_USART_BUFFER_EVENT_ERROR:
appData.state = APP_ERROR;
break;
case DRV_USART_BUFFER_EVENT_ABORT:
appData.state = APP_ERROR;
break;
}
}
//... in APP_Tasks somewhere:
appData.usartHandle = DRV_USART_Open(DRV_USART_INDEX_0,
DRV_IO_INTENT_READWRITE | DRV_IO_INTENT_NONBLOCKING);
DRV_USART_BufferEventHandlerSet(appData.usartHandle,
APP_BufferEventHandler, 0);
My questions are:
- Is this actually the right way to make sure
APP_BufferEventHandler
is called on an RX interrupt? - How can I distinguish between an RX and a TX event in the event handler, if the event is one of
COMPLETE
,ERROR
andABORT
?