From ed57ebb438cc2e4e7938b7b8b43b8759ccb6fb7f Mon Sep 17 00:00:00 2001 From: Bert Vermeulen Date: Sat, 11 Oct 2014 11:52:28 +0200 Subject: [PATCH 1/3] Document 'hd' option. --- hydrabus/hydrabus_microrl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hydrabus/hydrabus_microrl.c b/hydrabus/hydrabus_microrl.c index b4e432bd..90c2886d 100644 --- a/hydrabus/hydrabus_microrl.c +++ b/hydrabus/hydrabus_microrl.c @@ -84,6 +84,7 @@ void hydrabus_print_help(BaseSequentialStream *chp, int argc, const char* const* print(chp,"umount - unmount sd\n\r"); print(chp,"ls [opt dir] - list files in sd\n\r"); print(chp,"cat - display sd file (ASCII)\n\r"); + print(chp,"hd - hexdump sd file\n\r"); print(chp,"erase - erase sd\n\r"); } From b566baf2fa59436e43ccd454c19b1199226520cd Mon Sep 17 00:00:00 2001 From: Bert Vermeulen Date: Sun, 12 Oct 2014 14:03:48 +0200 Subject: [PATCH 2/3] Revamp console system. Each console now has its own struct to store data, and its thread is allocated dynamically. The 'struct hydra_console' is defined in common.h, and can be extended with console-specific fields. Every function callback gets this console's struct as a parameter, instead of ChibiOS's BaseStreamSequence output handle. This handle is included in the struct. These changes reduce overall code size. --- common/common.c | 94 ++++----- common/common.h | 29 ++- common/microrl_callback.h | 10 +- common/microrl_common.c | 84 ++++---- common/microrl_common.h | 4 +- common/microrl_config.h | 2 +- common/microsd.c | 376 +++++++++++++++++----------------- common/microsd.h | 18 +- hydrabus/hydrabus_microrl.c | 49 ++--- hydrabus/hydrabus_microrl.h | 6 +- hydranfc/hydranfc.c | 150 +++++++------- hydranfc/hydranfc.h | 12 +- hydranfc/hydranfc_cmd_sniff.c | 4 +- hydranfc/hydranfc_microrl.c | 53 +++-- hydranfc/hydranfc_microrl.h | 6 +- main.c | 316 +++++++++++----------------- 16 files changed, 575 insertions(+), 638 deletions(-) diff --git a/common/common.c b/common/common.c index ed3e48ca..17bbfb5a 100644 --- a/common/common.c +++ b/common/common.c @@ -71,7 +71,7 @@ void DelayUs(uint32_t delay_us) osalSysPolledDelayX(US2RTC(STM32_HCLK, delay_us)); } -void cmd_mem(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_mem(struct hydra_console *con, int argc, const char* const* argv) { size_t n, size; @@ -79,12 +79,12 @@ void cmd_mem(BaseSequentialStream *chp, int argc, const char* const* argv) (void)argv; n = chHeapStatus(NULL, &size); - chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus()); - chprintf(chp, "heap fragments : %u\r\n", n); - chprintf(chp, "heap free total : %u bytes\r\n", size); + chprintf(con->bss, "core free memory : %u bytes\r\n", chCoreStatus()); + chprintf(con->bss, "heap fragments : %u\r\n", n); + chprintf(con->bss, "heap free total : %u bytes\r\n", size); } -void cmd_threads(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_threads(struct hydra_console *con, int argc, const char* const* argv) { static const char *states[] = {CH_STATE_NAMES}; thread_t *tp; @@ -92,10 +92,10 @@ void cmd_threads(BaseSequentialStream *chp, int argc, const char* const* argv) (void)argc; (void)argv; - chprintf(chp, " addr stack prio refs state name\r\n"); + chprintf(con->bss, " addr stack prio refs state name\r\n"); tp = chRegFirstThread(); do { - chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %s\r\n", + chprintf(con->bss, "%.8lx %.8lx %4lu %4lu %9s %s\r\n", (uint32_t)tp, (uint32_t)tp->p_ctx.r13, (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1), states[tp->p_state], tp->p_name); @@ -104,7 +104,7 @@ void cmd_threads(BaseSequentialStream *chp, int argc, const char* const* argv) } -void cmd_test(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_test(struct hydra_console *con, int argc, const char* const* argv) { thread_t *tp; @@ -112,20 +112,20 @@ void cmd_test(BaseSequentialStream *chp, int argc, const char* const* argv) (void)argv; tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(), - TestThread, chp); + TestThread, con->sdu); if (tp == NULL) { - chprintf(chp, "out of memory\r\n"); + chprintf(con->bss, "out of memory\r\n"); return; } chThdWait(tp); } -void cmd_info(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_info(struct hydra_console *con, int argc, const char* const* argv) { - cmd_init(chp, argc, argv); + cmd_init(con, argc, argv); } -void cmd_init(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_init(struct hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; @@ -135,79 +135,79 @@ void cmd_init(BaseSequentialStream *chp, int argc, const char* const* argv) unsigned int cycles_stop; unsigned int cycles_delta; - chprintf(chp, "argc=%d\r\n",argc); + chprintf(con->bss, "argc=%d\r\n",argc); for(i=0; ibss, "argv[%d]=%s\r\n", i, argv[i]); } - chprintf(chp, "%s\r\n", HYDRAFW_VERSION); + chprintf(con->bss, "%s\r\n", HYDRAFW_VERSION); cycles_start = get_cyclecounter(); DelayUs(10000); cycles_stop = get_cyclecounter(); cycles_delta = cycles_stop-cycles_start; - chprintf(chp, "Test DelayUs(10000) start=%d end=%d delta=%d\r\nTime=%dus (@168MHz)\r\n", cycles_start, cycles_stop, cycles_delta, (cycles_delta/168)); - chprintf(chp, "\r\n"); + chprintf(con->bss, "Test DelayUs(10000) start=%d end=%d delta=%d\r\nTime=%dus (@168MHz)\r\n", cycles_start, cycles_stop, cycles_delta, (cycles_delta/168)); + chprintf(con->bss, "\r\n"); - chprintf(chp, "MCU Info\r\n"); - chprintf(chp, "%d: DBGMCU_IDCODE:0x%X\r\n", get_cyclecounter(), *((uint32_t*)0xE0042000)); - chprintf(chp, "%d: MCU CPUID: 0x%X\r\n", get_cyclecounter(), *((uint32_t*)0xE000ED00)); - chprintf(chp, "%d: MCU FlashUID: 0x%X 0x%X 0x%X\r\n", get_cyclecounter(), *((uint32_t*)0x1FFF7A10), *((uint32_t*)0x1FFF7A14), *((uint32_t*)0x1FFF7A18)); - chprintf(chp, "%d: MCU FlashSize:%dKB\r\n", get_cyclecounter(), *((uint16_t*)0x1FFF7A22)); - chprintf(chp, "\r\n"); + chprintf(con->bss, "MCU Info\r\n"); + chprintf(con->bss, "%d: DBGMCU_IDCODE:0x%X\r\n", get_cyclecounter(), *((uint32_t*)0xE0042000)); + chprintf(con->bss, "%d: MCU CPUID: 0x%X\r\n", get_cyclecounter(), *((uint32_t*)0xE000ED00)); + chprintf(con->bss, "%d: MCU FlashUID: 0x%X 0x%X 0x%X\r\n", get_cyclecounter(), *((uint32_t*)0x1FFF7A10), *((uint32_t*)0x1FFF7A14), *((uint32_t*)0x1FFF7A18)); + chprintf(con->bss, "%d: MCU FlashSize:%dKB\r\n", get_cyclecounter(), *((uint16_t*)0x1FFF7A22)); + chprintf(con->bss, "\r\n"); - chprintf(chp, "Kernel: %s\r\n", CH_KERNEL_VERSION); + chprintf(con->bss, "Kernel: %s\r\n", CH_KERNEL_VERSION); #ifdef PORT_COMPILER_NAME - chprintf(chp, "Compiler: %s\r\n", PORT_COMPILER_NAME); + chprintf(con->bss, "Compiler: %s\r\n", PORT_COMPILER_NAME); #endif - chprintf(chp, "Architecture: %s\r\n", PORT_ARCHITECTURE_NAME); + chprintf(con->bss, "Architecture: %s\r\n", PORT_ARCHITECTURE_NAME); #ifdef PORT_CORE_VARIANT_NAME - chprintf(chp, "Core Variant: %s\r\n", PORT_CORE_VARIANT_NAME); + chprintf(con->bss, "Core Variant: %s\r\n", PORT_CORE_VARIANT_NAME); #endif #ifdef PORT_INFO - chprintf(chp, "Port Info: %s\r\n", PORT_INFO); + chprintf(con->bss, "Port Info: %s\r\n", PORT_INFO); #endif #ifdef PLATFORM_NAME - chprintf(chp, "Platform: %s\r\n", PLATFORM_NAME); + chprintf(con->bss, "Platform: %s\r\n", PLATFORM_NAME); #endif #ifdef BOARD_NAME - chprintf(chp, "Board: %s\r\n", BOARD_NAME); + chprintf(con->bss, "Board: %s\r\n", BOARD_NAME); #endif #ifdef __DATE__ #ifdef __TIME__ - chprintf(chp, "Build time: %s%s%s\r\n", __DATE__, " - ", __TIME__); + chprintf(con->bss, "Build time: %s%s%s\r\n", __DATE__, " - ", __TIME__); #endif #endif /* - chprintf(chp, "Start Init HydraBus\r\n"); + chprintf(con->bss, "Start Init HydraBus\r\n"); hydrabus_init(); - chprintf(chp, "End Init HydraBus\r\n"); + chprintf(con->bss, "End Init HydraBus\r\n"); - chprintf(chp, "Start Init HydraNFC\r\n"); + chprintf(con->bss, "Start Init HydraNFC\r\n"); hydranfc_detected = hydranfc_init(); if(hydranfc_detected == FALSE) { - chprintf(chp, "HydraNFC Shield not present/not detected\r\n"); + chprintf(con->bss, "HydraNFC Shield not present/not detected\r\n"); }else { - chprintf(chp, "HydraNFC Shield detected\r\n"); + chprintf(con->bss, "HydraNFC Shield detected\r\n"); } - chprintf(chp, "End Init HydraNFC\r\n"); + chprintf(con->bss, "End Init HydraNFC\r\n"); */ if(hydranfc_is_detected() == FALSE) { - chprintf(chp, "HydraNFC Shield not present/not detected\r\n"); + chprintf(con->bss, "HydraNFC Shield not present/not detected\r\n"); }else { - chprintf(chp, "HydraNFC Shield detected\r\n"); + chprintf(con->bss, "HydraNFC Shield detected\r\n"); } } #define waitcycles(n) ( wait_nbcycles(n) ) /* Just debug to check Timing and accuracy with output pin */ -void cmd_dbg(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_dbg(struct hydra_console *con, int argc, const char* const* argv) { (void)argv; uint8_t i; @@ -226,17 +226,17 @@ void cmd_dbg(BaseSequentialStream *chp, int argc, const char* const* argv) volatile systime_t tick, ticks10MHz, ticks3_39MHz, tick1MHz; if (argc > 0) { - chprintf(chp, "Usage: dbg\r\n"); + chprintf(con->bss, "Usage: dbg\r\n"); return; } ticks10MHz = NS2RTT(50); ticks3_39MHz = NS2RTT(148); tick1MHz = NS2RTT(500); - chprintf(chp, "50ns=%.2ld ticks\r\n", (uint32_t)ticks10MHz); - chprintf(chp, "148ns=%.2ld ticks\r\n", (uint32_t)ticks3_39MHz); - chprintf(chp, "500ns=%.2ld ticks\r\n", (uint32_t)tick1MHz); - chprintf(chp, "Test dbg Out Freq Max 84Mhz(11.9ns),10MHz(100ns/2),3.39MHz(295ns/2),1MHz(1us/2)\r\nPress User Button to exit\r\n"); + chprintf(con->bss, "50ns=%.2ld ticks\r\n", (uint32_t)ticks10MHz); + chprintf(con->bss, "148ns=%.2ld ticks\r\n", (uint32_t)ticks3_39MHz); + chprintf(con->bss, "500ns=%.2ld ticks\r\n", (uint32_t)tick1MHz); + chprintf(con->bss, "Test dbg Out Freq Max 84Mhz(11.9ns),10MHz(100ns/2),3.39MHz(295ns/2),1MHz(1us/2)\r\nPress User Button to exit\r\n"); chThdSleepMilliseconds(5); while(1) @@ -351,5 +351,5 @@ void cmd_dbg(BaseSequentialStream *chp, int argc, const char* const* argv) } } - chprintf(chp, "Test dbg Out Freq end\r\n"); + chprintf(con->bss, "Test dbg Out Freq end\r\n"); } diff --git a/common/common.h b/common/common.h index fc95bfb4..af86a53d 100644 --- a/common/common.h +++ b/common/common.h @@ -17,17 +17,10 @@ #ifndef _COMMON_H_ #define _COMMON_H_ +#include "microrl.h" #include "ch.h" #include "hal.h" -void cmd_info(BaseSequentialStream *chp, int argc, const char* const* argv); -void cmd_init(BaseSequentialStream *chp, int argc, const char* const* argv); - -void cmd_mem(BaseSequentialStream *chp, int argc, const char* const* argv); -void cmd_threads(BaseSequentialStream *chp, int argc, const char* const* argv); -void cmd_test(BaseSequentialStream *chp, int argc, const char* const* argv); -void cmd_dbg(BaseSequentialStream *chp, int argc, const char* const* argv); - void scs_dwt_cycle_counter_enabled(void); #define clear_cyclecounter() ( DWTBase->CYCCNT = 0 ) #define get_cyclecounter() ( DWTBase->CYCCNT ) @@ -74,4 +67,24 @@ typedef struct #define MIN(a, b) (a < b ? a : b) #endif +/* How much thread working area to allocate per console. */ +#define CONSOLE_WA_SIZE 2048 + +struct hydra_console { + char *thread_name; + thread_t *thread; + union { + SerialUSBDriver *sdu; + BaseSequentialStream *bss; + }; + microrl_t *mrl; +}; + +void cmd_info(struct hydra_console *con, int argc, const char* const* argv); +void cmd_init(struct hydra_console *con, int argc, const char* const* argv); +void cmd_mem(struct hydra_console *con, int argc, const char* const* argv); +void cmd_threads(struct hydra_console *con, int argc, const char* const* argv); +void cmd_test(struct hydra_console *con, int argc, const char* const* argv); +void cmd_dbg(struct hydra_console *con, int argc, const char* const* argv); + #endif /* _COMMON_H_ */ diff --git a/common/microrl_callback.h b/common/microrl_callback.h index 7850d124..87844487 100644 --- a/common/microrl_callback.h +++ b/common/microrl_callback.h @@ -19,7 +19,7 @@ #include "ch.h" -typedef void (*ptFunc)(BaseSequentialStream *chp, int argc, const char* const* argv); +typedef void (*ptFunc)(struct hydra_console *con, int argc, const char* const* argv); typedef struct { @@ -28,18 +28,18 @@ typedef struct } microrl_exec_t; // print to stream callback -void print(void* user_handle, const char * str); +void print(void *user_handle, const char *str); // get_char from stream -char get_char(void* user_handle); +char get_char(struct hydra_console *con); // execute callback -unsigned int execute(void* user_handle, int argc, const char* const* argv); +unsigned int execute(void *user_handle, int argc, const char* const* argv); // completion callback char ** complet(void* user_handle, int argc, const char* const* argv); // ctrl+c callback -void sigint(void* user_handle); +void sigint(void *user_handle); #endif /* _MICRORL_CALLBACK_H_ */ diff --git a/common/microrl_common.c b/common/microrl_common.c index 3e3fb2b9..2097e643 100644 --- a/common/microrl_common.c +++ b/common/microrl_common.c @@ -33,43 +33,40 @@ char** compl_world; microrl_exec_t* keyworld; -void print_clear(BaseSequentialStream *chp, int argc, const char* const* argv) +void print_clear(struct hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; - print(chp,"\033[2J"); // ESC seq to clear entire screen - print(chp,"\033[H"); // ESC seq to move cursor at left-top corner + + print(con,"\033[2J"); // ESC seq to clear entire screen + print(con,"\033[H"); // ESC seq to move cursor at left-top corner } //***************************************************************************** -void print(void* user_handle, const char * str) +void print(void *user_handle, const char *str) { - int len; - if(str != NULL) - { - len = strlen(str); - if((len > 0) &&(len < 1024) ) - { - chSequentialStreamWrite( (BaseSequentialStream *)user_handle, (uint8_t *)str, len); - }else - { - /* Do nothing */ - } - }else - { - /* Do nothing */ - } + struct hydra_console *con; + int len; + + if(!str) + return; + + con = user_handle; + len = strlen(str); + if(len > 0 && len < 1024) + chSequentialStreamWrite((BaseSequentialStream *)con->sdu, + (uint8_t *)str, len); } //***************************************************************************** -char get_char(void* user_handle) +char get_char(struct hydra_console *con) { - uint8_t car; - if(chSequentialStreamRead( (BaseSequentialStream *)user_handle,(uint8_t *)&car, 1) == 0) - { - car = 0; - } - return car; + uint8_t car; + + if(chSequentialStreamRead(con->sdu,(uint8_t *)&car, 1) == 0) + car = 0; + + return car; } #ifdef _USE_COMPLETE @@ -131,30 +128,27 @@ char** complet(void* user_handle, int argc, const char * const * argv) //***************************************************************************** // execute callback for microrl library // do what you want here, but don't write to argv!!! read only!! -unsigned int execute(void* user_handle, int argc, const char* const* argv) +unsigned int execute(void *user_handle, int argc, const char* const* argv) { - /* HydraNFC Shield detected*/ - if(hydranfc_is_detected() == TRUE) - { - return hydranfc_execute(user_handle, argc, argv); - }else - { - return hydrabus_execute(user_handle, argc, argv); - } + struct hydra_console *con; + + con = user_handle; + if(hydranfc_is_detected()) + return hydranfc_execute(con, argc, argv); + else + return hydrabus_execute(con, argc, argv); } //***************************************************************************** -void sigint(void* user_handle) +void sigint(void *user_handle) { - /* HydraNFC Shield detected*/ - if(hydranfc_is_detected() == TRUE) - { - hydranfc_sigint(user_handle, 0, NULL); - }else - { - /* HydraBus */ - hydrabus_sigint(user_handle, 0, NULL); - } + struct hydra_console *con; + + con = user_handle; + if(hydranfc_is_detected()) + hydranfc_sigint(con); + else + hydrabus_sigint(con); } diff --git a/common/microrl_common.h b/common/microrl_common.h index fe01f6db..a22c8625 100644 --- a/common/microrl_common.h +++ b/common/microrl_common.h @@ -17,6 +17,6 @@ #ifndef _MICRORL_COMMON_H_ #define _MICRORL_COMMON_H_ -void print_clear(BaseSequentialStream *chp, int argc, const char* const* argv); +void print_clear(struct hydra_console *con, int argc, const char* const* argv); -#endif /* _MICRORL_COMMON_H_ */ \ No newline at end of file +#endif /* _MICRORL_COMMON_H_ */ diff --git a/common/microrl_config.h b/common/microrl_config.h index e4e20fb1..2f4d1359 100644 --- a/common/microrl_config.h +++ b/common/microrl_config.h @@ -25,7 +25,7 @@ Token is word separate by white space, for example 3 token line: */ #define _COMMAND_TOKEN_NMB 50 -#define _PROMPT_TXT ">" +#define _PROMPT_TXT "> " // Prompt START & END for green color (included automatically) #define _PROMPT_START "\033[32m" diff --git a/common/microsd.c b/common/microsd.c index 28027ea9..2397337a 100644 --- a/common/microsd.c +++ b/common/microsd.c @@ -22,6 +22,7 @@ #include "shell.h" #include "chprintf.h" +#include "common.h" #include "ff.h" #include "usb1cfg.h" @@ -29,7 +30,6 @@ #include "mcu.h" #include "microsd.h" -#include "common.h" #define SDC_BURST_SIZE 8 /* how many sectors reads at once */ #define IN_OUT_BUF_SIZE (MMCSD_BLOCK_SIZE * SDC_BURST_SIZE + 8) @@ -135,64 +135,64 @@ void fillbuffers(uint8_t pattern) /** * SDIO Test Non Destructive */ -void cmd_sdiotest(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_sdiotest(struct hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; uint32_t i = 0; - chprintf(chp, "Trying to connect SDIO... "); + chprintf(con->bss, "Trying to connect SDIO... "); chThdSleepMilliseconds(100); if(!sdcConnect(&SDCD1)) { - chprintf(chp, "OK\r\n"); - chprintf(chp, "*** Card CSD content is: "); - chprintf(chp, "%X %X %X %X \r\n", (&SDCD1)->csd[3], (&SDCD1)->csd[2], + chprintf(con->bss, "OK\r\n"); + chprintf(con->bss, "*** Card CSD content is: "); + chprintf(con->bss, "%X %X %X %X \r\n", (&SDCD1)->csd[3], (&SDCD1)->csd[2], (&SDCD1)->csd[1], (&SDCD1)->csd[0]); - chprintf(chp, "Single aligned read..."); + chprintf(con->bss, "Single aligned read..."); chThdSleepMilliseconds(100); if (sdcRead(&SDCD1, 0, inbuf, 1)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } - chprintf(chp, " OK\r\n"); + chprintf(con->bss, " OK\r\n"); chThdSleepMilliseconds(100); - chprintf(chp, "Single unaligned read..."); + chprintf(con->bss, "Single unaligned read..."); chThdSleepMilliseconds(100); if (sdcRead(&SDCD1, 0, inbuf + 1, 1)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } if (sdcRead(&SDCD1, 0, inbuf + 2, 1)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } if (sdcRead(&SDCD1, 0, inbuf + 3, 1)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } - chprintf(chp, " OK\r\n"); + chprintf(con->bss, " OK\r\n"); chThdSleepMilliseconds(10); - chprintf(chp, "Multiple aligned reads..."); + chprintf(con->bss, "Multiple aligned reads..."); chThdSleepMilliseconds(10); fillbuffers(0x55); /* fill reference buffer from SD card */ if (sdcRead(&SDCD1, 0, inbuf, SDC_BURST_SIZE)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } @@ -201,27 +201,27 @@ void cmd_sdiotest(BaseSequentialStream *chp, int argc, const char* const* argv) { if (sdcRead(&SDCD1, 0, outbuf, SDC_BURST_SIZE)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } if (memcmp(inbuf, outbuf, SDC_BURST_SIZE * MMCSD_BLOCK_SIZE) != 0) { - chprintf(chp, "memcmp KO\r\n"); + chprintf(con->bss, "memcmp KO\r\n"); umount(); return; } } - chprintf(chp, " OK\r\n"); + chprintf(con->bss, " OK\r\n"); chThdSleepMilliseconds(10); - chprintf(chp, "Multiple unaligned reads..."); + chprintf(con->bss, "Multiple unaligned reads..."); chThdSleepMilliseconds(10); fillbuffers(0x55); /* fill reference buffer from SD card */ if(sdcRead(&SDCD1, 0, inbuf + 1, SDC_BURST_SIZE)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } @@ -229,18 +229,18 @@ void cmd_sdiotest(BaseSequentialStream *chp, int argc, const char* const* argv) { if(sdcRead(&SDCD1, 0, outbuf + 1, SDC_BURST_SIZE)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } if(memcmp(inbuf, outbuf, SDC_BURST_SIZE * MMCSD_BLOCK_SIZE) != 0) { - chprintf(chp, "memcmp KO\r\n"); + chprintf(con->bss, "memcmp KO\r\n"); umount(); return; } } - chprintf(chp, " OK\r\n"); + chprintf(con->bss, " OK\r\n"); chThdSleepMilliseconds(10); /** @@ -256,96 +256,96 @@ void cmd_sdiotest(BaseSequentialStream *chp, int argc, const char* const* argv) FILINFO filinfo; uint8_t teststring[] = {"This is test file\r\n"}; - chprintf(chp, "Register working area for filesystem... "); + chprintf(con->bss, "Register working area for filesystem... "); chThdSleepMilliseconds(10); err = f_mount(&SDC_FS, "", 0); if (err != FR_OK) { - chprintf(chp, "f_mount KO err:%d\r\n", err); + chprintf(con->bss, "f_mount KO err:%d\r\n", err); umount(); return; } else { fs_ready = TRUE; - chprintf(chp, "OK\r\n"); + chprintf(con->bss, "OK\r\n"); } - chprintf(chp, "Mount filesystem... "); + chprintf(con->bss, "Mount filesystem... "); chThdSleepMilliseconds(10); err = f_getfree("/", &clusters, &fsp); if (err != FR_OK) { - chprintf(chp, "f_getfree KO err:%d\r\n", err); + chprintf(con->bss, "f_getfree KO err:%d\r\n", err); umount(); return; } - chprintf(chp, "OK\r\n"); - chprintf(chp, + chprintf(con->bss, "OK\r\n"); + chprintf(con->bss, "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n", clusters, (uint32_t)SDC_FS.csize, clusters * (uint32_t)SDC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE); - chprintf(chp, "Create file \"chtest.txt\"... "); + chprintf(con->bss, "Create file \"chtest.txt\"... "); chThdSleepMilliseconds(10); err = f_open(&FileObject, "0:chtest.txt", FA_WRITE | FA_OPEN_ALWAYS); if (err != FR_OK) { - chprintf(chp, "f_open KO err:%d\r\n", err); + chprintf(con->bss, "f_open KO err:%d\r\n", err); umount(); return; } - chprintf(chp, "OK\r\n"); - chprintf(chp, "Write some data in it... "); + chprintf(con->bss, "OK\r\n"); + chprintf(con->bss, "Write some data in it... "); chThdSleepMilliseconds(10); err = f_write(&FileObject, teststring, sizeof(teststring), (void *)&bytes_written); if (err != FR_OK) { - chprintf(chp, "f_write KO err:%d\r\n", err); + chprintf(con->bss, "f_write KO err:%d\r\n", err); umount(); return; } else - chprintf(chp, "OK\r\n"); + chprintf(con->bss, "OK\r\n"); - chprintf(chp, "Close file \"chtest.txt\"... "); + chprintf(con->bss, "Close file \"chtest.txt\"... "); err = f_close(&FileObject); if (err != FR_OK) { - chprintf(chp, "f_close KO err:%d\r\n", err); + chprintf(con->bss, "f_close KO err:%d\r\n", err); umount(); return; } else - chprintf(chp, "OK\r\n"); + chprintf(con->bss, "OK\r\n"); - chprintf(chp, "Check file size \"chtest.txt\"... "); + chprintf(con->bss, "Check file size \"chtest.txt\"... "); err = f_stat("0:chtest.txt", &filinfo); if (err != FR_OK) { - chprintf(chp, "f_stat KO err:%d\r\n", err); + chprintf(con->bss, "f_stat KO err:%d\r\n", err); umount(); return; }else { if (filinfo.fsize == sizeof(teststring)) { - chprintf(chp, "OK\r\n"); + chprintf(con->bss, "OK\r\n"); }else { - chprintf(chp, "filinfo.fsize KO obtained=%d expected=%d\r\n", + chprintf(con->bss, "filinfo.fsize KO obtained=%d expected=%d\r\n", filinfo.fsize,sizeof(teststring)); umount(); return; } } - chprintf(chp, "Check file content \"chtest.txt\"... "); + chprintf(con->bss, "Check file content \"chtest.txt\"... "); err = f_open(&FileObject, "0:chtest.txt", FA_READ | FA_OPEN_EXISTING); if (err != FR_OK) { - chprintf(chp, "f_open KO err:%d\r\n", err); + chprintf(con->bss, "f_open KO err:%d\r\n", err); umount(); return; } @@ -353,74 +353,74 @@ void cmd_sdiotest(BaseSequentialStream *chp, int argc, const char* const* argv) err = f_read(&FileObject, buf, sizeof(teststring), (void *)&bytes_read); if (err != FR_OK) { - chprintf(chp, "f_read KO err:%d\r\n", err); + chprintf(con->bss, "f_read KO err:%d\r\n", err); umount(); return; }else { if (memcmp(teststring, buf, sizeof(teststring)) != 0) { - chprintf(chp, "memcmp KO err:%d\r\n", err); + chprintf(con->bss, "memcmp KO err:%d\r\n", err); umount(); return; }else { - chprintf(chp, "OK\r\n"); + chprintf(con->bss, "OK\r\n"); } } - chprintf(chp, "Umount filesystem... "); + chprintf(con->bss, "Umount filesystem... "); f_mount(NULL, "", 0); - chprintf(chp, "OK\r\n"); + chprintf(con->bss, "OK\r\n"); - chprintf(chp, "Disconnecting from SDIO..."); + chprintf(con->bss, "Disconnecting from SDIO..."); chThdSleepMilliseconds(10); if (sdcDisconnect(&SDCD1)) { - chprintf(chp, "sdcDisconnect(&SDCD1) error\r\n"); + chprintf(con->bss, "sdcDisconnect(&SDCD1) error\r\n"); return; } - chprintf(chp, " OK\r\n"); - chprintf(chp, "------------------------------------------------------\r\n"); - chprintf(chp, "All tests passed successfully.\r\n"); + chprintf(con->bss, " OK\r\n"); + chprintf(con->bss, "------------------------------------------------------\r\n"); + chprintf(con->bss, "All tests passed successfully.\r\n"); chThdSleepMilliseconds(10); } else { - chprintf(chp, "sdcConnect(&SDCD1) error\r\n"); + chprintf(con->bss, "sdcConnect(&SDCD1) error\r\n"); } } -void cmd_sdc(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_sdc(struct hydra_console *con, int argc, const char* const* argv) { static const char *mode[] = {"SDV11", "SDV20", "MMC", NULL}; systime_t start, end; uint32_t n, startblk; if (argc != 1) { - chprintf(chp, "Usage: sdiotest read|write|all\r\n"); + chprintf(con->bss, "Usage: sdiotest read|write|all\r\n"); return; } /* Card presence check.*/ if (!blkIsInserted(&SDCD1)) { - chprintf(chp, "Card not inserted, aborting.\r\n"); + chprintf(con->bss, "Card not inserted, aborting.\r\n"); return; } /* Connection to the card.*/ - chprintf(chp, "Connecting... "); + chprintf(con->bss, "Connecting... "); if (sdcConnect(&SDCD1)) { - chprintf(chp, "failed\r\n"); + chprintf(con->bss, "failed\r\n"); return; } - chprintf(chp, "OK\r\n\r\nCard Info\r\n"); - chprintf(chp, "CSD : %08X %8X %08X %08X \r\n", + chprintf(con->bss, "OK\r\n\r\nCard Info\r\n"); + chprintf(con->bss, "CSD : %08X %8X %08X %08X \r\n", SDCD1.csd[3], SDCD1.csd[2], SDCD1.csd[1], SDCD1.csd[0]); - chprintf(chp, "CID : %08X %8X %08X %08X \r\n", + chprintf(con->bss, "CID : %08X %8X %08X %08X \r\n", SDCD1.cid[3], SDCD1.cid[2], SDCD1.cid[1], SDCD1.cid[0]); - chprintf(chp, "Mode : %s\r\n", mode[SDCD1.cardmode]); - chprintf(chp, "Capacity : %DMB\r\n", SDCD1.capacity / 2048); + chprintf(con->bss, "Mode : %s\r\n", mode[SDCD1.cardmode]); + chprintf(con->bss, "Capacity : %DMB\r\n", SDCD1.capacity / 2048); /* The test is performed in the middle of the flash area.*/ startblk = (SDCD1.capacity / MMCSD_BLOCK_SIZE) / 2; @@ -429,61 +429,61 @@ void cmd_sdc(BaseSequentialStream *chp, int argc, const char* const* argv) (strcmp(argv[0], "all") == 0)) { /* Single block read performance, aligned.*/ - chprintf(chp, "Single block aligned read performance: "); + chprintf(con->bss, "Single block aligned read performance: "); start = chVTGetSystemTime(); end = start + MS2ST(1000); n = 0; do { if (blkRead(&SDCD1, startblk, buf, 1)) { - chprintf(chp, "failed\r\n"); + chprintf(con->bss, "failed\r\n"); goto exittest; } n++; } while (chVTIsSystemTimeWithin(start, end)); - chprintf(chp, "%D blocks/S, %D bytes/S\r\n", n, n * MMCSD_BLOCK_SIZE); + chprintf(con->bss, "%D blocks/S, %D bytes/S\r\n", n, n * MMCSD_BLOCK_SIZE); /* Multiple sequential blocks read performance, aligned.*/ - chprintf(chp, "16 sequential blocks aligned read performance: "); + chprintf(con->bss, "16 sequential blocks aligned read performance: "); start = chVTGetSystemTime(); end = start + MS2ST(1000); n = 0; do { if (blkRead(&SDCD1, startblk, buf, SDC_BURST_SIZE)) { - chprintf(chp, "failed\r\n"); + chprintf(con->bss, "failed\r\n"); goto exittest; } n += SDC_BURST_SIZE; } while (chVTIsSystemTimeWithin(start, end)); - chprintf(chp, "%D blocks/S, %D bytes/S\r\n", n, n * MMCSD_BLOCK_SIZE); + chprintf(con->bss, "%D blocks/S, %D bytes/S\r\n", n, n * MMCSD_BLOCK_SIZE); #if STM32_SDC_SDIO_UNALIGNED_SUPPORT /* Single block read performance, unaligned.*/ - chprintf(chp, "Single block unaligned read performance: "); + chprintf(con->bss, "Single block unaligned read performance: "); start = chVTGetSystemTime(); end = start + MS2ST(1000); n = 0; do { if (blkRead(&SDCD1, startblk, buf + 1, 1)) { - chprintf(chp, "failed\r\n"); + chprintf(con->bss, "failed\r\n"); goto exittest; } n++; } while (chVTIsSystemTimeWithin(start, end)); - chprintf(chp, "%D blocks/S, %D bytes/S\r\n", n, n * MMCSD_BLOCK_SIZE); + chprintf(con->bss, "%D blocks/S, %D bytes/S\r\n", n, n * MMCSD_BLOCK_SIZE); /* Multiple sequential blocks read performance, unaligned.*/ - chprintf(chp, "16 sequential blocks unaligned read performance: "); + chprintf(con->bss, "16 sequential blocks unaligned read performance: "); start = chVTGetSystemTime(); end = start + MS2ST(1000); n = 0; do { if (blkRead(&SDCD1, startblk, buf + 1, SDC_BURST_SIZE)) { - chprintf(chp, "failed\r\n"); + chprintf(con->bss, "failed\r\n"); goto exittest; } n += SDC_BURST_SIZE; } while (chVTIsSystemTimeWithin(start, end)); - chprintf(chp, "%D blocks/S, %D bytes/S\r\n", n, n * MMCSD_BLOCK_SIZE); + chprintf(con->bss, "%D blocks/S, %D bytes/S\r\n", n, n * MMCSD_BLOCK_SIZE); #endif /* STM32_SDC_SDIO_UNALIGNED_SUPPORT */ } @@ -497,7 +497,7 @@ void cmd_sdc(BaseSequentialStream *chp, int argc, const char* const* argv) sdcDisconnect(&SDCD1); } -static FRESULT scan_files(BaseSequentialStream *chp, char *path) +static FRESULT scan_files(struct hydra_console *con, char *path) { FRESULT res; FILINFO fno; @@ -534,7 +534,7 @@ static FRESULT scan_files(BaseSequentialStream *chp, char *path) if(fno.fattrib & AM_DIR) /* It is a directory */ { sprintf(&path[i], "/%s", fn); - res = scan_files(chp, path); + res = scan_files(con, path); if (res != FR_OK) break; path[i] = 0; @@ -542,13 +542,13 @@ static FRESULT scan_files(BaseSequentialStream *chp, char *path) { if(strlen(path) > 0) { - chprintf(chp, "%s", path); + chprintf(con->bss, "%s", path); }else { - chprintf(chp, "."); + chprintf(con->bss, "."); } chThdSleepMilliseconds(1); - chprintf(chp, "/%s %ld bytes\r\n", fn, fsize); + chprintf(con->bss, "/%s %ld bytes\r\n", fn, fsize); chThdSleepMilliseconds(1); } } @@ -667,7 +667,7 @@ int umount(void) return 0; } -void cmd_sd_mount(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_sd_mount(struct hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; @@ -676,7 +676,7 @@ void cmd_sd_mount(BaseSequentialStream *chp, int argc, const char* const* argv) if (fs_ready) { - chprintf(chp, "File System already mounted\r\n"); + chprintf(con->bss, "File System already mounted\r\n"); return; } @@ -685,34 +685,34 @@ void cmd_sd_mount(BaseSequentialStream *chp, int argc, const char* const* argv) */ if (sdcConnect(&SDCD1)) { - chprintf(chp, "sdcConnect(&SDCD1) error\r\n"); + chprintf(con->bss, "sdcConnect(&SDCD1) error\r\n"); return; } err = f_mount(&SDC_FS, "", 0); if (err != FR_OK) { - chprintf(chp, "f_mount KO\r\n"); + chprintf(con->bss, "f_mount KO\r\n"); sdcDisconnect(&SDCD1); return; }else { - chprintf(chp, "f_mount OK\r\n"); + chprintf(con->bss, "f_mount OK\r\n"); } fs_ready = TRUE; } -void cmd_sd_umount(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_sd_umount(struct hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; if(!fs_ready) { - chprintf(chp, "File System already unmounted\r\n"); + chprintf(con->bss, "File System already unmounted\r\n"); return; } - chprintf(chp, "Umount filesystem...\r\n"); + chprintf(con->bss, "Umount filesystem...\r\n"); f_mount(NULL, "", 0); /* SDC Disconnect */ @@ -720,7 +720,7 @@ void cmd_sd_umount(BaseSequentialStream *chp, int argc, const char* const* argv) fs_ready = FALSE; } -void cmd_sd_ls(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_sd_ls(struct hydra_console *con, int argc, const char* const* argv) { FRESULT err; uint32_t clusters; @@ -734,7 +734,7 @@ void cmd_sd_ls(BaseSequentialStream *chp, int argc, const char* const* argv) if(argc > 2) { - chprintf(chp, "Error missing argument\r\nusage: %s [optional directory]\r\n", argv[0]); + chprintf(con->bss, "Error missing argument\r\nusage: %s [optional directory]\r\n", argv[0]); return; } if(argc == 2) @@ -750,36 +750,36 @@ void cmd_sd_ls(BaseSequentialStream *chp, int argc, const char* const* argv) err = mount(); if(err) { - chprintf(chp, "mount error:%d\r\n", err); + chprintf(con->bss, "mount error:%d\r\n", err); return; } } err = f_getfree("/", &clusters, &fsp); if (err != FR_OK) { - chprintf(chp, "FS: f_getfree() failed\r\n"); + chprintf(con->bss, "FS: f_getfree() failed\r\n"); }else { free_size_bytes = (uint64_t)(clusters * SDC_FS.csize) * (uint64_t)MMCSD_BLOCK_SIZE; free_size_kb = (uint32_t)(free_size_bytes/(uint64_t)1024); free_size_mb = (uint32_t)(free_size_kb/1024); - chprintf(chp, + chprintf(con->bss, "FS: %lu free clusters, %lu sectors/cluster, %lu bytes/sector\r\n", clusters, (uint32_t)SDC_FS.csize, (uint32_t)MMCSD_BLOCK_SIZE); - chprintf(chp, + chprintf(con->bss, "FS: %lu KBytes free (%lu MBytes free)\r\n", free_size_kb, free_size_mb); - err = scan_files(chp, (char *)fbuff); + err = scan_files(con, (char *)fbuff); if (err != FR_OK) { - chprintf(chp, "scan_files() on dir=%s failed\r\n", fbuff); + chprintf(con->bss, "scan_files() on dir=%s failed\r\n", fbuff); } } } /* Call only with len=multiples of 16 (unless end of dump). */ -static void dump_hexbuf(BaseSequentialStream *chp, uint32_t offset, +static void dump_hexbuf(struct hydra_console *con, uint32_t offset, const uint8_t *buf, int len) { int b, i; @@ -787,25 +787,25 @@ static void dump_hexbuf(BaseSequentialStream *chp, uint32_t offset, b = 0; while (len) { - chprintf(chp, "%.8x: ", offset + b); + chprintf(con->bss, "%.8x: ", offset + b); for (i = 0; i < MIN(len, 16); i++, b++) { - chprintf(chp, "%.2x", buf[b]); + chprintf(con->bss, "%.2x", buf[b]); if (i & 1) - chprintf(chp, " "); + chprintf(con->bss, " "); if (i == 7) - chprintf(chp, " "); + chprintf(con->bss, " "); if (buf[b] >= 0x20 && buf[b] < 0x7f) asc[i] = buf[b]; else asc[i] = '.'; } asc[i] = 0; - chprintf(chp, " %s\r\n", asc); + chprintf(con->bss, " %s\r\n", asc); len -= i; } } -void cmd_sd_cat(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_sd_cat(struct hydra_console *con, int argc, const char* const* argv) { #define MAX_FILE_SIZE (524288) bool hex; @@ -816,7 +816,7 @@ void cmd_sd_cat(BaseSequentialStream *chp, int argc, const char* const* argv) if(argc != 2) { - chprintf(chp, "Error missing argument\r\nusage: %s \r\n", argv[0]); + chprintf(con->bss, "Error missing argument\r\nusage: %s \r\n", argv[0]); return; } @@ -825,7 +825,7 @@ void cmd_sd_cat(BaseSequentialStream *chp, int argc, const char* const* argv) err = mount(); if(err) { - chprintf(chp, "mount error:%d\r\n", err); + chprintf(con->bss, "mount error:%d\r\n", err); return; } } @@ -834,17 +834,17 @@ void cmd_sd_cat(BaseSequentialStream *chp, int argc, const char* const* argv) err = f_open(&fp, filename, FA_READ | FA_OPEN_EXISTING); if (err != FR_OK) { - chprintf(chp, "Error to open file %s, err:%d\r\n", filename, err); + chprintf(con->bss, "Error to open file %s, err:%d\r\n", filename, err); return; } filelen = fp.fsize; if(filelen > MAX_FILE_SIZE) { - chprintf(chp, "Read file: %s, size=%d is too big shall not exceed %d\r\n", filename, filelen, MAX_FILE_SIZE); + chprintf(con->bss, "Read file: %s, size=%d is too big shall not exceed %d\r\n", filename, filelen, MAX_FILE_SIZE); }else { - chprintf(chp, "Read file: %s, size=%d\r\n", filename, filelen); + chprintf(con->bss, "Read file: %s, size=%d\r\n", filename, filelen); } hex = !strcmp(argv[0], "hd"); @@ -863,34 +863,34 @@ void cmd_sd_cat(BaseSequentialStream *chp, int argc, const char* const* argv) err = f_read(&fp, inbuf, cnt, (void *)&cnt); if (err != FR_OK) { - chprintf(chp, "Error to read file, err:%d\r\n", err); + chprintf(con->bss, "Error to read file, err:%d\r\n", err); break; } if (!cnt) break; if (hex) { - dump_hexbuf(chp, offset, inbuf, cnt); + dump_hexbuf(con, offset, inbuf, cnt); offset += cnt; } else { /* Force end of string at end of buffer */ inbuf[cnt] = 0; - chprintf(chp, "%s", inbuf); + chprintf(con->bss, "%s", inbuf); } } if (!hex) - chprintf(chp, "\r\n"); + chprintf(con->bss, "\r\n"); } /** * SDIO Test Destructive */ -void cmd_sd_erase(BaseSequentialStream *chp, int argc, const char* const* argv){ +void cmd_sd_erase(struct hydra_console *con, int argc, const char* const* argv){ (void)argc; (void)argv; uint32_t i = 0; - chprintf(chp, "SDIO Destructive test will format de SD press UBTN to continue ... "); + chprintf(con->bss, "SDIO Destructive test will format de SD press UBTN to continue ... "); while(1) { @@ -901,91 +901,91 @@ void cmd_sd_erase(BaseSequentialStream *chp, int argc, const char* const* argv){ chThdSleepMilliseconds(10); } - chprintf(chp, "Trying to connect SDIO... "); + chprintf(con->bss, "Trying to connect SDIO... "); chThdSleepMilliseconds(10); if (!sdcConnect(&SDCD1)) { - chprintf(chp, "OK\r\n"); - chprintf(chp, "*** Card CSD content is: "); - chprintf(chp, "%X %X %X %X \r\n", (&SDCD1)->csd[3], (&SDCD1)->csd[2], + chprintf(con->bss, "OK\r\n"); + chprintf(con->bss, "*** Card CSD content is: "); + chprintf(con->bss, "%X %X %X %X \r\n", (&SDCD1)->csd[3], (&SDCD1)->csd[2], (&SDCD1)->csd[1], (&SDCD1)->csd[0]); - chprintf(chp, "Single aligned read..."); + chprintf(con->bss, "Single aligned read..."); chThdSleepMilliseconds(10); if (sdcRead(&SDCD1, 0, inbuf, 1)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } - chprintf(chp, " OK\r\n"); + chprintf(con->bss, " OK\r\n"); chThdSleepMilliseconds(10); - chprintf(chp, "Single unaligned read..."); + chprintf(con->bss, "Single unaligned read..."); chThdSleepMilliseconds(10); if (sdcRead(&SDCD1, 0, inbuf + 1, 1)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } if (sdcRead(&SDCD1, 0, inbuf + 2, 1)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } if (sdcRead(&SDCD1, 0, inbuf + 3, 1)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } - chprintf(chp, " OK\r\n"); + chprintf(con->bss, " OK\r\n"); chThdSleepMilliseconds(10); - chprintf(chp, "Multiple aligned reads..."); + chprintf(con->bss, "Multiple aligned reads..."); chThdSleepMilliseconds(10); fillbuffers(0x55); /* fill reference buffer from SD card */ if (sdcRead(&SDCD1, 0, inbuf, SDC_BURST_SIZE)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } - chprintf(chp, "\r\n."); + chprintf(con->bss, "\r\n."); for (i=0; i<1000; i++) { if (sdcRead(&SDCD1, 0, outbuf, SDC_BURST_SIZE)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } if (memcmp(inbuf, outbuf, SDC_BURST_SIZE * MMCSD_BLOCK_SIZE) != 0) { - chprintf(chp, "memcmp KO\r\n"); + chprintf(con->bss, "memcmp KO\r\n"); umount(); return; } - chprintf(chp, "."); + chprintf(con->bss, "."); } - chprintf(chp, " OK\r\n"); + chprintf(con->bss, " OK\r\n"); chThdSleepMilliseconds(10); - chprintf(chp, "Multiple unaligned reads..."); + chprintf(con->bss, "Multiple unaligned reads..."); chThdSleepMilliseconds(10); fillbuffers(0x55); /* fill reference buffer from SD card */ if (sdcRead(&SDCD1, 0, inbuf + 1, SDC_BURST_SIZE)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } @@ -994,78 +994,78 @@ void cmd_sd_erase(BaseSequentialStream *chp, int argc, const char* const* argv){ { if (sdcRead(&SDCD1, 0, outbuf + 1, SDC_BURST_SIZE)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } if (memcmp(inbuf, outbuf, SDC_BURST_SIZE * MMCSD_BLOCK_SIZE) != 0) { - chprintf(chp, "memcmp KO\r\n"); + chprintf(con->bss, "memcmp KO\r\n"); umount(); return; } } - chprintf(chp, " OK\r\n"); + chprintf(con->bss, " OK\r\n"); chThdSleepMilliseconds(10); /* DESTRUCTIVE TEST START */ - chprintf(chp, "Single aligned write..."); + chprintf(con->bss, "Single aligned write..."); chThdSleepMilliseconds(10); fillbuffer(0xAA, inbuf); if (sdcWrite(&SDCD1, 0, inbuf, 1)) { - chprintf(chp, "sdcWrite KO\r\n"); + chprintf(con->bss, "sdcWrite KO\r\n"); umount(); return; } fillbuffer(0, outbuf); if (sdcRead(&SDCD1, 0, outbuf, 1)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } if (memcmp(inbuf, outbuf, MMCSD_BLOCK_SIZE) != 0) { - chprintf(chp, "memcmp KO\r\n"); + chprintf(con->bss, "memcmp KO\r\n"); umount(); return; } - chprintf(chp, " OK\r\n"); + chprintf(con->bss, " OK\r\n"); - chprintf(chp, "Single unaligned write..."); + chprintf(con->bss, "Single unaligned write..."); chThdSleepMilliseconds(10); fillbuffer(0xFF, inbuf); if (sdcWrite(&SDCD1, 0, inbuf+1, 1)) { - chprintf(chp, "sdcWrite KO\r\n"); + chprintf(con->bss, "sdcWrite KO\r\n"); umount(); return; } fillbuffer(0, outbuf); if (sdcRead(&SDCD1, 0, outbuf+1, 1)) { - chprintf(chp, "sdcRead KO\r\n"); + chprintf(con->bss, "sdcRead KO\r\n"); umount(); return; } if (memcmp(inbuf+1, outbuf+1, MMCSD_BLOCK_SIZE) != 0) { - chprintf(chp, "memcmp KO\r\n"); + chprintf(con->bss, "memcmp KO\r\n"); umount(); return; } - chprintf(chp, " OK\r\n"); + chprintf(con->bss, " OK\r\n"); - chprintf(chp, "Running badblocks at 0x10000 offset..."); + chprintf(con->bss, "Running badblocks at 0x10000 offset..."); chThdSleepMilliseconds(10); if(badblocks(0x10000, 0x11000, SDC_BURST_SIZE, 0xAA)) { - chprintf(chp, "badblocks KO\r\n"); + chprintf(con->bss, "badblocks KO\r\n"); umount(); return; } - chprintf(chp, " OK\r\n"); + chprintf(con->bss, " OK\r\n"); /* DESTRUCTIVE TEST END */ /** @@ -1079,90 +1079,90 @@ void cmd_sd_erase(BaseSequentialStream *chp, int argc, const char* const* argv){ uint32_t bytes_read; uint8_t teststring[] = {"This is test file\r\n"}; - chprintf(chp, "Register working area for filesystem... "); + chprintf(con->bss, "Register working area for filesystem... "); chThdSleepMilliseconds(10); err = f_mount(&SDC_FS, "", 0); if (err != FR_OK) { - chprintf(chp, "f_mount err:%d\r\n", err); + chprintf(con->bss, "f_mount err:%d\r\n", err); umount(); return; } else{ fs_ready = TRUE; - chprintf(chp, "OK\r\n"); + chprintf(con->bss, "OK\r\n"); } /* DESTRUCTIVE TEST START */ - chprintf(chp, "Formatting... "); + chprintf(con->bss, "Formatting... "); chThdSleepMilliseconds(10); err = f_mkfs("",0,0); if (err != FR_OK) { - chprintf(chp, "f_mkfs err:%d\r\n", err); + chprintf(con->bss, "f_mkfs err:%d\r\n", err); umount(); return; }else { - chprintf(chp, "OK\r\n"); + chprintf(con->bss, "OK\r\n"); } /* DESTRUCTIVE TEST END */ - chprintf(chp, "Mount filesystem... "); + chprintf(con->bss, "Mount filesystem... "); chThdSleepMilliseconds(10); err = f_getfree("/", &clusters, &fsp); if (err != FR_OK) { - chprintf(chp, "f_getfree err:%d\r\n", err); + chprintf(con->bss, "f_getfree err:%d\r\n", err); umount(); return; } - chprintf(chp, "OK\r\n"); - chprintf(chp, + chprintf(con->bss, "OK\r\n"); + chprintf(con->bss, "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n", clusters, (uint32_t)SDC_FS.csize, clusters * (uint32_t)SDC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE); - chprintf(chp, "Create file \"chtest.txt\"... "); + chprintf(con->bss, "Create file \"chtest.txt\"... "); chThdSleepMilliseconds(10); err = f_open(&FileObject, "0:chtest.txt", FA_WRITE | FA_OPEN_ALWAYS); if (err != FR_OK) { - chprintf(chp, "f_open err:%d\r\n", err); + chprintf(con->bss, "f_open err:%d\r\n", err); umount(); return; } - chprintf(chp, "OK\r\n"); - chprintf(chp, "Write some data in it... "); + chprintf(con->bss, "OK\r\n"); + chprintf(con->bss, "Write some data in it... "); chThdSleepMilliseconds(10); err = f_write(&FileObject, teststring, sizeof(teststring), (void *)&bytes_written); if (err != FR_OK) { - chprintf(chp, "f_write err:%d\r\n", err); + chprintf(con->bss, "f_write err:%d\r\n", err); umount(); return; } else - chprintf(chp, "OK\r\n"); + chprintf(con->bss, "OK\r\n"); - chprintf(chp, "Close file \"chtest.txt\"... "); + chprintf(con->bss, "Close file \"chtest.txt\"... "); err = f_close(&FileObject); if (err != FR_OK) { - chprintf(chp, "f_close err:%d\r\n", err); + chprintf(con->bss, "f_close err:%d\r\n", err); umount(); return; } else - chprintf(chp, "OK\r\n"); + chprintf(con->bss, "OK\r\n"); - chprintf(chp, "Check file content \"chtest.txt\"... "); + chprintf(con->bss, "Check file content \"chtest.txt\"... "); err = f_open(&FileObject, "0:chtest.txt", FA_READ | FA_OPEN_EXISTING); chThdSleepMilliseconds(10); if (err != FR_OK) { - chprintf(chp, "f_open err:%d\r\n", err); + chprintf(con->bss, "f_open err:%d\r\n", err); umount(); return; } @@ -1170,46 +1170,46 @@ void cmd_sd_erase(BaseSequentialStream *chp, int argc, const char* const* argv){ err = f_read(&FileObject, buf, sizeof(teststring), (void *)&bytes_read); if (err != FR_OK) { - chprintf(chp, "f_read KO\r\n"); + chprintf(con->bss, "f_read KO\r\n"); umount(); return; }else { if (memcmp(teststring, buf, sizeof(teststring)) != 0) { - chprintf(chp, "memcmp KO\r\n"); + chprintf(con->bss, "memcmp KO\r\n"); umount(); return; } else{ - chprintf(chp, "OK\r\n"); + chprintf(con->bss, "OK\r\n"); } } - chprintf(chp, "Delete file \"chtest.txt\"... "); + chprintf(con->bss, "Delete file \"chtest.txt\"... "); err = f_unlink("0:chtest.txt"); if (err != FR_OK) { - chprintf(chp, "f_unlink err:%d\r\n", err); + chprintf(con->bss, "f_unlink err:%d\r\n", err); umount(); return; } - chprintf(chp, "Umount filesystem... "); + chprintf(con->bss, "Umount filesystem... "); f_mount(NULL, "", 0); - chprintf(chp, "OK\r\n"); + chprintf(con->bss, "OK\r\n"); - chprintf(chp, "Disconnecting from SDIO..."); + chprintf(con->bss, "Disconnecting from SDIO..."); chThdSleepMilliseconds(10); if (sdcDisconnect(&SDCD1)) { - chprintf(chp, "sdcDisconnect KO\r\n"); + chprintf(con->bss, "sdcDisconnect KO\r\n"); umount(); return; } - chprintf(chp, " OK\r\n"); - chprintf(chp, "------------------------------------------------------\r\n"); - chprintf(chp, "All tests passed successfully.\r\n"); + chprintf(con->bss, " OK\r\n"); + chprintf(con->bss, "------------------------------------------------------\r\n"); + chprintf(con->bss, "All tests passed successfully.\r\n"); chThdSleepMilliseconds(10); umount(); diff --git a/common/microsd.h b/common/microsd.h index 228ad87b..c7305fb7 100644 --- a/common/microsd.h +++ b/common/microsd.h @@ -17,6 +17,8 @@ #ifndef _MICROSD_H_ #define _MICROSD_H_ +#include "common.h" + typedef struct { char filename[255]; @@ -31,13 +33,13 @@ int mount(void); int umount(void); /* Shell commands */ -void cmd_sd_mount(BaseSequentialStream *chp, int argc, const char* const* argv); -void cmd_sd_umount(BaseSequentialStream *chp, int argc, const char* const* argv); -void cmd_sd_ls(BaseSequentialStream *chp, int argc, const char* const* argv); -void cmd_sd_cat(BaseSequentialStream *chp, int argc, const char* const* argv); +void cmd_sd_mount(struct hydra_console *con, int argc, const char* const* argv); +void cmd_sd_umount(struct hydra_console *con, int argc, const char* const* argv); +void cmd_sd_ls(struct hydra_console *con, int argc, const char* const* argv); +void cmd_sd_cat(struct hydra_console *con, int argc, const char* const* argv); -void cmd_sdiotest(BaseSequentialStream *chp, int argc, const char* const* argv); -void cmd_sd_erase(BaseSequentialStream *chp, int argc, const char* const* argv); -void cmd_sdc(BaseSequentialStream *chp, int argc, const char* const* argv); +void cmd_sdiotest(struct hydra_console *con, int argc, const char* const* argv); +void cmd_sd_erase(struct hydra_console *con, int argc, const char* const* argv); +void cmd_sdc(struct hydra_console *con, int argc, const char* const* argv); -#endif /* _MICROSD_H_ */ \ No newline at end of file +#endif /* _MICROSD_H_ */ diff --git a/hydrabus/hydrabus_microrl.c b/hydrabus/hydrabus_microrl.c index 90c2886d..41e5818e 100644 --- a/hydrabus/hydrabus_microrl.c +++ b/hydrabus/hydrabus_microrl.c @@ -25,6 +25,7 @@ #include "microsd.h" #include "common.h" +#include "microrl.h" #include "microrl_common.h" #include "microrl_callback.h" @@ -68,30 +69,30 @@ microrl_exec_t hydrabus_keyworld[HYDRABUS_NUM_OF_CMD] = char* hydrabus_compl_world[HYDRABUS_NUM_OF_CMD + 1]; //***************************************************************************** -void hydrabus_print_help(BaseSequentialStream *chp, int argc, const char* const* argv) +void hydrabus_print_help(struct hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; - print(chp,"Use TAB key for completion\n\r"); - print(chp,"? or h - Help\t\n\r"); - print(chp,"clear - clear screen\n\r"); - print(chp,"info - info on FW & HW\n\r"); - print(chp,"ch_mem - memory info\t\n\r"); - print(chp,"ch_threads - threads\n\r"); - print(chp,"ch_test - chibios tests\n\r"); - print(chp,"mount - mount sd\n\r"); - print(chp,"umount - unmount sd\n\r"); - print(chp,"ls [opt dir] - list files in sd\n\r"); - print(chp,"cat - display sd file (ASCII)\n\r"); - print(chp,"hd - hexdump sd file\n\r"); - print(chp,"erase - erase sd\n\r"); + print(con, "Use TAB key for completion\n\r"); + print(con, "? or h - Help\t\n\r"); + print(con, "clear - clear screen\n\r"); + print(con, "info - info on FW & HW\n\r"); + print(con, "ch_mem - memory info\t\n\r"); + print(con, "ch_threads - threads\n\r"); + print(con, "ch_test - chibios tests\n\r"); + print(con, "mount - mount sd\n\r"); + print(con, "umount - unmount sd\n\r"); + print(con, "ls [opt dir] - list files in sd\n\r"); + print(con, "cat - display sd file (ASCII)\n\r"); + print(con, "hd - hexdump sd file\n\r"); + print(con, "erase - erase sd\n\r"); } //***************************************************************************** // execute callback for microrl library // do what you want here, but don't write to argv!!! read only!! -int hydrabus_execute(BaseSequentialStream *chp, int argc, const char* const* argv) +int hydrabus_execute(struct hydra_console *con, int argc, const char* const* argv) { bool cmd_found; int curr_arg = 0; @@ -107,7 +108,7 @@ int hydrabus_execute(BaseSequentialStream *chp, int argc, const char* const* arg { if( (strcmp(argv[curr_arg], hydrabus_keyworld[cmd].str_cmd)) == 0 ) { - hydrabus_keyworld[cmd].ptFunc_exe_cmd(chp, argc-curr_arg, &argv[curr_arg]); + hydrabus_keyworld[cmd].ptFunc_exe_cmd(con, argc-curr_arg, &argv[curr_arg]); cmd_found = TRUE; break; } @@ -115,9 +116,9 @@ int hydrabus_execute(BaseSequentialStream *chp, int argc, const char* const* arg } if(cmd_found == FALSE) { - print(chp,"command: '"); - print(chp,(char*)argv[curr_arg]); - print(chp,"' Not found.\n\r"); + print(con,"command: '"); + print(con,(char*)argv[curr_arg]); + print(con,"' Not found.\n\r"); } curr_arg++; } @@ -125,10 +126,10 @@ int hydrabus_execute(BaseSequentialStream *chp, int argc, const char* const* arg } //***************************************************************************** -void hydrabus_sigint(BaseSequentialStream *chp, int argc, const char* const* argv) +void hydrabus_sigint(struct hydra_console *con) { - (void)argc; - (void)argv; - - print(chp, "HydraBus ^C catched!\n\r"); + /* Hit ctrl-U and enter. */ + microrl_insert_char(con->mrl, 0x15); + microrl_insert_char(con->mrl, 0x0d); + microrl_insert_char(con->mrl, 0x0a); } diff --git a/hydrabus/hydrabus_microrl.h b/hydrabus/hydrabus_microrl.h index a0f40595..3cb03f11 100644 --- a/hydrabus/hydrabus_microrl.h +++ b/hydrabus/hydrabus_microrl.h @@ -21,8 +21,8 @@ extern char* hydrabus_compl_world[HYDRABUS_NUM_OF_CMD + 1]; extern microrl_exec_t hydrabus_keyworld[HYDRABUS_NUM_OF_CMD]; -void hydrabus_print_help(BaseSequentialStream *chp, int argc, const char* const* argv); -int hydrabus_execute(BaseSequentialStream *chp, int argc, const char* const* argv); -void hydrabus_sigint(BaseSequentialStream *chp, int argc, const char* const* argv); +void hydrabus_print_help(struct hydra_console *con, int argc, const char* const* argv); +int hydrabus_execute(struct hydra_console *con, int argc, const char* const* argv); +void hydrabus_sigint(struct hydra_console *con); #endif /* _HYDRABUS_MICRORL_H_ */ diff --git a/hydranfc/hydranfc.c b/hydranfc/hydranfc.c index b27b951c..2536381c 100644 --- a/hydranfc/hydranfc.c +++ b/hydranfc/hydranfc.c @@ -230,7 +230,7 @@ bool hydranfc_init(void) return TRUE; } -void cmd_nfc_vicinity(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_nfc_vicinity(struct hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; @@ -250,7 +250,7 @@ void cmd_nfc_vicinity(BaseSequentialStream *chp, int argc, const char* const* ar init_ms = Trf797xInitialSettings(); Trf797xReset(); - chprintf(chp, "Test nf ISO15693/Vicinity (high speed) read UID start, init_ms=%d ms\r\n", init_ms); + chprintf(con->bss, "Test nf ISO15693/Vicinity (high speed) read UID start, init_ms=%d ms\r\n", init_ms); /* Write Modulator and SYS_CLK Control Register (0x09) (13.56Mhz SYS_CLK and default Clock 13.56Mhz)) */ data_buf[0] = MODULATOR_CONTROL; @@ -261,7 +261,7 @@ void cmd_nfc_vicinity(BaseSequentialStream *chp, int argc, const char* const* ar Trf797xReadSingle(data_buf, 1); if(data_buf[0] != 0x31) { - chprintf(chp, "Error Modulator Control Register read=0x%.2lX (shall be 0x31)\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Error Modulator Control Register read=0x%.2lX (shall be 0x31)\r\n", (uint32_t)data_buf[0]); } /* Configure Mode ISO Control Register (0x01) to 0x02 (ISO15693 high bit rate, one subcarrier, 1 out of 4) */ data_buf[0] = ISO_CONTROL; @@ -272,7 +272,7 @@ void cmd_nfc_vicinity(BaseSequentialStream *chp, int argc, const char* const* ar Trf797xReadSingle(data_buf, 1); if(data_buf[0] != 0x02) { - chprintf(chp, "Error ISO Control Register read=0x%.2lX (shall be 0x02)\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Error ISO Control Register read=0x%.2lX (shall be 0x02)\r\n", (uint32_t)data_buf[0]); } /* Configure Test Settings 1 to BIT6/0x40 => MOD Pin becomes receiver subcarrier output (Digital Output for RX/TX) */ /* @@ -297,7 +297,7 @@ void cmd_nfc_vicinity(BaseSequentialStream *chp, int argc, const char* const* ar /* Read back (Chip Status Control Register (0x00) shall be set to RF ON */ data_buf[0] = CHIP_STATE_CONTROL; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RF ON Chip Status(Reg0) 0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RF ON Chip Status(Reg0) 0x%.2lX\r\n", (uint32_t)data_buf[0]); /* Send Inventory(3B) and receive data + UID */ data_buf[0] = 0x26; /* Request Flags */ @@ -310,23 +310,23 @@ void cmd_nfc_vicinity(BaseSequentialStream *chp, int argc, const char* const* ar if (fifo_size > 0) { // fifo_size shall be equal to 0x0A (10 bytes availables) - chprintf(chp, "RX (contains UID):"); + chprintf(con->bss, "RX (contains UID):"); for(i=0; ibss, " 0x%.2lX", (uint32_t)data_buf[i]); + chprintf(con->bss, "\r\n"); /* Read RSSI levels and oscillator status(0x0F/0x4F) */ data_buf[0] = RSSI_LEVELS; // read RSSI levels Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RSSI data: 0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RSSI data: 0x%.2lX\r\n", (uint32_t)data_buf[0]); // data_buf[0] shall be equal to value > 0x40 if(data_buf[0] < 0x40) { - chprintf(chp, "Error RSSI data: 0x%.2lX (shall be > 0x40)\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Error RSSI data: 0x%.2lX (shall be > 0x40)\r\n", (uint32_t)data_buf[0]); } }else { - chprintf(chp, "No data in RX FIFO\r\n"); + chprintf(con->bss, "No data in RX FIFO\r\n"); } /* Turn RF OFF (Chip Status Control Register (0x00)) */ @@ -335,16 +335,16 @@ void cmd_nfc_vicinity(BaseSequentialStream *chp, int argc, const char* const* ar /* Read back (Chip Status Control Register (0x00) shall be set to RF OFF */ data_buf[0] = CHIP_STATE_CONTROL; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RF OFF Chip Status(Reg0) 0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RF OFF Chip Status(Reg0) 0x%.2lX\r\n", (uint32_t)data_buf[0]); // data_buf[0] shall be equal to value 0x00 - chprintf(chp, "nb_irq: 0x%.2ld\r\n", (uint32_t)nb_irq); + chprintf(con->bss, "nb_irq: 0x%.2ld\r\n", (uint32_t)nb_irq); nb_irq = 0; - chprintf(chp, "Test nfv ISO15693/Vicinity end\r\n"); + chprintf(con->bss, "Test nfv ISO15693/Vicinity end\r\n"); } -void cmd_nfc_mifare(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_nfc_mifare(struct hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; @@ -365,7 +365,7 @@ void cmd_nfc_mifare(BaseSequentialStream *chp, int argc, const char* const* argv init_ms = Trf797xInitialSettings(); Trf797xReset(); - chprintf(chp, "Test nf ISO14443-A/Mifare read UID(4bytes only) start, init_ms=%d ms\r\n", init_ms); + chprintf(con->bss, "Test nf ISO14443-A/Mifare read UID(4bytes only) start, init_ms=%d ms\r\n", init_ms); /* Write Modulator and SYS_CLK Control Register (0x09) (13.56Mhz SYS_CLK and default Clock 13.56Mhz)) */ data_buf[0] = MODULATOR_CONTROL; @@ -374,7 +374,7 @@ void cmd_nfc_mifare(BaseSequentialStream *chp, int argc, const char* const* argv data_buf[0] = MODULATOR_CONTROL; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "Modulator Control Register read=0x%.2lX (shall be 0x31)\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Modulator Control Register read=0x%.2lX (shall be 0x31)\r\n", (uint32_t)data_buf[0]); /* Configure Mode ISO Control Register (0x01) to 0x88 (ISO14443A RX bit rate, 106 kbps) and no RX CRC (CRC is not present in the response)) */ data_buf[0] = ISO_CONTROL; @@ -385,7 +385,7 @@ void cmd_nfc_mifare(BaseSequentialStream *chp, int argc, const char* const* argv Trf797xReadSingle(data_buf, 1); if(data_buf[0] != 0x88) { - chprintf(chp, "Error ISO Control Register read=0x%.2lX (shall be 0x88)\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Error ISO Control Register read=0x%.2lX (shall be 0x88)\r\n", (uint32_t)data_buf[0]); } /* Configure Test Settings 1 to BIT6/0x40 => MOD Pin becomes receiver subcarrier output (Digital Output for RX/TX) */ /* @@ -408,7 +408,7 @@ void cmd_nfc_mifare(BaseSequentialStream *chp, int argc, const char* const* argv /* Read back (Chip Status Control Register (0x00) shall be set to RF ON */ data_buf[0] = CHIP_STATE_CONTROL; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RF ON Chip Status(Reg0) 0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RF ON Chip Status(Reg0) 0x%.2lX\r\n", (uint32_t)data_buf[0]); /* Send REQA(7bits) and receive ATQA(2bytes) */ data_buf[0] = 0x26; /* REQA (7bits) */ @@ -426,14 +426,14 @@ void cmd_nfc_mifare(BaseSequentialStream *chp, int argc, const char* const* argv } if (fifo_size > 0) { - chprintf(chp, "RX data(ATQA):"); + chprintf(con->bss, "RX data(ATQA):"); for(i=0; ibss, " 0x%.2lX", (uint32_t)data_buf[i]); + chprintf(con->bss, "\r\n"); data_buf[0] = RSSI_LEVELS; // read RSSI levels Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RSSI data: 0x%.2lX (shall be > 0x40)\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RSSI data: 0x%.2lX (shall be > 0x40)\r\n", (uint32_t)data_buf[0]); /* Send AntiColl(2Bytes) and receive UID+BCC(5bytes) */ data_buf[0] = 0x93; @@ -441,17 +441,17 @@ void cmd_nfc_mifare(BaseSequentialStream *chp, int argc, const char* const* argv fifo_size = Trf797x_transceive_bytes(data_buf, 2, uid_buf, UID_MAX, 10/* 10ms TX/RX Timeout */, 0/* TX CRC disabled */); if (fifo_size > 0) { - chprintf(chp, "RX data(UID+BCC):"); + chprintf(con->bss, "RX data(UID+BCC):"); for(i=0; ibss, " 0x%.2lX", (uint32_t)uid_buf[i]); + chprintf(con->bss, "\r\n"); data_buf[0] = RSSI_LEVELS; // read RSSI levels Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RSSI data: 0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RSSI data: 0x%.2lX\r\n", (uint32_t)data_buf[0]); if(data_buf[0] < 0x40) { - chprintf(chp, "Error RSSI data: 0x%.2lX (shall be > 0x40)\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Error RSSI data: 0x%.2lX (shall be > 0x40)\r\n", (uint32_t)data_buf[0]); } /* Select RX with CRC_A */ @@ -470,14 +470,14 @@ void cmd_nfc_mifare(BaseSequentialStream *chp, int argc, const char* const* argv fifo_size = Trf797x_transceive_bytes(data_buf, (2+UID_MAX), data_buf, DATA_MAX, 10/* 10ms TX/RX Timeout */, 1 /* TX CRC enabled */); if (fifo_size > 0) { - chprintf(chp, "RX data(SAK):"); + chprintf(con->bss, "RX data(SAK):"); for(i=0; ibss, " 0x%.2lX", (uint32_t)data_buf[i]); + chprintf(con->bss, "\r\n"); data_buf[0] = RSSI_LEVELS; // read RSSI levels Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RSSI data: 0x%.2lX (shall be > 0x40)\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RSSI data: 0x%.2lX (shall be > 0x40)\r\n", (uint32_t)data_buf[0]); /* Send Halt(2Bytes+CRC) */ data_buf[0] = 0x50; @@ -485,25 +485,25 @@ void cmd_nfc_mifare(BaseSequentialStream *chp, int argc, const char* const* argv fifo_size = Trf797x_transceive_bytes(data_buf, (2+UID_MAX), data_buf, DATA_MAX, 5 /* 5ms TX/RX Timeout => shall not receive answer */, 1/* TX CRC enabled */); if (fifo_size > 0) { - chprintf(chp, "RX data(HALT):"); + chprintf(con->bss, "RX data(HALT):"); for(i=0; ibss, " 0x%.2lX", (uint32_t)data_buf[i]); + chprintf(con->bss, "\r\n"); }else { - chprintf(chp, "Send HALT(No Answer OK)\r\n"); + chprintf(con->bss, "Send HALT(No Answer OK)\r\n"); } }else { - chprintf(chp, "No data(SAK) in RX FIFO\r\n"); + chprintf(con->bss, "No data(SAK) in RX FIFO\r\n"); } }else { - chprintf(chp, "No data(UID) in RX FIFO\r\n"); + chprintf(con->bss, "No data(UID) in RX FIFO\r\n"); } }else { - chprintf(chp, "No data(ATQA) in RX FIFO\r\n"); + chprintf(con->bss, "No data(ATQA) in RX FIFO\r\n"); } /* Turn RF OFF (Chip Status Control Register (0x00)) */ @@ -512,142 +512,142 @@ void cmd_nfc_mifare(BaseSequentialStream *chp, int argc, const char* const* argv /* Read back (Chip Status Control Register (0x00) shall be set to RF OFF */ data_buf[0] = CHIP_STATE_CONTROL; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RF OFF Chip Status(Reg0) 0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RF OFF Chip Status(Reg0) 0x%.2lX\r\n", (uint32_t)data_buf[0]); // data_buf[0] shall be equal to value 0x00 - chprintf(chp, "nb_irq: 0x%.2ld\r\n", (uint32_t)nb_irq); + chprintf(con->bss, "nb_irq: 0x%.2ld\r\n", (uint32_t)nb_irq); nb_irq = 0; - chprintf(chp, "Test nfm ISO14443-A/Mifare end\r\n"); + chprintf(con->bss, "Test nfm ISO14443-A/Mifare end\r\n"); } -void cmd_nfc_dump_regs(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_nfc_dump_regs(struct hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; static uint8_t data_buf[16]; - chprintf(chp, "Start Dump TRF7970A Registers\r\n"); + chprintf(con->bss, "Start Dump TRF7970A Registers\r\n"); data_buf[0] = CHIP_STATE_CONTROL; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "Chip Status(0x00)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Chip Status(0x00)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = ISO_CONTROL; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "ISO Control(0x01)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "ISO Control(0x01)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = ISO_14443B_OPTIONS; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "ISO 14443B Options(0x02)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "ISO 14443B Options(0x02)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = ISO_14443A_OPTIONS; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "ISO 14443A Options(0x03)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "ISO 14443A Options(0x03)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = TX_TIMER_EPC_HIGH; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "TX Timer HighByte(0x04)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "TX Timer HighByte(0x04)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = TX_TIMER_EPC_LOW; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "TX Timer LowByte(0x05)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "TX Timer LowByte(0x05)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = TX_PULSE_LENGTH_CONTROL; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "TX Pulse Length(0x06)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "TX Pulse Length(0x06)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = RX_NO_RESPONSE_WAIT_TIME; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RX No Response Wait Time(0x07)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RX No Response Wait Time(0x07)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = RX_WAIT_TIME; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RX Wait Time(0x08)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RX Wait Time(0x08)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = MODULATOR_CONTROL; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "Modulator SYS_CLK(0x09)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Modulator SYS_CLK(0x09)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = RX_SPECIAL_SETTINGS; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RX SpecialSettings(0x0A)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RX SpecialSettings(0x0A)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = REGULATOR_CONTROL; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "Regulator IO(0x0B)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Regulator IO(0x0B)=0x%.2lX\r\n", (uint32_t)data_buf[0]); /* Read/Clear IRQ Status(0x0C=>0x6C)+read dummy */ Trf797xReadIrqStatus(data_buf); - chprintf(chp, "IRQ Status(0x0C)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "IRQ Status(0x0C)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = IRQ_MASK; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "IRQ Mask+Collision Position1(0x0D)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "IRQ Mask+Collision Position1(0x0D)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = COLLISION_POSITION; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "Collision Position2(0x0E)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Collision Position2(0x0E)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = RSSI_LEVELS; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RSSI+Oscillator Status(0x0F)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RSSI+Oscillator Status(0x0F)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = SPECIAL_FUNCTION; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "Special Functions1(0x10)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Special Functions1(0x10)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = RAM_START_ADDRESS; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "Special Functions2(0x11)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Special Functions2(0x11)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = RAM_START_ADDRESS+1; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RAM ADDR0(0x12)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RAM ADDR0(0x12)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = RAM_START_ADDRESS+2; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RAM ADDR1(0x13)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RAM ADDR1(0x13)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = RAM_START_ADDRESS+3; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "Adjust FIFO IRQ Lev(0x14)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Adjust FIFO IRQ Lev(0x14)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = RAM_START_ADDRESS+4; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "RAM ADDR3(0x15)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "RAM ADDR3(0x15)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = NFC_LOW_DETECTION; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "NFC Low Field Level(0x16)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "NFC Low Field Level(0x16)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = NFC_TARGET_LEVEL; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "NFC Target Detection Level(0x18)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "NFC Target Detection Level(0x18)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = NFC_TARGET_PROTOCOL; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "NFC Target Protocol(0x19)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "NFC Target Protocol(0x19)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = TEST_SETTINGS_1; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "Test Settings1(0x1A)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Test Settings1(0x1A)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = TEST_SETTINGS_2; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "Test Settings2(0x1B)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "Test Settings2(0x1B)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = FIFO_CONTROL; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "FIFO Status(0x1C)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "FIFO Status(0x1C)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = TX_LENGTH_BYTE_1; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "TX Length Byte1(0x1D)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "TX Length Byte1(0x1D)=0x%.2lX\r\n", (uint32_t)data_buf[0]); data_buf[0] = TX_LENGTH_BYTE_2; Trf797xReadSingle(data_buf, 1); - chprintf(chp, "TX Length Byte2(0x1E)=0x%.2lX\r\n", (uint32_t)data_buf[0]); + chprintf(con->bss, "TX Length Byte2(0x1E)=0x%.2lX\r\n", (uint32_t)data_buf[0]); - chprintf(chp, "End Dump TRF7970A Registers\r\n"); + chprintf(con->bss, "End Dump TRF7970A Registers\r\n"); } diff --git a/hydranfc/hydranfc.h b/hydranfc/hydranfc.h index a5fd5128..5a140cce 100644 --- a/hydranfc/hydranfc.h +++ b/hydranfc/hydranfc.h @@ -17,6 +17,8 @@ #ifndef _HYDRANFC_H_ #define _HYDRANFC_H_ +#include "common.h" + extern volatile int nb_irq; extern volatile int irq; extern volatile int irq_end_rx; @@ -24,9 +26,9 @@ extern volatile int irq_end_rx; bool hydranfc_init(void); bool hydranfc_is_detected(void); -void cmd_nfc_vicinity(BaseSequentialStream *chp, int argc, const char* const* argv); -void cmd_nfc_mifare(BaseSequentialStream *chp, int argc, const char* const* argv); -void cmd_nfc_dump_regs(BaseSequentialStream *chp, int argc, const char* const* argv); -void cmd_nfc_sniff_14443A(BaseSequentialStream *chp, int argc, const char* const* argv); +void cmd_nfc_vicinity(struct hydra_console *con, int argc, const char* const* argv); +void cmd_nfc_mifare(struct hydra_console *con, int argc, const char* const* argv); +void cmd_nfc_dump_regs(struct hydra_console *con, int argc, const char* const* argv); +void cmd_nfc_sniff_14443A(struct hydra_console *con, int argc, const char* const* argv); -#endif /* _HYDRANFC_H_ */ \ No newline at end of file +#endif /* _HYDRANFC_H_ */ diff --git a/hydranfc/hydranfc_cmd_sniff.c b/hydranfc/hydranfc_cmd_sniff.c index 3a75ada4..62745ac6 100644 --- a/hydranfc/hydranfc_cmd_sniff.c +++ b/hydranfc/hydranfc_cmd_sniff.c @@ -483,9 +483,9 @@ void sniff_write_8b_ASCII_HEX(uint8_t data, bool add_space) } } -void cmd_nfc_sniff_14443A(BaseSequentialStream *chp, int argc, const char* const* argv) +void cmd_nfc_sniff_14443A(struct hydra_console *con, int argc, const char* const* argv) { - (void)chp; + (void)con; (void)argc; (void)argv; diff --git a/hydranfc/hydranfc_microrl.c b/hydranfc/hydranfc_microrl.c index 2ef75077..dac766aa 100644 --- a/hydranfc/hydranfc_microrl.c +++ b/hydranfc/hydranfc_microrl.c @@ -73,35 +73,35 @@ microrl_exec_t hydranfc_keyworld[HYDRANFC_NUM_OF_CMD] = char* hydranfc_compl_world[HYDRANFC_NUM_OF_CMD + 1]; //***************************************************************************** -void hydranfc_print_help(BaseSequentialStream *chp, int argc, const char* const* argv) +void hydranfc_print_help(struct hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; - print(chp,"Use TAB key for completion\n\r"); - print(chp,"? or h - Help\t\n\r"); - print(chp,"clear - clear screen\n\r"); - print(chp,"info - info on FW & HW\n\r"); - print(chp,"ch_mem - memory info\t\n\r"); - print(chp,"ch_threads - threads\n\r"); - print(chp,"ch_test - chibios tests\n\r"); - print(chp,"mount - mount sd\n\r"); - print(chp,"umount - unmount sd\n\r"); - print(chp,"ls [opt dir] - list files in sd\n\r"); - print(chp,"cat - display sd file (ASCII)\n\r"); - print(chp,"erase - erase sd\n\r"); - print(chp,"nfc_mifare - NFC read Mifare/ISO14443A UID\n\r"); - print(chp,"nfc_vicinity - NFC read Vicinity UID\n\r"); - print(chp,"nfc_dump - NFC dump registers\n\r"); - print(chp,"nfc_sniff - NFC start sniffer ISO14443A\n\r"); - print(chp,"nfc_sniff can be started by K3 and stopped by K4 buttons\n\r"); + print(con, "Use TAB key for completion\n\r"); + print(con, "? or h - Help\t\n\r"); + print(con, "clear - clear screen\n\r"); + print(con, "info - info on FW & HW\n\r"); + print(con, "ch_mem - memory info\t\n\r"); + print(con, "ch_threads - threads\n\r"); + print(con, "ch_test - chibios tests\n\r"); + print(con, "mount - mount sd\n\r"); + print(con, "umount - unmount sd\n\r"); + print(con, "ls [opt dir] - list files in sd\n\r"); + print(con, "cat - display sd file (ASCII)\n\r"); + print(con, "erase - erase sd\n\r"); + print(con, "nfc_mifare - NFC read Mifare/ISO14443A UID\n\r"); + print(con, "nfc_vicinity - NFC read Vicinity UID\n\r"); + print(con, "nfc_dump - NFC dump registers\n\r"); + print(con, "nfc_sniff - NFC start sniffer ISO14443A\n\r"); + print(con, "nfc_sniff can be started by K3 and stopped by K4 buttons\n\r"); } //***************************************************************************** // execute callback for microrl library // do what you want here, but don't write to argv!!! read only!! -int hydranfc_execute(BaseSequentialStream *chp, int argc, const char* const* argv) +int hydranfc_execute(struct hydra_console *con, int argc, const char* const* argv) { bool cmd_found; int curr_arg = 0; @@ -117,7 +117,7 @@ int hydranfc_execute(BaseSequentialStream *chp, int argc, const char* const* arg { if( (strcmp(argv[curr_arg], hydranfc_keyworld[cmd].str_cmd)) == 0 ) { - hydranfc_keyworld[cmd].ptFunc_exe_cmd(chp, argc-curr_arg, &argv[curr_arg]); + hydranfc_keyworld[cmd].ptFunc_exe_cmd(con, argc-curr_arg, &argv[curr_arg]); cmd_found = TRUE; break; } @@ -125,9 +125,9 @@ int hydranfc_execute(BaseSequentialStream *chp, int argc, const char* const* arg } if(cmd_found == FALSE) { - print(chp,"command: '"); - print(chp,(char*)argv[curr_arg]); - print(chp,"' Not found.\n\r"); + print(con->sdu,"command: '"); + print(con->sdu,(char*)argv[curr_arg]); + print(con->sdu,"' Not found.\n\r"); } curr_arg++; } @@ -135,10 +135,7 @@ int hydranfc_execute(BaseSequentialStream *chp, int argc, const char* const* arg } //***************************************************************************** -void hydranfc_sigint(BaseSequentialStream *chp, int argc, const char* const* argv) +void hydranfc_sigint(struct hydra_console *con) { - (void)argc; - (void)argv; - - print(chp, "HydraNFC microrl ^C catched!\n\r"); + print(con, "HydraNFC microrl ^C catched!\n\r"); } diff --git a/hydranfc/hydranfc_microrl.h b/hydranfc/hydranfc_microrl.h index ab6db0af..b53dd67a 100644 --- a/hydranfc/hydranfc_microrl.h +++ b/hydranfc/hydranfc_microrl.h @@ -21,8 +21,8 @@ extern char* hydranfc_compl_world[HYDRANFC_NUM_OF_CMD + 1]; extern microrl_exec_t hydranfc_keyworld[HYDRANFC_NUM_OF_CMD]; -void hydranfc_print_help(BaseSequentialStream *chp, int argc, const char* const* argv); -int hydranfc_execute(BaseSequentialStream *chp, int argc, const char* const* argv); -void hydranfc_sigint(BaseSequentialStream *chp, int argc, const char* const* argv); +void hydranfc_print_help(struct hydra_console *con, int argc, const char* const* argv); +int hydranfc_execute(struct hydra_console *con, int argc, const char* const* argv); +void hydranfc_sigint(struct hydra_console *con); #endif /* _HYDRANFC_MICRORL_H_ */ diff --git a/main.c b/main.c index 510b3248..2fcbf94d 100644 --- a/main.c +++ b/main.c @@ -37,14 +37,16 @@ #include "hydrabus.h" #include "hydranfc.h" -typedef void (*ptFunc_microrl)(BaseSequentialStream *chp, int argc, const char* const* argv); +typedef void (*ptFunc_microrl)(struct hydra_console *con, int argc, const char* const* argv); -// create microrl object and pointer on it -microrl_t rl_sdu1; -microrl_t* prl_sdu1 = &rl_sdu1; +// create microrl objects for each console +microrl_t rl_con1; +microrl_t rl_con2; -microrl_t rl_sdu2; -microrl_t* prl_sdu2 = &rl_sdu2; +struct hydra_console consoles[] = { + { "console USB1", NULL, .sdu=&SDU1, &rl_con1 }, + { "console USB2", NULL, .sdu=&SDU2, &rl_con2 }, +}; /* * This is a periodic thread that manage hydranfc sniffer @@ -82,7 +84,7 @@ THD_FUNCTION(ThreadHydraNFC, arg) D2_OFF; chThdSleepMilliseconds(25); } - cmd_nfc_sniff_14443A((BaseSequentialStream *)NULL, 0, NULL); + cmd_nfc_sniff_14443A(NULL, 0, NULL); } if(K4_BUTTON) @@ -95,203 +97,129 @@ THD_FUNCTION(ThreadHydraNFC, arg) return 0; } -/* -* This is a periodic thread that Terminal on USB1 -*/ -THD_WORKING_AREA(waThread_Thread_Term_USB1, 2048); -THD_FUNCTION(Thread_Term_USB1, arg) +THD_FUNCTION(console, arg) { - (void)arg; - - chRegSetThreadName("Thread_Term_USB1"); - // call init with ptr to microrl instance and print callback - microrl_init(prl_sdu1, &SDU1, print); - // set callback for execute - microrl_set_execute_callback(prl_sdu1, execute); -#ifdef _USE_COMPLETE - // set callback for completion - microrl_set_complete_callback(prl_sdu1, complet); -#endif - // set callback for Ctrl+C - microrl_set_sigint_callback(prl_sdu1, sigint); - - while(1) - { - // put received char from stdin to microrl lib - chThdSleepMilliseconds(1); - microrl_insert_char(prl_sdu1, get_char(&SDU1)); - } -} + struct hydra_console *con; -/* -* This is a periodic thread that Terminal on USB2 -*/ -THD_WORKING_AREA(waThread_Thread_Term_USB2, 2048); -THD_FUNCTION(Thread_Term_USB2, arg) -{ - (void)arg; - - chRegSetThreadName("Thread_Term_USB2"); - // call init with ptr to microrl instance and print callback - microrl_init(prl_sdu2, &SDU2, print); - // set callback for execute - microrl_set_execute_callback(prl_sdu2, execute); + con = arg; + chRegSetThreadName(con->thread_name); + microrl_init(con->mrl, con, print); + microrl_set_execute_callback(con->mrl, execute); #ifdef _USE_COMPLETE - // set callback for completion - microrl_set_complete_callback(prl_sdu2, complet); + microrl_set_complete_callback(con->mrl, complet); #endif - // set callback for Ctrl+C - microrl_set_sigint_callback(prl_sdu2, sigint); - - while(1) - { - // put received char from stdin to microrl lib - chThdSleepMilliseconds(1); - microrl_insert_char(prl_sdu2, get_char(&SDU2)); - } + microrl_set_sigint_callback(con->mrl, sigint); + + while (1) { + chThdSleepMilliseconds(1); + microrl_insert_char(con->mrl, get_char(con)); + } } /* -* Application entry point. -*/ + * Application entry point. + */ #define BLINK_FAST 50 #define BLINK_SLOW 250 int main(void) { - int sleep_ms; - thread_t *shell1tp = NULL; - thread_t *shell2tp = NULL; - - /* - * System initializations. - * - HAL initialization, this also initializes the configured device drivers - * and performs the board-specific initializations. - * - Kernel initialization, the main() function becomes a thread and the - * RTOS is active. - */ - halInit(); - chSysInit(); - - scs_dwt_cycle_counter_enabled(); - - hydrabus_init(); - if(hydranfc_init() == FALSE) - { - /* Reinit HydraBus */ - hydrabus_init(); - } - - /* - * Initializes a serial-over-USB CDC driver. - */ - sduObjectInit(&SDU1); - sduStart(&SDU1, &serusb1cfg); - - sduObjectInit(&SDU2); - sduStart(&SDU2, &serusb2cfg); - - /* - * Activates the USB1 & 2 driver and then the USB bus pull-up on D+. - * Note, a delay is inserted in order to not have to disconnect the cable - * after a reset. - */ - usbDisconnectBus(serusb1cfg.usbp); - usbDisconnectBus(serusb2cfg.usbp); - - chThdSleepMilliseconds(500); - - usbStart(serusb1cfg.usbp, &usb1cfg); - /* Disable VBUS sensing on USB1 (GPIOA9) is not connected to VUSB by default) */ - #define GCCFG_NOVBUSSENS (1U<<21) - stm32_otg_t *otgp = (&USBD1)->otg; - otgp->GCCFG |= GCCFG_NOVBUSSENS; - - usbConnectBus(serusb1cfg.usbp); - - usbStart(serusb2cfg.usbp, &usb2cfg); - usbConnectBus(serusb2cfg.usbp); - - chThdSleepMilliseconds(100); /* Wait USB Enumeration */ - - /* - * Creates HydraNFC Sniffer thread. - */ - if(hydranfc_is_detected() == TRUE) - { - chThdCreateStatic(waThreadHydraNFC, sizeof(waThreadHydraNFC), NORMALPRIO, ThreadHydraNFC, NULL); - } - - /* - * Normal main() thread activity - */ - chRegSetThreadName("main"); - while (TRUE) - { - /* USB1 CDC */ - if( (!shell1tp) ) - { - if (SDU1.config->usbp->state == USB_ACTIVE) - { - /* Spawns a new shell.*/ - shell1tp = chThdCreateStatic(waThread_Thread_Term_USB1, - sizeof(waThread_Thread_Term_USB1), - NORMALPRIO, - Thread_Term_USB1, NULL); - } - } - else - { - /* If the previous shell exited.*/ - if (chThdTerminatedX(shell1tp)) - { - shell1tp = NULL; - } - } - /* USB2 CDC */ - if (!shell2tp) - { - if (SDU2.config->usbp->state == USB_ACTIVE) - { - /* Spawns a new shell.*/ - shell2tp = chThdCreateStatic(waThread_Thread_Term_USB2, - sizeof(waThread_Thread_Term_USB2), - NORMALPRIO, - Thread_Term_USB2, NULL); - } - } - else - { - /* If the previous shell exited.*/ - if (chThdTerminatedX(shell2tp)) - { - shell2tp = NULL; - } - } - - /* For test purpose HydraBus ULED blink */ - if(USER_BUTTON) - { - sleep_ms = BLINK_FAST; - }else - { - sleep_ms = BLINK_SLOW; - } - /* chThdSleep(TIME_INFINITE); */ - ULED_ON; - - chThdSleepMilliseconds(sleep_ms); - - if(USER_BUTTON) - { - sleep_ms = BLINK_FAST; - }else - { - sleep_ms = BLINK_SLOW; - } - ULED_OFF; - - chThdSleepMilliseconds(sleep_ms); - } - + int sleep_ms, i; + + /* + * System initializations. + * - HAL initialization, this also initializes the configured device + * drivers and performs the board-specific initializations. + * - Kernel initialization, the main() function becomes a thread and the + * RTOS is active. + */ + halInit(); + chSysInit(); + + scs_dwt_cycle_counter_enabled(); + + hydrabus_init(); + if(hydranfc_init() == FALSE) + /* Reinit HydraBus */ + hydrabus_init(); + + /* + * Initializes a serial-over-USB CDC driver. + */ + sduObjectInit(&SDU1); + sduStart(&SDU1, &serusb1cfg); + + sduObjectInit(&SDU2); + sduStart(&SDU2, &serusb2cfg); + + /* + * Activates the USB1 & 2 driver and then the USB bus pull-up on D+. + * Note, a delay is inserted in order to not have to disconnect the cable + * after a reset. + */ + usbDisconnectBus(serusb1cfg.usbp); + usbDisconnectBus(serusb2cfg.usbp); + + chThdSleepMilliseconds(500); + + usbStart(serusb1cfg.usbp, &usb1cfg); + /* + * Disable VBUS sensing on USB1 (GPIOA9) is not connected to VUSB + * by default) + */ +#define GCCFG_NOVBUSSENS (1U<<21) + stm32_otg_t *otgp = (&USBD1)->otg; + otgp->GCCFG |= GCCFG_NOVBUSSENS; + + usbConnectBus(serusb1cfg.usbp); + + usbStart(serusb2cfg.usbp, &usb2cfg); + usbConnectBus(serusb2cfg.usbp); + + /* Wait for USB Enumeration. */ + chThdSleepMilliseconds(100); + + /* + * Creates HydraNFC Sniffer thread. + */ + if(hydranfc_is_detected() == TRUE) + chThdCreateStatic(waThreadHydraNFC, sizeof(waThreadHydraNFC), + NORMALPRIO, ThreadHydraNFC, NULL); + + /* + * Normal main() thread activity. + */ + chRegSetThreadName("main"); + while (TRUE) { + for (i = 0; i < 2; i++) { + if (!consoles[i].thread) { + if (consoles[i].sdu->config->usbp->state != USB_ACTIVE) + continue; + /* Spawn new console thread.*/ + consoles[i].thread = chThdCreateFromHeap(NULL, + CONSOLE_WA_SIZE, NORMALPRIO, console, &consoles[i]); + } else { + if (chThdTerminatedX(consoles[i].thread)) + /* This console thread terminated. */ + consoles[i].thread = NULL; + } + } + + /* For test purpose HydraBus ULED blink */ + if(USER_BUTTON) + sleep_ms = BLINK_FAST; + else + sleep_ms = BLINK_SLOW; + ULED_ON; + + chThdSleepMilliseconds(sleep_ms); + + if(USER_BUTTON) + sleep_ms = BLINK_FAST; + else + sleep_ms = BLINK_SLOW; + ULED_OFF; + + chThdSleepMilliseconds(sleep_ms); + } } From 69b6e965f4f22cbd33bb45baf0e115c94cf95eec Mon Sep 17 00:00:00 2001 From: Bert Vermeulen Date: Sun, 12 Oct 2014 16:58:38 +0200 Subject: [PATCH 3/3] Use t_hydra_console instead of struct hydra_console. --- common/common.c | 12 ++++++------ common/common.h | 16 ++++++++-------- common/microrl_callback.h | 4 ++-- common/microrl_common.c | 10 +++++----- common/microrl_common.h | 2 +- common/microsd.c | 18 +++++++++--------- common/microsd.h | 16 ++++++++-------- hydrabus/hydrabus_microrl.c | 6 +++--- hydrabus/hydrabus_microrl.h | 6 +++--- hydranfc/hydranfc.c | 6 +++--- hydranfc/hydranfc.h | 8 ++++---- hydranfc/hydranfc_cmd_sniff.c | 2 +- hydranfc/hydranfc_microrl.c | 6 +++--- hydranfc/hydranfc_microrl.h | 6 +++--- main.c | 6 +++--- 15 files changed, 62 insertions(+), 62 deletions(-) diff --git a/common/common.c b/common/common.c index 17bbfb5a..6bf1ed76 100644 --- a/common/common.c +++ b/common/common.c @@ -71,7 +71,7 @@ void DelayUs(uint32_t delay_us) osalSysPolledDelayX(US2RTC(STM32_HCLK, delay_us)); } -void cmd_mem(struct hydra_console *con, int argc, const char* const* argv) +void cmd_mem(t_hydra_console *con, int argc, const char* const* argv) { size_t n, size; @@ -84,7 +84,7 @@ void cmd_mem(struct hydra_console *con, int argc, const char* const* argv) chprintf(con->bss, "heap free total : %u bytes\r\n", size); } -void cmd_threads(struct hydra_console *con, int argc, const char* const* argv) +void cmd_threads(t_hydra_console *con, int argc, const char* const* argv) { static const char *states[] = {CH_STATE_NAMES}; thread_t *tp; @@ -104,7 +104,7 @@ void cmd_threads(struct hydra_console *con, int argc, const char* const* argv) } -void cmd_test(struct hydra_console *con, int argc, const char* const* argv) +void cmd_test(t_hydra_console *con, int argc, const char* const* argv) { thread_t *tp; @@ -120,12 +120,12 @@ void cmd_test(struct hydra_console *con, int argc, const char* const* argv) chThdWait(tp); } -void cmd_info(struct hydra_console *con, int argc, const char* const* argv) +void cmd_info(t_hydra_console *con, int argc, const char* const* argv) { cmd_init(con, argc, argv); } -void cmd_init(struct hydra_console *con, int argc, const char* const* argv) +void cmd_init(t_hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; @@ -207,7 +207,7 @@ void cmd_init(struct hydra_console *con, int argc, const char* const* argv) #define waitcycles(n) ( wait_nbcycles(n) ) /* Just debug to check Timing and accuracy with output pin */ -void cmd_dbg(struct hydra_console *con, int argc, const char* const* argv) +void cmd_dbg(t_hydra_console *con, int argc, const char* const* argv) { (void)argv; uint8_t i; diff --git a/common/common.h b/common/common.h index af86a53d..2de7ec9a 100644 --- a/common/common.h +++ b/common/common.h @@ -70,7 +70,7 @@ typedef struct /* How much thread working area to allocate per console. */ #define CONSOLE_WA_SIZE 2048 -struct hydra_console { +typedef struct hydra_console { char *thread_name; thread_t *thread; union { @@ -78,13 +78,13 @@ struct hydra_console { BaseSequentialStream *bss; }; microrl_t *mrl; -}; +} t_hydra_console; -void cmd_info(struct hydra_console *con, int argc, const char* const* argv); -void cmd_init(struct hydra_console *con, int argc, const char* const* argv); -void cmd_mem(struct hydra_console *con, int argc, const char* const* argv); -void cmd_threads(struct hydra_console *con, int argc, const char* const* argv); -void cmd_test(struct hydra_console *con, int argc, const char* const* argv); -void cmd_dbg(struct hydra_console *con, int argc, const char* const* argv); +void cmd_info(t_hydra_console *con, int argc, const char* const* argv); +void cmd_init(t_hydra_console *con, int argc, const char* const* argv); +void cmd_mem(t_hydra_console *con, int argc, const char* const* argv); +void cmd_threads(t_hydra_console *con, int argc, const char* const* argv); +void cmd_test(t_hydra_console *con, int argc, const char* const* argv); +void cmd_dbg(t_hydra_console *con, int argc, const char* const* argv); #endif /* _COMMON_H_ */ diff --git a/common/microrl_callback.h b/common/microrl_callback.h index 87844487..cf8382e4 100644 --- a/common/microrl_callback.h +++ b/common/microrl_callback.h @@ -19,7 +19,7 @@ #include "ch.h" -typedef void (*ptFunc)(struct hydra_console *con, int argc, const char* const* argv); +typedef void (*ptFunc)(t_hydra_console *con, int argc, const char* const* argv); typedef struct { @@ -31,7 +31,7 @@ typedef struct void print(void *user_handle, const char *str); // get_char from stream -char get_char(struct hydra_console *con); +char get_char(t_hydra_console *con); // execute callback unsigned int execute(void *user_handle, int argc, const char* const* argv); diff --git a/common/microrl_common.c b/common/microrl_common.c index 2097e643..b38fde70 100644 --- a/common/microrl_common.c +++ b/common/microrl_common.c @@ -33,7 +33,7 @@ char** compl_world; microrl_exec_t* keyworld; -void print_clear(struct hydra_console *con, int argc, const char* const* argv) +void print_clear(t_hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; @@ -45,7 +45,7 @@ void print_clear(struct hydra_console *con, int argc, const char* const* argv) //***************************************************************************** void print(void *user_handle, const char *str) { - struct hydra_console *con; + t_hydra_console *con; int len; if(!str) @@ -59,7 +59,7 @@ void print(void *user_handle, const char *str) } //***************************************************************************** -char get_char(struct hydra_console *con) +char get_char(t_hydra_console *con) { uint8_t car; @@ -130,7 +130,7 @@ char** complet(void* user_handle, int argc, const char * const * argv) // do what you want here, but don't write to argv!!! read only!! unsigned int execute(void *user_handle, int argc, const char* const* argv) { - struct hydra_console *con; + t_hydra_console *con; con = user_handle; if(hydranfc_is_detected()) @@ -142,7 +142,7 @@ unsigned int execute(void *user_handle, int argc, const char* const* argv) //***************************************************************************** void sigint(void *user_handle) { - struct hydra_console *con; + t_hydra_console *con; con = user_handle; if(hydranfc_is_detected()) diff --git a/common/microrl_common.h b/common/microrl_common.h index a22c8625..0e34cdbb 100644 --- a/common/microrl_common.h +++ b/common/microrl_common.h @@ -17,6 +17,6 @@ #ifndef _MICRORL_COMMON_H_ #define _MICRORL_COMMON_H_ -void print_clear(struct hydra_console *con, int argc, const char* const* argv); +void print_clear(t_hydra_console *con, int argc, const char* const* argv); #endif /* _MICRORL_COMMON_H_ */ diff --git a/common/microsd.c b/common/microsd.c index 2397337a..c21b2d89 100644 --- a/common/microsd.c +++ b/common/microsd.c @@ -135,7 +135,7 @@ void fillbuffers(uint8_t pattern) /** * SDIO Test Non Destructive */ -void cmd_sdiotest(struct hydra_console *con, int argc, const char* const* argv) +void cmd_sdiotest(t_hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; @@ -391,7 +391,7 @@ void cmd_sdiotest(struct hydra_console *con, int argc, const char* const* argv) } } -void cmd_sdc(struct hydra_console *con, int argc, const char* const* argv) +void cmd_sdc(t_hydra_console *con, int argc, const char* const* argv) { static const char *mode[] = {"SDV11", "SDV20", "MMC", NULL}; systime_t start, end; @@ -497,7 +497,7 @@ void cmd_sdc(struct hydra_console *con, int argc, const char* const* argv) sdcDisconnect(&SDCD1); } -static FRESULT scan_files(struct hydra_console *con, char *path) +static FRESULT scan_files(t_hydra_console *con, char *path) { FRESULT res; FILINFO fno; @@ -667,7 +667,7 @@ int umount(void) return 0; } -void cmd_sd_mount(struct hydra_console *con, int argc, const char* const* argv) +void cmd_sd_mount(t_hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; @@ -702,7 +702,7 @@ void cmd_sd_mount(struct hydra_console *con, int argc, const char* const* argv) fs_ready = TRUE; } -void cmd_sd_umount(struct hydra_console *con, int argc, const char* const* argv) +void cmd_sd_umount(t_hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; @@ -720,7 +720,7 @@ void cmd_sd_umount(struct hydra_console *con, int argc, const char* const* argv) fs_ready = FALSE; } -void cmd_sd_ls(struct hydra_console *con, int argc, const char* const* argv) +void cmd_sd_ls(t_hydra_console *con, int argc, const char* const* argv) { FRESULT err; uint32_t clusters; @@ -779,7 +779,7 @@ void cmd_sd_ls(struct hydra_console *con, int argc, const char* const* argv) } /* Call only with len=multiples of 16 (unless end of dump). */ -static void dump_hexbuf(struct hydra_console *con, uint32_t offset, +static void dump_hexbuf(t_hydra_console *con, uint32_t offset, const uint8_t *buf, int len) { int b, i; @@ -805,7 +805,7 @@ static void dump_hexbuf(struct hydra_console *con, uint32_t offset, } } -void cmd_sd_cat(struct hydra_console *con, int argc, const char* const* argv) +void cmd_sd_cat(t_hydra_console *con, int argc, const char* const* argv) { #define MAX_FILE_SIZE (524288) bool hex; @@ -885,7 +885,7 @@ void cmd_sd_cat(struct hydra_console *con, int argc, const char* const* argv) /** * SDIO Test Destructive */ -void cmd_sd_erase(struct hydra_console *con, int argc, const char* const* argv){ +void cmd_sd_erase(t_hydra_console *con, int argc, const char* const* argv){ (void)argc; (void)argv; uint32_t i = 0; diff --git a/common/microsd.h b/common/microsd.h index c7305fb7..fe06979d 100644 --- a/common/microsd.h +++ b/common/microsd.h @@ -33,13 +33,13 @@ int mount(void); int umount(void); /* Shell commands */ -void cmd_sd_mount(struct hydra_console *con, int argc, const char* const* argv); -void cmd_sd_umount(struct hydra_console *con, int argc, const char* const* argv); -void cmd_sd_ls(struct hydra_console *con, int argc, const char* const* argv); -void cmd_sd_cat(struct hydra_console *con, int argc, const char* const* argv); - -void cmd_sdiotest(struct hydra_console *con, int argc, const char* const* argv); -void cmd_sd_erase(struct hydra_console *con, int argc, const char* const* argv); -void cmd_sdc(struct hydra_console *con, int argc, const char* const* argv); +void cmd_sd_mount(t_hydra_console *con, int argc, const char* const* argv); +void cmd_sd_umount(t_hydra_console *con, int argc, const char* const* argv); +void cmd_sd_ls(t_hydra_console *con, int argc, const char* const* argv); +void cmd_sd_cat(t_hydra_console *con, int argc, const char* const* argv); + +void cmd_sdiotest(t_hydra_console *con, int argc, const char* const* argv); +void cmd_sd_erase(t_hydra_console *con, int argc, const char* const* argv); +void cmd_sdc(t_hydra_console *con, int argc, const char* const* argv); #endif /* _MICROSD_H_ */ diff --git a/hydrabus/hydrabus_microrl.c b/hydrabus/hydrabus_microrl.c index 41e5818e..c653dce7 100644 --- a/hydrabus/hydrabus_microrl.c +++ b/hydrabus/hydrabus_microrl.c @@ -69,7 +69,7 @@ microrl_exec_t hydrabus_keyworld[HYDRABUS_NUM_OF_CMD] = char* hydrabus_compl_world[HYDRABUS_NUM_OF_CMD + 1]; //***************************************************************************** -void hydrabus_print_help(struct hydra_console *con, int argc, const char* const* argv) +void hydrabus_print_help(t_hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; @@ -92,7 +92,7 @@ void hydrabus_print_help(struct hydra_console *con, int argc, const char* const* //***************************************************************************** // execute callback for microrl library // do what you want here, but don't write to argv!!! read only!! -int hydrabus_execute(struct hydra_console *con, int argc, const char* const* argv) +int hydrabus_execute(t_hydra_console *con, int argc, const char* const* argv) { bool cmd_found; int curr_arg = 0; @@ -126,7 +126,7 @@ int hydrabus_execute(struct hydra_console *con, int argc, const char* const* arg } //***************************************************************************** -void hydrabus_sigint(struct hydra_console *con) +void hydrabus_sigint(t_hydra_console *con) { /* Hit ctrl-U and enter. */ microrl_insert_char(con->mrl, 0x15); diff --git a/hydrabus/hydrabus_microrl.h b/hydrabus/hydrabus_microrl.h index 3cb03f11..c29038c8 100644 --- a/hydrabus/hydrabus_microrl.h +++ b/hydrabus/hydrabus_microrl.h @@ -21,8 +21,8 @@ extern char* hydrabus_compl_world[HYDRABUS_NUM_OF_CMD + 1]; extern microrl_exec_t hydrabus_keyworld[HYDRABUS_NUM_OF_CMD]; -void hydrabus_print_help(struct hydra_console *con, int argc, const char* const* argv); -int hydrabus_execute(struct hydra_console *con, int argc, const char* const* argv); -void hydrabus_sigint(struct hydra_console *con); +void hydrabus_print_help(t_hydra_console *con, int argc, const char* const* argv); +int hydrabus_execute(t_hydra_console *con, int argc, const char* const* argv); +void hydrabus_sigint(t_hydra_console *con); #endif /* _HYDRABUS_MICRORL_H_ */ diff --git a/hydranfc/hydranfc.c b/hydranfc/hydranfc.c index 2536381c..790e3eb7 100644 --- a/hydranfc/hydranfc.c +++ b/hydranfc/hydranfc.c @@ -230,7 +230,7 @@ bool hydranfc_init(void) return TRUE; } -void cmd_nfc_vicinity(struct hydra_console *con, int argc, const char* const* argv) +void cmd_nfc_vicinity(t_hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; @@ -344,7 +344,7 @@ void cmd_nfc_vicinity(struct hydra_console *con, int argc, const char* const* ar chprintf(con->bss, "Test nfv ISO15693/Vicinity end\r\n"); } -void cmd_nfc_mifare(struct hydra_console *con, int argc, const char* const* argv) +void cmd_nfc_mifare(t_hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; @@ -521,7 +521,7 @@ void cmd_nfc_mifare(struct hydra_console *con, int argc, const char* const* argv chprintf(con->bss, "Test nfm ISO14443-A/Mifare end\r\n"); } -void cmd_nfc_dump_regs(struct hydra_console *con, int argc, const char* const* argv) +void cmd_nfc_dump_regs(t_hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; diff --git a/hydranfc/hydranfc.h b/hydranfc/hydranfc.h index 5a140cce..fcbb9d8e 100644 --- a/hydranfc/hydranfc.h +++ b/hydranfc/hydranfc.h @@ -26,9 +26,9 @@ extern volatile int irq_end_rx; bool hydranfc_init(void); bool hydranfc_is_detected(void); -void cmd_nfc_vicinity(struct hydra_console *con, int argc, const char* const* argv); -void cmd_nfc_mifare(struct hydra_console *con, int argc, const char* const* argv); -void cmd_nfc_dump_regs(struct hydra_console *con, int argc, const char* const* argv); -void cmd_nfc_sniff_14443A(struct hydra_console *con, int argc, const char* const* argv); +void cmd_nfc_vicinity(t_hydra_console *con, int argc, const char* const* argv); +void cmd_nfc_mifare(t_hydra_console *con, int argc, const char* const* argv); +void cmd_nfc_dump_regs(t_hydra_console *con, int argc, const char* const* argv); +void cmd_nfc_sniff_14443A(t_hydra_console *con, int argc, const char* const* argv); #endif /* _HYDRANFC_H_ */ diff --git a/hydranfc/hydranfc_cmd_sniff.c b/hydranfc/hydranfc_cmd_sniff.c index 62745ac6..1bb99336 100644 --- a/hydranfc/hydranfc_cmd_sniff.c +++ b/hydranfc/hydranfc_cmd_sniff.c @@ -483,7 +483,7 @@ void sniff_write_8b_ASCII_HEX(uint8_t data, bool add_space) } } -void cmd_nfc_sniff_14443A(struct hydra_console *con, int argc, const char* const* argv) +void cmd_nfc_sniff_14443A(t_hydra_console *con, int argc, const char* const* argv) { (void)con; (void)argc; diff --git a/hydranfc/hydranfc_microrl.c b/hydranfc/hydranfc_microrl.c index dac766aa..122125d5 100644 --- a/hydranfc/hydranfc_microrl.c +++ b/hydranfc/hydranfc_microrl.c @@ -73,7 +73,7 @@ microrl_exec_t hydranfc_keyworld[HYDRANFC_NUM_OF_CMD] = char* hydranfc_compl_world[HYDRANFC_NUM_OF_CMD + 1]; //***************************************************************************** -void hydranfc_print_help(struct hydra_console *con, int argc, const char* const* argv) +void hydranfc_print_help(t_hydra_console *con, int argc, const char* const* argv) { (void)argc; (void)argv; @@ -101,7 +101,7 @@ void hydranfc_print_help(struct hydra_console *con, int argc, const char* const* //***************************************************************************** // execute callback for microrl library // do what you want here, but don't write to argv!!! read only!! -int hydranfc_execute(struct hydra_console *con, int argc, const char* const* argv) +int hydranfc_execute(t_hydra_console *con, int argc, const char* const* argv) { bool cmd_found; int curr_arg = 0; @@ -135,7 +135,7 @@ int hydranfc_execute(struct hydra_console *con, int argc, const char* const* arg } //***************************************************************************** -void hydranfc_sigint(struct hydra_console *con) +void hydranfc_sigint(t_hydra_console *con) { print(con, "HydraNFC microrl ^C catched!\n\r"); } diff --git a/hydranfc/hydranfc_microrl.h b/hydranfc/hydranfc_microrl.h index b53dd67a..a5e29e22 100644 --- a/hydranfc/hydranfc_microrl.h +++ b/hydranfc/hydranfc_microrl.h @@ -21,8 +21,8 @@ extern char* hydranfc_compl_world[HYDRANFC_NUM_OF_CMD + 1]; extern microrl_exec_t hydranfc_keyworld[HYDRANFC_NUM_OF_CMD]; -void hydranfc_print_help(struct hydra_console *con, int argc, const char* const* argv); -int hydranfc_execute(struct hydra_console *con, int argc, const char* const* argv); -void hydranfc_sigint(struct hydra_console *con); +void hydranfc_print_help(t_hydra_console *con, int argc, const char* const* argv); +int hydranfc_execute(t_hydra_console *con, int argc, const char* const* argv); +void hydranfc_sigint(t_hydra_console *con); #endif /* _HYDRANFC_MICRORL_H_ */ diff --git a/main.c b/main.c index 2fcbf94d..c6519f49 100644 --- a/main.c +++ b/main.c @@ -37,13 +37,13 @@ #include "hydrabus.h" #include "hydranfc.h" -typedef void (*ptFunc_microrl)(struct hydra_console *con, int argc, const char* const* argv); +typedef void (*ptFunc_microrl)(t_hydra_console *con, int argc, const char* const* argv); // create microrl objects for each console microrl_t rl_con1; microrl_t rl_con2; -struct hydra_console consoles[] = { +t_hydra_console consoles[] = { { "console USB1", NULL, .sdu=&SDU1, &rl_con1 }, { "console USB2", NULL, .sdu=&SDU2, &rl_con2 }, }; @@ -99,7 +99,7 @@ THD_FUNCTION(ThreadHydraNFC, arg) THD_FUNCTION(console, arg) { - struct hydra_console *con; + t_hydra_console *con; con = arg; chRegSetThreadName(con->thread_name);