Exemplo n.º 1
0
/**
 * Send the given byte to the USART. It is added to the transmit buffer, and asynchronously
 * transmitted.
 *
 * @param c     Byte to write out on the serial port
 */
void serPutByte(BYTE c) {
    //Check if buffer is full.
    #ifdef SER_WAIT_FOR_TXBUF
    //Wait until a byte is transmitted by the interrupt routine and buffer has place again.
    while (busIsTxBufFull(BUSID)) {
        FAST_USER_PROCESS();
    }
    #else
    if (busIsTxBufFull(BUSID)) {
        serStat |= SER1_TXBUF_OVERRUN;
        return;
    }
    #endif

    //Enter critical section
    DISBALE_INTERRUPTS();

    //If we are not currently TXing, the TX buffer will be empty. No need to transmit via buffer,
    //just write direct to TXREG
    if ( !PIE1_TXIE)
    {
        TXREG = c;      //Send byte
        PIE1_TXIE = 1;  //Indicate that we are currently TXing
        ENABLE_INTERRUPTS();
    }
    //We are currently TXing. This means that the TXIF will soon be set after the current byte
    //has been transmitted, and the TX buffer will be checked for any unsent data. Add current
    //byte to TX buffer.
    else {
        //Add byte to TX buffer, and update buffer pointers
        busPutByteTxBuf(BUFID, c);
        
        ENABLE_INTERRUPTS();
    }
}
Exemplo n.º 2
0
void serPutByte( BYTE c ) 
{

#ifdef SER_WAIT_FOR_TXBUF

    // Check if buffer is full. If this is the case, wait until a byte is transmitted by the
    // interrupt routine and buffer has place again.
    while ( ( ( idxSerTxbufPut + 1 ) & SER_TXBUF_MASK ) == idxSerTxbufGet ) {
        CLRWDT();
    }

#endif

    // Enter critical section
    DISBALE_INTERRUPTS();

    // If we are not currently transmitting, the TX buffer will be empty. 
    // 	No need to transmit via buffer,
    // just write direct to TXREG
    if ( !PIE1_TXIE ) {
        TXREG = c;      // Send byte
        PIE1_TXIE = 1;  // Indicate that we are currently TXing
        ENABLE_INTERRUPTS();
    }
    // We are currently trsanmitting. This means that the TXIF will soon be set after the current byte
    // has been transmitted, and the TX buffer will be checked for any unsent data. Add current
    // byte to TX buffer.
    else {
        // Seeing that an TX interrupt can happen any time during this function, only update idxTxbufPut
        // at the end of the routine
        txBuf[ idxSerTxbufPut ] = c;

        idxSerTxbufPut = ( ++idxSerTxbufPut ) & SER_TXBUF_MASK;
        ENABLE_INTERRUPTS();
    }
}