Skip to content

Commit

Permalink
Add event counting infrastructure to evaluate performance
Browse files Browse the repository at this point in the history
  • Loading branch information
bgamari committed Sep 13, 2013
1 parent 81995d9 commit 83697e0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions adc.c
Expand Up @@ -32,6 +32,8 @@ struct pin_t reset = { .port = GPIO5, .pin = GPIOPIN2 };
struct pin_t range = { .port = GPIO5, .pin = GPIOPIN6 };
struct pin_t standby = { .port = GPIO5, .pin = GPIOPIN0 }; // inverted

unsigned int adc_sample_counter = 0;

#ifdef USE_DMA
static void configure_rx_dma()
{
Expand Down Expand Up @@ -245,5 +247,7 @@ void pin_int0_isr(void)
setup_buffer(NULL);
}
}

increment_event_counter(adc_sample_counter);
}
}
20 changes: 18 additions & 2 deletions clock.c
@@ -1,10 +1,20 @@
#include <libopencm3/cm3/systick.h>

#include "clock.h"
#include "config.h"

#include <libopencm3/cm3/systick.h>
#include "utils.h"

volatile uint32_t msTicks; /* counts 1ms timeTicks */

volatile struct event_counters event_counters[N_EVENT_COUNTERS];
unsigned int active_event_counter_index = 0;
#define active_event_counters (&event_counters[active_event_counter_index])

struct event_counters get_last_event_counters(void)
{
return event_counters[(active_event_counter_index-1) % N_EVENT_COUNTERS];
}

void init_systick()
{
systick_set_reload(CLK_BASE_M4 / 8 / 1000);
Expand All @@ -20,4 +30,10 @@ void delay_ms(unsigned int ms) {

void sys_tick_handler() {
msTicks++;

if (msTicks % 1024 == 0) {
unsigned int next = (active_event_counter_index + 1) % N_EVENT_COUNTERS;
memzero((void*) &event_counters[next], sizeof(struct event_counters));
active_event_counter_index = next;
}
}
17 changes: 17 additions & 0 deletions clock.h
Expand Up @@ -6,3 +6,20 @@ extern volatile uint32_t msTicks; /* counts 1ms timeTicks */
void init_systick();
void delay_ms(unsigned int ms);

struct event_counters {
unsigned int feedback_counter;
unsigned int adc_sample_counter;
};

// public
struct event_counters get_last_event_counters(void);

// private
#define N_EVENT_COUNTERS 4
extern volatile struct event_counters event_counters[N_EVENT_COUNTERS];
extern unsigned int active_event_counter_index;

// public
#define increment_event_counter(counter) \
event_counters[active_event_counter_index].counter++;

1 change: 1 addition & 0 deletions feedback.c
Expand Up @@ -130,6 +130,7 @@ void do_feedback()
}

feedback_update();
increment_event_counter(feedback_counter);
}

void timer2_isr(void)
Expand Down
8 changes: 8 additions & 0 deletions utils.h
@@ -0,0 +1,8 @@
#pragma once

#include <string.h>

static inline void memzero(void* ptr, unsigned int size)
{
memset(ptr, 0, size);
}

0 comments on commit 83697e0

Please sign in to comment.