From aa1d0464905cfd0ade606c9846b980be034338c5 Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Sun, 29 Jul 2018 21:12:58 +0200 Subject: debug: Add support for second prefix Signed-off-by: Michael Buesch --- firmware/controller_current.c | 10 +++-- firmware/controller_temp.c | 8 ++-- firmware/debug_uart.c | 71 ++++++++++++++++++++----------- firmware/debug_uart.h | 99 +++++++++++++++++++++++++++++++------------ firmware/measure.c | 3 +- firmware/measure_current.c | 2 +- 6 files changed, 131 insertions(+), 62 deletions(-) diff --git a/firmware/controller_current.c b/firmware/controller_current.c index 47de396..8b84bdf 100644 --- a/firmware/controller_current.c +++ b/firmware/controller_current.c @@ -132,9 +132,10 @@ static void contrcurr_run(fixpt_t real_r) break; } - debug_report_int8(PSTR("rs"), &contrcurr.old_r_state, + debug_report_int8(DEBUG_PFX1("rs"), &contrcurr.old_r_state, (int8_t)contrcurr.r_state); - debug_report_fixpt(PSTR("cr2"), &contrcurr.old_current_used_feedback, r); + debug_report_fixpt(DEBUG_PFX1("cr2"), + &contrcurr.old_current_used_feedback, r); /* Run the PID controller */ y = pid_run(&contrcurr.pid, dt, r); @@ -146,7 +147,8 @@ static void contrcurr_run(fixpt_t real_r) y = float_to_fixpt(CONTRCURR_RESTRICT_MAXCURR); } - debug_report_fixpt(PSTR("cy"), &contrcurr.old_current_control, y); + debug_report_fixpt(DEBUG_PFX1("cy"), + &contrcurr.old_current_control, y); /* Reconfigure the PWM unit to output the * requested heater current (y). */ @@ -158,7 +160,7 @@ void contrcurr_set_feedback(fixpt_t r) { if (r != contrcurr.feedback) { contrcurr.feedback = r; - debug_report_fixpt(PSTR("cr1"), + debug_report_fixpt(DEBUG_PFX1("cr1"), &contrcurr.old_current_real_feedback, r); } diff --git a/firmware/controller_temp.c b/firmware/controller_temp.c index 4540229..9ba0b28 100644 --- a/firmware/controller_temp.c +++ b/firmware/controller_temp.c @@ -77,7 +77,7 @@ static void contrtemp_set_boost_mode(enum contrtemp_boostmode new_boost_mode) pid_set_factors(&contrtemp.pid, k_set); #if CONF_BOOST contrtemp.boost_mode = new_boost_mode; - debug_print_int16(PSTR("tb"), (int16_t)new_boost_mode); + debug_print_int16(DEBUG_PFX1("tb"), (int16_t)new_boost_mode); #endif menu_request_display_update(); @@ -135,7 +135,7 @@ static void contrtemp_run(fixpt_t r) /* Run the PID controller */ y = pid_run(&contrtemp.pid, dt, r); - debug_report_fixpt(PSTR("ty1"), &contrtemp.old_temp_control1, y); + debug_report_fixpt(DEBUG_PFX1("ty1"), &contrtemp.old_temp_control1, y); /* Map the requested temperature to a heater current. */ y_current = temp_to_amps(y); @@ -154,7 +154,7 @@ static void contrtemp_run(fixpt_t r) } contrcurr_set_emerg(emergency_flags); - debug_report_fixpt(PSTR("ty2"), &contrtemp.old_temp_control2, + debug_report_fixpt(DEBUG_PFX1("ty2"), &contrtemp.old_temp_control2, y_current); /* Set the current controller setpoint to the requested current. */ @@ -165,7 +165,7 @@ void contrtemp_set_feedback(fixpt_t r) { if (r != contrtemp.feedback) { contrtemp.feedback = r; - debug_report_fixpt(PSTR("tr"), + debug_report_fixpt(DEBUG_PFX1("tr"), &contrtemp.old_temp_feedback, r); menu_request_display_update(); } diff --git a/firmware/debug_uart.c b/firmware/debug_uart.c index 82e2eeb..65b24d8 100644 --- a/firmware/debug_uart.c +++ b/firmware/debug_uart.c @@ -1,7 +1,7 @@ /* * Debugging UART interface * - * Copyright (c) 2015 Michael Buesch + * Copyright (c) 2015-2018 Michael Buesch * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -81,7 +81,9 @@ static void debug_uart_print_timestamp(void) debug_uart_tx((uint8_t)' '); } -static void debug_print_str2(const char __flash *str0, const char *str1) +static void debug_print_str3(const char __memx *str0, + const char __memx *str1, + const char __memx *str2) { uint8_t sreg; @@ -92,17 +94,23 @@ static void debug_print_str2(const char __flash *str0, const char *str1) debug_uart_print_timestamp(); if (str0) - debug_uart_tx_string(to_memx(str0)); + debug_uart_tx_string(str0); if (str1) { debug_uart_tx((uint8_t)' '); - debug_uart_tx_string(to_memx(str1)); + debug_uart_tx_string(str1); + } + if (str2) { + debug_uart_tx((uint8_t)' '); + debug_uart_tx_string(str2); } debug_uart_tx_eol(); irq_restore(sreg); } -void debug_print_int32(const char __flash *prefix, int32_t value) +void debug_print_int32(const char __flash *prefix0, + const char __flash *prefix1, + int32_t value) { char buf[10 + 1 + 1]; @@ -111,76 +119,91 @@ void debug_print_int32(const char __flash *prefix, int32_t value) #endif ltoa(value, buf, 10); - debug_print_str2(prefix, buf); + debug_print_str3(to_memx(prefix0), + to_memx(prefix1), + to_memx(&buf[0])); } -void debug_print_int24(const char __flash *prefix, int24_t value) +void debug_print_int24(const char __flash *prefix0, + const char __flash *prefix1, + int24_t value) { - debug_print_int32(prefix, value); + debug_print_int32(prefix0, prefix1, value); } -void debug_print_int16(const char __flash *prefix, int16_t value) +void debug_print_int16(const char __flash *prefix0, + const char __flash *prefix1, + int16_t value) { - debug_print_int32(prefix, value); + debug_print_int32(prefix0, prefix1, value); } -void debug_print_int8(const char __flash *prefix, int8_t value) +void debug_print_int8(const char __flash *prefix0, + const char __flash *prefix1, + int8_t value) { - debug_print_int32(prefix, value); + debug_print_int32(prefix0, prefix1, value); } -void debug_print_fixpt(const char __flash *prefix, fixpt_t value) +void debug_print_fixpt(const char __flash *prefix0, + const char __flash *prefix1, + fixpt_t value) { - debug_print_int32(prefix, value); + debug_print_int32(prefix0, prefix1, value); } -void debug_report_int32(const char __flash *prefix, +void debug_report_int32(const char __flash *prefix0, + const char __flash *prefix1, int32_t *old_value, int32_t new_value) { if (*old_value != new_value) { *old_value = new_value; - debug_print_int32(prefix, new_value); + debug_print_int32(prefix0, prefix1, new_value); } } -void debug_report_int24(const char __flash *prefix, +void debug_report_int24(const char __flash *prefix0, + const char __flash *prefix1, int24_t *old_value, int24_t new_value) { if (*old_value != new_value) { *old_value = new_value; - debug_print_int24(prefix, new_value); + debug_print_int24(prefix0, prefix1, new_value); } } -void debug_report_int16(const char __flash *prefix, +void debug_report_int16(const char __flash *prefix0, + const char __flash *prefix1, int16_t *old_value, int16_t new_value) { if (*old_value != new_value) { *old_value = new_value; - debug_print_int16(prefix, new_value); + debug_print_int16(prefix0, prefix1, new_value); } } -void debug_report_int8(const char __flash *prefix, +void debug_report_int8(const char __flash *prefix0, + const char __flash *prefix1, int8_t *old_value, int8_t new_value) { if (*old_value != new_value) { *old_value = new_value; - debug_print_int8(prefix, new_value); + debug_print_int8(prefix0, prefix1, new_value); } } -void debug_report_fixpt(const char __flash *prefix, +void debug_report_fixpt(const char __flash *prefix0, + const char __flash *prefix1, fixpt_t *old_value, fixpt_t new_value) { if (*old_value != new_value) { *old_value = new_value; - debug_print_fixpt(prefix, new_value); + debug_print_fixpt(prefix0, prefix1, new_value); } } diff --git a/firmware/debug_uart.h b/firmware/debug_uart.h index f792ec0..8225dbd 100644 --- a/firmware/debug_uart.h +++ b/firmware/debug_uart.h @@ -9,28 +9,49 @@ #if CONF_DEBUG - -void debug_print_int32(const char __flash *prefix, int32_t value); -void debug_print_int24(const char __flash *prefix, int24_t value); -void debug_print_int16(const char __flash *prefix, int16_t value); -void debug_print_int8(const char __flash *prefix, int8_t value); -void debug_print_fixpt(const char __flash *prefix, fixpt_t value); - -void debug_report_int32(const char __flash *prefix, +#define DEBUG_PREFIX1(prefix0) prefix0, NULL +#define DEBUG_PREFIX2(prefix0, prefix1) prefix0, prefix1 + +#define DEBUG_PFX1(prefix0) DEBUG_PREFIX1(PSTR(prefix0)) +#define DEBUG_PFX2(prefix0, prefix1) DEBUG_PREFIX2(PSTR(prefix0), PSTR(prefix1)) + + +void debug_print_int32(const char __flash *prefix0, + const char __flash *prefix1, + int32_t value); +void debug_print_int24(const char __flash *prefix0, + const char __flash *prefix1, + int24_t value); +void debug_print_int16(const char __flash *prefix0, + const char __flash *prefix1, + int16_t value); +void debug_print_int8(const char __flash *prefix0, + const char __flash *prefix1, + int8_t value); +void debug_print_fixpt(const char __flash *prefix0, + const char __flash *prefix1, + fixpt_t value); + +void debug_report_int32(const char __flash *prefix0, + const char __flash *prefix1, int32_t *old_value, int32_t new_value); -void debug_report_int24(const char __flash *prefix, +void debug_report_int24(const char __flash *prefix0, + const char __flash *prefix1, int24_t *old_value, int24_t new_value); -void debug_report_int16(const char __flash *prefix, +void debug_report_int16(const char __flash *prefix0, + const char __flash *prefix1, int16_t *old_value, int16_t new_value); -void debug_report_int8(const char __flash *prefix, +void debug_report_int8(const char __flash *prefix0, + const char __flash *prefix1, int8_t *old_value, int8_t new_value); -void debug_report_fixpt(const char __flash *prefix, - fixpt_t *old_value, - fixpt_t new_value); +void debug_report_fixpt(const char __flash *prefix0, + const char __flash *prefix1, + fixpt_t *old_value, + fixpt_t new_value); void debug_enable(bool enable); bool debug_is_enabled(void); @@ -41,63 +62,85 @@ void debug_uart_init(void); #else /* CONF_DEBUG */ +#define DEBUG_PREFIX1(prefix0) NULL, NULL +#define DEBUG_PREFIX2(prefix0, prefix1) NULL, NULL + +#define DEBUG_PFX1(prefix0) DEBUG_PREFIX1(NULL) +#define DEBUG_PFX2(prefix0, prefix1) DEBUG_PREFIX2(NULL, NULL) + + static inline -void debug_print_int32(const char __flash *prefix, int32_t value) +void debug_print_int32(const char __flash *prefix0, + const char __flash *prefix1, + int32_t value) { } static inline -void debug_print_int24(const char __flash *prefix, int24_t value) +void debug_print_int24(const char __flash *prefix0, + const char __flash *prefix1, + int24_t value) { } static inline -void debug_print_int16(const char __flash *prefix, int16_t value) +void debug_print_int16(const char __flash *prefix0, + const char __flash *prefix1, + int16_t value) { } static inline -void debug_print_int8(const char __flash *prefix, int8_t value) +void debug_print_int8(const char __flash *prefix0, + const char __flash *prefix1, + int8_t value) { } static inline -void debug_print_fixpt(const char __flash *prefix, fixpt_t value) +void debug_print_fixpt(const char __flash *prefix0, + const char __flash *prefix1, + fixpt_t value) { } static inline -void debug_report_int32(const char __flash *prefix, +void debug_report_int32(const char __flash *prefix0, + const char __flash *prefix1, int32_t *old_value, int32_t new_value) { } static inline -void debug_report_int24(const char __flash *prefix, +void debug_report_int24(const char __flash *prefix0, + const char __flash *prefix1, int24_t *old_value, int24_t new_value) { } static inline -void debug_report_int16(const char __flash *prefix, +void debug_report_int16(const char __flash *prefix0, + const char __flash *prefix1, int16_t *old_value, int16_t new_value) { } static inline -void debug_report_int8(const char __flash *prefix, - int8_t *old_value, - int8_t new_value) +void debug_report_int8(const char __flash *prefix0, + const char __flash *prefix1, + int8_t *old_value, + int8_t new_value) { } static inline -void debug_report_fixpt(const char __flash *prefix, - fixpt_t *old_value, - fixpt_t new_value) +void debug_report_fixpt(const char __flash *prefix0, + const char __flash *prefix1, + fixpt_t *old_value, + fixpt_t new_value) { } diff --git a/firmware/measure.c b/firmware/measure.c index 36d11f9..3141917 100644 --- a/firmware/measure.c +++ b/firmware/measure.c @@ -217,7 +217,8 @@ static void measure_handle_result(void) /* Calculate the result of the averaging. */ raw_adc = (uint16_t)(meas.avg_sum / meas.avg_count); - debug_report_int16(config->name, &active_chan->old_report_value, + debug_report_int16(DEBUG_PREFIX1(config->name), + &active_chan->old_report_value, (int16_t)raw_adc); /* Filter the raw adc value, if we have a filter. */ diff --git a/firmware/measure_current.c b/firmware/measure_current.c index 3a712fa..f3f2dd3 100644 --- a/firmware/measure_current.c +++ b/firmware/measure_current.c @@ -66,7 +66,7 @@ uint16_t meascurr_filter_handler(uint16_t raw_adc) } filtered_adc = min(filtered_adc, MEASURE_MAX_RESULT); - debug_report_int16(PSTR("fc"), &meascurr.old_filter_report_value, + debug_report_int16(DEBUG_PFX1("fc"), &meascurr.old_filter_report_value, (int16_t)filtered_adc); return filtered_adc; -- cgit v1.2.3