- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Functions
csl_sar.c File Reference

SAR functional layer API source file. More...

`#include "csl_sar.h"`

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

## Detailed Description

SAR functional layer API source file.

Path: \(CSLPATH)\src

## Function Documentation

CSL_Status SAR_A2DMeasParamSet | ( | SAR_Handle | 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 - Invalid handler
- 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);

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

References CSL_SarHandleObj::baseAddr, CSL_BATTRY_MEAS, CSL_INT_VOLT_MEAS, CSL_KEYPAD_MEAS, CSL_PEN_PRESS_DOWN, CSL_SAR_CHAN_1, CSL_SAR_CHAN_3, CSL_SAR_CHAN_5, CSL_TOUCH_SCREEN_XAXIS, CSL_TOUCH_SCREEN_YAXIS, and CSL_VOLUME_CTRL.

CSL_Status SAR_chanClose | ( | SAR_Handle | 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 - Invalid handler

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);

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

References CSL_SarHandleObj::baseAddr, CSL_SarHandleObj::chanNo, CSL_SAR_ADC_START, CSL_SAR_CLOSE, CSL_SAR_NO_CHAN, and CSL_SarHandleObj::status.

CSL_Status SAR_chanConfig | ( | SAR_Handle | hSar,
|  | 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 or configParam 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);
             ...

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

References CSL_SarHandleObj::baseAddr, CSL_SarChConfig::SARCLKCTRL, CSL_SarChConfig::SARCTRL, CSL_SarChConfig::SARGPOCTRL, and CSL_SarChConfig::SARPINCTRL.

CSL_Status SAR_chanCycSet | ( | SAR_Handle | 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 - Invalid handle
- 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);

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

References CSL_SarHandleObj::baseAddr, CSL_SAR_CONTINUOUS_CONVERSION, and CSL_SAR_SINGLE_CONVERSION.

CSL_Status SAR_chanSetup | ( | SAR_Handle | hSar,
|  | 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 or SarParam 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);
             ...

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

References CSL_SarHandleObj::baseAddr, CSL_SAR_DISCHARGE_ARRAY, CSL_SAR_DMA, CSL_SAR_INTERRUPT, CSL_SAR_MAX_CLKDIV, CSL_SAR_NO_DISCHARGE, CSL_SAR_POLLING, CSL_SAR_REF_0_8v, CSL_SAR_REF_1v, CSL_SAR_REF_VIN, CSL_SarChSetup::MultiCh, CSL_SarChSetup::OpMode, CSL_SarChSetup::RefVoltage, and CSL_SarChSetup::SysClkDiv.

CSL_Status SAR_getConfig | ( | SAR_Handle | hSar,
|  | 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 or configParam 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);
             ...

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

References CSL_SarHandleObj::baseAddr, CSL_SarChConfig::SARCLKCTRL, CSL_SarChConfig::SARCTRL, CSL_SarChConfig::SARGPOCTRL, and CSL_SarChConfig::SARPINCTRL.

CSL_Status SAR_readData | ( | SAR_Handle | hSar,
|  | Uint16 * | readData
| ) |  |

============================================================================
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 - Invalid handler

Pre Condition
SAR_A2DMeasParamSet or (SAR_chanCoonfig API ) and SAR_startConversion 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);
                status = SAR_readData(hSar, &readData);

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

References CSL_SarHandleObj::baseAddr.

CSL_Status SAR_startConversion | ( | SAR_Handle | 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 - Invalid handle

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);

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

References CSL_SarHandleObj::baseAddr.

CSL_Status SAR_stopConversion | ( | SAR_Handle | 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 - Invalid handle

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);

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

References CSL_SarHandleObj::baseAddr, and CSL_SAR_ADC_START.