HPM SDK
HPMicro Software Development Kit
hpm_mcl_hw_loop.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2025 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 #ifndef HPM_MCL_HW_LOOP_H
8 #define HPM_MCL_HW_LOOP_H
9 #include "hpm_common.h"
10 #include "hpm_mcl_common.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
19 typedef struct {
20  void (*vsc_init)(void *data); /*< Initialize VSC hardware */
21  void (*clc_init)(void *data); /*< Initialize CLC hardware */
22  void (*qeo_init)(void *data); /*< Initialize QEO hardware */
23  /* Pre-processing callbacks */
24  void (*vsc_pre_process)(void *loop); /*< Pre-processing callback before VSC hardware loop */
25  void (*clc_pre_process)(void *loop); /*< Pre-processing callback before CLC hardware loop */
26  void (*qeo_pre_process)(void *loop); /*< Pre-processing callback before QEO hardware loop */
27  /* Post-processing callbacks */
28  void (*vsc_post_process)(void *loop); /*< Post-processing callback after VSC hardware loop */
29  void (*clc_post_process)(void *loop); /*< Post-processing callback after CLC hardware loop */
30  void (*qeo_post_process)(void *loop); /*< Post-processing callback after QEO hardware loop */
31  /* Input conversion callbacks - convert software values to hardware values */
32  void (*vsc_convert_input)(float ia, float ib, float ic, float position, uint32_t *ia_hardware, uint32_t *ib_hardware, uint32_t *ic_hardware, uint32_t *position_hardware); /*< Convert software value to VSC hardware value */
33  void (*clc_convert_input)(float d, float q, uint32_t *d_hardware, uint32_t *q_hardware); /*< Convert software value to CLC hardware value */
34  void (*qeo_convert_input)(float ud, float uq, float predicted_position, uint32_t *ud_hardware, uint32_t *uq_hardware, uint32_t *predicted_position_hardware); /*< Convert software value to QEO hardware value */
35  /* Output conversion callbacks - convert hardware values to software values */
36  void (*vsc_convert_output)(uint32_t alpha_hardware, uint32_t beta_hardware, uint32_t d_hardware, uint32_t q_hardware, float *alpha, float *beta, float *d, float *q); /*< Convert VSC hardware value to software value */
37  void (*clc_convert_output)(uint32_t ud_hardware, uint32_t uq_hardware, float *ud, float *uq); /*< Convert CLC hardware value to software value */
38  void (*qeo_convert_output)(uint32_t duty_u_hardware, uint32_t duty_v_hardware, uint32_t duty_w_hardware, float *duty_u, float *duty_v, float *duty_w); /*< Convert QEO hardware value to software value */
40 
44 typedef struct {
45  /* VSC configuration */
46  struct {
47  void *base;
48  } vsc_cfg;
49  /* CLC configuration */
50  struct {
51  void *base;
52  } clc_cfg;
53  /* QEO configuration */
54  struct {
55  void *base;
56  } qeo_cfg;
59 
60 typedef struct {
62  /* Hardware loop status */
63  struct {
64  bool vsc_enabled; /*< VSC hardware loop enabled */
65  bool clc_enabled; /*< CLC hardware loop enabled */
66  bool qeo_enabled; /*< QEO hardware loop enabled */
67  } hw_loop_status;
68  /* Hardware loop running data */
69  struct {
70  struct {
71  uint32_t ia; /*< phase current a */
72  uint32_t ib; /*< phase current b */
73  uint32_t ic; /*< phase current c */
74  uint32_t position; /*< position*/
75  uint32_t alpha; /*< alpha component */
76  uint32_t beta; /*< beta component */
77  uint32_t d; /*< d component */
78  uint32_t q; /*< q component */
79  uint32_t ud; /*< d component of voltage */
80  uint32_t uq; /*< q component of voltage */
81  uint32_t duty_u; /*< duty of phase u */
82  uint32_t duty_v; /*< duty of phase v */
83  uint32_t duty_w; /*< duty of phase w */
84  uint32_t predicted_position; /*< predicted position, if not needed, predicted_position = position*/
85  } hardware; /*< VSC raw data */
86  struct {
87  float ia; /*< phase current a */
88  float ib; /*< phase current b */
89  float ic; /*< phase current c */
90  float position; /*< position*/
91  float alpha; /*< alpha component */
92  float beta; /*< beta component */
93  float d; /*< d component */
94  float q; /*< q component */
95  float ud; /*< d component of voltage */
96  float uq; /*< q component of voltage */
97  float duty_u; /*< duty of phase u */
98  float duty_v; /*< duty of phase v */
99  float duty_w; /*< duty of phase w */
100  float predicted_position; /*< predicted position, if not needed, predicted_position = position*/
101  } software; /*< VSC converted data */
102  } hw_loop_data;
103 } mcl_hw_loop_t;
104 
105 
113 {
114  MCL_ASSERT_OPT(loop != NULL, mcl_invalid_pointer);
115  loop->hw_loop_status.vsc_enabled = true;
116 
117  return mcl_success;
118 }
119 
127 {
128  MCL_ASSERT_OPT(loop != NULL, mcl_invalid_pointer);
129  loop->hw_loop_status.vsc_enabled = false;
130 
131  return mcl_success;
132 }
133 
141 {
142  MCL_ASSERT_OPT(loop != NULL, mcl_invalid_pointer);
143  loop->hw_loop_status.clc_enabled = true;
144 
145  return mcl_success;
146 }
147 
155 {
156  MCL_ASSERT_OPT(loop != NULL, mcl_invalid_pointer);
157  loop->hw_loop_status.clc_enabled = false;
158 
159  return mcl_success;
160 }
161 
169 {
170  MCL_ASSERT_OPT(loop != NULL, mcl_invalid_pointer);
171  loop->hw_loop_status.qeo_enabled = true;
172 
173  return mcl_success;
174 }
175 
183 {
184  MCL_ASSERT_OPT(loop != NULL, mcl_invalid_pointer);
185  loop->hw_loop_status.qeo_enabled = false;
186 
187  return mcl_success;
188 }
189 
198 {
199  MCL_ASSERT_OPT(loop != NULL, mcl_invalid_pointer);
200  *status = loop->hw_loop_status.vsc_enabled;
201 
202  return mcl_success;
203 }
204 
213 {
214  MCL_ASSERT_OPT(loop != NULL, mcl_invalid_pointer);
215  *status = loop->hw_loop_status.clc_enabled;
216 
217  return mcl_success;
218 }
219 
228 {
229  MCL_ASSERT_OPT(loop != NULL, mcl_invalid_pointer);
230  *status = loop->hw_loop_status.qeo_enabled;
231 
232  return mcl_success;
233 }
234 
246 
257 
269 hpm_mcl_stat_t hpm_mcl_clc_run(mcl_hw_loop_t *loop, float d_expect, float q_expect);
270 
281 
282 #ifdef __cplusplus
283 }
284 #endif
285 
286 #endif
uint32_t hpm_mcl_stat_t
Definition: hpm_mcl_common.h:15
#define MCL_ASSERT_OPT
Definition: hpm_mcl_common.h:89
@ mcl_invalid_pointer
Definition: hpm_mcl_common.h:38
@ mcl_success
Definition: hpm_mcl_common.h:35
hpm_mcl_stat_t hpm_mcl_qeo_run(mcl_hw_loop_t *loop)
Run QEO (Quadrature Encoder Output) hardware acceleration.
Definition: hpm_mcl_hw_loop.c:148
static hpm_mcl_stat_t hpm_mcl_disable_clc_hardware_loop(mcl_hw_loop_t *loop)
Disable CLC hardware loop.
Definition: hpm_mcl_hw_loop.h:154
static hpm_mcl_stat_t hpm_mcl_enable_qeo_hardware_loop(mcl_hw_loop_t *loop)
Enable QEO hardware loop.
Definition: hpm_mcl_hw_loop.h:168
static hpm_mcl_stat_t hpm_mcl_get_qeo_hardware_loop_status(mcl_hw_loop_t *loop, bool *status)
Get QEO hardware loop status.
Definition: hpm_mcl_hw_loop.h:227
static hpm_mcl_stat_t hpm_mcl_disable_vsc_hardware_loop(mcl_hw_loop_t *loop)
Disable VSC hardware loop.
Definition: hpm_mcl_hw_loop.h:126
static hpm_mcl_stat_t hpm_mcl_enable_vsc_hardware_loop(mcl_hw_loop_t *loop)
Enable VSC hardware loop.
Definition: hpm_mcl_hw_loop.h:112
hpm_mcl_stat_t hpm_mcl_clc_run(mcl_hw_loop_t *loop, float d_expect, float q_expect)
Run CLC (Current Loop Controller) hardware acceleration.
Definition: hpm_mcl_hw_loop.c:100
hpm_mcl_stat_t hpm_mcl_hw_loop_init(mcl_hw_loop_t *loop, mcl_hw_loop_cfg_t *cfg)
Initialize hardware loop components.
Definition: hpm_mcl_hw_loop.c:19
static hpm_mcl_stat_t hpm_mcl_get_clc_hardware_loop_status(mcl_hw_loop_t *loop, bool *status)
Get CLC hardware loop status.
Definition: hpm_mcl_hw_loop.h:212
static hpm_mcl_stat_t hpm_mcl_enable_clc_hardware_loop(mcl_hw_loop_t *loop)
Enable CLC hardware loop.
Definition: hpm_mcl_hw_loop.h:140
static hpm_mcl_stat_t hpm_mcl_disable_qeo_hardware_loop(mcl_hw_loop_t *loop)
Disable QEO hardware loop.
Definition: hpm_mcl_hw_loop.h:182
static hpm_mcl_stat_t hpm_mcl_get_vsc_hardware_loop_status(mcl_hw_loop_t *loop, bool *status)
Get VSC hardware loop status.
Definition: hpm_mcl_hw_loop.h:197
hpm_mcl_stat_t hpm_mcl_vsc_run(mcl_hw_loop_t *loop)
Run VSC (Vector Signal Controller) hardware acceleration.
Definition: hpm_mcl_hw_loop.c:57
Hardware loop callback.
Definition: hpm_mcl_hw_loop.h:19
Hardware loop configuration.
Definition: hpm_mcl_hw_loop.h:44
mcl_hw_loop_callback_t callback
Definition: hpm_mcl_hw_loop.h:57
void * base
Definition: hpm_mcl_hw_loop.h:47
Definition: hpm_mcl_hw_loop.h:60
bool clc_enabled
Definition: hpm_mcl_hw_loop.h:65
float duty_w
Definition: hpm_mcl_hw_loop.h:99
float position
Definition: hpm_mcl_hw_loop.h:90
float beta
Definition: hpm_mcl_hw_loop.h:92
uint32_t duty_w
Definition: hpm_mcl_hw_loop.h:83
uint32_t ud
Definition: hpm_mcl_hw_loop.h:79
float duty_v
Definition: hpm_mcl_hw_loop.h:98
float uq
Definition: hpm_mcl_hw_loop.h:96
float q
Definition: hpm_mcl_hw_loop.h:94
float ic
Definition: hpm_mcl_hw_loop.h:89
bool vsc_enabled
Definition: hpm_mcl_hw_loop.h:64
float ib
Definition: hpm_mcl_hw_loop.h:88
bool qeo_enabled
Definition: hpm_mcl_hw_loop.h:66
uint32_t q
Definition: hpm_mcl_hw_loop.h:78
uint32_t ib
Definition: hpm_mcl_hw_loop.h:72
mcl_hw_loop_cfg_t * cfg
Definition: hpm_mcl_hw_loop.h:61
uint32_t position
Definition: hpm_mcl_hw_loop.h:74
uint32_t duty_v
Definition: hpm_mcl_hw_loop.h:82
float predicted_position
Definition: hpm_mcl_hw_loop.h:100
uint32_t d
Definition: hpm_mcl_hw_loop.h:77
uint32_t ic
Definition: hpm_mcl_hw_loop.h:73
uint32_t predicted_position
Definition: hpm_mcl_hw_loop.h:84
float duty_u
Definition: hpm_mcl_hw_loop.h:97
struct mcl_hw_loop_t::@1006 hw_loop_status
uint32_t ia
Definition: hpm_mcl_hw_loop.h:71
uint32_t uq
Definition: hpm_mcl_hw_loop.h:80
uint32_t beta
Definition: hpm_mcl_hw_loop.h:76
float ud
Definition: hpm_mcl_hw_loop.h:95
uint32_t alpha
Definition: hpm_mcl_hw_loop.h:75
float ia
Definition: hpm_mcl_hw_loop.h:87
float d
Definition: hpm_mcl_hw_loop.h:93
uint32_t duty_u
Definition: hpm_mcl_hw_loop.h:81
float alpha
Definition: hpm_mcl_hw_loop.h:91