Changeset - 28bdbd881b55
[Not reviewed]
default
0 6 2
ethanzonca@CL-SEC241-08.cedarville.edu - 12 years ago 2012-11-19 22:04:11
ethanzonca@CL-SEC241-08.cedarville.edu
Added looptime and other optimizations. LoopTime interrupt is firing, but incrementing may or may not work.
8 files changed with 68 insertions and 13 deletions:
0 comments (0 inline, 0 general)
master/master/lib/led.c
Show inline comments
 
@@ -10,7 +10,7 @@
 
void led_setup() {
 
	// Configure ports/pins for LEDs
 
	DDRA = 0xff;
 
	PORTA = 0x00;
 
	//PORTA = 0x00;
 
}
 
 
void led_on(uint8_t led) {
master/master/lib/logger.c
Show inline comments
 
@@ -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;
master/master/lib/looptime.c
Show inline comments
 
new file 100644
 
/*
 
 * looptime.c
 
 *
 
 * Created: 11/19/2012 8:56:42 PM
 
 *  Author: ethanzonca
 
 */ 
 
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
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
 
}
master/master/lib/looptime.h
Show inline comments
 
new file 100644
 
/*
 
 * 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
master/master/lib/sd/sd_raw.c
Show inline comments
 
@@ -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;
master/master/lib/watchdog.c
Show inline comments
 
@@ -26,5 +26,5 @@ void watchdog_setup(void)
 
// ISR for watchdog timeout. Not currently used, interrupt is disabled.
 
ISR(WDT_vect)
 
{
 
	PORTA = 0xff;
 
	
 
}
master/master/master.c
Show inline comments
 
@@ -16,6 +16,7 @@
 
#include <avr/io.h>
 
#include <util/delay.h>
 
#include <avr/wdt.h>
 
#include <avr/interrupt.h>
 

	
 
#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);
 
		
master/master/master.cproj
Show inline comments
 
@@ -144,6 +144,12 @@
 
    <Compile Include="lib\logger.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\looptime.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\looptime.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sd\byteordering.c">
 
      <SubType>compile</SubType>
 
    </Compile>
0 comments (0 inline, 0 general)