From 19c1c4bb76436402c195d23f3622848759229c51 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Sun, 31 Mar 2013 21:13:51 -0600 Subject: [PATCH] Add TI support back in --- Makefile | 31 ++------------------------- Makefile.avr | 31 +++++++++++++++++++++++++++ Makefile.ti | 17 +++++++++++++++ avr.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ avr.h | 27 +++++++++++++++++++++++ main.c | 2 +- ti.c | 34 +++++++++++++++++++++++++++++ ti.h | 26 +++++++++++++++++++++++ 8 files changed, 198 insertions(+), 30 deletions(-) create mode 100644 Makefile.avr create mode 100644 Makefile.ti create mode 100644 avr.c create mode 100644 avr.h create mode 100644 ti.c create mode 100644 ti.h diff --git a/Makefile b/Makefile index e046538..744cd7a 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,4 @@ -PROG = main +ARCH = ti -CC = avr-gcc -CFLAGS += -mmcu=atmega328p -CFLAGS += -DF_CPU=16000000UL -CFLAGS += -Os -CFLAGS += -w +include Makefile.$(ARCH) -AVDFLAGS += -p m328p -AVDFLAGS += -c arduino -AVDFLAGS += -b 115200 -AVDFLAGS += -P /dev/ttyACM0 - - -upload: .upload - -.upload: $(PROG).hex - avrdude $(AVDFLAGS) -U flash:w:$< - touch $@ - -$(PROG).hex: $(PROG) - avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@ - -main: main.o avr.o - -clean: - rm -f $(PROG) *.hex .upload - - - - diff --git a/Makefile.avr b/Makefile.avr new file mode 100644 index 0000000..e5a39d2 --- /dev/null +++ b/Makefile.avr @@ -0,0 +1,31 @@ +PROG = main + +CC = avr-gcc +CFLAGS += -mmcu=atmega328p +CFLAGS += -DF_CPU=16000000UL +CFLAGS += -Os +CFLAGS += -w + +AVDFLAGS += -p m328p +AVDFLAGS += -c arduino +AVDFLAGS += -b 115200 +AVDFLAGS += -P /dev/ttyACM0 + + +upload: .upload + +.upload: $(PROG).hex + avrdude $(AVDFLAGS) -U flash:w:$< + touch $@ + +$(PROG).hex: $(PROG) + avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@ + +main: main.o avr.o + +clean: + rm -f $(PROG) *.hex .upload + + + + \ No newline at end of file diff --git a/Makefile.ti b/Makefile.ti new file mode 100644 index 0000000..9cfdc4c --- /dev/null +++ b/Makefile.ti @@ -0,0 +1,17 @@ +CC = msp430-gcc +LDFLAGS += -mmcu=msp430g2553 +CFLAGS += -mmcu=msp430g2553 +CFLAGS += -Wall +CFLAGS += -Os +CFLAGS += -w + +upload: .upload + +.upload: main + mspdebug rf2500 "prog $<" + touch $@ + +main: main.o ti.o + +clean: + rm -f main *.o .upload diff --git a/avr.c b/avr.c new file mode 100644 index 0000000..f46b64c --- /dev/null +++ b/avr.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include "avr.h" + +#define cbi(byt, bit) (byt &= ~_BV(bit)) +#define sbi(byt, bit) (byt |= _BV(bit)) + +extern volatile bool tick; +extern volatile uint32_t jiffies; + +// Count microseconds +volatile uint32_t micros = 0; + +// Interrupt called every 1024 µs +SIGNAL(TIMER0_OVF_vect) +{ + uint32_t m = micros; + + m += 1024; + if (m >= JIFFY_uS) { + m %= JIFFY_uS; + tick = true; + jiffies += 1; + } + micros = m; +} + + +#define mode(on) bit(PORTD, _BV(0), on) +#define sin(on) bit(PORTD, _BV(1), on) +#define sclk(on) bit(PORTD, _BV(2), on) +#define xlat(on) bit(PORTD, _BV(3), on) +// Connect GSCLK to SCLK +// Connect BLANK to XLAT +// TRUST ME, THIS TOTALLY WORKS + +#define nesclk(on) bit(PORTD, _BV(4), on) +#define nesltch(on) bit(PORTD, _BV(5), on) +#define nesout() ((PIND & _BV(6)) << 6) + +void +init(void) +{ + // Set timer 0 interrupt clock divider to 64 + TCCR0B = 0x03; + + // enable timer 0 overflow interrupt + TIMSK0 = 0x01; + + // Enable interrupts + sei(); + + DDRD = ~(_BV(NESOUT)); + DDRB = 0xff; + + PORTD = 0; + +} diff --git a/avr.h b/avr.h new file mode 100644 index 0000000..a248e20 --- /dev/null +++ b/avr.h @@ -0,0 +1,27 @@ +#ifndef AVR_H +#define AVR_H + +#include +#include +#include + +// Make sure JIFFY_uS is going to be an integer and not a float! +#define JIFFIES_PER_SECOND 50 +#define JIFFY_uS (1000000 / JIFFIES_PER_SECOND) + +#define mode(on) bit(PORTD, _BV(0), on) +#define sin(on) bit(PORTD, _BV(1), on) +#define sclk(on) bit(PORTD, _BV(2), on) +#define xlat(on) bit(PORTD, _BV(3), on) +// Connect GSCLK to SCLK +// Connect BLANK to XLAT +// TRUST ME, THIS TOTALLY WORKS + +#define NESOUT 6 +#define nesclk(on) bit(PORTD, _BV(4), on) +#define nesltch(on) bit(PORTD, _BV(5), on) +#define nesout() ((PIND & _BV(NESOUT)) << NESOUT) + +void init(void); + +#endif \ No newline at end of file diff --git a/main.c b/main.c index 37b13ce..89baf06 100644 --- a/main.c +++ b/main.c @@ -1,7 +1,7 @@ #include #include #include -#include "avr.h" +#include "ti.h" // Number of shift registers in your scoreboard // If you want scores to go over 199, you need 8 diff --git a/ti.c b/ti.c new file mode 100644 index 0000000..17d8853 --- /dev/null +++ b/ti.c @@ -0,0 +1,34 @@ +#include +#include +#include "ti.h" + +extern volatile bool tick; +extern volatile uint32_t jiffies; + +// Count microseconds +volatile uint32_t micros = 0; + +// Interrupt called every 1024 µs +__attribute__((interrupt(TIMER0_A0_VECTOR))) +void +timer_a(void) +{ + tick = true; + jiffies += 1; +} + + + +void +init() +{ + WDTCTL = WDTPW + WDTHOLD; // Disable Watchdog Timer + P1DIR = ~(_BV(NESOUT)); + P1OUT = 0; + + CCTL0 |= CCIE; // Trigger interrupt on A checkpoint + TACTL = TASSEL_2 + MC_1; // Set timer A to SMCLCK, up mode + TACCR0 = 0x4444; // Interrupt 60 times per second + + __enable_interrupt(); +} diff --git a/ti.h b/ti.h new file mode 100644 index 0000000..8323788 --- /dev/null +++ b/ti.h @@ -0,0 +1,26 @@ +#ifndef TI_H +#define TI_H + +#include +#include + +#define _BV(x) (1 << x) + +#define JIFFIES_PER_SECOND 60 + +#define mode(on) bit(P1OUT, _BV(0), on) +#define sin(on) bit(P1OUT, _BV(1), on) +#define sclk(on) bit(P1OUT, _BV(2), on) +#define xlat(on) bit(P1OUT, _BV(3), on) +// Connect GSCLK to SCLK +// Connect BLANK to XLAT +// TRUST ME, THIS TOTALLY WORKS + +#define NESOUT 6 +#define nesclk(on) bit(P1OUT, _BV(4), on) +#define nesltch(on) bit(P1OUT, _BV(5), on) +#define nesout() ((P1IN & _BV(NESOUT)) << NESOUT) + +void init(); + +#endif