From 0ba3fd9a0f1bfc599afb209df383cc5c98175b98 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Thu, 20 May 2021 19:25:08 +0200 Subject: filesystem test app --- fw/fe310/test/fs.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++ fw/fe310/test/fs.h | 3 ++ 2 files changed, 107 insertions(+) create mode 100644 fw/fe310/test/fs.c create mode 100644 fw/fe310/test/fs.h diff --git a/fw/fe310/test/fs.c b/fw/fe310/test/fs.c new file mode 100644 index 0000000..e8b3587 --- /dev/null +++ b/fw/fe310/test/fs.c @@ -0,0 +1,104 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include + +#include "fs.h" + +FATFS fs; + +#define TEXT_SIZE 128 +#define TEXT_FN "test.txt" +#define KEY "passwordpassword" + +PARTITION VolToPart[FF_VOLUMES] = { + {0, 1} /* "0:" ==> 1st partition on the pd#0 */ +}; + +static EOSSDCCrypto sdcc; +static AESCtx ctx_crypt; +static AESCtx ctx_essiv; + +void app_fs(EVEWindow *window, EVEViewStack *stack) { + EVEWidgetSpec spec[] = { + { + .label.title = "Text", + .widget.type = EVE_WIDGET_TYPE_STR, + .widget.spec.str.str_size = TEXT_SIZE, + }, + }; + EVEForm *form = eve_form_create(window, stack, spec, 1, NULL, NULL, app_fs_close); + EVEStrWidget *text = (EVEStrWidget *)eve_page_widget(&form->p, 0); + FIL f; + FRESULT rv; + + eos_spi_select(EOS_SPI_DEV_SDC); + rv = f_open(&f, TEXT_FN, FA_READ); + printf("f_open:%d\n", rv); + if (!rv) { + UINT r; + + rv = f_read(&f, text->str, TEXT_SIZE-1, &r); + printf("f_read:%d\n", rv); + if (rv != FR_OK) r = 0; + text->str[r] = '\0'; + f_close(&f); + } + eos_spi_select(EOS_SPI_DEV_EVE); + eve_strw_update(text); +} + +void app_fs_close(EVEForm *form) { + EVEStrWidget *text = (EVEStrWidget *)eve_page_widget(&form->p, 0); + FIL f; + FRESULT rv; + + eos_spi_select(EOS_SPI_DEV_SDC); + rv = f_open(&f, TEXT_FN, FA_WRITE | FA_CREATE_ALWAYS); + printf("f_open:%d\n", rv); + if (!rv) { + UINT w; + + rv = f_write(&f, text->str, strlen(text->str), &w); + printf("f_write:%d\n", rv); + f_close(&f); + } + eos_spi_select(EOS_SPI_DEV_EVE); + eve_form_destroy(form); +} + +void app_fs_init(void) { + FRESULT rv; + + eos_sdcc_init(&sdcc, KEY, &ctx_crypt, (eve_sdcc_init_t)aes_init, (eve_sdcc_crypt_t)aes_cbc_encrypt, (eve_sdcc_crypt_t)aes_cbc_decrypt, &ctx_essiv, (eve_sdcc_init_t)aes_init, (eve_sdcc_essiv_t)aes_ecb_encrypt); + eos_spi_select(EOS_SPI_DEV_SDC); + rv = f_mount(&fs, "", 1); + printf("f_mount:%d\n", rv); + if (rv == FR_NO_FILESYSTEM) { + uint8_t w[FF_MAX_SS]; + LBA_t plist[] = {100, 0}; + + rv = f_fdisk(0, plist, w); + printf("f_fdisk:%d\n", rv); + rv = f_mkfs("0:", 0, w, sizeof(w)); + printf("f_mkfs:%d\n", rv); + rv = f_mount(&fs, "", 1); + printf("f_mount:%d\n", rv); + } + eos_spi_deselect(); +} \ No newline at end of file diff --git a/fw/fe310/test/fs.h b/fw/fe310/test/fs.h new file mode 100644 index 0000000..c525c5b --- /dev/null +++ b/fw/fe310/test/fs.h @@ -0,0 +1,3 @@ +void app_fs(EVEWindow *window, EVEViewStack *stack); +void app_fs_close(EVEForm *form); +void app_fs_init(void); -- cgit v1.2.3