From 915d3c35102bd51223c80ce7363a43fab840d06f Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 25 May 2016 21:48:39 -0500 Subject: [PATCH] Flesh out more stuff, including AVR timer setup --- avr/main.c | 42 +++++++++++++++++++++++++++++++++++++++++ include/tabby/clock.h | 12 ++++++------ include/tabby/command.h | 4 ++-- 3 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 avr/main.c diff --git a/avr/main.c b/avr/main.c new file mode 100644 index 0000000..66c95ba --- /dev/null +++ b/avr/main.c @@ -0,0 +1,42 @@ +#include + +#include + +uint16_t timer_counter_intervals[4] = { + 1953, 977, 61, 31 +}; + +void setup_internal_clock(tabby_clock_speed speed) { + /* + * Enable timer interrupt vector + */ + TIMSK = (1 << TOIE1); + + /* + * Reset timer counter to zero + */ + TCNT1 = 0; + + /* + * Set timer interval + */ + OCR1A = timer_counter_intervals[speed]; + + /* + * Set timer clock divider to 1/1 + */ + TCCR1B = (1 << CS10); +} + +void setup_external_clock() { + /* + * Disable internal timer interrupts + */ + TCCR1B = 0; + OCR1A = 0; + TIMSK = 0; +} + +int main() { + return 0; +} diff --git a/include/tabby/clock.h b/include/tabby/clock.h index 4da840f..21d6e41 100644 --- a/include/tabby/clock.h +++ b/include/tabby/clock.h @@ -1,16 +1,16 @@ #ifndef _TABBY_CLOCK_H #define _TABBY_CLOCK_H -typedef enum tabby_clock_mode { +typedef enum { TABBY_CLOCK_SOURCE_INTERNAL = 0x01, TABBY_CLOCK_SOURCE_EXTERNAL = 0x02 -}; +} tabby_clock_mode; -typedef enum tabby_clock_speed { +typedef enum { TABBY_CLOCK_SPEED_8192HZ = 0x01, TABBY_CLOCK_SPEED_16384HZ = 0x02, - TABBY_CLOCK_SPEED_262144HZ = 0x20, - TABBY_CLOCK_SPEED_524288HZ = 0x40 -}; + TABBY_CLOCK_SPEED_262144HZ = 0x03, + TABBY_CLOCK_SPEED_524288HZ = 0x04 +} tabby_clock_speed; #endif /* _TABBY_CLOCK_H */ diff --git a/include/tabby/command.h b/include/tabby/command.h index 9829ee3..40e2a0d 100644 --- a/include/tabby/command.h +++ b/include/tabby/command.h @@ -1,10 +1,10 @@ #ifndef _TABBY_COMMAND_H #define _TABBY_COMMAND_H -typedef enum tabby_command { +typedef enum { TABBY_COMMAND_SEND = 0x01, TABBY_COMMAND_CLOCK_SOURCE = 0x02, TABBY_COMMAND_CLOCK_SPEED = 0x03 -}; +} tabby_command; #endif /* _TABBY_COMMAND_H */