Skip to content

AD5940 Lib Functions

/**
 * @defgroup Exported_Functions
 * @{
*/
/* 1. Basic SPI functions */
void      AD5940_WriteReg(uint16_t RegAddr, uint32_t RegData);
uint32_t  AD5940_ReadReg(uint16_t RegAddr);
void      AD5940_FIFORd(uint32_t *pBuffer,uint32_t uiReadCount);

/* 2. AD5940 Top Control functions */
void      AD5940_Initialize(void); /* Call this function firstly once AD5940 power on or come from soft reset */
void      AD5940_AFECtrlS(uint32_t AfeCtrlSet, BoolFlag State);
AD5940Err AD5940_LPModeCtrlS(uint32_t EnSet);
void      AD5940_AFEPwrBW(uint32_t AfePwr, uint32_t AfeBw); /* AFE power mode and system bandwidth control */
void      AD5940_REFCfgS(AFERefCfg_Type *pBufCfg);

/* 3. High_Speed_Loop Functions */
void      AD5940_HSLoopCfgS(HSLoopCfg_Type *pHsLoopCfg);
void      AD5940_SWMatrixCfgS(SWMatrixCfg_Type *pSwMatrix);
void      AD5940_HSDacCfgS(HSDACCfg_Type *pHsDacCfg);
AD5940Err AD5940_HSTIACfgS(HSTIACfg_Type *pHsTiaCfg);
void      AD5940_HSRTIACfgS(uint32_t HSTIARtia);
void __AD5940_SetDExRTIA(uint32_t DExPin, uint32_t DeRtia, uint32_t DeRload);

/* 4. Low_Power_Loop Functions*/
void      AD5940_LPLoopCfgS(LPLoopCfg_Type *pLpLoopCfg);
void      AD5940_LPDACCfgS(LPDACCfg_Type *pLpDacCfg);
//void      AD5940_LPDACWriteS(uint16_t Data12Bit, uint8_t Data6Bit);
void      AD5940_LPDAC0WriteS(uint16_t Data12Bit, uint8_t Data6Bit);
void      AD5940_LPDAC1WriteS(uint16_t Data12Bit, uint8_t Data6Bit);
void      AD5940_LPAMPCfgS(LPAmpCfg_Type *pLpAmpCfg);

/* 5. DSP_Block_Functions */
void      AD5940_DSPCfgS(DSPCfg_Type *pDSPCfg);
uint32_t  AD5940_ReadAfeResult(uint32_t AfeResultSel);
/* 5.1 ADC Block */
void      AD5940_ADCBaseCfgS(ADCBaseCfg_Type *pADCInit);
void      AD5940_ADCFilterCfgS(ADCFilterCfg_Type *pFiltCfg);
void      AD5940_ADCPowerCtrlS(BoolFlag State);
void      AD5940_ADCConvtCtrlS(BoolFlag State);
void      AD5940_ADCMuxCfgS(uint32_t ADCMuxP, uint32_t ADCMuxN);
void      AD5940_ADCDigCompCfgS(ADCDigComp_Type *pCompCfg);
void      AD5940_StatisticCfgS(StatCfg_Type *pStatCfg);
void      AD5940_ADCRepeatCfgS(uint32_t Number);
void      AD5940_DFTCfgS(DFTCfg_Type *pDftCfg);
/* 5.2 Waveform Generator Block */
void      AD5940_WGCfgS(WGCfg_Type *pWGInit);
AD5940Err AD5940_WGDACCodeS(uint32_t code); /* Directly write DAC Code */
void      AD5940_WGFreqCtrlS(float SinFreqHz, float WGClock);
uint32_t  AD5940_WGFreqWordCal(float SinFreqHz, float WGClock);
//uint32_t AD5940_WGAmpWordCal(float Amp, BoolFlag DacGain, BoolFlag ExcitGain);

/* 6. Sequencer_FIFO */
void      AD5940_FIFOCfg(FIFOCfg_Type *pFifoCfg);
AD5940Err AD5940_FIFOGetCfg(FIFOCfg_Type *pFifoCfg);  /* Read back current configuration */
void      AD5940_FIFOCtrlS(uint32_t FifoSrc, BoolFlag FifoEn);   /* Configure FIFO data source. And disable/enable it.*/
void      AD5940_FIFOThrshSet(uint32_t FIFOThresh);
uint32_t  AD5940_FIFOGetCnt(void);     /* Get current FIFO count */
void      AD5940_SEQCfg(SEQCfg_Type *pSeqCfg);
AD5940Err AD5940_SEQGetCfg(SEQCfg_Type *pSeqCfg);    /* Read back current configuration */
void      AD5940_SEQCtrlS(BoolFlag SeqEn);
void      AD5940_SEQHaltS(void);
void      AD5940_SEQMmrTrig(uint32_t SeqId); /* Manually trigger sequence */
void      AD5940_SEQCmdWrite(uint32_t StartAddr, const uint32_t *pCommand, uint32_t CmdCnt);
void      AD5940_SEQInfoCfg(SEQInfo_Type *pSeq);
AD5940Err AD5940_SEQInfoGet(uint32_t SeqId, SEQInfo_Type *pSeqInfo);
void      AD5940_SEQGpioCtrlS(uint32_t GpioSet);   /* Sequencer can control GPIO0~7 if the GPIO function is set to SYNC */
uint32_t  AD5940_SEQTimeOutRd(void);  /* Read back current sequence time out value */
AD5940Err AD5940_SEQGpioTrigCfg(SeqGpioTrig_Cfg *pSeqGpioTrigCfg);
void      AD5940_WUPTCfg(WUPTCfg_Type *pWuptCfg);
void      AD5940_WUPTCtrl(BoolFlag Enable);  /* Enable or disable Wakeup timer */
AD5940Err AD5940_WUPTTime(uint32_t SeqId, uint32_t SleepTime, uint32_t WakeupTime);

/* 7. MISC_Block */
/* 7.1 Clock system */
void      AD5940_CLKCfg(CLKCfg_Type *pClkCfg);
void      AD5940_HFOSC32MHzCtrl(BoolFlag Mode32MHz);
void            AD5940_HPModeEn(BoolFlag Enable);   /* Switch system clocks to high power mode for EIS >80kHz)*/
/* 7.2 AFE Interrupt */
void      AD5940_INTCCfg(uint32_t AfeIntcSel, uint32_t AFEIntSrc, BoolFlag State);
uint32_t  AD5940_INTCGetCfg(uint32_t AfeIntcSel);
void      AD5940_INTCClrFlag(uint32_t AfeIntSrcSel);
BoolFlag  AD5940_INTCTestFlag(uint32_t AfeIntcSel, uint32_t AfeIntSrcSel); /* Check if selected interrupt happened */
uint32_t  AD5940_INTCGetFlag(uint32_t AfeIntcSel); /* Get current INTC interrupt flag */
/* 7.3 GPIO */
void      AD5940_AGPIOCfg(AGPIOCfg_Type *pAgpioCfg);
void      AD5940_AGPIOFuncCfg(uint32_t uiCfgSet);
void      AD5940_AGPIOOen(uint32_t uiPinSet);
void      AD5940_AGPIOIen(uint32_t uiPinSet);
uint32_t  AD5940_AGPIOIn(void);
void      AD5940_AGPIOPen(uint32_t uiPinSet);
void      AD5940_AGPIOSet(uint32_t uiPinSet);
void      AD5940_AGPIOClr(uint32_t uiPinSet);
void      AD5940_AGPIOToggle(uint32_t uiPinSet);

/* 7.4 LPMODE */
AD5940Err AD5940_LPModeEnS(BoolFlag LPModeEn); /* Enable LP mode or disable it. */
void      AD5940_LPModeClkS(uint32_t LPModeClk);
void      AD5940_ADCRepeatCfg(uint32_t Number);
/* 7.5 Power */
void      AD5940_SleepKeyCtrlS(uint32_t SlpKey); /* enter the correct key to allow AFE to enter sleep mode */
void      AD5940_EnterSleepS(void);      /* Put AFE to hibernate/sleep mode and keep LP loop as the default settings. */
void      AD5940_ShutDownS(void);    /* Unlock the key, turn off LP loop and enter sleep/hibernate mode  */
uint32_t  AD5940_WakeUp(int32_t TryCount);   /* Try to wakeup AFE by read register */
uint32_t  AD5940_GetADIID(void);   /* Read ADIID */
uint32_t  AD5940_GetChipID(void);  /* Read Chip ID */
AD5940Err AD5940_SoftRst(void);
void      AD5940_HWReset(void);       /* Do hardware reset to AD5940 using RESET pin */
/* Calibration functions */
/* 8. Calibration */
AD5940Err AD5940_ADCPGACal(ADCPGACal_Type *ADCPGACal);
AD5940Err AD5940_LPDACCal(LPDACCal_Type *pCalCfg, LPDACPara_Type *pResult);
AD5940Err AD5940_LPTIAOffsetCal(LPTIAOffsetCal_Type *pLPTIAOffsetCal);
AD5940Err AD5940_HSRtiaCal(HSRTIACal_Type *pCalCfg, void *pResult);
AD5940Err AD5940_HSDACCal(HSDACCal_Type *pCalCfg);
AD5940Err AD5940_LPRtiaCal(LPRTIACal_Type *pCalCfg, void *pResult);
AD5940Err AD5940_LFOSCMeasure(LFOSCMeasure_Type *pCfg, float *pFreq);
//void      AD5940_LFOSCTrim(uint32_t TrimValue);  /* TrimValue: 0 to 15 */
//void      AD5940_HFOSC16MHzTrim(uint32_t TrimValue);
//void      AD5940_HFOSC32MHzTrim(uint32_t TrimValue);

/* 9. Pure software functions. Functions with no register access. These functions are helpers */
  /* Sequence Generator */
void      AD5940_SEQGenInit(uint32_t *pBuffer, uint32_t BufferSize);/* Initialize sequence generator workspace */
void      AD5940_SEQGenCtrl(BoolFlag bFlag);  /* Enable or disable sequence generator */
void      AD5940_SEQGenInsert(uint32_t CmdWord); /* Manually insert a sequence command */
AD5940Err AD5940_SEQGenFetchSeq(const uint32_t **ppSeqCmd, uint32_t *pSeqCount);  /* Fetch generated sequence and start a new sequence */
void      AD5940_ClksCalculate(ClksCalInfo_Type *pFilterInfo, uint32_t *pClocks);
uint32_t  AD5940_SEQCycleTime(void);
void      AD5940_SweepNext(SoftSweepCfg_Type *pSweepCfg, float *pNextFreq);
void      AD5940_StructInit(void *pStruct, uint32_t StructSize);
float     AD5940_ADCCode2Volt(uint32_t code, uint32_t ADCPga, float VRef1p82); /* Calculate ADC code to voltage */
BoolFlag  AD5940_Notch50HzAvailable(ADCFilterCfg_Type *pFilterInfo, uint8_t *dl);
BoolFlag  AD5940_Notch60HzAvailable(ADCFilterCfg_Type *pFilterInfo, uint8_t *dl);
fImpCar_Type AD5940_ComplexDivFloat(fImpCar_Type *a, fImpCar_Type *b);
fImpCar_Type AD5940_ComplexMulFloat(fImpCar_Type *a, fImpCar_Type *b);
fImpCar_Type AD5940_ComplexAddFloat(fImpCar_Type *a, fImpCar_Type *b);
fImpCar_Type AD5940_ComplexSubFloat(fImpCar_Type *a, fImpCar_Type *b);

fImpCar_Type AD5940_ComplexDivInt(iImpCar_Type *a, iImpCar_Type *b);
fImpCar_Type AD5940_ComplexMulInt(iImpCar_Type *a, iImpCar_Type *b);
float     AD5940_ComplexMag(fImpCar_Type *a);
float     AD5940_ComplexPhase(fImpCar_Type *a);
FreqParams_Type AD5940_GetFreqParameters(float freq);
/**
 * @} Exported_Functions
*/

/**
 * @defgroup Library_Interface
 *  The functions user should provide for specific MCU platform
 * @{
*/
void      AD5940_CsClr(void);
void      AD5940_CsSet(void);
void      AD5940_RstClr(void);
void      AD5940_RstSet(void);
void      AD5940_Delay10us(uint32_t time);
/* (Not used for now.)AD5940 has 8 GPIOs, some of them are connected to MCU. MCU can set or read the status of these pins. */
void      AD5940_MCUGpioWrite(uint32_t data);   /*  */
uint32_t  AD5940_MCUGpioRead(uint32_t);
void      AD5940_MCUGpioCtrl(uint32_t, BoolFlag);
void      AD5940_ReadWriteNBytes(unsigned char *pSendBuffer,unsigned char *pRecvBuff,unsigned long length);
/* Below functions are frequently used in example code but not necessary for library */
uint32_t  AD5940_GetMCUIntFlag(void);
uint32_t  AD5940_ClrMCUIntFlag(void);
uint32_t  AD5940_MCUResourceInit(void *pCfg);
/**
 * @} Library_Interface
*/