
/* ////////////////////////////////////////////////////////////////////////////
                                  CharAvail()
                                   GetChar()
///////////////////////////////////////////////////////////////////////////////
DESCRIPTION:    CharAvail() indicates whether or not unread data has
                accumulated in the input buffer.  GetChar() waits for such data
                and returns the oldest character in the buffer.

REVISIONS:      27 Dec 06 - RAC - Adapted from the old kbhit() and getch()
                                   functions
//////////////////////////////////////////////////////////////////////////// */

char CharAvail(char ID) {                       /* The buffer contains data */
    return uarts[ID].rxIn !=                    /*  if the in and out */
           uarts[ID].rxOut;                     /*  indexes are different */
    }                                           /* End CharAvail() */

/* ///////////////////////////////////////////////////////////////////////// */

char GetChar(char ID) {

    char        rv;                             /* Put return character here */

    while (!CharAvail(ID)) ;                    /* Wait for a character */
    rv = uarts[ID].rxBuff[uarts[ID].rxOut++];   /* Grab byte from rx buffer */
    if (uarts[ID].rxOut == uarts[ID].buffSize) { /* Just reached buffer end */
        uarts[ID].rxOut = 0;                    /* Wrap to the beginning */
        }                                       /* End 'reached buffer end' */
    return rv;                                  /* The answer */
    }                                           /* End getch() */
