Changeset - 94648aa82312
[Not reviewed]
default
0 3 0
ethanzonca@CL-SEC241-08.cedarville.edu - 12 years ago 2012-11-15 15:50:20
ethanzonca@CL-SEC241-08.cedarville.edu
Cleanup of logger
3 files changed with 32 insertions and 29 deletions:
0 comments (0 inline, 0 general)
master/master/lib/logger.c
Show inline comments
 
@@ -5,6 +5,8 @@
 
 *  Author: mkanning
 
 */ 
 
 
#include "../config.h"
 
#include <util/delay.h>
 
#include <string.h>
 
#include <avr/pgmspace.h>
 
#include <avr/sleep.h>
 
@@ -16,7 +18,7 @@
 
#include "sd/sd_raw.h"
 
#include "sd/sd_raw_config.h"
 
#include "logger.h"
 
#include "../config.h"
 
 
 
/* 
 
	//config edits
 
@@ -78,7 +80,8 @@ void logger_setup()
 
	if(!dd)
 
	{
 
		// opening root directory failed
 
		PORTA |= 0b00000101;
 
		//PORTA |= 0b00000101;
 
		_delay_ms(10);
 
		return;
 
	}
 
	
 
@@ -86,27 +89,32 @@ void logger_setup()
 
	// Create new log file
 
	uint8_t logid = eeprom_read_byte(LOGGER_ID_EEPROM_ADDR);
 
	char filename[48];
 
	
 
	// we pre-increment logid here because it starts at 255, then wraps to 0
 
	sprintf(filename, "data%d.csv",++logid);
 
	// @TODO: Catch errors here
 
	
 
	// TODO: Catch errors here
 
	fat_create_file(dd, filename, &directory);
 
		
 
	eeprom_update_byte(LOGGER_ID_EEPROM_ADDR, logid);
 

	
 

	
 
	/* search file in current directory and open it */
 
	fd = open_file_in_dir(fs, dd, filename); //logger.h
 
	// Search for file in current directory and open it
 
	fd = open_file_in_dir(fs, dd, filename);
 
	if(!fd)
 
	{
 
		PORTA |= 0b00000110;
 
		_delay_ms(10);
 
		//PORTA |= 0b00000110;
 
		return;
 
	}
 
	
 
	int32_t offset = 0; //strtolong(offset_value);
 
	if(!fat_seek_file(fd, &offset, FAT_SEEK_SET)) //seek to begin or end or what ??
 
	// Seek to beginning of file
 
	// TODO: Is this needed?
 
	int32_t offset = 0; 
 
	if(!fat_seek_file(fd, &offset, FAT_SEEK_SET))
 
	{
 
		//error seek to file handling
 
		PORTA |= 0b00000111;	
 
		// Error seeking to file
 
		//PORTA |= 0b00000111;	
 
		_delay_ms(10);
 
		fat_close_file(fd);
 
		return;
 
	}
 
@@ -122,23 +130,16 @@ void logger_log(char *buffer) {
 
	uint8_t len = strlen(buffer);
 
	if(fat_write_file(fd, (uint8_t*) buffer, len) != len)
 
	{
 
		//uart_puts_p(PSTR("error writing to file\n"));
 
		// Error writing to file
 
		return;
 
	}
 
}
 
 
void logger_closeLog() {
 
	
 
	fat_close_file(fd); //may want to leave file open ??
 
 
	/* close directory */
 
	fat_close_dir(dd); //fat.c
 

	
 
	/* close file system */
 
	fat_close(fs); //fat.c
 

	
 
	/* close partition */
 
	partition_close(partition); //partition.c
 
	fat_close_file(fd);
 
	fat_close_dir(dd);
 
	fat_close(fs);
 
	partition_close(partition);
 
}
 
 
master/master/lib/sd/sd_raw.c
Show inline comments
 
@@ -393,9 +393,9 @@ uint8_t sd_raw_rec_byte()
 
    /* send dummy data for receiving some */
 

	
 
    SPDR0 = 0xff;
 
		PORTA = 0x01;
 
		//PORTA = 0x01;
 
    while(!(SPSR0 & (1 << SPIF0)));
 
	PORTA = 0x02;
 
	//PORTA = 0x02;
 
    SPSR0 &= ~(1 << SPIF0);
 

	
 
    return SPDR0;
master/master/master.c
Show inline comments
 
@@ -36,12 +36,14 @@ int main(void)
 
	//micro_setup();
 
	led_setup();
 

	
 

	
 
	//serial_setup(); // Config serial ports
 
	
 
	logger_setup(); // this takes a few ms
 
	
 
	afsk_setup();
 
	logger_setup(); // this takes a few ms
 
 
 
    while(1)
 
	while(afsk_busy());
 
    
 
	while(1)
 
    {
 
		logger_log("123,43,1,2,4,3\n");
 
		
0 comments (0 inline, 0 general)