Figure 1122 Buffered serial IO receiving bytes

Application Interface

TimeOTt [^-^TRinqBufRxOutPtr

TimeOTt [^-^TRinqBufRxOutPtr

].RingBufRxCtr

COMMRTOS Module

Figure 11.22 shows a flow diagram for data reception using the COMMRTOS module and how COMMRTOS interfaces with the COMM_PC module. Your application still calls CommGetChar () except that your task will be suspended if the buffer is empty. You can specify to CommGetChar () a time-out value to prevent suspending your application task forever. When a byte is received, your task will "wake-up" and will receive the byte from the serial port.

CommPutRxChar () is an interface function between the COMMRTOS module and the COMM_PC module. The COMM_PC module calls this function when a byte is received. CommPutRxChar () deposits the byte into the receive ring buffer but only if the buffer is not already full. The byte is discarded if the buffer is full. When the byte is inserted in the buffer, CommPutRxChar () signals the data reception semaphore to indicate to any pending task that data was received.

To prevent suspending your application code, you can find out whether there are bytes in the ring buffer by calling CommlsEmpty ().

Figure 11.23 shows a flow diagram for data transmission using the COMMRTOS module and how it interfaces with the COMM_PC module. Again, everything is identical to the COMMBGND module except for the semaphore. When you want to send data to a serial port, CommPutChar () waits for the semaphore. Because the transmit semaphore is initialized to the size of the buffer when the COMMRTOS module is initialized, CommPutChar () will suspend your application code when there is no more room in the buffer. The suspended task will resume as soon as the UART catches up sending the bytes.

Was this article helpful?

0 0

Post a comment