7 #ifndef HPM_MCL_COMMON_H
8 #define HPM_MCL_COMMON_H
51 #define MCL_DEBUG printf
53 #define MCL_2PI HPM_2_PI
54 #define MCL_PI_DIV3 (MCL_PI / 3.0f)
56 #define MCL_DELAY_US(x) mcl_user_delay_us(x)
57 #define MCL_DELAY_MS(x) MCL_DELAY_US(1000*x)
60 #define MCL_ASSERT_BOOL(b, code_extend, errcode) \
64 MCL_DEBUG("errcode:%d, file:%s, line:%d.\r\n", errcode, __FILE__, __LINE__); \
69 #define MCL_ASSERT_EXEC_CODE_BOOL(b, code_extend) \
76 #define MCL_ASSERT(x, return_errcode) MCL_ASSERT_BOOL(((uint32_t)(x) != 0), MCL_EMPTY, return_errcode)
78 #define MCL_ASSERT_EXEC_CODE(x, code) MCL_ASSERT_EXEC_CODE_BOOL((x), code)
80 #define MCL_ASSERT_EXEC_CODE_AND_RETURN(x, code, return_errcode) MCL_ASSERT_BOOL((x), code, return_errcode)
83 #define MCL_ASSERT_EXEC_CODE_OPT(x, code) ((void)0)
84 #define MCL_ASSERT_OPT(x, return_errcode) ((void)0)
85 #define MCL_ASSERT_EXEC_CODE_AND_RETURN_OPT(x, code, return_errcode) ((void)0)
87 #define MCL_ASSERT_EXEC_CODE_OPT MCL_ASSERT_EXEC_CODE
88 #define MCL_ASSERT_OPT MCL_ASSERT
89 #define MCL_ASSERT_EXEC_CODE_AND_RETURN_OPT MCL_ASSERT_EXEC_CODE_AND_RETURN
92 #define MCL_FUNCTION_EXC_IF_ENABLE(b, str_f, f) \
99 #define MCL_FUNCTION_EXC_IF_ELSE_ENABLE(b, str_f, _if, _else) \
108 #define MCL_FUNCTION_INIT_IF_EMPTY(str_function, function) MCL_FUNCTION_EXC_IF_ENABLE((str_function == NULL), str_function, function)
110 #define MCL_FUNCTION_INIT_IF_NO_EMPTY(function, str_function) MCL_FUNCTION_EXC_IF_ENABLE((str_function != NULL), function, str_function)
112 #define MCL_STATUS_SET_IF_TRUE(real, str, status) MCL_FUNCTION_EXC_IF_ENABLE((real), str, status)
114 #define MCL_VALUE_SET_IF_TRUE(real, str, value) MCL_FUNCTION_EXC_IF_ENABLE((real), str, value)
116 #define MCL_FUNCTION_SET_IF_ELSE_TRUE(real, str, _if, _else) MCL_FUNCTION_EXC_IF_ELSE_ENABLE((real), str, _if, _else)
122 #define _FUNC_OPTIONAL_
128 #define MCL_ANGLE_MOD_X(down, up, val) \
134 val_ = (val_) - (up - down); \
135 } while ((val_) > up); \
136 } else if ((val) < down) { \
139 val_ = (val_) + (up - down); \
140 } while ((val_) < down); \
158 #define MCL_GET_ANGLE_DELTA(val, offset) \
165 temp = (val) - offset; \
166 } else if ((val) < 0) { \
167 temp = (val) + offset; \
171 if (fabs(val) < fabs(temp)) { \
183 #define MCL_VALUE_LIMIT(val, min, max) \
185 if ((val) > (max)) { \
187 } else if ((val) < (min)) { \
196 #define MCL_GET_ADC_12BIT_VALID_DATA(x) ((x & 0xffff) >> 4)
#define MAKE_STATUS(group, code)
Definition: hpm_common.h:132
@ mcl_group_common
Definition: hpm_mcl_common.h:18
@ mcl_group_analog
Definition: hpm_mcl_common.h:21
@ mcl_group_motor
Definition: hpm_mcl_common.h:19
@ mcl_group_encoder
Definition: hpm_mcl_common.h:20
@ mcl_group_drivers
Definition: hpm_mcl_common.h:22
void mcl_user_delay_us(uint64_t tick)
user define code
uint32_t hpm_mcl_stat_t
Definition: hpm_mcl_common.h:15
@ mcl_timeout
Definition: hpm_mcl_common.h:39
@ mcl_in_development
Definition: hpm_mcl_common.h:40
@ mcl_fail
Definition: hpm_mcl_common.h:36
@ mcl_invalid_argument
Definition: hpm_mcl_common.h:37
@ mcl_invalid_pointer
Definition: hpm_mcl_common.h:38
@ mcl_success
Definition: hpm_mcl_common.h:35
@ mcl_running
Definition: hpm_mcl_common.h:41
Definition: hpm_mcl_common.h:198
mcl_physical_para_q_t physical_q
Definition: hpm_mcl_common.h:200
mcl_physical_para_t physical
Definition: hpm_mcl_common.h:199
Definition: hpm_mcl_physical.h:115
Definition: hpm_mcl_physical.h:109
User-defined data with data and enable bits.
Definition: hpm_mcl_common.h:29
float value
Definition: hpm_mcl_common.h:30
bool enable
Definition: hpm_mcl_common.h:31