Embedded Systems Building Blocks, Second Edition

The COMMBGND module allows data received from and sent to a UART to be buffered. Specifically, you would use the COMMBGND module if you write an application destined for a foreground/background environment. The COMMBGND module is designed to work in conjunction with the COMM_PC module described in the previous section. COMMBGND allows you to do full-duplex communication on either serial port (concurrently). The source code for the COMMBGND module is found in the \SOFTWARE\BLOCKS\COMM\SOURCE directory and specifically, in COMMBGND.C (Listing 11.4) and COMMBGND.H (Listing 11.5).
| Warning | In the previous edition of this book, COMMBGND was called COMMBUF1. The file COMMBUF1.C is now COMMBGND.C and, COMMBUF1.H is now COMMBGND.H. |
As a convention, all functions and variables related to the COMMBGND module start with Comm while all #define constants start with COMM_.
Each serial port is assigned two ring buffers: one for byte reception and another for byte transmission. Both ring buffers are stored in a structure called COMM_RING_BUF (see COMMBGND.C on page 473). Each ring buffer consists of four elements:
storage for data (an array of INT8Us)
a counter containing the number of bytes in the ring buffer
a pointer where the next byte will be placed in the ring buffer
a pointer where the next byte will be extracted from the ring buffer
Figure 11.20 shows a flow diagram for data reception...