From 953c42c0ea7e1c27793ba465db862e2fbc7ffdf9 Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Fri, 25 Mar 2011 16:04:35 -0400 Subject: [PATCH] Speedup write to SD card with various tricks --- rmslog/cfg/cfg_ser.h | 87 ++------------------------------------------ rmslog/main.c | 49 +++++++++++++------------ 2 files changed, 29 insertions(+), 107 deletions(-) diff --git a/rmslog/cfg/cfg_ser.h b/rmslog/cfg/cfg_ser.h index b5ce58a..b2524cc 100644 --- a/rmslog/cfg/cfg_ser.h +++ b/rmslog/cfg/cfg_ser.h @@ -49,7 +49,7 @@ * $WIZ$ type = "int" * $WIZ$ min = 2 */ -#define CONFIG_UART0_TXBUFSIZE 32 +#define CONFIG_UART0_TXBUFSIZE 16 /** * Size of the inbound FIFO buffer for port 0 [bytes]. @@ -58,62 +58,13 @@ */ #define CONFIG_UART0_RXBUFSIZE 512 -/** - * Size of the outbound FIFO buffer for port 1 [bytes]. - * $WIZ$ type = "int" - * $WIZ$ min = 2 - * $WIZ$ supports = "lm3s or lpc2 or (at91 and not atmega8 and not atmega168 and not atmega32)" - */ -#define CONFIG_UART1_TXBUFSIZE 32 - -/** - * Size of the inbound FIFO buffer for port 1 [bytes]. - * $WIZ$ type = "int" - * $WIZ$ min = 2 - * $WIZ$ supports = "lm3s or lpc2 or (at91 and not atmega8 and not atmega168 and not atmega32)" - */ -#define CONFIG_UART1_RXBUFSIZE 32 - -/** - * Size of the outbound FIFO buffer for port 2 [bytes]. - * $WIZ$ type = "int" - * $WIZ$ min = 2 - * $WIZ$ supports = "lm3s or lpc2" - */ -#define CONFIG_UART2_TXBUFSIZE 32 - -/** - * Size of the inbound FIFO buffer for port 2 [bytes]. - * $WIZ$ type = "int" - * $WIZ$ min = 2 - * $WIZ$ supports = "lm3s or lpc2" - */ -#define CONFIG_UART2_RXBUFSIZE 32 - -/** - * Size of the outbound FIFO buffer for port 3 [bytes]. - * $WIZ$ type = "int" - * $WIZ$ min = 2 - * $WIZ$ supports = "lpc2" - */ -#define CONFIG_UART3_TXBUFSIZE 32 - -/** - * Size of the inbound FIFO buffer for port 3 [bytes]. - * $WIZ$ type = "int" - * $WIZ$ min = 2 - * $WIZ$ supports = "lpc2" - */ -#define CONFIG_UART3_RXBUFSIZE 32 - - /** * Size of the outbound FIFO buffer for SPI port [bytes]. * $WIZ$ type = "int" * $WIZ$ min = 2 * $WIZ$ supports = "avr" */ -#define CONFIG_SPI_TXBUFSIZE 32 +#define CONFIG_SPI_TXBUFSIZE 0 /** * Size of the inbound FIFO buffer for SPI port [bytes]. @@ -121,39 +72,7 @@ * $WIZ$ min = 2 * $WIZ$ supports = "avr" */ -#define CONFIG_SPI_RXBUFSIZE 32 - -/** - * Size of the outbound FIFO buffer for SPI port 0 [bytes]. - * $WIZ$ type = "int" - * $WIZ$ min = 2 - * $WIZ$ supports = "at91" - */ -#define CONFIG_SPI0_TXBUFSIZE 32 - -/** - * Size of the inbound FIFO buffer for SPI port 0 [bytes]. - * $WIZ$ type = "int" - * $WIZ$ min = 2 - * $WIZ$ supports = "at91" - */ -#define CONFIG_SPI0_RXBUFSIZE 32 - -/** - * Size of the outbound FIFO buffer for SPI port 1 [bytes]. - * $WIZ$ type = "int" - * $WIZ$ min = 2 - * $WIZ$ supports = "at91" - */ -#define CONFIG_SPI1_TXBUFSIZE 32 - -/** - * Size of the inbound FIFO buffer for SPI port 1 [bytes]. - * $WIZ$ type = "int" - * $WIZ$ min = 2 - * $WIZ$ supports = "at91" - */ -#define CONFIG_SPI1_RXBUFSIZE 32 +#define CONFIG_SPI_RXBUFSIZE 0 /** * SPI data order. diff --git a/rmslog/main.c b/rmslog/main.c index 9f52d5f..d4bb6a0 100644 --- a/rmslog/main.c +++ b/rmslog/main.c @@ -10,6 +10,11 @@ * console messages. */ +#define FILE_NAME "log.txt" +#define FILE_OVERWRITE 1 +#define FILE_PREALLOC_SIZE 102400 + + #include "hw/hw_led.h" #define LOG_LEVEL 3 @@ -150,9 +155,6 @@ static void init(void) timer_delay(1000); kfile_printf(&ser.fd, "Hello, world!\r\n"); -#ifdef BERTOS_FAT - ser_init(&spi, SER_SPI); -#else DDRB |= BV(PORTB0) | BV(PORTB2) | BV(PORTB3) | BV(PORTB5); if (!sd_raw_init()) { @@ -168,35 +170,36 @@ int main(void) { init(); -#ifdef BERTOS_FAT + size_t size; + char buf[256]; + bool sync_pending = false; - FRESULT fat_err; - if ((fat_err = f_mount(0, &fs)) != FR_OK) + /* create file */ + if(!fat_create_file(dd, FILE_NAME, &dir_entry)) { - LOG_ERR("Error mounting FAT volume: %d\n", fat_err); + #if FILE_OVERWRITE + fat_delete_file(fs, &dir_entry); + fat_create_file(dd, FILE_NAME, &dir_entry); + #endif } - fat_err = fatfile_open(&file, "foo.txt", FA_WRITE | FA_CREATE_ALWAYS); - ASSERT(fat_err == FR_OK); - - size_t count = kfile_write(&file.fd, "Hello, world!", strlen("Hello, world!")); - ASSERT(count == strlen("Hello, world!")); + fd = open_file_in_dir(fs, dd, FILE_NAME); -#else - - fat_create_file(dd, "log.txt", &dir_entry); - fd = open_file_in_dir(fs, dd, "log.txt"); - int32_t offset = 0; - fat_seek_file(fd, &offset, FAT_SEEK_END); + /* preallocate file */ + #if FILE_PREALLOC_SIZE + { + LED_ON(); + for (int i = 0; i < (int)(FILE_PREALLOC_SIZE / sizeof(buf)); ++i) + fat_write_file(fd, (void *)buf, sizeof(buf)); -#endif + int32_t offset = 0; + fat_seek_file(fd, &offset, FAT_SEEK_SET); + LED_OFF(); + } + #endif while (1) { - size_t size; - char buf[128]; - bool sync_pending = false; - if ((size = ser_read(&ser, buf, sizeof(buf))) != 0) { LED_ON(); -- 2.25.1