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 67 insertions and 12 deletions:
0 comments (0 inline, 0 general)
master/master/lib/led.c
Show inline comments
 
@@ -7,13 +7,13 @@
 
 
#include <avr/io.h>
 
 
void led_setup() {
 
	// Configure ports/pins for LEDs
 
	DDRA = 0xff;
 
	PORTA = 0x00;
 
	//PORTA = 0x00;
 
}
 
 
void led_on(uint8_t led) {
 
	// Turn the specified LED on
 
	PORTA |= (1<<led);
 
}
master/master/lib/logger.c
Show inline comments
 
@@ -77,13 +77,12 @@ void logger_setup()
 
	fat_get_dir_entry_of_path(fs, "/", &directory);
 

	
 
	dd = fat_open_dir(fs, &directory);
 
	if(!dd)
 
	{
 
		// opening root directory failed
 
		//PORTA |= 0b00000101;
 
		_delay_ms(10);
 
		return;
 
	}
 
	
 
		
 
	// Create new log file
 
@@ -100,23 +99,21 @@ void logger_setup()
 

	
 
	// Search for file in current directory and open it
 
	fd = open_file_in_dir(fs, dd, filename);
 
	if(!fd)
 
	{
 
		_delay_ms(10);
 
		//PORTA |= 0b00000110;
 
		return;
 
	}
 
	
 
	// Seek to beginning of file
 
	// TODO: Is this needed?
 
	int32_t offset = 0; 
 
	if(!fat_seek_file(fd, &offset, FAT_SEEK_SET))
 
	{
 
		// Error seeking to file
 
		//PORTA |= 0b00000111;	
 
		_delay_ms(10);
 
		fat_close_file(fd);
 
		return;
 
	}
 
		
 
	// Write header information
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
 
@@ -351,13 +351,13 @@ uint8_t sd_raw_available()
 
	return 1; // !!TODO: OH GOSH CHANGE ME
 
    return get_pin_available() == 0x00;
 
}
 

	
 
/**
 
 * \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.
 
 */
 
uint8_t sd_raw_locked()
 
{
 
	int i;
 
@@ -390,15 +390,13 @@ void sd_raw_send_byte(uint8_t b)
 
 */
 
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
 
@@ -23,8 +23,8 @@ void watchdog_setup(void)
 
	sei();
 
}
 
 
// ISR for watchdog timeout. Not currently used, interrupt is disabled.
 
ISR(WDT_vect)
 
{
 
	PORTA = 0xff;
 
	
 
}
master/master/master.c
Show inline comments
 
@@ -13,47 +13,50 @@
 

	
 
#include "config.h"
 

	
 
#include <avr/io.h>
 
#include <util/delay.h>
 
#include <avr/wdt.h>
 
#include <avr/interrupt.h>
 

	
 
#include "lib/serial.h"
 
#include "lib/aprs.h"
 
#include "lib/afsk.h"
 
#include "lib/led.h"
 
#include "lib/logger.h"
 
#include "lib/watchdog.h"
 
#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;
 
		
 
	char logbuf[32];
 
	
 
	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);
 
		
 
		// Wait for transmission to complete before starting another.
 
		// Hopefully this will never delay because it should issue on a timed schedule. Software timers!
 
		while(afsk_busy());
master/master/master.cproj
Show inline comments
 
@@ -141,12 +141,18 @@
 
    <Compile Include="lib\led.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <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>
 
    <Compile Include="lib\sd\byteordering.h">
 
      <SubType>compile</SubType>
 
    </Compile>
0 comments (0 inline, 0 general)