Add TI support back in

This commit is contained in:
Neale Pickett 2013-03-31 21:13:51 -06:00
parent 679ee4d014
commit 19c1c4bb76
8 changed files with 198 additions and 30 deletions

View File

@ -1,31 +1,4 @@
PROG = main ARCH = ti
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
include Makefile.$(ARCH)

31
Makefile.avr Normal file
View File

@ -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

17
Makefile.ti Normal file
View File

@ -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

60
avr.c Normal file
View File

@ -0,0 +1,60 @@
#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#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;
}

27
avr.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef AVR_H
#define AVR_H
#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
// 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

2
main.c
View File

@ -1,7 +1,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include "avr.h" #include "ti.h"
// Number of shift registers in your scoreboard // Number of shift registers in your scoreboard
// If you want scores to go over 199, you need 8 // If you want scores to go over 199, you need 8

34
ti.c Normal file
View File

@ -0,0 +1,34 @@
#include <stdbool.h>
#include <stdint.h>
#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();
}

26
ti.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef TI_H
#define TI_H
#include <stdint.h>
#include <msp430.h>
#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