diff --git a/apps/boot/application/func/firmware.c b/apps/boot/application/func/firmware.c index fe41d04..5541197 100644 --- a/apps/boot/application/func/firmware.c +++ b/apps/boot/application/func/firmware.c @@ -56,6 +56,7 @@ void FM_Init (void) #endif #endif +#if 0 printf("onchip size : 0x%lX\r\n", SIZE_ONCHIP_FLASH); printf("0x%08lX+0x%lX 'parameters'.\r\n", BASE_PARAMETERS, SIZE_PART_PARAMETERS); printf("0x%08X+0x%X 'app'.\r\n", _flash_app_part.addr, _flash_app_part.len); @@ -65,6 +66,7 @@ void FM_Init (void) printf("0x%08X+0x%X 'factory'.\r\n", _flash_factory_part.addr, _flash_app_part.len); #endif #endif +#endif #if (CONFIG_DECRYPT) AES_init_ctx_iv(&aesCtx, (uint8_t *)AES256_KEY, (uint8_t *)AES256_IV); diff --git a/apps/boot/application/main.c b/apps/boot/application/main.c index 6082407..5304dbe 100644 --- a/apps/boot/application/main.c +++ b/apps/boot/application/main.c @@ -168,7 +168,7 @@ int main (void) MX_GPIO_Init(); MX_DMA_Init(); MX_USART_Init(); - +#if 0 printf("\r\n\r\n========================================\r\n"); printf("\t%s boot V%d.%d.%d\r\n", NAME_CHIP, VERSION_MAIN, VERSION_SUB, VERSION_FIX); @@ -176,7 +176,10 @@ int main (void) printf("Chip UID: %08X - %08X - %08X\r\n", HAL_GetUIDw0(), HAL_GetUIDw1(), HAL_GetUIDw2()); printf("========================================\r\n"); - +#else + printf("\tboot V%d.%d.%d built @ %s\r\n", + VERSION_MAIN, VERSION_SUB, VERSION_FIX, BUILD_TIMESTAMP); +#endif APP_Init(); while (1) { diff --git a/apps/chrg/applications/bsp/chrg_vcom.c b/apps/chrg/applications/bsp/chrg_vcom.c index c4a974b..34e85bd 100644 --- a/apps/chrg/applications/bsp/chrg_vcom.c +++ b/apps/chrg/applications/bsp/chrg_vcom.c @@ -3,6 +3,8 @@ #include #include "chrg_vcom.h" +#include "chrg_lcd.h" + #define DBG_TAG "chrg.vcom" #include @@ -34,6 +36,8 @@ int chrg_vcom_console_init (void) { rt_console_set_device(DEV_NAME_VCOM); + chrg_lcd_init(); + return 0; } diff --git a/apps/chrg/applications/main.c b/apps/chrg/applications/main.c index dd3f21c..b825a15 100644 --- a/apps/chrg/applications/main.c +++ b/apps/chrg/applications/main.c @@ -7,11 +7,11 @@ #include #include "shell.h" -#include "main.h" #include "chrg_wdt.h" void show_app_version (void) { +#if 0 rt_kprintf("\r\n\r\n================================================\r\n"); rt_kprintf("\tcharger control via RT-Thread v%d.%d.%d\r\n", RT_VERSION_MAJOR, RT_VERSION_MINOR, RT_VERSION_PATCH); @@ -19,6 +19,10 @@ void show_app_version (void) rt_kprintf("\tUID: %08X %08X %08X\r\n", HAL_GetUIDw2(), HAL_GetUIDw1(), HAL_GetUIDw0()); rt_kprintf("================================================\r\n"); +#else + rt_kprintf("\tcharger control via RT-Thread v%d.%d.%d built @ %s, %s\r\n", + RT_VERSION_MAJOR, RT_VERSION_MINOR, RT_VERSION_PATCH, __DATE__, __TIME__); +#endif } int main(void) diff --git a/apps/chrg/applications/main.h b/apps/chrg/applications/main.h deleted file mode 100644 index a6d6dfc..0000000 --- a/apps/chrg/applications/main.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __MAIN_H__ -#define __MAIN_H__ - -#include - - -#endif - diff --git a/apps/chrg/applications/thread/chrg_lcd.c b/apps/chrg/applications/thread/chrg_lcd.c index 3b7b08a..277f95d 100644 --- a/apps/chrg/applications/thread/chrg_lcd.c +++ b/apps/chrg/applications/thread/chrg_lcd.c @@ -1,4 +1,155 @@ +#include +#include + +#include "chrg_roll.h" +#include "chrg_north.h" +#include "chrg_south.h" #include "chrg_lcd.h" +#define LOG_TAG "chrg.lcd" +#define DBG_LEVEL DBG_LOG +#include + +struct chrg_lcd_t chrglcd = { + .name = THR_NAME_LCD, + .devname = DEV_NAME_LCD, + .tid = RT_NULL, + .tty = RT_NULL, + +}; + + +static int chrg_lcd_parse (char *recv) +{ + + if (strstr(recv, "main.CH1_RunStop.txt")) { + if (strstr(recv, "run")) { + chrgroll.en_nor[IDX_CH_0] = 1; + } else if (strstr(recv, "stop")) { + chrgroll.en_nor[IDX_CH_0] = 0; + } + +// ... + + } + + return 0; +} + + +int chrg_lcd_send (char *cmd) +{ + rt_ssize_t ret = -1; + struct chrg_tty_t *pTTY = chrglcd.tty; + if (RT_NULL == cmd) { + return -1; + } + + int len = strlen(cmd); + rt_uint8_t *data = rt_malloc(len+3); + if (RT_NULL == data) { + LOG_E("malloc failed."); + return -1; + } + + memcpy(data, cmd, len); + memset(&data[len], 0xFF, 3); + + if (RT_NULL != pTTY) { + ret = chrg_tty_send(pTTY, data, len+3); + } + + if (RT_NULL != data) { + rt_free(data); + data = RT_NULL; + } + + return ret; +} + +static void chrg_lcd_thread_entry (void *data) +{ + struct chrg_lcd_t *pLCD = (struct chrg_lcd_t *)data; + + if ((RT_NULL == pLCD)||(RT_NULL == pLCD->tty)) { + return ; + } + + int len = 0; + struct chrg_tty_t *pTTY = pLCD->tty; + + chrg_tty_set_recv_tmo(pTTY, 100); + if (chrg_tty_connect(pTTY) != RT_EOK) { + chrg_tty_destory(pTTY); + return; + } + + while (1) { + len = chrg_tty_recv(pTTY, pLCD->rx_buf, sizeof(pLCD->rx_buf)); + if (len <= 0) { + rt_thread_mdelay(1); + continue; + } + + rt_kprintf("%s\r\n", (char *)pLCD->rx_buf); + + chrg_lcd_parse((char *)pLCD->rx_buf); + } + +} + +int chrg_lcd_init (void) +{ + rt_err_t ret; + struct chrg_lcd_t *pLCD = &chrglcd; + + pLCD->tty = chrg_tty_create(pLCD->devname, 115200, 0, -1, 1); + if (RT_NULL == pLCD->tty) { + LOG_E("tty can't create."); + return -1; + } + + rt_memset(pLCD->rx_buf, 0, SIZE_BUF_TTY); + + ret = rt_mutex_init(&pLCD->lock, pLCD->name, RT_IPC_FLAG_FIFO); + if (ret != RT_EOK) { + LOG_E("init mutex '%s' failed.", pLCD->name); + return ret; + } + + pLCD->tid = rt_thread_create(pLCD->name, chrg_lcd_thread_entry, pLCD, 4096, + RT_MAIN_THREAD_PRIORITY, 20); + if (RT_NULL != pLCD->tid) { + rt_thread_startup(pLCD->tid); + } else { + LOG_E("create thread '%s' failed.", pLCD->name); + } + + return 0; +} + + +//INIT_APP_EXPORT(chrg_lcd_init); + +#if 1 +static int lcdsend(rt_uint8_t argc, char **argv) +{ + if (2 != argc) { + rt_kprintf("help : %s \r\n e.g. %s main.CH1_Volt_Show.txt=\"5.000\"", + argv[0], argv[0]); + return -1; + } + + chrg_lcd_send(argv[1]); + + return 0; +} + + +MSH_CMD_EXPORT(lcdsend, lcd send test); +#endif + + + diff --git a/apps/chrg/applications/thread/chrg_lcd.h b/apps/chrg/applications/thread/chrg_lcd.h index 856043f..0f5738c 100644 --- a/apps/chrg/applications/thread/chrg_lcd.h +++ b/apps/chrg/applications/thread/chrg_lcd.h @@ -1,6 +1,29 @@ #ifndef __CHRG_LCD_H__ #define __CHRG_LCD_H__ +#include + +#include "chrg_tty.h" + +#define THR_NAME_LCD "thr.lcd" +#define DEV_NAME_LCD "uart2" + +struct chrg_lcd_t { + const char *name; + const char *devname; + struct rt_thread *tid; + struct rt_mutex lock; + + struct chrg_tty_t *tty; + rt_uint8_t rx_buf[SIZE_BUF_TTY]; + +}; + +extern struct chrg_lcd_t chrglcd; + +extern int chrg_lcd_send (char *cmd); + +extern int chrg_lcd_init (void); #endif diff --git a/apps/chrg/applications/thread/chrg_roll.c b/apps/chrg/applications/thread/chrg_roll.c index 80f4d61..4ccd311 100644 --- a/apps/chrg/applications/thread/chrg_roll.c +++ b/apps/chrg/applications/thread/chrg_roll.c @@ -76,7 +76,7 @@ static void chrg_roll_thread_entry (void *data) sink_get_vc(pSW->sink.loadv, pSW->sink.loadc); } - rt_kprintf("Nor[%d].%d\r\n", pNOR->idx, pSW->id); + //rt_kprintf("Nor[%d].%d\r\n", pNOR->idx, pSW->id); } } else { sou_idx = pROLL->idx - TOTAL_CHS; @@ -89,11 +89,11 @@ static void chrg_roll_thread_entry (void *data) chrg_switch_south(pSOU->idx); pSW = &pSOU->sw[pSOU->idx]; - // todo pkg send if (ID_ELOAD == pSW->id) { source_get_vc(pSW->source.voltage, pSW->source.current); + // change pro modbus } - rt_kprintf("Sou[%d].%d\r\n", pSOU->idx, pSW->id); + //rt_kprintf("Sou[%d].%d\r\n", pSOU->idx, pSW->id); } } diff --git a/apps/chrg/applications/thread/chrg_south.c b/apps/chrg/applications/thread/chrg_south.c index 56f3435..7ae321d 100644 --- a/apps/chrg/applications/thread/chrg_south.c +++ b/apps/chrg/applications/thread/chrg_south.c @@ -83,7 +83,7 @@ static int chrg_south_init (void) rt_err_t ret; struct chrg_south_t *pSOU = &chrgsouth; - pSOU->tty = chrg_tty_create(pSOU->devname, 2000000, 0, -1, 1); + pSOU->tty = chrg_tty_create(pSOU->devname, 115200, 0, -1, 1); if (RT_NULL == pSOU->tty) { LOG_E("tty can't create."); return -1; @@ -111,10 +111,11 @@ static int chrg_south_init (void) INIT_APP_EXPORT(chrg_south_init); -#if 0 +#if 1 static int south_send(rt_uint8_t argc, char **argv) { - return chrg_south_send("1234567890abcdef", 16); + return source_get_vc(5000, 1000); + //return chrg_south_send("1234567890abcdef", 16); } diff --git a/apps/chrg/applications/utils/chrg_pkg.c b/apps/chrg/applications/utils/chrg_pkg.c index e07498c..ae9a84f 100644 --- a/apps/chrg/applications/utils/chrg_pkg.c +++ b/apps/chrg/applications/utils/chrg_pkg.c @@ -2,6 +2,8 @@ #include #include +#include "chrg_north.h" +#include "chrg_south.h" #include "chrg_pkg.h" #include "chrg_utils.h" @@ -38,10 +40,10 @@ int chrg_pkg_send (eIDX_TTY idx, rt_uint8_t *data, rt_uint16_t len) switch (idx) { case IDX_TTY_NORTH: -// pTTY = chrgnorth.tty; + pTTY = chrgnorth.tty; break; case IDX_TTY_SOUTH: -// pTTY = chrgsouth.tty; + pTTY = chrgsouth.tty; break; default: return -1; diff --git a/docs/1.HMI b/docs/1.HMI index 58f0285..4274306 100644 Binary files a/docs/1.HMI and b/docs/1.HMI differ