Skip to Content
Programming Embedded Systems in C and C++
book

Programming Embedded Systems in C and C++

by Michael Barr
January 1999
Beginner to intermediate
200 pages
7h 43m
English
O'Reilly Media, Inc.
Content preview from Programming Embedded Systems in C and C++
136 Chapter 9: Putting It All Together
The receive method getchar is similar to putchar. It starts by checking if the
receive buffer is empty. If so, an error code is returned. Otherwise, one byte of
data is removed from the receive buffer and returned to the caller. The gets
method calls getchar repeatedly until either a newline character is found or there
is no more data available at the serial port. It then returns whatever string was
found up to that point. The code for both of these methods follows:
/**********************************************************************
*
* Method: getchar()
*
* Description: Read one character from the serial port.
*
* Notes:
*
* Returns: The next character found on this input stream.
* -1 is returned in the case of an error.
*
**********************************************************************/
int
SerialPort::getchar(void)
{
int c;
if (pRxQueue->isEmpty())
{
return (-1); // There is no input data available.
}
int rxStalled = pRxQueue->isFull();
//
// Read the next byte out of the receive FIFO.
//
c = pRxQueue->remove();
//
// If the receive engine is stalled, restart it.
//
if (rxStalled)
{
scc.rxStart(channel);
}
return (c);
} /* getchar() */
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

You might also like

Embedded Systems Object-Oriented Programming in C and C++

Embedded Systems Object-Oriented Programming in C and C++

Israel Gbati

Publisher Resources

ISBN: 1565923545Catalog PageErrata