From b7a2df558345b6c2f25ff9037ba689499acda0b0 Mon Sep 17 00:00:00 2001 From: wmano Date: Mon, 22 Sep 2025 23:29:53 +0800 Subject: [PATCH] fix sn74lv4052a --- .gitignore | 1 - apps/boot/boot.uvprojx | 2 +- apps/chrg/applications/bsp/chrg_clk.c | 42 +++++++++++++++++----- apps/chrg/applications/bsp/chrg_clk.h | 3 ++ apps/chrg/applications/bsp/chrg_switch.c | 17 ++++++--- apps/chrg/applications/thread/chrg_north.c | 3 +- apps/chrg/chrg.uvprojx | 2 +- mdks/all_mdks.uvmpw | 1 - 8 files changed, 53 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index a5e06f4..71d7e9c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,6 @@ build Debug .vs -rtthread settings documentation/html *~ diff --git a/apps/boot/boot.uvprojx b/apps/boot/boot.uvprojx index 11b31c0..b5ae971 100644 --- a/apps/boot/boot.uvprojx +++ b/apps/boot/boot.uvprojx @@ -16,7 +16,7 @@ STM32F405RGTx STMicroelectronics - Keil.STM32F4xx_DFP.2.17.1 + Keil.STM32F4xx_DFP.3.1.0 https://www.keil.com/pack/ IRAM(0x20000000,0x00020000) IRAM2(0x10000000,0x00010000) IROM(0x08000000,0x00100000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE diff --git a/apps/chrg/applications/bsp/chrg_clk.c b/apps/chrg/applications/bsp/chrg_clk.c index 208ae96..6542cf3 100644 --- a/apps/chrg/applications/bsp/chrg_clk.c +++ b/apps/chrg/applications/bsp/chrg_clk.c @@ -10,6 +10,8 @@ #include struct chrg_clk_t chrgclk = { + .name = TMR_NAME_CLOCK, + .timer_fd = RT_NULL, .cnt = 0, }; @@ -20,26 +22,26 @@ static void chrg_clk_callback (void *args) pCLK->cnt++; if (pCLK->cnt % 60 == 0) { - rt_kprintf("R : %d mins\r\n", pCLK->cnt/60); + //rt_kprintf("R : %d mins\r\n", pCLK->cnt/60); } - //rt_kprintf("\r\n"); + } static int chrg_clk_init (void) { rt_err_t ret = RT_EOK; - rt_timer_t timer_fd; + struct chrg_clk_t *pCLK = &chrgclk; - timer_fd = rt_timer_create("clk", chrg_clk_callback, - &chrgclk, RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC); - if (timer_fd == RT_NULL) { - //rt_kprintf("create clk.\r\n"); + pCLK->timer_fd = rt_timer_create(pCLK->name, chrg_clk_callback, + pCLK, RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC); + if (pCLK->timer_fd == RT_NULL) { + LOG_E("create '%s' failed.", pCLK->name); return -1; } else { - ret = rt_timer_start(timer_fd); + ret = rt_timer_start(pCLK->timer_fd); if (ret != RT_EOK) { - rt_kprintf("start clk failed.\r\n"); + LOG_E("start '%s' failed.", pCLK->name); return ret; } } @@ -50,3 +52,25 @@ static int chrg_clk_init (void) INIT_APP_EXPORT(chrg_clk_init); +int uptime (void) +{ + struct chrg_clk_t *pCLK = &chrgclk; + + if (pCLK != RT_NULL) { + int day = pCLK->cnt/86400; + int hour = (pCLK->cnt%86400)/3600; + int minute = ((pCLK->cnt%86400)%3600)/60; + int second = ((pCLK->cnt%86400)%3600)%60; + rt_tick_t tick = rt_tick_get(); + + rt_kprintf("up %d days, %02d:%02d:%02d.%03d \r\n", + day, hour, minute, second, tick%1000); + } + + return 0; +} + +MSH_CMD_EXPORT(uptime, System running time.); + + + diff --git a/apps/chrg/applications/bsp/chrg_clk.h b/apps/chrg/applications/bsp/chrg_clk.h index c5a78f8..707d4e7 100644 --- a/apps/chrg/applications/bsp/chrg_clk.h +++ b/apps/chrg/applications/bsp/chrg_clk.h @@ -1,8 +1,11 @@ #ifndef __CHRG_CLK_H__ #define __CHRG_CLK_H__ +#define TMR_NAME_CLOCK "tmr.clk" struct chrg_clk_t { + const char *name; + rt_timer_t timer_fd; rt_uint32_t cnt; }; diff --git a/apps/chrg/applications/bsp/chrg_switch.c b/apps/chrg/applications/bsp/chrg_switch.c index c4cecbe..2c5dae7 100644 --- a/apps/chrg/applications/bsp/chrg_switch.c +++ b/apps/chrg/applications/bsp/chrg_switch.c @@ -2,6 +2,15 @@ #include "chrg_switch.h" + +/* sn74lv4052a +INH B A CHANNELS +L L L 1Y0, 2Y0 +L L H 1Y1, 2Y1 +L H L 1Y2, 2Y2 +L H H 1Y3, 2Y3 +H X X None +*/ int chrg_switch_ch (rt_base_t inA, rt_base_t inB, eIDX_CH ch) { rt_uint8_t a,b; @@ -13,13 +22,13 @@ int chrg_switch_ch (rt_base_t inA, rt_base_t inB, eIDX_CH ch) break; case IDX_CH_1: - a = PIN_LOW; - b = PIN_HIGH; + a = PIN_HIGH; + b = PIN_LOW; break; case IDX_CH_2: - a = PIN_HIGH; - b = PIN_LOW; + a = PIN_LOW; + b = PIN_HIGH; break; case IDX_CH_3: diff --git a/apps/chrg/applications/thread/chrg_north.c b/apps/chrg/applications/thread/chrg_north.c index 91c6bdb..1676ee9 100644 --- a/apps/chrg/applications/thread/chrg_north.c +++ b/apps/chrg/applications/thread/chrg_north.c @@ -124,6 +124,7 @@ static int chrg_north_init (void) INIT_APP_EXPORT(chrg_north_init); +#if 1 static int north_send(rt_uint8_t argc, char **argv) { return chrg_north_send("1234567890abcdef", 16); @@ -131,6 +132,6 @@ static int north_send(rt_uint8_t argc, char **argv) MSH_CMD_EXPORT(north_send, north send test); - +#endif diff --git a/apps/chrg/chrg.uvprojx b/apps/chrg/chrg.uvprojx index c0fbe8d..72c96b2 100644 --- a/apps/chrg/chrg.uvprojx +++ b/apps/chrg/chrg.uvprojx @@ -16,7 +16,7 @@ STM32F405RG STMicroelectronics - Keil.STM32F4xx_DFP.2.17.1 + Keil.STM32F4xx_DFP.3.1.0 https://www.keil.com/pack/ IRAM(0x20000000-0x2001FFFF) IRAM2(0x10000000-0x1000FFFF) IROM(0x8000000-0x80FFFFF) CLOCK(25000000) CPUTYPE("Cortex-M4") FPU2 diff --git a/mdks/all_mdks.uvmpw b/mdks/all_mdks.uvmpw index 750406b..d656cdd 100644 --- a/mdks/all_mdks.uvmpw +++ b/mdks/all_mdks.uvmpw @@ -9,7 +9,6 @@ ..\apps\boot\boot.uvprojx - 1