Skip to content

Commit

Permalink
fixup! Allow in-systick logging over bluetooth with DMA
Browse files Browse the repository at this point in the history
  • Loading branch information
Peque committed Nov 24, 2018
1 parent d55aa28 commit cdefc49
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
34 changes: 34 additions & 0 deletions src/logging.c
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 1 addition & 32 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -59,8 +29,7 @@ void sys_tick_handler(void)
update_gyro_readings();
update_encoder_readings();
motor_control();
if (systick_logging)
systick_log();
log_data();
}

/**
Expand Down

0 comments on commit cdefc49

Please sign in to comment.