src/cpu/arm/at91sam7/serialio.c
int rem_mayget(u_char *byte)
{
    // The software buffer pointer chases the hardware pointer
    // around the ring
    if (nextbyte == (u_char *) USART0(RPR))
        return 0;
    
    *byte = *nextbyte++;

    if (nextbyte == &ubuf[UBUFLEN*2])  // Wraparound
        nextbyte = &ubuf[0];

    if (US0_CSR & ENDRX) {      // Keep recycling buffer halves    
        // XXX we need something like:
        //  int offset = nextbyte - nextbuf;
        //  if (offset < 0 || offset >= UBUFLEN) {
        // but then we would have to worry about restarting
        // after an overflow (we probably should worry about
        // that anyway because the current code is not entirely
        // overflow-proof).
        USART0(RNPR) = (u_long) nextbuf;
        USART0(RNCR) = UBUFLEN;
        USART0(PTCR) = RXTEN;
        nextbuf = (nextbuf == &ubuf[0]) ? &ubuf[UBUFLEN] : &ubuf[0];
    }
    return 1;
}
// Poll for an input character from the serial line.
// If one is available store it in byte and return true.
Poll for an input character from the serial line.
If one is available store it in byte and return true.
Poll for an input character from the serial line . If one is available store it in byte and return true .
int rem_mayget(u_char *byte)
{
    if (nextbyte == (u_char *) USART0(RPR))
        return 0;
    *byte = *nextbyte++;
    if (nextbyte == &ubuf[UBUFLEN*2])  
        nextbyte = &ubuf[0];
    if (US0_CSR & ENDRX) {      
        USART0(RNPR) = (u_long) nextbuf;
        USART0(RNCR) = UBUFLEN;
        USART0(PTCR) = RXTEN;
        nextbuf = (nextbuf == &ubuf[0]) ? &ubuf[UBUFLEN] : &ubuf[0];
    }
    return 1;
}
int rem_mayget ( u_char * byte ) { if ( nextbyte == ( u_char * ) USART0 ( RPR ) ) return 0 ; * byte = * nextbyte ++ ; if ( nextbyte == & ubuf [ UBUFLEN * 2 ] ) nextbyte = & ubuf [ 0 ] ; if ( US0_CSR & ENDRX ) { USART0 ( RNPR ) = ( u_long ) nextbuf ; USART0 ( RNCR ) = UBUFLEN ; USART0 ( PTCR ) = RXTEN ; nextbuf = ( nextbuf == & ubuf [ 0 ] ) ? & ubuf [ UBUFLEN ] : & ubuf [ 0 ] ; } return 1 ; }
Poll for an input character from the serial line.
Poll for an input character from the serial line .
// The software buffer pointer chases the hardware pointer // around the ring // Wraparound // Keep recycling buffer halves     // XXX we need something like: //  int offset = nextbyte - nextbuf; //  if (offset < 0 || offset >= UBUFLEN) { // but then we would have to worry about restarting // after an overflow (we probably should worry about // that anyway because the current code is not entirely // overflow-proof).