Code: Select all
static void USART1_IrqHandler( void )
{
printf( "here, usart1 interrupted\r\n" );
}
static void _configureUsart( void *pInstance )
{
const uint16_t receivedTimeOut = 500;
assert( NULL != pInstance );
DataSource *pSource = ( DataSource * )pInstance;
Usart *pUsart = ( Usart * )pSource->dev.instanceHandle;
uint32_t mode = US_MR_USART_MODE_NORMAL
// uint32_t mode = US_MR_USART_MODE_HW_HANDSHAKING
| US_MR_USCLKS_MCK
| US_MR_CHRL_8_BIT
| US_MR_PAR_NO
| US_MR_NBSTOP_1_BIT
| US_MR_CHMODE_NORMAL ;
/* Enable the peripheral clock in the PMC*/
PMC_EnablePeripheral( pSource->dev.identify );
/* Configure the USART in the desired mode @115200 bauds*/
USART_Configure( pUsart, mode, 115200, BOARD_MCK ) ;
/* Configure the interrupt */
USART_SetReceivedTimeout( pUsart,receivedTimeOut );
/* Configure the interrupt */
USART_EnableIt(pUsart,( 1 << 8 ) );
if( pSource->dev.identify == ID_USART0 )
IRQ_ConfigureIT( ID_USART0, 0, USART0_IrqHandler );
else if( pSource->dev.identify == ID_USART1 )
IRQ_ConfigureIT( ID_USART1, 0, USART1_IrqHandler );
else
;
/* Enable receiver & transmitter*/
USART_SetTransmitterEnabled( pUsart, 1 ) ;
USART_SetReceiverEnabled( pUsart, 1 ) ;
}
void usart_init( void *pInstance , void *parameter )
{
assert( NULL != pInstance );
parameter = parameter;
static const Pin pins0[] = { PINS_USART0 };
static const Pin pins1[] = { PINS_USART1 };
DataSource *pSource = ( DataSource * )pInstance;
if( pSource->dev.identify == ID_USART0 )
{
/* Configure pins*/
PIO_Configure( pins0, PIO_LISTSIZE( pins0 ) ) ;
}
else
{
PIO_Configure( pins1, PIO_LISTSIZE( pins1 ) ) ;
}
_configureUsart( pInstance );
}
uint8_t usart_read( void )
{
return usart->US_RHR;
}