# HG changeset patch # User ethanzonca@CL-SEC241-08.cedarville.edu # Date 2012-11-09 00:00:05 # Node ID 5109fd6856e1918484deba08560b047b3cc2087a # Parent ade367f855754e658cc451556fe226d74984f482 Work on SD card diff --git a/master/master/lib/afsk.c b/master/master/lib/afsk.c --- a/master/master/lib/afsk.c +++ b/master/master/lib/afsk.c @@ -214,10 +214,6 @@ void afsk_setup() { // Enable interrupt when TCNT2 reaches TOP (0xFF) (p.151, 163) //TIMSK2 |= _BV(TOIE2); TIMSK2 |= 0b00000001; - - // Initialize PORTA - DDRA = 0xff; - PORTA = 0x00; DDRD = 0xff; PORTD = 0xff; 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 @@ -9,14 +9,18 @@ void led_setup() { // Configure ports/pins for LEDs + DDRA = 0xff; + PORTA = 0x00; } void led_On(uint8_t led) { // Turn the specified LED on + PORTA |= led; } void led_Off(uint8_t led) { // Turn the specified LED off + PORTA &= ~(led); } void led_Toggle(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 @@ -26,67 +26,53 @@ void logger_setup() { - while(1) - { - //check for SD exist/power/ready BEGIN - /* setup SD card slot */ + if(!sd_raw_init()) //sd_raw.c this function may need an overhaul { - #if DEBUG - uart_puts_p(PSTR("MMC/SD initialization failed\n")); - #endif - continue; + // initialization failed!!!!!!! + PORTA |= 0b00000001; + return; } +return; //check for SD exist/power/ready END - //create partition BEGIN /* open first partition */ struct partition_struct* partition = partition_open(sd_raw_read, sd_raw_read_interval, - //#if SD_RAW_WRITE_SUPPORT //probably want this to be true ?? sd_raw_write, sd_raw_write_interval, - //#endif 0 ); //check that partition was created correctly if(!partition) { + // OH GOSH TERRIBLE ERROR HERE /* If the partition did not open, assume the storage device * is a "superfloppy", i.e. has no MBR. */ - //what is MBR ?? partition = partition_open(sd_raw_read, sd_raw_read_interval, - #if SD_RAW_WRITE_SUPPORT //probably want this to be true ?? sd_raw_write, sd_raw_write_interval, - #else - 0, - 0, - #endif -1 ); if(!partition) { - #if DEBUG - uart_puts_p(PSTR("opening partition failed\n")); - #endif - continue; + // oh frick opening partition failed + PORTA |= 0b00000010; + return; } } //open partition END //open file system BEGIN - /* open file system */ struct fat_fs_struct* fs = fat_open(partition); if(!fs) { - #if DEBUG - uart_puts_p(PSTR("opening file system failed\n")); - #endif - continue; + // opening fs failed! + PORTA |= 0b00000100; + return; } //open file system END @@ -99,54 +85,60 @@ void logger_setup() struct fat_dir_struct* dd = fat_open_dir(fs, &directory); if(!dd) { - #if DEBUG - uart_puts_p(PSTR("opening root directory failed\n")); - #endif - continue; + // frick opening root dir failed + PORTA |= 0b00000101; + return; } //open directory END //simplified version of console BEGIN - /* provide a simple shell */ char buffer[24]; + + /* search file in current directory and open it */ + struct fat_file_struct* fd = open_file_in_dir(fs, dd, "data.csv"); //logger.h + if(!fd) + { + 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 ?? + { + //error seek to file handling + PORTA |= 0b00000111; + fat_close_file(fd); + return; + } + + buffer[0] = 'H'; + buffer[1] = 'e'; + buffer[2] = 'l'; + buffer[3] = 'l'; + buffer[4] = 'o'; + buffer[5] = 'w'; + buffer[6] = 'o'; + buffer[7] = 'r'; + buffer[8] = 'l'; + buffer[9] = 'd'; + + /* read text from the shell and write it to the file */ + uint8_t data_len = sizeof(buffer); + while(1) { - /* execute command */ - /* search file in current directory and open it */ - struct fat_file_struct* fd = open_file_in_dir(fs, dd, "data.csv"); //logger.h - if(!fd) + /* write text to file !! */ + if(fat_write_file(fd, (uint8_t*) buffer, data_len) != data_len) { - //error open file handling - continue; + //uart_puts_p(PSTR("error writing to file\n")); + break; } - - int32_t offset = 5;//strtolong(offset_value); - if(!fat_seek_file(fd, &offset, FAT_SEEK_SET)) //seek to begin or end or what ?? - { - //error seek to file handling - - fat_close_file(fd); - continue; - } + } - /* read text from the shell and write it to the file */ - uint8_t data_len = sizeof(buffer); - - while(1) - { - /* write text to file !! */ - if(fat_write_file(fd, (uint8_t*) buffer, data_len) != data_len) - { - //uart_puts_p(PSTR("error writing to file\n")); - break; - } - } - - fat_close_file(fd); //may want to leave file open ?? - } - //simplified version of console END + fat_close_file(fd); //may want to leave file open ?? + //prepare for closing SD connection BEGIN /* close directory */ @@ -158,7 +150,6 @@ void logger_setup() /* close partition */ partition_close(partition); //partition.c //prepare for closing SD connection END - } } //writes a single line to the SD card 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 @@ -191,9 +191,15 @@ uint8_t sd_raw_init() (1 << MSTR0) | /* Master mode */ (0 << CPOL0) | /* Clock Polarity: SCK low when idle */ (0 << CPHA0) | /* Clock Phase: sample on rising SCK edge */ - (1 << SPR10) | /* Clock Frequency: f_OSC / 128 */ - (1 << SPR00); + (1 << SPR10); /* Clock Frequency: f_OSC / 128 */ + //(1 << SPR00); // commentnig this out means /64, which gives over 100khz as required SPSR0 &= ~(1 << SPI2X0); /* No doubled clock frequency */ +// transmit a char + while ( ! ( SPSR0 & ( 1 << SPIF0 ))); // wait for completion of + SPDR0 = 'c'; // begin transmission + + +return; /* initialization procedure */ sd_raw_card_type = 0; @@ -339,6 +345,8 @@ uint8_t sd_raw_init() */ uint8_t sd_raw_available() { + int i; + return 1; // !!TODO: OH GOSH CHANGE ME return get_pin_available() == 0x00; } @@ -350,6 +358,9 @@ uint8_t sd_raw_available() */ uint8_t sd_raw_locked() { + int i; + // !!TODO oh gosh change me + return 0; return get_pin_locked() == 0x00; } @@ -378,8 +389,11 @@ 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; diff --git a/master/master/lib/sd/sd_raw_config.h b/master/master/lib/sd/sd_raw_config.h --- a/master/master/lib/sd/sd_raw_config.h +++ b/master/master/lib/sd/sd_raw_config.h @@ -71,54 +71,15 @@ extern "C" * @} */ -/* defines for customisation of sd/mmc port access */ -#if defined(__AVR_ATmega8__) || \ - defined(__AVR_ATmega48__) || \ - defined(__AVR_ATmega48P__) || \ - defined(__AVR_ATmega88__) || \ - defined(__AVR_ATmega88P__) || \ - defined(__AVR_ATmega168__) || \ - defined(__AVR_ATmega168P__) || \ - defined(__AVR_ATmega328P__) - #define configure_pin_mosi() DDRB |= (1 << DDB3) - #define configure_pin_sck() DDRB |= (1 << DDB5) - #define configure_pin_ss() DDRB |= (1 << DDB2) - #define configure_pin_miso() DDRB &= ~(1 << DDB4) - - #define select_card() PORTB &= ~(1 << PORTB2) - #define unselect_card() PORTB |= (1 << PORTB2) -#elif defined(__AVR_ATmega16__) || \ - defined(__AVR_ATmega32__) - #define configure_pin_mosi() DDRB |= (1 << DDB5) - #define configure_pin_sck() DDRB |= (1 << DDB7) - #define configure_pin_ss() DDRB |= (1 << DDB4) - #define configure_pin_miso() DDRB &= ~(1 << DDB6) +#define configure_pin_mosi() DDRB |= (1 << DDRB5) //PB5 +#define configure_pin_sck() DDRB |= (1 << DDRB7) //PB7 +#define configure_pin_ss() DDRB |= (1 << DDRB0) //PB0 - custom pin +#define configure_pin_miso() DDRB &= ~(1 << DDRB6) //PB6 + +#define select_card() PORTB &= ~(1 << PORTB0) +#define unselect_card() PORTB |= (1 << PORTB0) - #define select_card() PORTB &= ~(1 << PORTB4) - #define unselect_card() PORTB |= (1 << PORTB4) -#elif defined(__AVR_ATmega64__) || \ - defined(__AVR_ATmega128__) || \ - defined(__AVR_ATmega169__) - #define configure_pin_mosi() DDRB |= (1 << DDB2) - #define configure_pin_sck() DDRB |= (1 << DDB1) - #define configure_pin_ss() DDRB |= (1 << DDB0) - #define configure_pin_miso() DDRB &= ~(1 << DDB3) - #define select_card() PORTB &= ~(1 << PORTB0) - #define unselect_card() PORTB |= (1 << PORTB0) -#elif defined(__AVR_ATmega164P__) || \ - defined(__AVR_ATmega324P__) || \ - defined(__AVR_ATmega664P__) - #define configure_pin_mosi() DDRB |= (1 << DDRB5) //PB5 - #define configure_pin_sck() DDRB |= (1 << DDRB7) //PB7 - #define configure_pin_ss() DDRB |= (1 << DDRB0) //PB0 - custom pin - #define configure_pin_miso() DDRB &= ~(1 << DDRB6) //PB6 - - #define select_card() PORTB &= ~(1 << PORTB0) - #define unselect_card() PORTB |= (1 << PORTB0) -#else - #error "no sd/mmc pin mapping available!" //sends error if micro not specified -#endif #define configure_pin_available() DDRC &= ~(1 << DDRC4) #define configure_pin_locked() DDRC &= ~(1 << DDRC5) @@ -126,12 +87,16 @@ extern "C" #define get_pin_available() (PINC & (1 << PINC4)) #define get_pin_locked() (PINC & (1 << PINC5)) + + #if SD_RAW_SDHC typedef uint64_t offset_t; #else typedef uint32_t offset_t; #endif + + /* configuration checks */ #if SD_RAW_WRITE_SUPPORT #undef SD_RAW_SAVE_RAM diff --git a/master/master/master.c b/master/master/master.c --- a/master/master/master.c +++ b/master/master/master.c @@ -18,11 +18,15 @@ #include "lib/serial.h" #include "lib/aprs.h" +#include "lib/afsk.h" #include "lib/led.h" +#include "lib/logger.h" + +#include "lib/sd/sd_raw_config.h" void micro_setup() { // Generic microcontroller config options - + } int main(void) @@ -30,19 +34,24 @@ int main(void) // Initialize micro_setup(); led_setup(); + + serial_setup(); // Config serial ports afsk_setup(); + + _delay_ms(400); + _delay_ms(400); + + logger_setup(); while(1) { //afsk_test(); - aprs_send(); - _delay_ms(400); - _delay_ms(400); + //aprs_send(); + _delay_ms(400); - _delay_ms(400); - _delay_ms(400); - _delay_ms(400); - serial_SendCommand('0','A',0,0); + //serial_SendCommand('0','A',0,0); + + } } \ No newline at end of file