Functions
SAR Functions
SAR

Functions

CSL_Status SAR_init (void)
CSL_Status SAR_deInit (void)
CSL_Status SAR_chanOpen (CSL_SarHandleObj *Sarobj, CSL_SarChanSel chanSel)
CSL_Status SAR_chanClose (CSL_SarHandleObj *hsar)
CSL_Status SAR_chanInit (SAR_Handle hSar)
CSL_Status SAR_chanConfig (CSL_SarHandleObj *pSarHandle, CSL_SarChConfig *pConfigParam)
CSL_Status SAR_getConfig (CSL_SarHandleObj *pSarHandle, CSL_SarChConfig *pConfigParam)
CSL_Status SAR_chanSetup (CSL_SarHandleObj *pSarHandle, CSL_SarChSetup *pSarParam)
CSL_Status SAR_chanCycSet (CSL_SarHandleObj *hSar, CSL_SarChanCyc cycSelect)
CSL_Status SAR_startConversion (CSL_SarHandleObj *hSar)
CSL_Status SAR_stopConversion (CSL_SarHandleObj *hSar)
CSL_Status SAR_A2DMeasParamSet (CSL_SarHandleObj *hSar, CSL_SARMeasParam param, CSL_SarChanSel *chanNo)
CSL_Status SAR_readData (CSL_SarHandleObj *hSar, Uint16 *buffer)
CSL_Status SAR_GPODirSet (CSL_SarHandleObj *hSar, CSL_SarGPOPinSel Index, CSL_SarGPODir dir)
Bool SAR_getStatus (CSL_SarHandleObj *hSar, CSL_Status *status)

Function Documentation

CSL_Status SAR_A2DMeasParamSet ( CSL_SarHandleObj hSar,
CSL_SARMeasParam  param,
CSL_SarChanSel chanNo 
)

============================================================================
SAR_A2DMeasParamSet();

Description
This function initializes the device registers according to the type of A/D conversion

Arguments

            hSar      Pointer to SAR Object structure
            param     Enum variable for type of A/D conversion
            chanNo    Pointer to the channel number
     

Return Value CSL_Status

  • CSL_SOK - SAR_A2DMeasParamSet API call is successful
  • CSL_ESYS_BADHANDLE - SAR obj structure is NULL
  • CSL_ESYS_INVPARAMS - Invalid parameter

Pre Condition
SAR_chanSetup API must be called before calling this API

Post Condition
The registers will be configured according to input A/D type.

Modifies
Hardware registers of the specified SAR instance.

Example

        SAR_Handle          hSar;
        CSL_SarChSetup      SetupParam;
        CSL_SARMeasParam    param;
        CSL_SarChanSel      chanNo
        CSL_Status          status;
        ...
        status = SAR_chanSetup(hSar,&setupParam);
        ...
        status = SAR_A2DMeasParamSet (hSar, param , &chanNo);
     

============================================================================

CSL_Status SAR_chanClose ( CSL_SarHandleObj hsar)

============================================================================
SAR_chanClose

Description
This function closes the allocated channel .

Arguments

            hSar    Pointer to SAR object structure
     

Return Value CSL_Status

  • CSL_SOK - SAR_chanClose is successful
  • CSL_ESYS_BADHANDLE - SAR obj structure is NULL

Pre Condition
SAR_chanOpen API should be called before this API call

Post Condition
The particular channel will be free

Modifies
1. The status variable Example

            CSL_SarHandleObj    SarObj;
            CSL_SarHandle   hSar;
            CSL_status       status;
            CSL_SarChanSel      chanSel;

            SAR_init(NULL);
            ....
            status = CSL_sarOpen(&Sarobj,chanSel);
            hSar = &SarObj;
            ...

            status = SAR_chanClose(hSar);
     

============================================================================

CSL_Status SAR_chanConfig ( CSL_SarHandleObj pSarHandle,
CSL_SarChConfig pConfigParam 
)

============================================================================
SAR_chanConfig

Description
It provides Registers fields to configure SAR A/D Hardware Registers It configures the SAR registers as per the values passed in the corresponding SAR A/D Registers

Arguments

            SarHandle      Pointer to SAR object structure
            ConfigParam    Pointer to Config structure
     

Return Value CSL_Status

  • CSL_SOK - Config call is successful
  • CSL_ESYS_BADHANDLE - SAR obj structure is NULL
  • CSL_ESYS_INVPARAMS - Invalid parameter

Pre Condition
SAR_chanOpen API should be called before this API call

Post Condition
SAR Registers will be configured according to Hardware config structure parameters

Modifies
1. The status variable 2. SAR A/D Registers

Example

         CSL_SarHandleObj SarObj;
         CSL_Status     status;
         CSL_SarHandle  hSar ;
         CSL_SarChConfig  ConfigParam;
         ...
         status = SAR_chanOpen(&Sarobj,chanNo);
         hSar = &SarObj;
         status = SAR_chanConfig(hSar,&ConfigParam);
         ...
    

============================================================================

CSL_Status SAR_chanCycSet ( CSL_SarHandleObj hSar,
CSL_SarChanCyc  cycSelect 
)

============================================================================
SAR_chanCycSet

Description
It configures the SAR module in single conversion or continuous conversion mode as per the values passed in the CSL_SarChanCyc enum variables.

Arguments

            hSar            Pointer to SAR Object structure
            cycSelect       variable for selecting conversion type
     

Return Value CSL_Status

  • CSL_SOK - SAR_chanCycSet API call is successful
  • CSL_ESYS_BADHANDLE - Sar Object handle is NULL
  • CSL_ESYS_INVPARAMS - Ivalid parameter

Pre Condition
SAR_chanSetup API should be called before this API

Post Condition
SAR conversion type are configured according to the parameter

Modifies
SAR A/D Registers

Example

            CSL_SarHandle    hSar;
            CSL_SarChanCyc   cycSelect;
            CSL_status       status;
            CSL_SarChSetup  SarParam;
            ...

            status = SAR_chanOpen(&Sarobj,chanNo);
            SarHandle = &SarObj;
            status = SAR_chanSetup(SarHandle,&SarParam);
            status = SAR_chanCycSet(hSar, cycSelect);
     

============================================================================

CSL_Status SAR_chanInit ( SAR_Handle  hSar)

============================================================================
SAR_chanInit

Description
Dummy function .

Arguments

            hSar     pointer to Sar object handler
 *   

Return Value CSL_Status

  • CSL_SOK - SAR_chanInit call is successful
  • CSL_ESYS_BADHANDLE - SAR obj structure is NULL
  • CSL_ESYS_INVPARAMS - Invalid parameter

Pre Condition
SAR_chanOpen API should be called before this API call

Post Condition

Modifies
1. The status variable

Example

            CSL_SarHandleObj    SarObj;
            CSL_SarChanSel      chanNo;
            SAR_Handle          hSar;
            CSL_Status          status
            ...
            status = SAR_chanOpen(&Sarobj,chanNo);
            hSar = &SarObj;
            status = SAR_chanInit(hSar);
            ...

    

============================================================================

============================================================================
SAR_chanInit

Description
Dummy function .

Arguments

            hSar     pointer to Sar object handler                    
 *   

Return Value CSL_Status

  • CSL_SOK - SAR_chanInit call is successful
  • CSL_ESYS_BADHANDLE - Invalid handler

Pre Condition
SAR_chanOpen API should be called before this API call

Post Condition

Modifies
1. The status variable

Example

            CSL_SarHandleObj    SarObj;
            CSL_SarChanSel      chanNo;
            SAR_Handle          hSar;
            CSL_Status          status  
            ...
            status = SAR_chanOpen(&Sarobj,chanNo);
            hSar = &SarObj;
            status = SAR_chanInit(hSar);
            ...

    

============================================================================

CSL_Status SAR_chanOpen ( CSL_SarHandleObj SarObj,
CSL_SarChanSel  chanSel 
)

============================================================================
SAR_chanOpen

Description
This function populates the SAR object structure information ,

Arguments

 *              SarObj - Pointer to SAR Object structure
 *              chanNo - Channel Number to be selected
 *   

Return Value CSL_Status
CSL_SOK - SAR_chanOpen is successful
CSL_ESYS_BADHANDLE - SAR obj structure is NULL
CSL_ESYS_INVPARAMS - Invalid channel number requested

Pre Condition
SAR_init should be called before this API call

Post Condition
SAR object structure is populated

Modifies
SAR object structure

Example

            CSL_SarHandleObj    SarObj;
            CSL_SarChanSel      chanSel;
            SAR_Handle          hSar;
            CSL_Status          status;
            ...
            SAR_init(NULL);
            ....
            status = CSL_sarOpen(&Sarobj,chanSel);
            hSar = &SarObj;
            ...

    

============================================================================

References CSL_SarHandleObj::baseAddr, CSL_SarHandleObj::chanNo, CSL_SAR_CHAN_5, CSL_SAR_OPEN, and CSL_SarHandleObj::status.

CSL_Status SAR_chanSetup ( CSL_SarHandleObj pSarHandle,
CSL_SarChSetup pSarParam 
)

============================================================================
SAR_chanSetup

Description
It provides the setup parameters to the user to setup SAR A/D Registers accordingly .It setup the values in SAR registers as per the values passed in the hardware setup structure accordingly. Arguments

            SarHandle     Pointer to SAR Object structure
            SarParam      Module specific setup parameters
 *   

Return Value CSL_Status

  • CSL_SOK - SAR_chanSetup API call is successful
  • CSL_ESYS_BADHANDLE - SAR obj structure is NULL
  • CSL_ESYS_INVPARAMS - Invalid parameter

Pre Condition
SAR_chanOpen API should be called before this API call

Post Condition
SAR Registers will be configured according to Hardware setup parameters Modifies
1. The status variable
2. SAR A/D Registers Example

         CSL_SarHandleObj SarObj;
         CSL_Status     status;
         CSL_SarHandle  SarHandle;
         CSL_SarChSetup  SarParam;
         ...
         status = SAR_chanOpen(&Sarobj,chanNo);
         SarHandle = &SarObj;
         status = SAR_chanSetup(SarHandle,&SarParam);
         ...
    

============================================================================

CSL_Status SAR_deInit ( void  )

============================================================================
SAR_deInit

Description
This is the de-initialization function for the SAR CSL.

Return Value CSL_Status

  • CSL_SOK - SAR_deInit is successful

Pre Condition
SAR_init should be called before calling this API

Post Condition
It disable the SAR module

Modifies
status variable

Example

            SAR_deInit(NULL);
     

============================================================================

============================================================================
SAR_deInit

Description
This is the de-initialization function for the SAR CSL.

Return Value CSL_Status

  • CSL_SOK - SAR_deInit is successful

Pre Condition
None

Post Condition
It disable the SAR module

Modifies
None

Example

            SAR_deInit(NULL);
     

============================================================================

CSL_Status SAR_getConfig ( CSL_SarHandleObj pSarHandle,
CSL_SarChConfig pConfigParam 
)

============================================================================
SAR_getConfig

Description
It populates the values of the SAR registers in config structure

Arguments

            SarHandle      Pointer to SAR Object structure
            ConfigParam    Register specific parameters
     

Return Value CSL_Status

  • CSL_SOK - SAR_getConfig call is successful
  • CSL_ESYS_BADHANDLE - SAR obj structure is NULL
  • CSL_ESYS_INVPARAMS - Invalid parameter

Pre Condition
SAR_chanOpen API should be called before this API call

Post Condition
It populates the SAR register values in config structure

Modifies
1. The status variable

Example

         CSL_SarHandleObj SarObj;
         CSL_Status     status;
         CSL_SarHandle  SarHandle ;
         CSL_SarChConfig  ConfigParam;
         ...
         status = SAR_chanOpen(&Sarobj,chanNo);
         hSar = &SarObj;
         status = SAR_getConfig(SarHandle,&ConfigParam);
         ...
    

============================================================================

Bool SAR_getStatus ( CSL_SarHandleObj hSar,
CSL_Status *  status 
)

============================================================================
SAR_getStatus

Description
This function is useful for checking busy bit in SAR A/D Data Register It should be called in while loop till return value becomes zero before calling SAR_readData Arguments

            hSar         Pointer to SAR object structure
            status       status variable
 *   

Return Value Bool busyBit status CSL_SAR_DATA_AVAILABLE(0) - ADC data is available CSL_SAR_ADC_BUSY(1) - ADC conversion is going on

Pre Condition
SAR_A2DMeasParamSet or (SAR_chanCoonfig API ) and SAR_startConversion must be called before calling this API

Post Condition
Reads the busy bit- check whether ADC data is available or not and when return value is CSL_SAR_DATA_AVAILABLE ,SAR_readData should be called

Modifies
return value status variable

Example

            CSL_SarHandle   hSar;
            Uint32          readData;
            CSL_SarChSetup  SetupParam;
            ...
            status = SAR_chanSetup(hSar,&setupParam);
            status = SAR_A2DMeasParamSet (hSar, param , &chanNo);
            Or
            status = SAR_chanConfig(hSar,&configParam);

            status = SAR_startConversion(hSar);
            while(CSL_SAR_DATA_AVAILABLE != SAR_getStatus(hSar,&status));
            status = SAR_readData(hSar, &readData);
     

============================================================================

References CSL_SarHandleObj::baseAddr, and CSL_SAR_ADC_BUSY.

CSL_Status SAR_GPODirSet ( CSL_SarHandleObj hSar,
CSL_SarGPOPinSel  Index,
CSL_SarGPODir  dir 
)

============================================================================
SAR_GPODirSet

Description
This function is useful for configuring GPAIN pin as i/p or o/p

Arguments

            hSar         Pointer to SAR object structure
            Index        GPAIN Pin Index
            dir          Pin Direction i/p or o/p
     

Return Value CSL_Status

  • CSL_SOK - SAR_GPODataSet
  • CSL_ESYS_BADHANDLE - Invalid handler
  • CSL_ESYS_INVPARAMS - Invalid parameter

Pre Condition
SAR_chanOpen must be called before calling this API

Post Condition
Sets the direction for the given GPAIN pin

Modifies
SAR A/D GPO Register

Example

            CSL_SarHandle     hSar;
            CSL_SarGPOPinSel  Index;
            CSL_SarGPODir     dir;
            ...
            status = SAR_chanOpen(SarObj,chanSel);

            status = SAR_GPODirSet(hSar,Index,dir);
     

============================================================================

References CSL_SarHandleObj::baseAddr, CSL_SAR_GPO_0, CSL_SAR_GPO_1, CSL_SAR_GPO_2, CSL_SAR_GPO_3, CSL_SAR_GPO_IN, and CSL_SAR_GPO_OUT.

CSL_Status SAR_init ( void  )

============================================================================
SAR_init

Description
This is the initialization function for the SAR CSL. The function must be called before calling any other API from this CSL.

Return Value CSL_Status

  • CSL_SOK - Always returns

Pre Condition
None

Post Condition
It enables SAR module and resets the SAR registers to their default values

Modifies
SAR A/D Registers

Example

            SAR_init(NULL);
     

============================================================================

============================================================================
SAR_init

Description
This is the initialization function for the SAR CSL. The function must be called before calling any other API from this CSL.

Return Value CSL_Status

  • CSL_SOK - Always returns

Pre Condition
None

Post Condition
It enables SAR module and resets the SAR registers to their default value

Modifies
SAR A/D Registers

Example

            SAR_init(NULL);
     

============================================================================

CSL_Status SAR_readData ( CSL_SarHandleObj hSar,
Uint16 *  buffer 
)

============================================================================
SAR_readData

Description
It retrives the analog value converted in digital format (A/D output )

Arguments

            hSar     Pointer to SAR Object structure
            readData Pointer to the output of A/D converted result
     

Return Value CSL_Status

  • CSL_SOK - SAR_readData API call is successful
  • CSL_ESYS_BADHANDLE - SAR obj structure is NULL

Pre Condition
SAR_A2DMeasParamSet or (SAR_chanCoonfig API ) and SAR_startConversion , SAR_readData must be called before this API

Post Condition
The output of A/D conversion will be populated in the output buffer passed in the API

Modifies
readData variable

Example

            CSL_SarHandle   hSar;
            Uint32          readData;
            CSL_SarChSetup  SetupParam;
            ...
            status = SAR_chanSetup(hSar,&setupParam);
            status = SAR_A2DMeasParamSet (hSar, param , &chanNo);
            Or
            status = SAR_chanConfig(hSar,&configParam);

            status = SAR_startConversion(hSar);
            while(CSL_SAR_DATA_AVAILABLE != SAR_getStatus(hSar));
            status = SAR_readData(hSar, &readData);
     

============================================================================

CSL_Status SAR_startConversion ( CSL_SarHandleObj hSar)

============================================================================
SAR_startConversion

Description
It sets ADC start bit in SAR control Register and start SAR A/D conversion.

Arguments

           hSar    Pointer to SAR Object structure
 *   

Return Value CSL_Status

  • CSL_SOK - SAR_startConversion API call is successful.
  • CSL_ESYS_BADHANDLE - SAR obj structure is NULL

Pre Condition
Any of SAR-chanSetup, SAR_chanConfig and SAR_A2DMeasParamSet must be called before calling this API

Post Condition
SAR module will start A/D Conversion

Modifies
The hardware registers of SAR.

Example

        CSL_SarHandle hSar;
        ...

        status = SAR_startConversion (hSar);
     

============================================================================

CSL_Status SAR_stopConversion ( CSL_SarHandleObj hSar)

============================================================================
SAR_stopConversion

Description
Stops SAR Module A/D conversion

Arguments

            hSar   Pointer to SAR Object structure
 *   

Return Value CSL_Status

  • CSL_SOK - SAR_stopConversion API call is successful
  • CSL_ESYS_BADHANDLE - SAR obj structure is NULL

Pre Condition
SAR_startConversion API must be called before calling this API

Post Condition
SAR module stops conversion

Modifies
SAR hardware registers

Example

        CSL_SarHandle           hSar;
        CSL_Status              status
        ...

        status = SAR_stopConversion (hSar);
     

============================================================================