From cdefc49de36110be5d3c977edd839106bba6820a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20S=C3=A1nchez=20de=20Le=C3=B3n=20Peque?= Date: Sat, 24 Nov 2018 17:46:45 +0100 Subject: [PATCH] fixup! Allow in-systick logging over bluetooth with DMA --- src/logging.c | 34 ++++++++++++++++++++++++++++++++++ src/logging.h | 3 +++ src/main.c | 33 +-------------------------------- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/logging.c b/src/logging.c index 8c10f2e6..8645b003 100644 --- a/src/logging.c +++ b/src/logging.c @@ -1,5 +1,39 @@ #include "logging.h" +#define TX_SIZE 100 + +static volatile bool systick_logging; +static char systick_log_buffer[TX_SIZE]; + +void enable_systick_logging(void) +{ + LOG_INFO("Systick logging on"); + sleep_ticks(2); + led_right_on(); + systick_logging = true; +} + +void disable_systick_logging(void) +{ + systick_logging = false; + led_right_off(); + sleep_ticks(2); + LOG_INFO("Systick logging off"); +} + +void log_data(void) +{ + uint32_t time; + + if (!systick_logging) + return; + time = get_clock_ticks(); + sprintf(systick_log_buffer, "%" PRIu32 ",DATA,,,%.4f,%.4f,%.4f,%.4f\n", + time, get_front_left_distance(), get_front_right_distance(), + get_side_left_distance(), get_side_right_distance()); + dma_write(systick_log_buffer, strlen(systick_log_buffer)); +} + /** * @brief Log the current battery voltage. */ diff --git a/src/logging.h b/src/logging.h index a2a48086..9703e67a 100644 --- a/src/logging.h +++ b/src/logging.h @@ -36,6 +36,9 @@ static const char *const log_level_strings[] = {"DEBUG", "INFO", "WARNING", LOG_MESSAGE(LOG_LEVEL_WARNING, format, ##arg) #define LOG_ERROR(format, arg...) LOG_MESSAGE(LOG_LEVEL_ERROR, format, ##arg) +void enable_systick_logging(void); +void disable_systick_logging(void); +void log_data(void); void log_battery_voltage(void); void log_configuration_variables(void); void log_linear_speed(void); diff --git a/src/main.c b/src/main.c index ed085954..7037fd88 100644 --- a/src/main.c +++ b/src/main.c @@ -16,38 +16,8 @@ #include "speaker.h" #include "speed.h" -static volatile bool systick_logging; -#define TX_SIZE 100 -static char systick_log_buffer[TX_SIZE]; - static void competition(void); -static void enable_systick_logging(void) -{ - LOG_INFO("Systick logging on: %d", TX_SIZE); - sleep_ticks(2); - led_right_on(); - systick_logging = true; -} - -static void disable_systick_logging(void) -{ - systick_logging = false; - led_right_off(); - sleep_ticks(2); - LOG_INFO("Systick logging off"); -} - -static void systick_log(void) -{ - uint32_t time = get_clock_ticks(); - - sprintf(systick_log_buffer, "%" PRIu32 ",DATA,,,%.4f,%.4f,%.4f,%.4f\n", - time, get_front_left_distance(), get_front_right_distance(), - get_side_left_distance(), get_side_right_distance()); - dma_write(systick_log_buffer, strlen(systick_log_buffer)); -} - /** * @brief Handle the SysTick interruptions. */ @@ -59,8 +29,7 @@ void sys_tick_handler(void) update_gyro_readings(); update_encoder_readings(); motor_control(); - if (systick_logging) - systick_log(); + log_data(); } /**