Possible Duplicate:
UART ISR Tx Rx Architecture
I'm working with a TI micro right now that includes a DMA UART Driver and an operating system that supports parallel tasks. The UART driver's functions include:
- static void HalUARTInitDMA(void);
- static void HalUARTOpenDMA(halUARTCfg_t *config);
- static uint16 HalUARTReadDMA(uint8 *buf, uint16 len);
- static uint16 HalUARTWriteDMA(uint8 *buf, uint16 len);
- static void HalUARTPollDMA(void);
- static uint16 HalUARTRxAvailDMA(void);
- static void HalUARTSuspendDMA(void);
- static void HalUARTResumeDMA(void);
I'm trying to communicate with another peripheral that accepts messages terminated with a carriage return and responds with messages afterwards with a carriage return.
I was curious what the best way to architect this type of communication state machine. My problem is designing the callback function for the UART port such that it...
- does not hang the system waiting for a response. (Some sort of timeout)
- If a response is read too soon, it will concat the responses together
- A carriage return will signify the end of the message
The basic theory is something like this:
//send messsage to peripheral
HalUARTWriteDMA("tx\r",4);
//wait a little bit for the device to process the message
//start reading from the peripheral
do {
//how many bytes are at the RX port?
int len = HalUARTRxAvailDMA();
//Read those bytes
HalUARTReadDMA(msg, len);
//append the rx msg to the buffer
strcat(rxbuf, msg)
//does the response contain a CR?
} while(strchr(rxbuf, 0x0D));
There are a couple of obvious flaws with this idea. I was hoping someone could share some ideas on how this type of communication is performed?
Thanks!