/* SysBios header files */ #include #include #include #include #include #include #include #include "board_support.h" #include "board.h" #include "soc.h" #include "types.h" #include "error.h" #include "device.h" #include "chipdb.h" #include "adc_app.h" #include "tsc_adc_ss.h" /* ========================================================================== */ /* Macros */ /* ========================================================================== */ /** * \name Macros used by the application. */ /** @{ */ /* Macro representing the voltage resolution. */ #define VOLTAGE_RESOLUTION (439U) /* Macro representing the module clock of TSCADC. */ #define TSCADC_MODULE_CLOCK (24000000U) /* Macro representing the AFE clock of TSCADC. */ #define TSCADC_AFE_CLOCK (3000000U) /** @} */ /* ========================================================================== */ /* Structures and Enums */ /* ========================================================================== */ /* None */ /* ========================================================================== */ /* Internal Function Declarations */ /* ========================================================================== */ /** * \brief Fetch the ADC instance address. * * \param pObj Pointer to the ADC application configuration * structure. * * \retval #S_PASS - ADC instance is present. * \retVal #E_FAIL - ADC instance is not present. */ static int32_t AdcAppSocInfoGet(adcAppCfgObj_t *pObj); /* ========================================================================== */ /* Global Variables */ /* ========================================================================== */ /** \brief Application default configuration */ static const adcAppCfgObj_t ADCAPPVOLTMEASURE_DEFAULT = { 0U, /* instNum */ 0U, /* instAddr */ 24000000U, /* modClk */ 3000000U, /* afeInClk */ NULL, /* pSample */ { FALSE, /* diffCtrl */ 0U /* fifoSel */ }, { INTC_TRIG_HIGH_LEVEL, /* trigType */ 0U, /* intrLine */ 16U, /* intrPriority */ FALSE, /* isIntrSecure */ 0U, /* endOfSeqIntr */ NULL /* pFnIntrHandler */ }, { ADC_GP_MODE_ENABLE /* adcMode. */ } }; /** \brief Global object for the ADC volt measure application. */ static adcAppCfgObj_t gVoltMeasureAppCfg; /** \brief Variable to hold the sample values. */ static uint32_t gVoltMeasureAppSampleVal[2U]; /* * ======== taskFxn and TaskHandle ======== */ Void ADCtask(UArg a0, UArg a1); Task_Handle adctask; Void ADCtask(UArg a0, UArg a1) { int32_t status = S_PASS; uint32_t chan1, chan2 = 0U; CONSOLEUtilsPrintf("\nCheck Point 1\n"); gVoltMeasureAppCfg = ADCAPPVOLTMEASURE_DEFAULT; gVoltMeasureAppCfg.pSample = gVoltMeasureAppSampleVal; status = AdcAppSocInfoGet(&gVoltMeasureAppCfg); if (S_PASS == status) { CONSOLEUtilsPrintf("\nCheck Point 2\n"); /* Initialize the ADC application.*/ status = ADCAppInit(&gVoltMeasureAppCfg); CONSOLEUtilsPrintf("\nCheck Point 3\n"); if (S_PASS == status) { CONSOLEUtilsPrintf("\nCheck Point 4\n"); /* Wait till the ADC processes the analog lines.*/ while(1U != gVoltMeasureAppCfg.appIntrCfg.endOfSeqIntr); /* Read the sample data from the FIFO.*/ gVoltMeasureAppSampleVal[0U] = TSCADCFIFOADCDataRead(gVoltMeasureAppCfg.instAddr, TSCADC_FIFO_SEL_0); gVoltMeasureAppSampleVal[1U] = TSCADCFIFOADCDataRead(gVoltMeasureAppCfg.instAddr, TSCADC_FIFO_SEL_1); chan1 = (gVoltMeasureAppSampleVal[0U] * VOLTAGE_RESOLUTION) / 1000U; chan2 = (gVoltMeasureAppSampleVal[1U] * VOLTAGE_RESOLUTION) / 1000U; CONSOLEUtilsPrintf("Voltage sensed on the AN0 line :"); CONSOLEUtilsPrintf("%dmV\r\n", chan1); CONSOLEUtilsPrintf("Voltage sensed on the AN1 line :"); CONSOLEUtilsPrintf("%dmV\r\n", chan2); } else { CONSOLEUtilsPrintf("TSCADC initialization failed\n"); } } else { CONSOLEUtilsPrintf("Exiting from the application\n"); } } int main() { SDKMMUInit(applMmuEntries); // needed first BOARDInit(NULL); /* Initialize the UART console */ CONSOLEUtilsInit(); /* Select the console type based on compile time check */ CONSOLEUtilsSetType(CONSOLE_UTILS_TYPE_UART); Task_Params taskParams; Task_Params_init(&taskParams); taskParams.priority = 4; taskParams.stackSize = 0x400; adctask = Task_create(ADCtask, &taskParams, NULL); CONSOLEUtilsPrintf("\nStarterWare ADC voltage measure application!!\n"); BIOS_start(); /* enable interrupts and start SYS/BIOS */ return 0; } static int32_t AdcAppSocInfoGet(adcAppCfgObj_t *pObj) { int32_t status = E_FAIL; pObj->instNum = 0U; if (TRUE == CHIPDBIsResourcePresent(CHIPDB_MOD_ID_ADC0, pObj->instNum)) { /* Update the Interrupt Line number */ if(SOC_FAMILY_ID_AM43XX == SOCGetSocFamilyId()) { pObj->appIntrCfg.intrLine = 48U; } else if(SOC_FAMILY_ID_AM335X == SOCGetSocFamilyId()) { pObj->appIntrCfg.intrLine = 16U; } else { CONSOLEUtilsPrintf("ADC interrupts not supported on the SOC.\n"); } /* TODO: Need to update the interrupt Numberdata base of ChipDB */ /* pObj->appIntrCfg.intrLine = ChipDBInterruptNum(CHIPDB_MOD_ID_ADC0, 0, 0); */ /* Read the ADC instance number. */ pObj->instAddr = CHIPDBBaseAddress(CHIPDB_MOD_ID_ADC0, 0U); status = S_PASS; } else { CONSOLEUtilsPrintf("ADC instance is not present on the SOC.\n"); } return(status); }