HPM SDK
HPMicro Software Development Kit
hpm_clc_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_CLC_DRV_H
9 #define HPM_CLC_DRV_H
10 
11 #include "hpm_common.h"
12 #include "hpm_clc_regs.h"
13 #include "hpm_soc_feature.h"
14 
25 typedef enum {
28 } clc_chn_t;
33 typedef enum {
42 typedef enum {
55 
59 typedef struct {
60  int32_t eadc_lowth;
61  int32_t eadc_mid_lowth;
62  int32_t eadc_mid_highth;
63  int32_t eadc_highth;
64  int32_t _2p2z_clamp_lowth;
65  int32_t _2p2z_clamp_highth;
66  int32_t _3p3z_clamp_lowth;
67  int32_t _3p3z_clamp_highth;
76 typedef struct {
77  float b0;
78  float b1;
79  float b2;
80  float b3;
81  float a0;
82  float a1;
83  float a2;
86 #ifdef __cplusplus
87 extern "C" {
88 #endif
89 
97 static inline void clc_set_enable(CLC_Type *clc, clc_chn_t chn, bool enable)
98 {
99  if (enable) {
101  } else {
103  }
104 }
105 
113 static inline void clc_set_mask_mode_enable(CLC_Type *clc, clc_chn_t chn, bool enable)
114 {
115  if (enable) {
117  } else {
119  }
120 }
121 
129 static inline void clc_set_sw_inject_dq_mode_enable(CLC_Type *clc, clc_chn_t chn, bool enable)
130 {
131  if (enable) {
133  } else {
135  }
136 }
137 
147 static inline void clc_set_irq_enable(CLC_Type *clc, clc_chn_t chn, uint32_t irq_mask, bool enable)
148 {
149  if (enable) {
150  clc->VDVQ_CHAN[chn].MODE |= CLC_VDVQ_CHAN_MODE_ENABLE_IRQ_SET(irq_mask);
151  } else {
152  clc->VDVQ_CHAN[chn].MODE &= ~CLC_VDVQ_CHAN_MODE_ENABLE_IRQ_SET(irq_mask);
153  }
154 }
155 
163 static inline uint32_t clc_get_irq_status(CLC_Type *clc, clc_chn_t chn)
164 {
166 }
167 
174 static inline void clc_clear_irq_status(CLC_Type *clc, clc_chn_t chn, uint32_t irq_mask)
175 {
176  clc->VDVQ_CHAN[chn].STATUS = CLC_VDVQ_CHAN_STATUS_STATUS_SET(irq_mask);
177 }
178 
187 static inline bool clc_get_irq_flag(CLC_Type *clc, clc_chn_t chn, uint32_t irq_mask)
188 {
189  return ((clc->VDVQ_CHAN[chn].STATUS & irq_mask) == irq_mask) ? true : false;
190 }
191 
199 static inline void clc_set_adc_chn_offset(CLC_Type *clc, clc_chn_t chn, uint32_t adc_chn, uint32_t adc_offset)
200 {
201  clc->VDVQ_CHAN[chn].ADC_CHAN = adc_chn;
202  clc->VDVQ_CHAN[chn].ADC_OFFSET = adc_offset;
203 }
204 
211 static inline void clc_set_pwm_period(CLC_Type *clc, clc_chn_t chn, uint32_t pwm_period)
212 {
213  clc->VDVQ_CHAN[chn].PWM_PERIOD = pwm_period;
214 }
215 
222 static inline uint32_t clc_get_pwm_period(CLC_Type *clc, clc_chn_t chn)
223 {
224  return clc->VDVQ_CHAN[chn].PWM_PERIOD;
225 }
226 
233 static inline uint32_t clc_get_output_value(CLC_Type *clc, clc_chn_t chn)
234 {
235  return clc->VDVQ_CHAN[chn].OUTPUT_VALUE;
236 }
237 
244 static inline uint32_t clc_get_timestamp(CLC_Type *clc, clc_chn_t chn)
245 {
246  return clc->VDVQ_CHAN[chn].TIMESTAMP;
247 }
248 
255 static inline int32_t clc_get_eadc_current_value(CLC_Type *clc, clc_chn_t chn)
256 {
257  return (int32_t)clc->VDVQ_CHAN[chn].EADC_CURR;
258 }
259 
266 static inline int32_t clc_get_eadc_previous0_value(CLC_Type *clc, clc_chn_t chn)
267 {
268  return (int32_t)clc->VDVQ_CHAN[chn].EADC_PRE0;
269 }
270 
277 static inline void clc_sw_inject_eadc_previous0_value(CLC_Type *clc, clc_chn_t chn, int32_t value)
278 {
279  clc->VDVQ_CHAN[chn].EADC_PRE0 = (uint32_t)value;
280 }
281 
288 static inline int32_t clc_get_eadc_previous1_value(CLC_Type *clc, clc_chn_t chn)
289 {
290  return (int32_t)clc->VDVQ_CHAN[chn].EADC_PRE1;
291 }
292 
299 static inline void clc_sw_inject_eadc_previous1_value(CLC_Type *clc, clc_chn_t chn, int32_t value)
300 {
301  clc->VDVQ_CHAN[chn].EADC_PRE1 = (uint32_t)value;
302 }
303 
310 static inline int32_t clc_get_2p2z_current_value(CLC_Type *clc, clc_chn_t chn)
311 {
312  return (int32_t)clc->VDVQ_CHAN[chn].P2Z2_CURR;
313 }
314 
321 static inline void clc_sw_inject_2p2z_current_value(CLC_Type *clc, clc_chn_t chn, int32_t value)
322 {
323  clc->VDVQ_CHAN[chn].P2Z2_CURR = (uint32_t)value;
324 }
325 
332 static inline int32_t clc_get_2p2z_previous0_value(CLC_Type *clc, clc_chn_t chn)
333 {
334  return (int32_t)clc->VDVQ_CHAN[chn].P2Z2_PRE0;
335 }
336 
343 static inline void clc_sw_inject_2p2z_previous0_value(CLC_Type *clc, clc_chn_t chn, int32_t value)
344 {
345  clc->VDVQ_CHAN[chn].P2Z2_PRE0 = (uint32_t)value;
346 }
347 
354 static inline int32_t clc_get_3p3z_current_value(CLC_Type *clc, clc_chn_t chn)
355 {
356  return (int32_t)clc->VDVQ_CHAN[chn].P3Z3_CURR;
357 }
358 
365 static inline void clc_sw_inject_3p3z_current_value(CLC_Type *clc, clc_chn_t chn, int32_t value)
366 {
367  clc->VDVQ_CHAN[chn].P3Z3_CURR = (uint32_t)value;
368 }
369 
376 static inline void clc_set_expect_adc_value(CLC_Type *clc, clc_chn_t chn, int32_t expect)
377 {
378  clc->VDVQ_CHAN[chn].ADC_EXPECT = (uint32_t)expect;
379 }
380 
387 static inline void clc_sw_inject_adc_value(CLC_Type *clc, clc_chn_t chn, uint32_t value)
388 {
389  clc->VDVQ_CHAN[chn].ADC_SW = value;
390 }
391 
397 {
399 }
400 
407 void clc_config_param(CLC_Type *clc, clc_chn_t chn, clc_param_config_t *param);
408 
420 
421 #if defined(HPM_IP_FEATURE_CLC_DECOUPLING) && HPM_IP_FEATURE_CLC_DECOUPLING
427 static inline void clc_sw_inject_speed_value(CLC_Type *clc, int32_t value)
428 {
429  clc->VDVQ_CHAN[clc_vd_chn].SPEED_SW = value;
430 }
431 
438 static inline void clc_set_decoupling_scaling(CLC_Type *clc, clc_chn_t chn, uint32_t left_shift_value)
439 {
440  clc->VDVQ_CHAN[chn].DECOUPLE_SCALING = left_shift_value;
441 }
442 
453 hpm_stat_t clc_set_decoupling_ind_ke(CLC_Type *clc, clc_chn_t chn, float ind, float ke);
454 #endif
455 
462 void clc_sw_inject_dq_adc_value(CLC_Type *clc, uint32_t d_value, uint32_t q_value);
463 
464 
465 #ifdef __cplusplus
466 }
467 #endif
471 #endif /* HPM_CLC_DRV_H */
static void clc_set_irq_enable(CLC_Type *clc, clc_chn_t chn, uint32_t irq_mask, bool enable)
CLC set irq enable or disable.
Definition: hpm_clc_drv.h:147
static void clc_set_adc_chn_offset(CLC_Type *clc, clc_chn_t chn, uint32_t adc_chn, uint32_t adc_offset)
CLC set adc channel.
Definition: hpm_clc_drv.h:199
static void clc_sw_inject_3p3z_current_value(CLC_Type *clc, clc_chn_t chn, int32_t value)
CLC software inject 3p3z last value.
Definition: hpm_clc_drv.h:365
static void clc_set_sw_inject_dq_adc_value_ready(CLC_Type *clc)
CLC set software inject dq adc value ready, this will trig clc calculation.
Definition: hpm_clc_drv.h:396
static uint32_t clc_get_output_value(CLC_Type *clc, clc_chn_t chn)
CLC get output caculated value.
Definition: hpm_clc_drv.h:233
static int32_t clc_get_2p2z_current_value(CLC_Type *clc, clc_chn_t chn)
CLC get 2p2z last value.
Definition: hpm_clc_drv.h:310
static uint32_t clc_get_timestamp(CLC_Type *clc, clc_chn_t chn)
CLC get timestamp.
Definition: hpm_clc_drv.h:244
static void clc_set_sw_inject_dq_mode_enable(CLC_Type *clc, clc_chn_t chn, bool enable)
CLC set software inject dq work mode.
Definition: hpm_clc_drv.h:129
void clc_config_param(CLC_Type *clc, clc_chn_t chn, clc_param_config_t *param)
CLC parameter configuration.
Definition: hpm_clc_drv.c:10
static bool clc_get_irq_flag(CLC_Type *clc, clc_chn_t chn, uint32_t irq_mask)
CLC check irq request flag.
Definition: hpm_clc_drv.h:187
static void clc_set_expect_adc_value(CLC_Type *clc, clc_chn_t chn, int32_t expect)
CLC set expected adc value.
Definition: hpm_clc_drv.h:376
clc_coeff_zone_t
clc coefficient zone
Definition: hpm_clc_drv.h:33
static void clc_sw_inject_2p2z_previous0_value(CLC_Type *clc, clc_chn_t chn, int32_t value)
CLC software inject 2p2z previous0 value.
Definition: hpm_clc_drv.h:343
void clc_sw_inject_dq_adc_value(CLC_Type *clc, uint32_t d_value, uint32_t q_value)
CLC software inject dq adc value.
Definition: hpm_clc_drv.c:97
static uint32_t clc_get_pwm_period(CLC_Type *clc, clc_chn_t chn)
CLC set pwm period.
Definition: hpm_clc_drv.h:222
static void clc_sw_inject_eadc_previous1_value(CLC_Type *clc, clc_chn_t chn, int32_t value)
CLC software inject error adc previous1 value.
Definition: hpm_clc_drv.h:299
static void clc_sw_inject_2p2z_current_value(CLC_Type *clc, clc_chn_t chn, int32_t value)
CLC software inject 2p2z last value.
Definition: hpm_clc_drv.h:321
clc_irq_mask_t
clc irq mask bit
Definition: hpm_clc_drv.h:42
static void clc_clear_irq_status(CLC_Type *clc, clc_chn_t chn, uint32_t irq_mask)
CLC clear irq status.
Definition: hpm_clc_drv.h:174
static void clc_set_mask_mode_enable(CLC_Type *clc, clc_chn_t chn, bool enable)
CLC keep working even if bad irq status ocurred.
Definition: hpm_clc_drv.h:113
static int32_t clc_get_eadc_current_value(CLC_Type *clc, clc_chn_t chn)
CLC get error adc latest value.
Definition: hpm_clc_drv.h:255
static int32_t clc_get_eadc_previous0_value(CLC_Type *clc, clc_chn_t chn)
CLC get error adc previous0 value.
Definition: hpm_clc_drv.h:266
static int32_t clc_get_2p2z_previous0_value(CLC_Type *clc, clc_chn_t chn)
CLC get 2p2z previous0 value.
Definition: hpm_clc_drv.h:332
static int32_t clc_get_3p3z_current_value(CLC_Type *clc, clc_chn_t chn)
CLC get 3p3z last value.
Definition: hpm_clc_drv.h:354
hpm_stat_t clc_config_coeff(CLC_Type *clc, clc_chn_t chn, clc_coeff_zone_t zone, clc_coeff_config_t *coeff)
CLC coefficient configuration.
Definition: hpm_clc_drv.c:25
static void clc_sw_inject_eadc_previous0_value(CLC_Type *clc, clc_chn_t chn, int32_t value)
CLC software inject error adc previous0 value.
Definition: hpm_clc_drv.h:277
clc_chn_t
clc channel
Definition: hpm_clc_drv.h:25
static int32_t clc_get_eadc_previous1_value(CLC_Type *clc, clc_chn_t chn)
CLC get error adc previous1 value.
Definition: hpm_clc_drv.h:288
static void clc_set_pwm_period(CLC_Type *clc, clc_chn_t chn, uint32_t pwm_period)
CLC set pwm period.
Definition: hpm_clc_drv.h:211
static void clc_sw_inject_adc_value(CLC_Type *clc, clc_chn_t chn, uint32_t value)
CLC software inject adc value. If it's not dq mode, this will trig clc calculation.
Definition: hpm_clc_drv.h:387
static uint32_t clc_get_irq_status(CLC_Type *clc, clc_chn_t chn)
CLC get irq status.
Definition: hpm_clc_drv.h:163
static void clc_set_enable(CLC_Type *clc, clc_chn_t chn, bool enable)
CLC enable or disable.
Definition: hpm_clc_drv.h:97
@ clc_coeff_zone_1
Definition: hpm_clc_drv.h:35
@ clc_coeff_zone_0
Definition: hpm_clc_drv.h:34
@ clc_coeff_zone_2
Definition: hpm_clc_drv.h:36
@ clc_irq_2p2z_over_hi
Definition: hpm_clc_drv.h:46
@ clc_irq_calc_done
Definition: hpm_clc_drv.h:43
@ clc_irq_2p2z_clamp_setting_err
Definition: hpm_clc_drv.h:45
@ clc_irq_2p2z_over_lo
Definition: hpm_clc_drv.h:47
@ clc_irq_forb_setting_err
Definition: hpm_clc_drv.h:52
@ clc_irq_2p2z_over_sf
Definition: hpm_clc_drv.h:48
@ clc_irq_eadc_setting_err
Definition: hpm_clc_drv.h:44
@ clc_irq_3p3z_over_lo
Definition: hpm_clc_drv.h:51
@ clc_irq_3p3z_clamp_setting_err
Definition: hpm_clc_drv.h:49
@ clc_irq_data_in_forbid
Definition: hpm_clc_drv.h:53
@ clc_irq_3p3z_over_hi
Definition: hpm_clc_drv.h:50
@ clc_vd_chn
Definition: hpm_clc_drv.h:26
@ clc_vq_chn
Definition: hpm_clc_drv.h:27
#define BIT4_MASK
Definition: hpm_common.h:90
uint32_t hpm_stat_t
Definition: hpm_common.h:123
#define BIT8_MASK
Definition: hpm_common.h:94
#define BIT2_MASK
Definition: hpm_common.h:88
#define BIT5_MASK
Definition: hpm_common.h:91
#define BIT1_MASK
Definition: hpm_common.h:87
#define BIT7_MASK
Definition: hpm_common.h:93
#define BIT10_MASK
Definition: hpm_common.h:96
#define BIT3_MASK
Definition: hpm_common.h:89
#define BIT6_MASK
Definition: hpm_common.h:92
#define BIT0_MASK
Definition: hpm_common.h:86
#define BIT9_MASK
Definition: hpm_common.h:95
#define CLC_VDVQ_CHAN_STATUS_STATUS_GET(x)
Definition: hpm_clc_regs.h:482
#define CLC_VDVQ_CHAN_VQ
Definition: hpm_clc_regs.h:504
#define CLC_VDVQ_CHAN_STATUS_STATUS_SET(x)
Definition: hpm_clc_regs.h:481
#define CLC_COEFF_0
Definition: hpm_clc_regs.h:498
#define CLC_VDVQ_CHAN_MODE_DQ_MODE_MASK
Definition: hpm_clc_regs.h:86
#define CLC_VDVQ_CHAN_MODE_ENABLE_CLC_MASK
Definition: hpm_clc_regs.h:66
#define CLC_VDVQ_CHAN_MODE_MASK_MODE_MASK
Definition: hpm_clc_regs.h:76
#define CLC_VDVQ_CHAN_VD
Definition: hpm_clc_regs.h:503
#define CLC_VDVQ_CHAN_MODE_ENABLE_IRQ_SET(x)
Definition: hpm_clc_regs.h:109
#define CLC_DQ_ADC_SW_READY_DQ_ADC_SW_READY_MASK
Definition: hpm_clc_regs.h:490
#define CLC_COEFF_2
Definition: hpm_clc_regs.h:500
#define CLC_COEFF_1
Definition: hpm_clc_regs.h:499
Definition: hpm_clc_regs.h:12
__RW uint32_t MODE
Definition: hpm_clc_regs.h:14
__R uint32_t OUTPUT_VALUE
Definition: hpm_clc_regs.h:38
__RW uint32_t P3Z3_CURR
Definition: hpm_clc_regs.h:46
__W uint32_t STATUS
Definition: hpm_clc_regs.h:54
__RW uint32_t ADC_EXPECT
Definition: hpm_clc_regs.h:15
__RW uint32_t ADC_SW
Definition: hpm_clc_regs.h:52
__RW uint32_t ADC_CHAN
Definition: hpm_clc_regs.h:16
__R uint32_t TIMESTAMP
Definition: hpm_clc_regs.h:39
__RW uint32_t P2Z2_CURR
Definition: hpm_clc_regs.h:43
__RW uint32_t EADC_PRE0
Definition: hpm_clc_regs.h:41
__RW uint32_t PWM_PERIOD
Definition: hpm_clc_regs.h:37
__RW uint32_t EADC_PRE1
Definition: hpm_clc_regs.h:42
__RW uint32_t P2Z2_PRE0
Definition: hpm_clc_regs.h:44
__RW uint32_t ADC_OFFSET
Definition: hpm_clc_regs.h:17
__RW uint32_t EADC_CURR
Definition: hpm_clc_regs.h:40
struct CLC_Type::@647 VDVQ_CHAN[2]
__W uint32_t DQ_ADC_SW_READY
Definition: hpm_clc_regs.h:56
clc coefficient configuration
Definition: hpm_clc_drv.h:76
float b3
Definition: hpm_clc_drv.h:80
float a2
Definition: hpm_clc_drv.h:83
float b2
Definition: hpm_clc_drv.h:79
float b0
Definition: hpm_clc_drv.h:77
float b1
Definition: hpm_clc_drv.h:78
float a0
Definition: hpm_clc_drv.h:81
float a1
Definition: hpm_clc_drv.h:82
clc parameter configuration
Definition: hpm_clc_drv.h:59
int32_t eadc_lowth
Definition: hpm_clc_drv.h:60
int32_t output_forbid_highth
Definition: hpm_clc_drv.h:70
int32_t output_forbid_mid
Definition: hpm_clc_drv.h:69
int32_t output_forbid_lowth
Definition: hpm_clc_drv.h:68
int32_t eadc_mid_highth
Definition: hpm_clc_drv.h:62
int32_t eadc_highth
Definition: hpm_clc_drv.h:63
int32_t eadc_mid_lowth
Definition: hpm_clc_drv.h:61