/*******************************************************************************
* Function Name: UART_1_SendBreak
********************************************************************************
*
* Summary:
* Write a Break command to the UART
*
* Parameters:
* uint8 retMode: Wait mode,
* 0 - Initialize registers for Break, sends the Break signal and return
* imediately.
* 1 - Wait until Break sending is complete, reinitialize registers to normal
* transmission mode then return.
* 2 - Reinitialize registers to normal transmission mode then return.
* 3 - both steps: 0 and 1
* init registers for Break, send Break signal
* wait until Break sending is complete, reinit registers to normal
* transmission mode then return.
*
* Return:
* None.
*
* Global Variables:
* UART_1_initVar - checked to identify that the component has been
* initialized.
* tx_period - static variable, used for keeping TX period configuration.
*
* Reentrant:
* No.
*
* Theory:
* SendBreak function initializes registers to send 13-bit break signal. It is
* important to return the registers configuration to normal for continue 8-bit
* operation.
* Trere are 3 variants for this API usage:
* 1) SendBreak(3) - function will send the Break signal and take care on the
* configuration returning. Funcition will block CPU untill transmition
* complete.
* 2) User may want to use bloking time if UART configured to the low speed
* operation
* Emample for this case:
* SendBreak(0); - init Break signal transmition
* Add your code here to use CPU time
* SendBreak(1); - complete Break operation
* 3) Same to 2) but user may want to init and use the interrupt for complete
* break operation.
* Example for this case:
* Init TX interrupt whith "TX - On TX Complete" parameter
* SendBreak(0); - init Break signal transmition
* Add your code here to use CPU time
* When interrupt appear with UART_TX_STS_COMPLETE status:
* SendBreak(2); - complete Break operation
*
* Side Effects:
* Uses static variable to keep registers configuration.
*
*******************************************************************************/
void UART_1_SendBreak(uint8 retMode)
{
/* If not Initialized then skip this function*/
if(UART_1_initVar != 0u)
{
/*Set the Counter to 13-bits and transmit a 00 byte*/
/*When that is done then reset the counter value back*/
uint8 tmpStat;
#if(UART_1_HD_ENABLED) /* Half Duplex mode*/
if( (retMode == UART_1_SEND_BREAK) ||
(retMode == UART_1_SEND_WAIT_REINIT ) )
{
/* CTRL_HD_SEND_BREAK - sends break bits in HD mode*/
UART_1_WriteControlRegister(UART_1_ReadControlRegister() |
UART_1_CTRL_HD_SEND_BREAK);
/* Send zeros*/
UART_1_TXDATA_REG = 0u;
do /*wait until transmit starts*/
{
tmpStat = UART_1_TXSTATUS_REG;
}while((tmpStat & UART_1_TX_STS_FIFO_EMPTY) != 0u);
}
if( (retMode == UART_1_WAIT_FOR_COMPLETE_REINIT) ||
(retMode == UART_1_SEND_WAIT_REINIT) )
{
do /*wait until transmit complete*/
{
tmpStat = UART_1_TXSTATUS_REG;
}while(((uint8)~tmpStat & UART_1_TX_STS_COMPLETE) != 0u);
}
if( (retMode == UART_1_WAIT_FOR_COMPLETE_REINIT) ||
(retMode == UART_1_REINIT) ||
(retMode == UART_1_SEND_WAIT_REINIT) )
{
UART_1_WriteControlRegister(UART_1_ReadControlRegister() &
(uint8)~UART_1_CTRL_HD_SEND_BREAK);
}
#else /* UART_1_HD_ENABLED Full Duplex mode */
static uint8 tx_period;
if( (retMode == UART_1_SEND_BREAK) ||
(retMode == UART_1_SEND_WAIT_REINIT) )
{
/* CTRL_HD_SEND_BREAK - skip to send parity bit at Break signal in Full Duplex mode*/
#if( (UART_1_PARITY_TYPE != UART_1__B_UART__NONE_REVB) || \
(UART_1_PARITY_TYPE_SW != 0u) )
UART_1_WriteControlRegister(UART_1_ReadControlRegister() |
UART_1_CTRL_HD_SEND_BREAK);
#endif /* End UART_1_PARITY_TYPE != UART_1__B_UART__NONE_REVB */
#if(UART_1_TXCLKGEN_DP)
tx_period = UART_1_TXBITCLKTX_COMPLETE_REG;
UART_1_TXBITCLKTX_COMPLETE_REG = UART_1_TXBITCTR_BREAKBITS;
#else
tx_period = UART_1_TXBITCTR_PERIOD_REG;
UART_1_TXBITCTR_PERIOD_REG = UART_1_TXBITCTR_BREAKBITS8X;
#endif /* End UART_1_TXCLKGEN_DP */
/* Send zeros*/
UART_1_TXDATA_REG = 0u;
do /* wait until transmit starts */
{
tmpStat = UART_1_TXSTATUS_REG;
}while((tmpStat & UART_1_TX_STS_FIFO_EMPTY) != 0u);
}
if( (retMode == UART_1_WAIT_FOR_COMPLETE_REINIT) ||
(retMode == UART_1_SEND_WAIT_REINIT) )
{
do /*wait until transmit complete*/
{
tmpStat = UART_1_TXSTATUS_REG;
}while(((uint8)~tmpStat & UART_1_TX_STS_COMPLETE) != 0u);
}
if( (retMode == UART_1_WAIT_FOR_COMPLETE_REINIT) ||
(retMode == UART_1_REINIT) ||
(retMode == UART_1_SEND_WAIT_REINIT) )
{
#if(UART_1_TXCLKGEN_DP)
UART_1_TXBITCLKTX_COMPLETE_REG = tx_period;
#else
UART_1_TXBITCTR_PERIOD_REG = tx_period;
#endif /* End UART_1_TXCLKGEN_DP */
#if( (UART_1_PARITY_TYPE != UART_1__B_UART__NONE_REVB) || \
(UART_1_PARITY_TYPE_SW != 0u) )
UART_1_WriteControlRegister(UART_1_ReadControlRegister() &
(uint8)~UART_1_CTRL_HD_SEND_BREAK);
#endif /* End UART_1_PARITY_TYPE != NONE */
}
#endif /* End UART_1_HD_ENABLED */
}
} |