CH5XX_GetTimeStamp测试还是有点问题

This commit is contained in:
stark1898y 2025-05-16 18:56:51 +08:00
parent 5ef5c8842a
commit 1a75fc3c56
6 changed files with 124 additions and 23 deletions

View File

@ -291,6 +291,8 @@ int main(void)
BSP_BEEP_LED_EMV_Init(); BSP_BEEP_LED_EMV_Init();
PRINT("PRINT\r\n");
logDebug("Start @ChipID=%02X\n", R8_CHIP_ID); logDebug("Start @ChipID=%02X\n", R8_CHIP_ID);
logError("中文测试 %2.2f", 123.456); logError("中文测试 %2.2f", 123.456);
@ -422,14 +424,14 @@ int main(void)
IWDG_Init(IWDG_TIMEOUT_MS); IWDG_Init(IWDG_TIMEOUT_MS);
logDebug("123");
DelayMs(1000);
logDebug("456");
// 在连接间隔和广播间隔到来时,会进入回调中喂狗 // 在连接间隔和广播间隔到来时,会进入回调中喂狗
// LL_AdvertiseEventRegister(BLE_AdvertiseEventCB); // LL_AdvertiseEventRegister(BLE_AdvertiseEventCB);
// LL_ConnectEventRegister(BLE_ConnectEventCB); // LL_ConnectEventRegister(BLE_ConnectEventCB);
// FEED_IWDG();
// logDebug("IWDG_Init 1");
Main_Circulation(); Main_Circulation();
} }

View File

@ -2,17 +2,7 @@
* @Author : stark1898y 1658608470@qq.com * @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-15 16:13:37 * @Date : 2024-12-15 16:13:37
* @LastEditors : stark1898y 1658608470@qq.com * @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2025-05-16 14:17:34 * @LastEditTime : 2025-05-16 17:31:12
* @FilePath : \BLE_TYQ_CH584M\BSP\inc\bsp_iwdg.h
* @Description :
*
* Copyright (c) 2024 by yzy, All Rights Reserved.
*/
/*
* @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-14 10:51:01
* @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2024-12-15 11:16:24
* @FilePath : \BLE_TYQ_CH584M\BSP\inc\bsp_iwdg.h * @FilePath : \BLE_TYQ_CH584M\BSP\inc\bsp_iwdg.h
* @Description : * @Description :
* *
@ -32,7 +22,7 @@
#define RB_IWDG_EN 0x80000000 // RO, watch-dog enable #define RB_IWDG_EN 0x80000000 // RO, watch-dog enable
#define IWDG_TIMEOUT_MS (6000) #define IWDG_TIMEOUT_MS (6000)
#define IWDG_FEED_MS (5000) #define IWDG_FEED_MS (1000)
#define IWIG_FEED_EVENT (0x01 << 0) #define IWIG_FEED_EVENT (0x01 << 0)

View File

@ -2,8 +2,8 @@
* @Author : stark1898y 1658608470@qq.com * @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-15 15:01:15 * @Date : 2024-12-15 15:01:15
* @LastEditors : stark1898y 1658608470@qq.com * @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2024-12-15 16:24:28 * @LastEditTime : 2025-05-16 18:20:04
* @FilePath : \BLE_TYQ_CH584M - \BSP\inc\bsp_tim.h * @FilePath : \BLE_TYQ_CH584M\BSP\inc\bsp_tim.h
* @Description : * @Description :
* *
* Copyright (c) 2024 by yzy, All Rights Reserved. * Copyright (c) 2024 by yzy, All Rights Reserved.
@ -13,7 +13,7 @@
#include "CONFIG.h" #include "CONFIG.h"
uint32_t CH5XX_GetTimeStamp(uint16_t *tick);
uint32_t BSP_Get_Tick(void); uint32_t BSP_Get_Tick(void);

View File

@ -2,7 +2,7 @@
* @Author : stark1898y 1658608470@qq.com * @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-15 16:13:41 * @Date : 2024-12-15 16:13:41
* @LastEditors : stark1898y 1658608470@qq.com * @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2025-05-16 14:23:06 * @LastEditTime : 2025-05-16 18:35:06
* @FilePath : \BLE_TYQ_CH584M\BSP\src\bsp_iwdg.c * @FilePath : \BLE_TYQ_CH584M\BSP\src\bsp_iwdg.c
* @Description : * @Description :
* *
@ -12,6 +12,7 @@
#include "bsp_uart.h" #include "bsp_uart.h"
#include "log.h" #include "log.h"
#include "bsp_tim.h"
// https://www.cnblogs.com/debugdabiaoge/p/17580033.html // https://www.cnblogs.com/debugdabiaoge/p/17580033.html
// https://www.cnblogs.com/risc5-ble/p/17853714.html // https://www.cnblogs.com/risc5-ble/p/17853714.html
@ -28,6 +29,10 @@ uint16_t IWDG_ProcessEvent(uint8_t task_id, uint16_t events)
{ {
if (events & IWIG_FEED_EVENT) if (events & IWIG_FEED_EVENT)
{ {
// uint32_t seconds = 0;
// uint16_t tick_1sec = 0;
// seconds = CH5XX_GetTimeStamp(&tick_1sec);
// logDebug("seconds = %d.%d", seconds, tick_1sec * 1000 / 32768);
FEED_IWDG(); FEED_IWDG();
logDebug("IWDG feed"); logDebug("IWDG feed");
// 获取tmos系统堆的剩余内存大小 // 获取tmos系统堆的剩余内存大小

View File

@ -2,8 +2,8 @@
* @Author : stark1898y 1658608470@qq.com * @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-15 15:01:15 * @Date : 2024-12-15 15:01:15
* @LastEditors : stark1898y 1658608470@qq.com * @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2024-12-15 16:24:32 * @LastEditTime : 2025-05-16 18:21:05
* @FilePath : \BLE_TYQ_CH584M - \BSP\src\bsp_tim.c * @FilePath : \BLE_TYQ_CH584M\BSP\src\bsp_tim.c
* @Description : * @Description :
* *
* Copyright (c) 2024 by yzy, All Rights Reserved. * Copyright (c) 2024 by yzy, All Rights Reserved.
@ -13,6 +13,62 @@
// tick_1ms_cnt在SysTick_Handler()中1ms +1 // tick_1ms_cnt在SysTick_Handler()中1ms +1
volatile uint32_t tick_1ms_cnt = 0; volatile uint32_t tick_1ms_cnt = 0;
#if 0
// 要是用32k做差可以这样
// 最大就是一天
__HIGH_CODE
uint32_t plat_rtc_get(void)
{
volatile uint32_t i;
do {
i = R32_RTC_CNT_32K;
} while (i != R32_RTC_CNT_32K);
return (i);
}
__HIGH_CODE
uint32_t ch5xx_get_rtc_gap(uint32_t last, uint32_t current)
{
if (current > last)
{
return (current - last);
}
else
{
return (32768 * 3600 * 24UL - last + current);
}
}
uint32_t last_rtc_cnt = plat_rtc_get();
// do sleep
uint32_t current_rtc_cnt = plat_rtc_get();
if (ch5xx_get_rtc_gap(last_rtc_cnt, current_rtc_cnt) > 32768 * 10)
{
// do bat level sample
}
#endif
// return local time in seconds, max 44 year
__HIGH_CODE
uint32_t CH5XX_GetTimeStamp(uint16_t *tick)
{
uint32_t t, t32k;
uint16_t day, sec2;
do {
t32k = R32_RTC_CNT_32K;
day = R32_RTC_CNT_DAY & 0x3FFF;
sec2 = R16_RTC_CNT_2S;
} while (t32k != R32_RTC_CNT_32K);
t = day * 86400 + (sec2 << 1) + ((t32k < 0x8000) ? 0 : 1);
if (tick != NULL)
{
*tick = t32k & 0X7FFF;
}
return t;
}
/** /**
* @description: SysTick1ms * @description: SysTick1ms
* @return {uint32_t} * @return {uint32_t}
@ -21,7 +77,13 @@ uint32_t BSP_Get_Tick(void)
{ {
/* Platform implementation */ /* Platform implementation */
// current system clock (in 0.625ms) // current system clock (in 0.625ms)
return (uint32_t)((double)TMOS_GetSystemClock() / 1.6); // return (uint32_t)((double)TMOS_GetSystemClock() / 1.6);
uint32_t seconds = 0;
uint16_t tick_1sec = 0;
seconds = CH5XX_GetTimeStamp(&tick_1sec);
return (seconds * 1000 + (tick_1sec * 1000 / 32768));
// logDebug("seconds = %d.%d", seconds, tick_1sec * 1000 / 32768);
} }
// SysTick中断函数 // SysTick中断函数

View File

@ -460,6 +460,7 @@ __INTERRUPT
__HIGH_CODE __HIGH_CODE
__attribute__((weak)) void HardFault_Handler(void) __attribute__((weak)) void HardFault_Handler(void)
{ {
#if 0
uint32_t v_mepc, v_mcause, v_mtval; uint32_t v_mepc, v_mcause, v_mtval;
printf("hardfault\n"); printf("hardfault\n");
@ -478,6 +479,47 @@ __attribute__((weak)) void HardFault_Handler(void)
sys_safe_access_enable(); sys_safe_access_enable();
R8_RST_WDOG_CTRL |= RB_SOFTWARE_RESET; R8_RST_WDOG_CTRL |= RB_SOFTWARE_RESET;
sys_safe_access_disable(); sys_safe_access_disable();
#endif
struct __MEMORY_CTL
{
struct __MEMORY_CTL *pNext;
uint16_t len;
uint16_t used;
};
typedef struct __MEMORY_CTL MemoryCtl;
extern MemoryCtl *MemCtlStart;
extern MemoryCtl *MemCtlEnd;
MemoryCtl *MemHead;
MemHead = MemCtlStart;
while (MemHead != MemCtlEnd)
{
printf("|%8x,%8x,%8d.....\n", MemHead->used, (uint32_t)MemHead,
(uint32_t)(MemHead->pNext) - (uint32_t)MemHead - sizeof(struct __MEMORY_CTL));
MemHead = MemHead->pNext;
}
printf("\n");
uint32_t v_mepc, v_mcause, v_mtval;
printf("hardfault\n");
v_mepc = __get_MEPC();
v_mcause = __get_MCAUSE();
v_mtval = __get_MTVAL();
printf("mepc:%08x\n", v_mepc);
printf("mcause:%08x\n", v_mcause);
printf("mtval:%08x\n", v_mtval);
#if 0
FLASH_ROM_SW_RESET();
sys_safe_access_enable();
R16_INT32K_TUNE = 0xFFFF;
sys_safe_access_disable();
sys_safe_access_enable();
R8_RST_WDOG_CTRL |= RB_SOFTWARE_RESET;
sys_safe_access_disable();
#endif
while (1); while (1);
} }