3.2.2 DIAG_ADC
The DIAG_ADC module is designed to verify the correct functionality of the Analog to Digital Controller (ADC) through a set of C function calls.
The DIAG_ADC software test API is mapped to the following safety mechanisms:
| Function | Diagnostic Mechanism | Use Case | Elapsed Time (us)~ |
|---|---|---|---|
| DIAG_ADC_Boundary() | ADC_BOUNDARY | POST / OnDemand | 650 |
| DIAG_ADC_Disable() | ADC_DISABLE | POST / OnDemand | 100 |
| DIAG_ADC_Dma() | ADC_DMA | POST | 96.52 |
| DIAG_ADC_Enable() | ADC_ENABLE | POST / OnDemand | 100 |
| DIAG_ADC_Interrupts() |
ADC_INTERRUPTS | POST | 500 |
| DIAG_ADC_Linearity() | ADC_LINEARITY | POST | 3065.06 |
| DIAG_ADC_Operation() | ADC_OPERATION | POST | 5331.07 |
| DIAG_ADC_SFRReset() | SFR_RESET_STATE | POST | 94.89 |
| DIAG_ADC_SFRWriteRead() | SFR_WRITE_READ | POST / OnDemand | 128.12 |
Configuring the Diagnostic
DIAG_ADC must be configured as illustrated to supported to support all diagnostics:

Note: If the user is going to be testing both ADC0 and ADC1
both must be checked
ADC Safe-Plib must be configured as illustrated to supported to support all diagnostics:

Configuring the System

Using the Diagnostic
#include "definitions.h"
// ADC SFR testing
DIAG_TEST_STATUS DIAG_ADC_SFRPost (DIAG_ADC_PERIPHS adc_periph)
{
DIAG_TEST_STATUS result = DIAG_TEST_NOT_EXECUTED;
if (!(adc_periph & DIAG_ADC_PERIPHS_CHECK_VALUE))
{
DIAG_LogSpecialError(DIAG_BAD_PARAMETER);
return DIAG_TEST_FAILED;
}
int j,k;
j = 1;
for (k=0; k < NUM_ADCS; k++)
{
if (adc_periph & j)
{
result = DIAG_ADC_SFRReset(j,NULL,0,false);
if (result != DIAG_TEST_PASSED)
{
break;
}
result = DIAG_ADC_SFRWriteRead(j,NULL,0,false);
if (result != DIAG_TEST_PASSED)
{
break;
}
}
j *= 2; // increment to next bit
}
return result;
}
// ADC Post Testing
DIAG_TEST_STATUS DIAG_ADC_Post (DIAG_ADC_PERIPHS adc_periph)
{
DIAG_TEST_STATUS result = DIAG_TEST_NOT_EXECUTED;
if (!(adc_periph & DIAG_ADC_PERIPHS_CHECK_VALUE))
{
DIAG_LogSpecialError(DIAG_BAD_PARAMETER);
return DIAG_TEST_FAILED;
}
int j,k;
j = 1;
for (k=0; k < NUM_ADCS; k++)
{
if (adc_periph & j)
{
result = DIAG_ADC_Enable(j);
if (result == DIAG_TEST_PASSED)
{
result = DIAG_ADC_Disable(j);
}
if (result == DIAG_TEST_PASSED)
{
result = DIAG_ADC_Linearity(j);
}
if (result == DIAG_TEST_PASSED)
{
result = DIAG_ADC_Boundary(j);
}
if (result == DIAG_TEST_PASSED)
{
result = DIAG_ADC_Operation(j);
}
if (result == DIAG_TEST_PASSED)
{
result = DIAG_ADC_Dma(j, DMAC_CHANNEL_2);
}
if (result == DIAG_TEST_PASSED)
{
result = DIAG_ADC_Interrupts(j);
}
if (result != DIAG_TEST_PASSED )
{
break;
}
}
j *= 2; // increment to next bit
}
return result;
}
