Good Afternoon All,
I'm doing some embedded programming with Microchip Harmony 3 and for the first time i've come accross a callback whilst trying to read and write to a serial port.
Harmony has placed the following structure in the code but i'm not quite sure of its purpose. Any pointers (excuse the pun) would be appreciated.
The read serial interrupt handler also has this code auto generated which from first glance doesn't seem to do any reading of the port so some clarification of how this is to be used would be appreciated.
Thanks in advance
I'm doing some embedded programming with Microchip Harmony 3 and for the first time i've come accross a callback whilst trying to read and write to a serial port.
Harmony has placed the following structure in the code but i'm not quite sure of its purpose. Any pointers (excuse the pun) would be appreciated.
Code:
typedef struct
{
uint8_t * txBuffer;
size_t txSize;
size_t txProcessedSize;
UART_CALLBACK txCallback;
uintptr_t txContext;
bool txBusyStatus;
uint8_t * rxBuffer;
size_t rxSize;
size_t rxProcessedSize;
UART_CALLBACK rxCallback;
uintptr_t rxContext;
bool rxBusyStatus;
} UART_OBJECT ;
Code:
static void UART2_RX_InterruptHandler (void)
{
if(uart2Obj.rxBusyStatus == true)
{
while((_U2STA_URXDA_MASK == (U2STA & _U2STA_URXDA_MASK)) && (uart2Obj.rxSize > uart2Obj.rxProcessedSize) )
{
uart2Obj.rxBuffer[uart2Obj.rxProcessedSize++] = (uint8_t )(U2RXREG);
}
/* Clear UART2 RX Interrupt flag */
IFS1CLR = _IFS1_U2RXIF_MASK;
/* Check if the buffer is done */
if(uart2Obj.rxProcessedSize >= uart2Obj.rxSize)
{
uart2Obj.rxBusyStatus = false;
/* Disable the fault interrupt */
IEC1CLR = _IEC1_U2EIE_MASK;
/* Disable the receive interrupt */
IEC1CLR = _IEC1_U2RXIE_MASK;
if(uart2Obj.rxCallback != NULL)
{
uart2Obj.rxCallback(uart2Obj.rxContext);
}
}
}
else
{
// Nothing to process
;
}
}
Last edited: