// TODO 10.01
#include <stdio.h>
#include <string.h>


// TODO 10.02
uint8_t USARTRTxBuffer[100];
uint8_t USART5_ReceiveData[1];
volatile uint8_t USART5_IsReceived = 0;
volatile uint8_t USART5_IsTransmitted = 1;

void USART5_Transmit( uintptr_t context )
{
    USART5_IsTransmitted = 1;
} 

void USART5_Receive( uintptr_t context )
{
    USART5_IsReceived = 1;
}


// TODO 10.03
    SERCOM5_USART_ReadCallbackRegister( USART5_Receive, (uintptr_t )NULL );
    SERCOM5_USART_WriteCallbackRegister( USART5_Transmit, (uintptr_t )NULL );
    SERCOM5_USART_Read( USART5_ReceiveData, 1 );


// TODO 10.04
        if( USART5_IsReceived )
        {
            USART5_IsReceived = 0;
            sprintf((char *) USARTRTxBuffer, "\r\nReceived Data : %1c\r\n", USART5_ReceiveData[0] );
            SERCOM5_USART_Write( USARTRTxBuffer, strlen((char*)USARTRTxBuffer) );
            while( SERCOM5_USART_WriteIsBusy() );
            SERCOM5_USART_Read( USART5_ReceiveData, 1 );
        }


// TODO 10.05
        sprintf((char *) USARTRTxBuffer, "Hello world!\r\n" );
        SERCOM5_USART_Write( USARTRTxBuffer, strlen((char*)USARTRTxBuffer) );