/* Testing of SAR A/D Keypad Voltage Measurement */
int  sar_test_keypad_voltage(void)
{
    CSL_Status    status;
    CSL_SarHandleObj *SarHandle;
    CSL_SarChSetup param;
    int result;
    int chanNo;
    Uint16 readBuffer;
    result = CSL_TEST_FAILED;

    printf("Testing SAR in polling mode\n");

    /* Initialize the SAR module */
    status = SAR_init();
    if(status != CSL_SOK)
    {
        printf("SAR Init Failed!!\n");
        return(result);
    }
    /* Open SAR channel */
    status = SAR_chanOpen(&SarObj,CSL_SAR_CHAN_3);
    SarHandle = &SarObj;
    if(status != CSL_SOK)
    {
        printf("SAR_chanOpen Failed!!\n");
        return result;
    }
    /* Initialize channel */
    status = SAR_chanInit(SarHandle);
    if(status != CSL_SOK)
    {
        printf("SAR_chanInit Failed!!\n");
        return(result);
    }
    param.OpMode = CSL_SAR_POLLING;
    param.MultiCh = CSL_SAR_NO_DISCHARGE;
    param.RefVoltage = CSL_SAR_REF_VIN;
    param.SysClkDiv = 0x0b ;
    /* Configuration for SAR module */
    status = SAR_chanSetup(SarHandle,&param);
    if(status != CSL_SOK)
    {
        printf("SAR_chanConfig Failed!!\n");
        return(result);
    }
    /* Set channel cycle set */
    status = SAR_chanCycSet(SarHandle,CSL_SAR_CONTINUOUS_CONVERSION);
    if(status != CSL_SOK)
    {
        printf("SAR_chanCycSet Failed!!\n");
        return(result);
    }
    /* set ADC Measurement parameters */
    status = SAR_A2DMeasParamSet(SarHandle,CSL_KEYPAD_MEAS,&chanNo);
    if(status != CSL_SOK)
    {
        printf("SAR_A2DMeasParamSet Failed!!\n");
        return(result);
    }
    printf("Channel Number selected %d\n",chanNo);
    /* start the conversion */
    status = SAR_startConversion(SarHandle);
    if(status != CSL_SOK)
    {
        printf("SAR_startConversion Failed!!\n");
        return(result);
    }
    i = 0;
    /* Read the ADC data continously 40 times */
    while(i < 40)
    {
    /* Check whether the ADC data is available or not */
        while(CSL_SAR_DATA_AVAILABLE !=
        SAR_getStatus(SarHandle,&status));

        status = SAR_readData(SarHandle, &readBuffer);
        if(status != CSL_SOK)
        {
        printf("SAR_readData Failed!!\n");
        return(result);
        }
        i++;
        printf("SAR ADC read data 0x%x\n",readBuffer);
    }
    /* Stop the conversion */
    status = SAR_stopConversion(SarHandle);
    if(status != CSL_SOK)
    {
        printf("SAR_stopConversion Failed!!\n");
        return(result);
    }
    /* Close the channel */
    status = SAR_chanClose(SarHandle);
    if(status != CSL_SOK)
    {
        printf("SAR_chanClose Failed!!\n");
        return(result);
    }
    /* Deinit */
    status = SAR_deInit();
    if(status != CSL_SOK)
    {
        printf("SAR_deInit Failed!!\n");
        return(result);
    }
    result = CSL_TEST_PASSED;
    return(result);
}
Exemple #2
0
/* User Interface SWI */
void UserInterfaceSwi(void)
{
    Bool sarDataReady;
    Int16 status;
    Uint16 sarReadData;
    UI_PBNState pbnState;
    Int16 pbnStateAllowed;
    pUsbContext pContext;

    pContext = &gUsbContext;

    /* Check SAR status */
    sarDataReady = SAR_getStatus(gsSarHandle, &status); /* SAR data should always be ready since Timer frequency is very slow compared with SAR sampling frequency */
    if ((sarDataReady != CSL_SAR_DATA_AVAILABLE) || (status != CSL_SOK))
    {
        LOG_printf(&trace, "ERROR: SAR_getStatus()");
    }

    /* Read SAR data */
    status = SAR_readData(gsSarHandle, &sarReadData);
    if (status != CSL_SOK)
    {
        LOG_printf(&trace, "ERROR: SAR_readData()");
    }

    /* Start next conversion */
    status = SAR_startConversion(gsSarHandle);
    if (status != CSL_SOK)
    {
        LOG_printf(&trace, "ERROR: SAR_startConversion()");
    }

    /* Get current push-button network state */
    status = getCurrentPBNState(sarReadData, &pbnState);
    if (status != UI_SOK)
    {
        LOG_printf(&trace, "ERROR: getCurrentPBNState()");
    }
    //if (pbnState == UI_PUSH_BUTTON_UNKNOWN) LOG_printf(&trace, "pbnState = 0x%04X", pbnState);

    /* Check push-button network state is allowed state */
    status = chkAllowedPBNState(pbnState, gAllowedPbnStates, NUM_ALLOWED_PBN_STATES, &pbnStateAllowed);
    if (status != UI_SOK)
    {
        LOG_printf(&trace, "ERROR: chkAllowedPBNState()");
    }

    /* Filter disallowed push-button network states,  */
    /* Check change in push-button network state */
    if ((pbnStateAllowed) && (pbnState != gPrevPbnState))
    {
        /* Generate HID report */
        genHidReport(pbnState, gHidReport);

        gPrevPbnState = pbnState;
        gHidReportReady = TRUE;

        if (hidIntInEpReady == TRUE)
        {
            DeviceNotification(pContext, CSL_USB_EVENT_HID_REPORT_TX);
            gHidReportReady = FALSE;
            hidIntInEpReady = FALSE;
        }
    }
}