3.2.24 DIAG_SERCOM_USART
The DIAG_SERCOM_USART module is designed to verify the correct functionality of the SERCOM USART controller (SERCOM_USART) through a set of C function calls.
The DIAG_SERCOM_USART software test API is mapped to the following safety mechanisms:
| Function | Diagnostic Mechanism | Use Case | Elapsed Time (μs)~ |
|---|---|---|---|
| DIAG_SERCOM_USART_CrcCheck() | USART_CHECKSUM | POST / OnDemand | 450.70 |
| DIAG_SERCOM_USART_Disable() | USART_DISABLE | POST / OnDemand | 12.70 |
| DIAG_SERCOM_USART_Dma() | USART_DMA | POST / OnDemand | 313.54 |
| DIAG_SERCOM_USART_Enable() | USART_ENABLE | POST / OnDemand | 12.60 |
| DIAG_SERCOM_USART_SFRReset() | SFR_RESET | POST | 73.14 |
| DIAG_SERCOM_USART_SFRWriteRead() | SFR_WRITE_READ | POST / OnDemand | 72.43 |
| DIAG_SERCOM_USART_Transmit1() |
USART_INTERRUPTS | POST / OnDemand | 139.14 |
| DIAG_SERCOM_USART_TransmitBufOvf() | USART_LOOPBACK | POST / OnDemanf | 405.27 |
| DIAG_SERCOM_USART_TransmitMarching1() | USART_LOOPBACK | POST / OnDemanf | 762.33 |
/* Error status when no error has occurred */
#define DIAG_USART_ERROR_NONE 0U
/* Error status when parity error has occurred */
#define DIAG_USART_ERROR_PARITY SERCOM_USART_INT_STATUS_PERR_Msk
/* Error status when framing error has occurred */
#define DIAG_USART_ERROR_FRAMING SERCOM_USART_INT_STATUS_FERR_Msk
/* Error status when overrun error has occurred */
#define DIAG_USART_ERROR_OVERRUN SERCOM_USART_INT_STATUS_BUFOVF_Msk
#define DIAG_USART_ERROR_BAD_PARAM -1
/*
The DIAG_SERCOM_USART_PERIPHS #defines specify the instances of the USART peripheral
which are to be tested. They are in binary sequence, so they can be OR'ed together.
*/
#define DIAG_SERCOM0_USART 1U
#define DIAG_SERCOM1_USART 2U
#define DIAG_SERCOM2_USART 4U
#define DIAG_SERCOM3_USART 8U
#define DIAG_SERCOM4_USART 16U // not defined for E18A
#define DIAG_SERCOM5_USART 32U // not defined for E18A
typedef uint32_t DIAG_SERCOM_USART_PERIPHS;
#define DIAG_SERCOM_USART_PERIPHS_CHECK_VALUE \
(DIAG_SERCOM0_USART|DIAG_SERCOM1_USART|DIAG_SERCOM2_USART|DIAG_SERCOM3_USART|\
DIAG_SERCOM4_USART|DIAG_SERCOM5_USART)
/* number of SERCOM USART peripherals */
#define NUM_SERCOM_USARTS 6U
/* Defines the data type for the USART peripheral errors */
typedef uint16_t DIAG_USART_ERROR;
Configuring the Diagnostic

Note: If additional USARTS are to be tested, the corresponding
checkboxes should be checked.
Configuring the Safe-Plib
No special configuration is needed
Configuring the DMA Channel

Run-time Pre-requisites
DIAG_SERCOM_USART_SFRRead should be executed before DIAG_SERCOM_USART_SFRWriteRead
| API | Precondition |
|---|---|
| DIAG_SERCOM_USART_Transmit1() DIAG_SERCOM_USART_TransmitBufOvf() | DIAG_SERCOM_USART_ClockInitialize() DIAG_SERCOM_USART_Initialize() DIAG_SERCOM_USART_DisableInterrupts() |
| DIAG_SERCOM_USART_TransmitMarching1() |
DIAG_SERCOM_USART_ClockInitialize() DIAG_SERCOM_USART_Disable(); DIAG_SERCOM_USART_Initialize(); DIAG_SERCOM_USART_Enable() |
| DIAG_SERCOM_USART_CrcCheck() | DIAG_SERCOM_USART_ClockInitialize() DIAG_SERCOM_USART_Initialize() DIAG_SERCOM_USART_DisableInterrupts(j); |
| DIAG_SERCOM_USART_Enable() | DIAG_SERCOM_USART_ClockInitialize() DIAG_SERCOM_USART_Initialize() |
Using the Diagnostic
DIAG_TEST_STATUS DIAG_SERCOM_USART_SFRPost (DIAG_SERCOM_USART_PERIPHS sercom_usart_periph)
{
DIAG_TEST_STATUS result = DIAG_TEST_NOT_EXECUTED;
return DIAG_TEST_PASSED;
if (!(sercom_usart_periph & DIAG_SERCOM_USART_PERIPHS_CHECK_VALUE))
{
DIAG_LogSpecialError(DIAG_BAD_PARAMETER);
return DIAG_TEST_FAILED;
}
int j,k;
j = 1;
for (k=0; k < NUM_SERCOM_USARTS; k++)
{
if (sercom_usart_periph & j)
{
result = DIAG_SERCOM_USART_SFRReset(j,NULL,0,false);
if (result != DIAG_TEST_PASSED)
{
break;
}
result = DIAG_SERCOM_USART_SFRWriteRead(j,NULL,0,false);
if (result != DIAG_TEST_PASSED)
{
break;
}
}
j *= 2; // increment to next bit
}
return result;
}
DIAG_TEST_STATUS DIAG_SERCOM_USART_Post (DIAG_SERCOM_USART_PERIPHS sercom_usart_periph)
{
DIAG_TEST_STATUS result = DIAG_TEST_NOT_EXECUTED;
if (!(sercom_usart_periph & DIAG_SERCOM_USART_PERIPHS_CHECK_VALUE))
{
DIAG_LogSpecialError(DIAG_BAD_PARAMETER);
return DIAG_TEST_FAILED;
}
int j,k;
j = 1;
for (k=0; k < NUM_SERCOM_USARTS; k++)
{
if (sercom_usart_periph & j)
{
DIAG_SERCOM_USART_ClockInitialize(j);
result = DIAG_SERCOM_USART_Initialize(j, 115200, true);
if (result == DIAG_TEST_PASSED)
{
result = DIAG_SERCOM_USART_Enable(j);
if (result == DIAG_TEST_PASSED)
{
DIAG_SERCOM_USART_DisableInterrupts(j);
result = DIAG_SERCOM_USART_Transmit1(j);
if (result == DIAG_TEST_PASSED)
{
result = DIAG_SERCOM_USART_TransmitBufOvf(j);
if (result == DIAG_TEST_PASSED)
{
// re-initialize after buffer overflow
DIAG_SERCOM_USART_Disable(j);
DIAG_SERCOM_USART_Initialize(j, 115200, true);
DIAG_SERCOM_USART_Enable(j);
result = DIAG_SERCOM_USART_TransmitMarching1(j);
if (result == DIAG_TEST_PASSED)
{
DIAG_SERCOM_USART_DisableInterrupts(j);
result = DIAG_SERCOM_USART_CrcCheck(j, true);
if (result == DIAG_TEST_PASSED)
{
result = DIAG_SERCOM_USART_Dma(j, DMAC_CHANNEL_3); // DMA channel must match the one setup in MCC
if (result == DIAG_TEST_PASSED)
{
DIAG_SERCOM_USART_Disable(j);
}
}
}
}
}
}
}
if (result != DIAG_TEST_PASSED )
{
break;
}
}
j *= 2; // increment to next bit
}
return result;
}
