From 8aed5965278fca951d7da1002ec6e6251e11850e Mon Sep 17 00:00:00 2001 From: jzlv Date: Tue, 27 Apr 2021 12:26:44 +0800 Subject: [PATCH] [feat] add shell filesystem --- bsp/bsp_common/fatfs/fatfs_spi_sd.c | 13 +++++++++++++ bsp/bsp_common/platform/bflb_platform.c | 19 ++++++++++++++++++- bsp/bsp_common/platform/bflb_platform.h | 3 +++ components/shell/drv_shell.c | 14 ++++++++++++-- components/shell/drv_shell.h | 1 + components/shell/shell_cfg.h | 8 +++++++- 6 files changed, 54 insertions(+), 4 deletions(-) diff --git a/bsp/bsp_common/fatfs/fatfs_spi_sd.c b/bsp/bsp_common/fatfs/fatfs_spi_sd.c index 24d20c0e..4237f463 100644 --- a/bsp/bsp_common/fatfs/fatfs_spi_sd.c +++ b/bsp/bsp_common/fatfs/fatfs_spi_sd.c @@ -23,6 +23,8 @@ #include "diskio.h" #include "bsp_spi_sd.h" +#include "string.h" + const char * FR_Table[]= { "FR_OK:成功", /* (0) Succeeded */ @@ -107,4 +109,15 @@ void fatfs_sd_driver_register(void) pNewDiskioDriver.MMC_disk_ioctl = sd_disk_ioctl; pNewDiskioDriver.Translate_Result_Code = Translate_Result_Code; disk_driver_callback_init(&pNewDiskioDriver); +} + +int shellGetcwd(char *path, unsigned int len) +{ + int err; + err = f_getcwd(path, len); + if(err) + { + strcpy(path, "unknow"); + } + return 0; } \ No newline at end of file diff --git a/bsp/bsp_common/platform/bflb_platform.c b/bsp/bsp_common/platform/bflb_platform.c index aaeec362..71cb0b71 100644 --- a/bsp/bsp_common/platform/bflb_platform.c +++ b/bsp/bsp_common/platform/bflb_platform.c @@ -52,13 +52,24 @@ void userShellWrite(char data) device_write(uart, 0, (uint8_t *)&data, 1); } +#if SHELL_FS == 1 +__WEAK__ int shellGetcwd(char *path, unsigned int len) +{ + return 0; +} +#endif + void shell_init(void) { - shell.write = userShellWrite; +#if SHELL_FS == 1 + shell.getcwd = shellGetcwd; +#endif shellInit(&shell, shellBuffer, 512); } + #else + void uart0_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state) { if (state == UART_EVENT_RX_FIFO) @@ -134,6 +145,12 @@ void bflb_platform_print_set(uint8_t disable) { uart_dbg_disable=disable; } + +void bflb_platform_deinit(void) +{ + +} + void bflb_platform_dump(uint8_t *data, uint32_t len) { uint32_t i = 0; diff --git a/bsp/bsp_common/platform/bflb_platform.h b/bsp/bsp_common/platform/bflb_platform.h index d908d464..6bc98e1c 100644 --- a/bsp/bsp_common/platform/bflb_platform.h +++ b/bsp/bsp_common/platform/bflb_platform.h @@ -25,8 +25,10 @@ #define _BFLB_PLATFORM_H #include "misc.h" +//#include "mcu_sdk_version.h" #define MSG(a,...) bflb_platform_printf(a,##__VA_ARGS__) +#define MSG_DBG(a,...) bflb_platform_printf(a,##__VA_ARGS__) #define MSG_ERR(a,...) bflb_platform_printf(a,##__VA_ARGS__) #define BL_CASE_FAIL {MSG(" Case Fail\r\n");while(1){bflb_platform_delay_ms(1);}} #define BL_CASE_SUCCESS {MSG(" Case Success\r\n");while(1){bflb_platform_delay_ms(1);}} @@ -78,6 +80,7 @@ void check_failed(uint8_t *file, uint32_t line); void bflb_platform_init(uint32_t baudrate); void bflb_platform_printf(char *fmt,...); void bflb_platform_dump(uint8_t *data, uint32_t len); +void bflb_platform_deinit(void); void bflb_platform_init_time(void); void bflb_platform_clear_time(void); diff --git a/components/shell/drv_shell.c b/components/shell/drv_shell.c index 7df72834..2fa64683 100644 --- a/components/shell/drv_shell.c +++ b/components/shell/drv_shell.c @@ -326,7 +326,15 @@ static void shellWriteCommandLine(Shell *shell) { shellWriteString(shell, "\r\n"); shellWriteString(shell, shell->info.user->data.user.name); - shellWriteString(shell, "/> "); + #if SHELL_FS == 1 + char path[SHELL_PRINT_BUFFER]; + shell->getcwd(path, SHELL_PRINT_BUFFER); + shellWriteString(shell, ":/"); + shellWriteString(shell, path); + shellWriteString(shell, "$ "); + #else + shellWriteString(shell, "/$ "); + #endif } else { @@ -1962,7 +1970,7 @@ static unsigned int shellExtParseNumber(char *string) if (type == NUM_TYPE_FLOAT && devide != 0) { valueFloat = (float)valueInt / devide * sign; - return (uint32_t)valueFloat; + return (unsigned int)valueFloat; } else { @@ -2083,3 +2091,5 @@ int shellExtRun(Shell *shell, ShellCommand *command, int argc, char *argv[]) } } + + diff --git a/components/shell/drv_shell.h b/components/shell/drv_shell.h index 4ed3fdfc..1e7341ce 100644 --- a/components/shell/drv_shell.h +++ b/components/shell/drv_shell.h @@ -316,6 +316,7 @@ typedef struct } status; signed char (*read)(char *); /**< shell读函数 */ void (*write)(const char); /**< shell写函数 */ + int (*getcwd)(char *path, unsigned int len); } Shell; diff --git a/components/shell/shell_cfg.h b/components/shell/shell_cfg.h index a411cfd5..498d2949 100644 --- a/components/shell/shell_cfg.h +++ b/components/shell/shell_cfg.h @@ -81,7 +81,7 @@ /** * @brief 历史命令记录数量 */ -#define SHELL_HISTORY_MAX_NUMBER 30 +#define SHELL_HISTORY_MAX_NUMBER 5 /** * @brief 双击间隔(ms) @@ -136,4 +136,10 @@ */ #define SHELL_LOCK_TIMEOUT 0 * 60 * 1000 + +/** + * @brief shell是否在命令提示符输出路径,需要引用文件系统 + */ +#define SHELL_FS 1 + #endif