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:

Table 3-3. 
FunctionDiagnostic MechanismUse CaseElapsed Time (us)~
DIAG_ADC_Boundary()ADC_BOUNDARYPOST / OnDemand650
DIAG_ADC_Disable()ADC_DISABLEPOST / OnDemand100
DIAG_ADC_Dma()ADC_DMAPOST96.52
DIAG_ADC_Enable()ADC_ENABLEPOST / OnDemand100
DIAG_ADC_Interrupts()

ADC_INTERRUPTS

POST 500
DIAG_ADC_Linearity()ADC_LINEARITYPOST3065.06
DIAG_ADC_Operation()ADC_OPERATIONPOST5331.07
DIAG_ADC_SFRReset()SFR_RESET_STATEPOST94.89
DIAG_ADC_SFRWriteRead()SFR_WRITE_READPOST / OnDemand128.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; 
}