示例#1
0
/*************************************************************************//*!
 * \brief Drops a character into the transmit ring buffer.
 *
 * If the ring buffer is full, the function delays to allow transmission of characters to free
 * up space in buffer.  The function turns on the transmit interrupt for the USART.
 * @param usartId
 * @param cOutChar
 * @return
 */
UBaseType_t usart_xputChar(USART_ID usartId, const UBaseType_t cOutChar )
{
	// Return false if there remains no room on the Tx ring buffer
	UBaseType_t retVal = pdPASS;
	if( ! ringBuffer_IsFull( &(usartComBuf[usartId].xCharsForTx) ) )
		ringBuffer_Poke( &(usartComBuf[usartId].xCharsForTx), cOutChar ); // poke in a fast byte
	else
	{
		 // go slower, per character rate for 115200 is 86us
		_delay_us(25); // delay for about one character (maximum _delay_loop_1() delay is 32 us at 22MHz)
		_delay_us(25);
		_delay_us(25);
		_delay_us(25);

		if( ! ringBuffer_IsFull( &(usartComBuf[usartId].xCharsForTx) ) )
			ringBuffer_Poke( &(usartComBuf[usartId].xCharsForTx), cOutChar ); // poke in a byte slowly
		else
			retVal = pdFAIL; // if the Tx ring buffer remains full
	}
	xmitInterrupt_On(usartId);
	return retVal;
}
示例#2
0
inline portBASE_TYPE xSerialPutChar( xComPortHandlePtr pxPort, unsigned const portBASE_TYPE cOutChar )
{
    /* Return false if there remains no room on the Tx ring buffer */

    if( ! ringBuffer_IsFull( &(pxPort->xCharsForTx) ) )
        ringBuffer_Poke( &(pxPort->xCharsForTx), cOutChar ); // poke in a fast byte
    else
    {
        // go slower, per character rate for 115200 is 86us
        _delay_us(25); // delay for about one character (maximum _delay_loop_1() delay is 32 us at 22MHz)
        _delay_us(25);
        _delay_us(25);
        _delay_us(25);

        if( ! ringBuffer_IsFull( &(pxPort->xCharsForTx) ) )
            ringBuffer_Poke( &(pxPort->xCharsForTx), cOutChar ); // poke in a byte slowly
        else
            return pdFAIL; // if the Tx ring buffer remains full
    }

    switch (pxPort->usart)
    {
    case USART0:
        vInterrupt0_On();
        break;

    case USART1:
        vInterrupt1_On();
        break;

    case USART2:
    case USART3:
    default:
        break;
    }

    return pdPASS;
}
示例#3
0
/*************************************************************************************//*!
 *  \private Interrupt service routine for character reception.
 * Saves a received character in the receive ring buffer.  If an error occurred, nothing is done.
 * If the ring buffer is full, the character is lost.
 * @param usartId - USART id
******************************************************************************************/
void usart_rx_isr(USART_ID usartId)
{
	uint8_t cChar;

	/* Get status and data from buffer */

	/* If error bit set (Frame Error, Data Over Run, Parity), do nothing */
	if ( ! (*usartReg[usartId].ucsrAPtr & ((1<<FE0)|(1<<DOR0)|(1<<UPE0)) ) )
	{
		/* If no error, get the character and post it on the buffer of Rxed characters.*/
		cChar = *usartReg[usartId].udrPtr;

		if( ! ringBuffer_IsFull( &(usartComBuf[usartId].xRxedChars) ) )
			ringBuffer_Poke( &(usartComBuf[usartId].xRxedChars), cChar);
	}
}