Пример #1
0
/* 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);
}
Пример #2
0
/* Testing of SAR API's */
int sar_api_test()
{

    CSL_Status    status;
    CSL_SarHandleObj *SarHandle;
    CSL_SarChConfig param;
    int result;
    result = CSL_TEST_FAILED;

	printf("calling sar_api_test\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);
    }
    printf("Before calling SAR_chanConfig API\n");
    /* Retrieve SAR A/D Registers */
    SAR_getConfig(SarHandle, &param);
    printf(" SARCTRL 0x%x\n",param.SARCTRL);
    printf(" SARCLKCTR 0x%x\n",param.SARCLKCTRL);
    printf(" SARPINCTR 0x%x\n",param.SARPINCTRL);
    printf(" SARGPOCTRL 0x%x\n",param.SARGPOCTRL);

    param.SARCTRL = 0x3800;
    param.SARCLKCTRL = 0x000b;
    param.SARPINCTRL = 0x0100;
    /* Configure SAR A/D Registers */
    status = SAR_chanConfig(SarHandle, &param);
    if(status != CSL_SOK)
    {
    printf("SAR_chanConfig Failed\n");
    return(result);
    }

   /* Test SAR_GPODirSet API */
    status = SAR_GPODirSet(SarHandle,CSL_SAR_GPO_3,CSL_SAR_GPO_OUT);
    if(CSL_SOK != status)
    {
        printf("SAR_GPODirSet test Failed\n");
        return (result);
    }


    printf("After calling SAR_chanConfig API\n");

    /* Get config */
    SAR_getConfig(SarHandle, &param);
    printf(" SARCTRL 0x%x\n",param.SARCTRL);
    printf(" SARCLKCTRL 0x%x\n",param.SARCLKCTRL);
    printf(" SARPINCTRL 0x%x\n",param.SARPINCTRL);
    printf(" SARGPOCTRL 0x%x\n",param.SARGPOCTRL);

   /* 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);
}
Пример #3
0
/* Initializes user interface */
Int16 userInterfaceInit(
     Float32 cpuFreq,
     Float32 pbnSampFreq,
     CSL_Status *pCslStatus
)
{
    CSL_SarChSetup SarParam;
    CSL_SarChanSel sarChanNo;
    CSL_Config hwConfig;
    Uint32 tmrPrd;
    CSL_Status status;
#ifdef PBN_SIM
    PbnSimPrms pbnSimPrms;
#endif

#ifdef PBN_SIM
    /* Initialize push-button network simulation */
    pbnSimPrms.pbnSimLoop = TRUE;
    PbnSimInit(&pbnSimPrms, &gPbnSimState);
#endif

    /* Initialize SAR CSL */
    SAR_init();

    /* Populate SAR object information */
    status = SAR_chanOpen(&gsSarObj, CSL_SAR_CHAN_3);
    if (status != CSL_SOK)
    {
        *pCslStatus = status;
        return UI_CSL_FAIL;
    }
    gsSarHandle = &gsSarObj;

    /* Initialize SAR registers */
    SarParam.SysClkDiv = (Uint16)((Float32)cpuFreq/SAR_MAX_CLK_FREQ + 0.5)-1;
    SarParam.OpMode = CSL_SAR_POLLING;
    SarParam.MultiCh = CSL_SAR_NO_DISCHARGE;
    SarParam.RefVoltage = CSL_SAR_REF_VIN;
    status = SAR_chanSetup(gsSarHandle, &SarParam);
    if (status != CSL_SOK)
    {
        *pCslStatus = status;
        return UI_CSL_FAIL;
    }

    /* Initialize A/D conversion type */
    status = SAR_A2DMeasParamSet(gsSarHandle, CSL_KEYPAD_MEAS, &sarChanNo);
    if ((status != CSL_SOK) || (sarChanNo != CSL_SAR_CHAN_3))
    {
        *pCslStatus = status;
        return UI_CSL_FAIL;
    }

    /* Initialize A/D conversion type */
    status = SAR_chanCycSet(gsSarHandle, CSL_SAR_SINGLE_CONVERSION);
    if (status != CSL_SOK)
    {
        *pCslStatus = status;
        return UI_CSL_FAIL;
    }

    /* Initialize UI control variables */
    gPrevPbnState = UI_PUSH_BUTTON_NONE;
    genHidReport(UI_PUSH_BUTTON_NONE, gHidReport);
    gHidReportReady = FALSE;

    /* Open GPT1 -- used as timer for SAR sampling for HID */
    gsGptHandle = GPT_open(GPT_1, &gsGptObj, &status);
    if (status != CSL_SOK)
    {
        *pCslStatus = status;
        return UI_CSL_FAIL;
    }

    /* Reset GPT1 */
    status = GPT_reset(gsGptHandle);
    if(status != CSL_SOK)
    {
        *pCslStatus = status;
        return UI_CSL_FAIL;
    }

    /* Configure GPT1 */
    tmrPrd = (Uint32)((Float32)cpuFreq/2.0/pbnSampFreq + 0.5)-1;
    hwConfig.autoLoad = GPT_AUTO_ENABLE;
    hwConfig.ctrlTim = GPT_TIMER_ENABLE;
    hwConfig.preScaleDiv = GPT_PRE_SC_DIV_0;
    hwConfig.prdLow = (Uint16)tmrPrd;
    hwConfig.prdHigh = (Uint16)(tmrPrd>>16);
    status = GPT_config(gsGptHandle, &hwConfig);
    if (status != CSL_SOK)
    {
        *pCslStatus = status;
        return UI_CSL_FAIL;
    }

    /* Clear pending interrupts */
    CSL_SYSCTRL_REGS->TIAFR = 0x7;

    return UI_SOK;
}