178 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			178 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /****************************************************************************
 | |
|  *
 | |
|  * Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | |
|  *
 | |
|  * This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | |
|  * be copied by any method or incorporated into another program without
 | |
|  * the express written consent of Aerospace C.Power. This Information or any portion
 | |
|  * thereof remains the property of Aerospace C.Power. The Information contained herein
 | |
|  * is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | |
|  * liability for its use in any way and conveys no license or title under
 | |
|  * any patent or copyright and makes no representation or warranty that this
 | |
|  * Information is free from patent or copyright infringement.
 | |
|  *
 | |
|  * ****************************************************************************/
 | |
| 
 | |
| #ifndef SADC_H
 | |
| #define SADC_H
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| typedef enum {
 | |
|     ANA_SADC0                   = 0,
 | |
|     ANA_SADC1                   = 1,
 | |
| } sadc_id_t;
 | |
| 
 | |
| typedef enum {
 | |
|     SADC_CLK_FREQ_25M,
 | |
|     SADC_CLK_FREQ_12M5
 | |
| } sadc_clk_freq_t;
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_init(sadc_id_t sadc_id) - init sadc sub system.
 | |
|  *
 | |
|  * @param sadc_id:          sadc0 or sadc1
 | |
|  * @param clk_freq:         sadc clock frequency, see sadc_clk_freq_t
 | |
|  */
 | |
| void sadc_init(sadc_id_t sadc_id, sadc_clk_freq_t *clk_freq);
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_phase_sel() - set phase channel
 | |
|  *
 | |
|  * @param sadc_id:      sadc0 or sadc1
 | |
|  * @param phs:          phase
 | |
|  *
 | |
|  * @return 0:           success
 | |
|  * @return NON-0:       error
 | |
|  */
 | |
| int32_t sadc_phase_sel(sadc_id_t sadc_id,uint8_t phs);
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_data_num_set() - set data number
 | |
|  *
 | |
|  * @param sadc_id:      sadc0 or sadc1
 | |
|  * @param phs:          phase
 | |
|  * @param num:          data number
 | |
|  *
 | |
|  * @return 0:           success
 | |
|  * @return NON-0:       error
 | |
|  */
 | |
| int32_t sadc_data_num_set(sadc_id_t sadc_id, uint8_t phs, uint32_t num);
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_discard_num_set() - discard number for crosstalk.
 | |
|  *
 | |
|  * @param sadc_id:      sadc0 or sadc1
 | |
|  * @param phs:          phase
 | |
|  * @param num:          discard number
 | |
|  *
 | |
|  * @return 0:           success
 | |
|  * @return NON-0:       error
 | |
|  */
 | |
| int32_t sadc_discard_num_set(sadc_id_t sadc_id, uint8_t phs, uint32_t num);
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_phase_sel_scl_mux() - set adc gain value
 | |
|  *
 | |
|  * @param phase:        mux adc channel select
 | |
|  * @param channel_num:  adc channel number
 | |
|  *
 | |
|  * @return 0:           success
 | |
|  * @return NON-0:       error
 | |
|  */
 | |
| int32_t sadc_phase_sel_scl_mux(uint8_t phase, uint8_t channel_num);
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_poll_data_start() - get adc value code which is calibrated.
 | |
|  * @note  code convert to voltage is different for kl1/2/3.
 | |
|  * @param ch:               adc channel.
 | |
|  * @param acc:              enum ADC_ACC
 | |
|  * @param gain:             enum ADC_GAIN
 | |
|  * @param err_num:          err_num return value;
 | |
|                             0 - normal. data is OK
 | |
|                             1 - timeout, data is not OK.
 | |
|  * @return                  adc value code which is calibrated.
 | |
|  */
 | |
| int32_t sadc_poll_data_start(uint32_t ch, uint8_t acc, uint8_t gain,
 | |
|     uint8_t *err_num);
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_poll_volt_start() - get adc voltage which is calibrated.
 | |
|  * @param ch:               adc channel.
 | |
|  * @param gain:             enum ADC_GAIN
 | |
|  * @param err_num:          err_num return value;
 | |
|                             0 - normal. data is OK
 | |
|                             1 - timeout, data is not OK.
 | |
|  * @return                  adc voltage which is calibrated, uint: mV.
 | |
|  */
 | |
| int32_t sadc_poll_volt_start(uint32_t ch, uint8_t gain, uint8_t *err_num);
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_poll_volt_start_real() - get adc voltage which is not calibrated.
 | |
|  * @param ch:               adc channel.
 | |
|  * @param gain:             enum ADC_GAIN
 | |
|  * @param err_num:          err_num return value;
 | |
|                             0 - normal. data is OK
 | |
|                             1 - timeout, data is not OK.
 | |
|  * @return                  adc voltage which is not calibrated, uint: mV.
 | |
|  */
 | |
| int32_t sadc_poll_volt_start_real(uint32_t ch, uint8_t gain, uint8_t *err_num);
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_m_cali_data_refresh() - adc module cali data changed, need to reload.
 | |
|  *
 | |
|  * @param none
 | |
|  * @return none
 | |
|  */
 | |
| void sadc_m_cali_data_refresh(void);
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_temperature_val_get(uint8_t type) - get core temperature.
 | |
|  * @param :                 type:temperature type: 0 rawdata 1 Calibrated data
 | |
|  * @return:                 core temperature, unit: ℃;
 | |
|  */
 | |
| float sadc_temperature_val_get(uint8_t type);
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_temperature_val_get_raw() - get core temperature raw.
 | |
|  * @param temp:             to get temperature, unit: ℃;
 | |
|  * @return:                 0: success othre:fail;
 | |
|  */
 | |
| int32_t sadc_temperature_val_get_raw(float *temp);
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_temperature_val_update() - update temperature in variables.
 | |
|  * @param :                 [none.]
 | |
|  * @return:                 0:sucess other:fail;
 | |
|  */
 | |
| int32_t sadc_temperature_val_update(void);
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_start_en() - enable sadc module
 | |
|  *
 | |
|  * @param sadc_id:      sadc0 or sadc1
 | |
|  * @param en:           0--disable, 1--enable
 | |
|  *
 | |
|  * @return none
 | |
|  */
 | |
| void sadc_start_en(sadc_id_t sadc_id, uint8_t en);
 | |
| 
 | |
| /**
 | |
|  * @brief sadc_phase_mode_set() - set phase mode
 | |
|  *
 | |
|  * @param sadc_id:      sadc0 or sadc1
 | |
|  * @param mode:         0-1 phase, >0-multi phase, refs SADC_PHS_MODE.
 | |
|  *
 | |
|  * @return none
 | |
|  */
 | |
| void sadc_phase_mode_set(sadc_id_t sadc_id, uint8_t mode);
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif/*SADC_H*/
 | |
| 
 |