# HG changeset patch # User ethanzonca@CL-SEC241-08.cedarville.edu # Date 2012-11-19 22:04:11 # Node ID 28bdbd881b5517eca7e703cf0e4770e611f1c1c7 # Parent 51c8e8809a90e1d513f2f7d5a3b6da83e68ec186 Added looptime and other optimizations. LoopTime interrupt is firing, but incrementing may or may not work. diff --git a/master/master/lib/led.c b/master/master/lib/led.c --- a/master/master/lib/led.c +++ b/master/master/lib/led.c @@ -10,7 +10,7 @@ void led_setup() { // Configure ports/pins for LEDs DDRA = 0xff; - PORTA = 0x00; + //PORTA = 0x00; } void led_on(uint8_t led) { diff --git a/master/master/lib/logger.c b/master/master/lib/logger.c --- a/master/master/lib/logger.c +++ b/master/master/lib/logger.c @@ -80,7 +80,6 @@ void logger_setup() if(!dd) { // opening root directory failed - //PORTA |= 0b00000101; _delay_ms(10); return; } @@ -103,7 +102,6 @@ void logger_setup() if(!fd) { _delay_ms(10); - //PORTA |= 0b00000110; return; } @@ -113,7 +111,6 @@ void logger_setup() if(!fat_seek_file(fd, &offset, FAT_SEEK_SET)) { // Error seeking to file - //PORTA |= 0b00000111; _delay_ms(10); fat_close_file(fd); return; diff --git a/master/master/lib/looptime.c b/master/master/lib/looptime.c new file mode 100644 --- /dev/null +++ b/master/master/lib/looptime.c @@ -0,0 +1,34 @@ +/* + * looptime.c + * + * Created: 11/19/2012 8:56:42 PM + * Author: ethanzonca + */ + +#include +#include +volatile uint32_t millis = 0; // Milliseconds since initialization + + + +void time_setup() { + DDRA = 0xff; + + // Generic microcontroller config options + OCR0A = 173; // Approx 172.7969 ticks per ms with 64 prescaler + + TCCR0A |= (1 << WGM01) | (1 << WGM00); // Count until OCR0A, then overflow (wgm02 in the next line specifies this as well) + TCCR0B |= (1 << CS01) | (1 << CS00) | (1 << WGM02); // clock div by 64 + TIFR0 |= ( 1 << TOV0 ); // clear pending interrupts + TIMSK0 |= (1 << TOIE0); // enable overflow interrupt +} + + +ISR(TIMER0_OVF_vect) { + PORTA = 0xff; + millis++; +} + +uint32_t time_millis() { + return millis; // meh accuracy, but that's OK +} diff --git a/master/master/lib/looptime.h b/master/master/lib/looptime.h new file mode 100644 --- /dev/null +++ b/master/master/lib/looptime.h @@ -0,0 +1,17 @@ +/* + * looptime.h + * + * Created: 11/19/2012 8:56:49 PM + * Author: ethanzonca + */ + + +#ifndef LOOPTIME_H_ +#define LOOPTIME_H_ + + +void time_setup(); + +uint32_t time_millis(); + +#endif /* LOOPTIME_H_ */ \ No newline at end of file diff --git a/master/master/lib/sd/sd_raw.c b/master/master/lib/sd/sd_raw.c --- a/master/master/lib/sd/sd_raw.c +++ b/master/master/lib/sd/sd_raw.c @@ -354,7 +354,7 @@ uint8_t sd_raw_available() /** * \ingroup sd_raw - * Checks wether the memory card is locked for write access. + * Checks whether the memory card is locked for write access. * * \returns 1 if the card is locked, 0 if it is not. */ @@ -393,9 +393,7 @@ uint8_t sd_raw_rec_byte() /* send dummy data for receiving some */ SPDR0 = 0xff; - //PORTA = 0x01; while(!(SPSR0 & (1 << SPIF0))); - //PORTA = 0x02; SPSR0 &= ~(1 << SPIF0); return SPDR0; diff --git a/master/master/lib/watchdog.c b/master/master/lib/watchdog.c --- a/master/master/lib/watchdog.c +++ b/master/master/lib/watchdog.c @@ -26,5 +26,5 @@ void watchdog_setup(void) // ISR for watchdog timeout. Not currently used, interrupt is disabled. ISR(WDT_vect) { - PORTA = 0xff; + } diff --git a/master/master/master.c b/master/master/master.c --- a/master/master/master.c +++ b/master/master/master.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "lib/serial.h" #include "lib/aprs.h" @@ -26,21 +27,23 @@ #include "lib/sd/sd_raw_config.h" void micro_setup() { - // Generic microcontroller config options + } - int main(void) { + // Initialize. If this takes more than 4 seconds, be sure to reset the WDT + time_setup(); micro_setup(); watchdog_setup(); led_setup(); serial_setup(); // Config serial ports logger_setup(); // this takes a few ms afsk_setup(); // can take a few ms - - led_on(POWER); + + + //led_on(POWER); uint16_t ctr1 = 0; uint16_t ctr2 = 255; @@ -50,7 +53,7 @@ int main(void) while(1) { led_on(STAT); - sprintf(logbuf, "%d,%d,%d,%d,%d,%d\n", ctr1,5*ctr1,ctr2, 12*ctr2,43*ctr1,5*ctr2); + sprintf(logbuf, "%d,%d,%d,%d,%d,%d\n", time_millis(),5*ctr1,ctr2, 12*ctr2,43*ctr1,5*ctr2); logger_log(logbuf); led_off(STAT); diff --git a/master/master/master.cproj b/master/master/master.cproj --- a/master/master/master.cproj +++ b/master/master/master.cproj @@ -144,6 +144,12 @@ compile + + compile + + + compile + compile