# HG changeset patch # User Matt Johnston # Date 1372332296 0 # Node ID 9e888708f33d330797b1240e7214767a5ccd2ef1 # Parent c6f77df67ddecc5e5a30f31c08c9fdd35acd0d60 sd test code diff -r c6f77df67dde -r 9e888708f33d main.c --- a/main.c Thu Jun 27 14:05:10 2013 +0800 +++ b/main.c Thu Jun 27 11:24:56 2013 +0000 @@ -296,22 +296,65 @@ return fat_open_file(fs, &file_entry); } +static uint32_t sd_serial = 0; +static char conf_start[30]; + static void hmac_file(const char* fn) { - sd_raw_init(); + uint8_t res; struct partition_struct* partition = partition_open(sd_raw_read, sd_raw_read_interval, 0, 0, 0); + + if (!partition) + { + sprintf(conf_start, "part"); + return; + } + struct fat_fs_struct* fs = fat_open(partition); + if (!fs) + { + sprintf(conf_start, "bad fs"); + return; + } struct fat_dir_entry_struct directory; - fat_get_dir_entry_of_path(fs, "/", &directory); + res = fat_get_dir_entry_of_path(fs, "/", &directory); + if (!res) + { + sprintf(conf_start, "bad direc"); + return; + } struct sd_raw_info disk_info; sd_raw_get_info(&disk_info); - printf("diskinfo size %d", disk_info.capacity); + sd_serial = disk_info.serial; struct fat_dir_struct* dd = fat_open_dir(fs, &directory); - struct fat_file_struct* fd = open_file_in_dir(fs, dd, "fn"); + if (!dd) + { + sprintf(conf_start, "bad dd"); + return; + } + struct fat_file_struct* fd = open_file_in_dir(fs, dd, fn); + if (!fd) + { + sprintf(conf_start, "bad fd"); + return; + } + fat_read_file(fd, conf_start, sizeof(conf_start)-1); + conf_start[sizeof(conf_start)-1] = '\0'; + + fat_close_file(fd); + fd = NULL; + fat_close_dir(dd); + dd = NULL; + fat_close(fs); + fs = NULL; + partition_close(partition); + partition = NULL; + +#if 0 char c = 0; char buf[512]; for (int i = 0; i < 10; i++) @@ -320,6 +363,24 @@ c ^= buf[0]; } printf("total %d\n", c); +#endif +} + + +static void +cmd_testsd(const char *param) +{ + PORT_PI_RESET &= ~_BV(PIN_PI_RESET); + DDR_PI_RESET |= _BV(PIN_PI_RESET); + _delay_ms(200); + + sd_raw_init(); + hmac_file(param); + sd_raw_deinit(); + + _delay_ms(200); + + DDR_PI_RESET &= ~_BV(PIN_PI_RESET); } static void cmd_reset() __attribute__ ((noreturn)); @@ -379,13 +440,17 @@ "oneshot (%lu)\n" "uptime %lu rem %u\n" "boot normal %hhu\n" + "disk serial %lx\n" + "disk start '%s'\n" ), watchdog_long_limit, cur_watchdog_long, long_reboot_mode, watchdog_short_limit, cur_watchdog_short, newboot_limit, cur_newboot, cur_oneshot, t.ticks, t.rem, - boot_normal_status); + boot_normal_status, + sd_serial, + conf_start); } static void @@ -945,6 +1010,7 @@ LOCAL_PSTR(status); LOCAL_PSTR(random); LOCAL_PSTR(prog); + LOCAL_PSTR(testsd); LOCAL_HELP(set_params, " "); LOCAL_HELP(set_key, "20_byte_hex>"); LOCAL_HELP(oneshot, ""); @@ -952,6 +1018,7 @@ LOCAL_HELP(random, " "); LOCAL_HELP(hmac, " <20_byte_hex_data>"); LOCAL_HELP(decrypt, " <20_byte_hmac|16_byte_aes_block>"); + LOCAL_HELP(testsd, ""); static const struct handler { PGM_P name; @@ -973,6 +1040,7 @@ {random_str, cmd_random, random_help}, {vcc_str, cmd_vcc, NULL}, {reset_str, cmd_reset, NULL}, + {testsd_str, cmd_testsd, testsd_help}, {prog_str, cmd_prog, prog_help}, }; diff -r c6f77df67dde -r 9e888708f33d sd_raw.c --- a/sd_raw.c Thu Jun 27 14:05:10 2013 +0800 +++ b/sd_raw.c Thu Jun 27 11:24:56 2013 +0000 @@ -330,6 +330,14 @@ return 1; } +void +sd_raw_deinit(void) +{ + configure_pin_mosi(); + configure_pin_sck(); + configure_pin_ss(); +} + /** * \ingroup sd_raw * Checks wether a memory card is located in the slot. diff -r c6f77df67dde -r 9e888708f33d sd_raw.h --- a/sd_raw.h Thu Jun 27 14:05:10 2013 +0800 +++ b/sd_raw.h Thu Jun 27 11:24:56 2013 +0000 @@ -125,6 +125,7 @@ typedef uintptr_t (*sd_raw_write_interval_handler_t)(uint8_t* buffer, offset_t offset, void* p); uint8_t sd_raw_init(); +void sd_raw_deinit(void); uint8_t sd_raw_available(); uint8_t sd_raw_locked(); diff -r c6f77df67dde -r 9e888708f33d sd_raw_config.h --- a/sd_raw_config.h Thu Jun 27 14:05:10 2013 +0800 +++ b/sd_raw_config.h Thu Jun 27 11:24:56 2013 +0000 @@ -85,6 +85,10 @@ #define configure_pin_ss() DDRB |= (1 << DDB2) #define configure_pin_miso() DDRB &= ~(1 << DDB4) + #define deonfigure_pin_mosi() DDRB &= ~(1 << DDB3) + #define deonfigure_pin_sck() DDRB &= ~(1 << DDB5) + #define deonfigure_pin_ss() DDRB &= ~(1 << DDB2) + #define select_card() PORTB &= ~(1 << PORTB2) #define unselect_card() PORTB |= (1 << PORTB2) #elif defined(__AVR_ATmega16__) || \ @@ -110,11 +114,13 @@ #error "no sd/mmc pin mapping available!" #endif -#define configure_pin_available() DDRC &= ~(1 << DDC4) -#define configure_pin_locked() DDRC &= ~(1 << DDC5) +#define configure_pin_available() DDRC &= ~(1 << DDC3) +//#define configure_pin_locked() DDRC &= ~(1 << DDC5) +#define configure_pin_locked() do {} while (0) -#define get_pin_available() (PINC & (1 << PINC4)) -#define get_pin_locked() (PINC & (1 << PINC5)) +#define get_pin_available() (PINC & (1 << PINC3)) +//#define get_pin_locked() (PINC & (1 << PINC5)) +#define get_pin_locked() 0 #if SD_RAW_SDHC typedef uint64_t offset_t;