libdsp: introduce libdsp-specific debug assertion (LIBDSP_DEBUGASSERT)

This commit is contained in:
raiden00pl
2021-02-28 21:41:59 +01:00
committed by Xiang Xiao
parent 66972d947e
commit 5034e4d8ba
8 changed files with 69 additions and 68 deletions
+3 -2
View File
@@ -44,9 +44,10 @@
# ifndef CONFIG_DEBUG_ASSERTIONS # ifndef CONFIG_DEBUG_ASSERTIONS
# warning "Need CONFIG_DEBUG_ASSERTIONS to work properly" # warning "Need CONFIG_DEBUG_ASSERTIONS to work properly"
# endif # endif
# define LIBDSP_DEBUGASSERT(x) DEBUGASSERT(x)
#else #else
# undef DEBUGASSERT # undef LIBDSP_DEBUGASSERT
# define DEBUGASSERT(x) # define LIBDSP_DEBUGASSERT(x)
#endif #endif
#ifndef CONFIG_LIBDSP_PRECISION #ifndef CONFIG_LIBDSP_PRECISION
+3 -3
View File
@@ -233,9 +233,9 @@ void foc_process(FAR struct foc_data_f32_s *foc,
FAR abc_frame_f32_t *i_abc, FAR abc_frame_f32_t *i_abc,
FAR phase_angle_f32_t *angle) FAR phase_angle_f32_t *angle)
{ {
DEBUGASSERT(foc != NULL); LIBDSP_DEBUGASSERT(foc != NULL);
DEBUGASSERT(i_abc != NULL); LIBDSP_DEBUGASSERT(i_abc != NULL);
DEBUGASSERT(angle != NULL); LIBDSP_DEBUGASSERT(angle != NULL);
/* Copy ABC current to foc data */ /* Copy ABC current to foc data */
+1 -1
View File
@@ -435,7 +435,7 @@ void angle_norm_2pi(FAR float *angle, float bottom, float top)
void phase_angle_update(FAR struct phase_angle_f32_s *angle, float val) void phase_angle_update(FAR struct phase_angle_f32_s *angle, float val)
{ {
DEBUGASSERT(angle != NULL); LIBDSP_DEBUGASSERT(angle != NULL);
/* Normalize angle to <0.0, 2PI> */ /* Normalize angle to <0.0, 2PI> */
+19 -19
View File
@@ -53,9 +53,9 @@
void motor_openloop_init(FAR struct openloop_data_f32_s *op, float max, void motor_openloop_init(FAR struct openloop_data_f32_s *op, float max,
float per) float per)
{ {
DEBUGASSERT(op != NULL); LIBDSP_DEBUGASSERT(op != NULL);
DEBUGASSERT(max > 0.0f); LIBDSP_DEBUGASSERT(max > 0.0f);
DEBUGASSERT(per > 0.0f); LIBDSP_DEBUGASSERT(per > 0.0f);
/* Reset openloop structure */ /* Reset openloop structure */
@@ -86,9 +86,9 @@ void motor_openloop_init(FAR struct openloop_data_f32_s *op, float max,
void motor_openloop(FAR struct openloop_data_f32_s *op, float speed, void motor_openloop(FAR struct openloop_data_f32_s *op, float speed,
float dir) float dir)
{ {
DEBUGASSERT(op != NULL); LIBDSP_DEBUGASSERT(op != NULL);
DEBUGASSERT(speed >= 0.0f); LIBDSP_DEBUGASSERT(speed >= 0.0f);
DEBUGASSERT(dir == DIR_CW || dir == DIR_CCW); LIBDSP_DEBUGASSERT(dir == DIR_CW || dir == DIR_CCW);
float phase_step = 0.0f; float phase_step = 0.0f;
@@ -130,7 +130,7 @@ void motor_openloop(FAR struct openloop_data_f32_s *op, float speed,
float motor_openloop_angle_get(FAR struct openloop_data_f32_s *op) float motor_openloop_angle_get(FAR struct openloop_data_f32_s *op)
{ {
DEBUGASSERT(op != NULL); LIBDSP_DEBUGASSERT(op != NULL);
return op->angle; return op->angle;
} }
@@ -182,8 +182,8 @@ float motor_openloop_angle_get(FAR struct openloop_data_f32_s *op)
void motor_angle_init(FAR struct motor_angle_f32_s *angle, uint8_t p) void motor_angle_init(FAR struct motor_angle_f32_s *angle, uint8_t p)
{ {
DEBUGASSERT(angle != NULL); LIBDSP_DEBUGASSERT(angle != NULL);
DEBUGASSERT(p > 0); LIBDSP_DEBUGASSERT(p > 0);
/* Reset structure */ /* Reset structure */
@@ -217,9 +217,9 @@ void motor_angle_init(FAR struct motor_angle_f32_s *angle, uint8_t p)
void motor_angle_e_update(FAR struct motor_angle_f32_s *angle, void motor_angle_e_update(FAR struct motor_angle_f32_s *angle,
float angle_new, float dir) float angle_new, float dir)
{ {
DEBUGASSERT(angle != NULL); LIBDSP_DEBUGASSERT(angle != NULL);
DEBUGASSERT(angle_new >= 0.0f && angle_new <= MOTOR_ANGLE_E_MAX); LIBDSP_DEBUGASSERT(angle_new >= 0.0f && angle_new <= MOTOR_ANGLE_E_MAX);
DEBUGASSERT(dir == DIR_CW || dir == DIR_CCW); LIBDSP_DEBUGASSERT(dir == DIR_CW || dir == DIR_CCW);
/* Check if we crossed electrical angle boundaries */ /* Check if we crossed electrical angle boundaries */
@@ -286,9 +286,9 @@ void motor_angle_e_update(FAR struct motor_angle_f32_s *angle,
void motor_angle_m_update(FAR struct motor_angle_f32_s *angle, void motor_angle_m_update(FAR struct motor_angle_f32_s *angle,
float angle_new, float dir) float angle_new, float dir)
{ {
DEBUGASSERT(angle != NULL); LIBDSP_DEBUGASSERT(angle != NULL);
DEBUGASSERT(angle_new >= 0.0f && angle_new <= MOTOR_ANGLE_E_MAX); LIBDSP_DEBUGASSERT(angle_new >= 0.0f && angle_new <= MOTOR_ANGLE_E_MAX);
DEBUGASSERT(dir == DIR_CW || dir == DIR_CCW); LIBDSP_DEBUGASSERT(dir == DIR_CW || dir == DIR_CCW);
float angle_el = 0.0f; float angle_el = 0.0f;
@@ -325,7 +325,7 @@ void motor_angle_m_update(FAR struct motor_angle_f32_s *angle,
float motor_angle_m_get(FAR struct motor_angle_f32_s *angle) float motor_angle_m_get(FAR struct motor_angle_f32_s *angle)
{ {
DEBUGASSERT(angle != NULL); LIBDSP_DEBUGASSERT(angle != NULL);
return angle->anglem; return angle->anglem;
} }
@@ -346,7 +346,7 @@ float motor_angle_m_get(FAR struct motor_angle_f32_s *angle)
float motor_angle_e_get(FAR struct motor_angle_f32_s *angle) float motor_angle_e_get(FAR struct motor_angle_f32_s *angle)
{ {
DEBUGASSERT(angle != NULL); LIBDSP_DEBUGASSERT(angle != NULL);
return angle->angle_el.angle; return angle->angle_el.angle;
} }
@@ -372,7 +372,7 @@ float motor_angle_e_get(FAR struct motor_angle_f32_s *angle)
void motor_phy_params_init(FAR struct motor_phy_params_f32_s *phy, void motor_phy_params_init(FAR struct motor_phy_params_f32_s *phy,
uint8_t poles, float res, float ind) uint8_t poles, float res, float ind)
{ {
DEBUGASSERT(phy != NULL); LIBDSP_DEBUGASSERT(phy != NULL);
phy->p = poles; phy->p = poles;
phy->res_base = res; phy->res_base = res;
@@ -404,7 +404,7 @@ void motor_phy_params_init(FAR struct motor_phy_params_f32_s *phy,
void motor_phy_params_temp_set(FAR struct motor_phy_params_f32_s *phy, void motor_phy_params_temp_set(FAR struct motor_phy_params_f32_s *phy,
float res_alpha, float res_temp_ref) float res_alpha, float res_temp_ref)
{ {
DEBUGASSERT(phy != NULL); LIBDSP_DEBUGASSERT(phy != NULL);
phy->res_alpha = res_alpha; phy->res_alpha = res_alpha;
phy->res_temp_ref = res_temp_ref; phy->res_temp_ref = res_temp_ref;
+19 -19
View File
@@ -54,10 +54,10 @@
void motor_observer_init(FAR struct motor_observer_f32_s *observer, void motor_observer_init(FAR struct motor_observer_f32_s *observer,
FAR void *ao, FAR void *so, float per) FAR void *ao, FAR void *so, float per)
{ {
DEBUGASSERT(observer != NULL); LIBDSP_DEBUGASSERT(observer != NULL);
DEBUGASSERT(ao != NULL); LIBDSP_DEBUGASSERT(ao != NULL);
DEBUGASSERT(so != NULL); LIBDSP_DEBUGASSERT(so != NULL);
DEBUGASSERT(per > 0.0f); LIBDSP_DEBUGASSERT(per > 0.0f);
/* Reset observer data */ /* Reset observer data */
@@ -95,9 +95,9 @@ void motor_observer_init(FAR struct motor_observer_f32_s *observer,
void motor_observer_smo_init(FAR struct motor_observer_smo_f32_s *smo, void motor_observer_smo_init(FAR struct motor_observer_smo_f32_s *smo,
float kslide, float err_max) float kslide, float err_max)
{ {
DEBUGASSERT(smo != NULL); LIBDSP_DEBUGASSERT(smo != NULL);
DEBUGASSERT(kslide > 0.0f); LIBDSP_DEBUGASSERT(kslide > 0.0f);
DEBUGASSERT(err_max > 0.0f); LIBDSP_DEBUGASSERT(err_max > 0.0f);
/* Reset structure */ /* Reset structure */
@@ -170,10 +170,10 @@ void motor_observer_smo(FAR struct motor_observer_f32_s *o,
FAR ab_frame_f32_t *i_ab, FAR ab_frame_f32_t *v_ab, FAR ab_frame_f32_t *i_ab, FAR ab_frame_f32_t *v_ab,
FAR struct motor_phy_params_f32_s *phy, float dir) FAR struct motor_phy_params_f32_s *phy, float dir)
{ {
DEBUGASSERT(o != NULL); LIBDSP_DEBUGASSERT(o != NULL);
DEBUGASSERT(i_ab != NULL); LIBDSP_DEBUGASSERT(i_ab != NULL);
DEBUGASSERT(v_ab != NULL); LIBDSP_DEBUGASSERT(v_ab != NULL);
DEBUGASSERT(phy != NULL); LIBDSP_DEBUGASSERT(phy != NULL);
FAR struct motor_observer_smo_f32_s *smo = FAR struct motor_observer_smo_f32_s *smo =
(FAR struct motor_observer_smo_f32_s *)o->ao; (FAR struct motor_observer_smo_f32_s *)o->ao;
@@ -382,9 +382,9 @@ void motor_observer_smo(FAR struct motor_observer_f32_s *o,
void motor_sobserver_div_init(FAR struct motor_sobserver_div_f32_s *so, void motor_sobserver_div_init(FAR struct motor_sobserver_div_f32_s *so,
uint8_t samples, float filter, float per) uint8_t samples, float filter, float per)
{ {
DEBUGASSERT(so != NULL); LIBDSP_DEBUGASSERT(so != NULL);
DEBUGASSERT(samples > 0); LIBDSP_DEBUGASSERT(samples > 0);
DEBUGASSERT(filter > 0.0f); LIBDSP_DEBUGASSERT(filter > 0.0f);
/* Reset observer data */ /* Reset observer data */
@@ -421,9 +421,9 @@ void motor_sobserver_div_init(FAR struct motor_sobserver_div_f32_s *so,
void motor_sobserver_div(FAR struct motor_observer_f32_s *o, void motor_sobserver_div(FAR struct motor_observer_f32_s *o,
float angle, float dir) float angle, float dir)
{ {
DEBUGASSERT(o != NULL); LIBDSP_DEBUGASSERT(o != NULL);
DEBUGASSERT(angle >= 0.0f && angle <= 2*M_PI_F); LIBDSP_DEBUGASSERT(angle >= 0.0f && angle <= 2*M_PI_F);
DEBUGASSERT(dir == DIR_CW || dir == DIR_CCW); LIBDSP_DEBUGASSERT(dir == DIR_CW || dir == DIR_CCW);
FAR struct motor_sobserver_div_f32_s *so = FAR struct motor_sobserver_div_f32_s *so =
(FAR struct motor_sobserver_div_f32_s *)o->so; (FAR struct motor_sobserver_div_f32_s *)o->so;
@@ -515,7 +515,7 @@ void motor_sobserver_div(FAR struct motor_observer_f32_s *o,
float motor_observer_speed_get(FAR struct motor_observer_f32_s *o) float motor_observer_speed_get(FAR struct motor_observer_f32_s *o)
{ {
DEBUGASSERT(o != NULL); LIBDSP_DEBUGASSERT(o != NULL);
return o->speed; return o->speed;
} }
@@ -536,7 +536,7 @@ float motor_observer_speed_get(FAR struct motor_observer_f32_s *o)
float motor_observer_angle_get(FAR struct motor_observer_f32_s *o) float motor_observer_angle_get(FAR struct motor_observer_f32_s *o)
{ {
DEBUGASSERT(o != NULL); LIBDSP_DEBUGASSERT(o != NULL);
return o->angle; return o->angle;
} }
+8 -8
View File
@@ -49,7 +49,7 @@
void pid_controller_init(FAR pid_controller_f32_t *pid, float KP, float KI, void pid_controller_init(FAR pid_controller_f32_t *pid, float KP, float KI,
float KD) float KD)
{ {
DEBUGASSERT(pid != NULL); LIBDSP_DEBUGASSERT(pid != NULL);
/* Reset controller data */ /* Reset controller data */
@@ -81,7 +81,7 @@ void pid_controller_init(FAR pid_controller_f32_t *pid, float KP, float KI,
void pi_controller_init(FAR pid_controller_f32_t *pid, float KP, float KI) void pi_controller_init(FAR pid_controller_f32_t *pid, float KP, float KI)
{ {
DEBUGASSERT(pid != NULL); LIBDSP_DEBUGASSERT(pid != NULL);
/* Reset controller data */ /* Reset controller data */
@@ -114,8 +114,8 @@ void pi_controller_init(FAR pid_controller_f32_t *pid, float KP, float KI)
void pid_saturation_set(FAR pid_controller_f32_t *pid, float min, float max) void pid_saturation_set(FAR pid_controller_f32_t *pid, float min, float max)
{ {
DEBUGASSERT(pid != NULL); LIBDSP_DEBUGASSERT(pid != NULL);
DEBUGASSERT(min < max); LIBDSP_DEBUGASSERT(min < max);
pid->sat.max = max; pid->sat.max = max;
pid->sat.min = min; pid->sat.min = min;
@@ -138,8 +138,8 @@ void pid_saturation_set(FAR pid_controller_f32_t *pid, float min, float max)
void pi_saturation_set(FAR pid_controller_f32_t *pid, float min, float max) void pi_saturation_set(FAR pid_controller_f32_t *pid, float min, float max)
{ {
DEBUGASSERT(pid != NULL); LIBDSP_DEBUGASSERT(pid != NULL);
DEBUGASSERT(min < max); LIBDSP_DEBUGASSERT(min < max);
pid_saturation_set(pid, min, max); pid_saturation_set(pid, min, max);
} }
@@ -179,7 +179,7 @@ void pi_integral_reset(FAR pid_controller_f32_t *pid)
float pi_controller(FAR pid_controller_f32_t *pid, float err) float pi_controller(FAR pid_controller_f32_t *pid, float err)
{ {
DEBUGASSERT(pid != NULL); LIBDSP_DEBUGASSERT(pid != NULL);
/* Store error in controller structure */ /* Store error in controller structure */
@@ -254,7 +254,7 @@ float pi_controller(FAR pid_controller_f32_t *pid, float err)
float pid_controller(FAR pid_controller_f32_t *pid, float err) float pid_controller(FAR pid_controller_f32_t *pid, float err)
{ {
DEBUGASSERT(pid != NULL); LIBDSP_DEBUGASSERT(pid != NULL);
/* Get PI output */ /* Get PI output */
+6 -6
View File
@@ -195,7 +195,7 @@ static void svm3_duty_calc(FAR struct svm3_state_f32_s *s,
{ {
/* We should not get here */ /* We should not get here */
DEBUGASSERT(0); LIBDSP_DEBUGASSERT(0);
break; break;
} }
} }
@@ -260,7 +260,7 @@ static void svm3_duty_calc(FAR struct svm3_state_f32_s *s,
{ {
/* We should not get here */ /* We should not get here */
DEBUGASSERT(0); LIBDSP_DEBUGASSERT(0);
break; break;
} }
} }
@@ -323,8 +323,8 @@ static void svm3_duty_calc(FAR struct svm3_state_f32_s *s,
void svm3(FAR struct svm3_state_f32_s *s, FAR ab_frame_f32_t *v_ab) void svm3(FAR struct svm3_state_f32_s *s, FAR ab_frame_f32_t *v_ab)
{ {
DEBUGASSERT(s != NULL); LIBDSP_DEBUGASSERT(s != NULL);
DEBUGASSERT(v_ab != NULL); LIBDSP_DEBUGASSERT(v_ab != NULL);
abc_frame_f32_t ijk; abc_frame_f32_t ijk;
@@ -435,8 +435,8 @@ void svm3_current_correct(FAR struct svm3_state_f32_s *s,
void svm3_init(FAR struct svm3_state_f32_s *s, float min, float max) void svm3_init(FAR struct svm3_state_f32_s *s, float min, float max)
{ {
DEBUGASSERT(s != NULL); LIBDSP_DEBUGASSERT(s != NULL);
DEBUGASSERT(max > min); LIBDSP_DEBUGASSERT(max > min);
memset(s, 0, sizeof(struct svm3_state_f32_s)); memset(s, 0, sizeof(struct svm3_state_f32_s));
+10 -10
View File
@@ -53,8 +53,8 @@
void clarke_transform(FAR abc_frame_f32_t *abc, void clarke_transform(FAR abc_frame_f32_t *abc,
FAR ab_frame_f32_t *ab) FAR ab_frame_f32_t *ab)
{ {
DEBUGASSERT(abc != NULL); LIBDSP_DEBUGASSERT(abc != NULL);
DEBUGASSERT(ab != NULL); LIBDSP_DEBUGASSERT(ab != NULL);
ab->a = abc->a; ab->a = abc->a;
ab->b = ONE_BY_SQRT3_F*abc->a + TWO_BY_SQRT3_F*abc->b; ab->b = ONE_BY_SQRT3_F*abc->a + TWO_BY_SQRT3_F*abc->b;
@@ -78,8 +78,8 @@ void clarke_transform(FAR abc_frame_f32_t *abc,
void inv_clarke_transform(FAR ab_frame_f32_t *ab, void inv_clarke_transform(FAR ab_frame_f32_t *ab,
FAR abc_frame_f32_t *abc) FAR abc_frame_f32_t *abc)
{ {
DEBUGASSERT(ab != NULL); LIBDSP_DEBUGASSERT(ab != NULL);
DEBUGASSERT(abc != NULL); LIBDSP_DEBUGASSERT(abc != NULL);
/* Assume non-power-invariant transform and balanced system */ /* Assume non-power-invariant transform and balanced system */
@@ -108,9 +108,9 @@ void park_transform(FAR phase_angle_f32_t *angle,
FAR ab_frame_f32_t *ab, FAR ab_frame_f32_t *ab,
FAR dq_frame_f32_t *dq) FAR dq_frame_f32_t *dq)
{ {
DEBUGASSERT(angle != NULL); LIBDSP_DEBUGASSERT(angle != NULL);
DEBUGASSERT(ab != NULL); LIBDSP_DEBUGASSERT(ab != NULL);
DEBUGASSERT(dq != NULL); LIBDSP_DEBUGASSERT(dq != NULL);
dq->d = angle->cos * ab->a + angle->sin * ab->b; dq->d = angle->cos * ab->a + angle->sin * ab->b;
dq->q = angle->cos * ab->b - angle->sin * ab->a; dq->q = angle->cos * ab->b - angle->sin * ab->a;
@@ -136,9 +136,9 @@ void inv_park_transform(FAR phase_angle_f32_t *angle,
FAR dq_frame_f32_t *dq, FAR dq_frame_f32_t *dq,
FAR ab_frame_f32_t *ab) FAR ab_frame_f32_t *ab)
{ {
DEBUGASSERT(angle != NULL); LIBDSP_DEBUGASSERT(angle != NULL);
DEBUGASSERT(dq != NULL); LIBDSP_DEBUGASSERT(dq != NULL);
DEBUGASSERT(ab != NULL); LIBDSP_DEBUGASSERT(ab != NULL);
ab->a = angle->cos * dq->d - angle->sin * dq->q; ab->a = angle->cos * dq->d - angle->sin * dq->q;
ab->b = angle->cos * dq->q + angle->sin * dq->d; ab->b = angle->cos * dq->q + angle->sin * dq->d;