2026-03-20 21:16:58 +08:00
|
|
|
|
#include "../main/SystemInclude.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**------------------------------------------------------------------------
|
2026-03-20 21:19:04 +08:00
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ӳ<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
* @note <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><EFBFBD>-ѡ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Դ
|
|
|
|
|
|
* @param
|
2026-03-20 21:16:58 +08:00
|
|
|
|
**/
|
|
|
|
|
|
static void LPTIM_Init(LPTIM_TypeDef *lptimer)
|
|
|
|
|
|
{
|
|
|
|
|
|
LPTIM_InitTypeDef LPTIM_InitStructure; /* 1. <20><>ʼ<EFBFBD><CABC>LPTimer Base */
|
|
|
|
|
|
LPTIM_InitStructure.Mode = LPTIM_MODE_TIMER_COUNTER; // <20><>ʱ<EFBFBD><CAB1>ģʽ
|
|
|
|
|
|
#if LPTIM_CLK_ENABLE_LSE
|
|
|
|
|
|
LHL_RCC_LSEConfig(ENABLE);
|
|
|
|
|
|
LPTIM_InitStructure.Clock = LPTIM_CLOCKSOURCE_LSE; // LPTIMʱ<4D><CAB1>ԴLSE
|
|
|
|
|
|
#else
|
2026-03-20 21:19:04 +08:00
|
|
|
|
LHL_RCC_LSEConfig(DISABLE);
|
2026-03-20 21:16:58 +08:00
|
|
|
|
LPTIM_InitStructure.Clock = LPTIM_CLOCKSOURCE_LSI; // LPTIMʱ<4D><CAB1>ԴLSI
|
|
|
|
|
|
#endif
|
2026-03-20 21:19:04 +08:00
|
|
|
|
LPTIM_InitStructure.Prescaler = LPTIM_PRESCALER_DIV1; // Ԥ<><D4A4>Ƶϵ<C6B5><CFB5>2
|
|
|
|
|
|
LPTIM_InitStructure.FreeRunning = DISABLE; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
2026-03-20 21:16:58 +08:00
|
|
|
|
LHL_LPTIM_Init(lptimer, &LPTIM_InitStructure);
|
|
|
|
|
|
}
|
|
|
|
|
|
/*==================================================================================*/
|
|
|
|
|
|
/*LPTimer1==========================================================================*/
|
|
|
|
|
|
/*==================================================================================*/
|
|
|
|
|
|
/**------------------------------------------------------------------------
|
2026-03-20 21:19:04 +08:00
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ӳ<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
* @note LPTimer ʱ<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>32768Hz
|
|
|
|
|
|
* @param uploadCounter : <EFBFBD><EFBFBD><EFBFBD>㷽<EFBFBD><EFBFBD>(uploadCounter=32.768 ->t=1ms)
|
2026-03-20 21:16:58 +08:00
|
|
|
|
**/
|
|
|
|
|
|
void StartLPTimer1(u16 uploadCounter)//125ms 250ms ......
|
|
|
|
|
|
{
|
|
|
|
|
|
/* 1. <20><>ʼ<EFBFBD><CABC>LPTimer Base */
|
|
|
|
|
|
LHL_LPTIM_DeInit(LPTIM1);
|
|
|
|
|
|
LPTIM_Init(LPTIM1);
|
|
|
|
|
|
/* 2. <20><><EFBFBD><EFBFBD>LPTimer<65>ж<EFBFBD> */
|
|
|
|
|
|
LHL_LPTIM_ITConfig(LPTIM1, ENABLE);
|
|
|
|
|
|
NVIC_EnableIRQ(LPTIM1_IRQn);
|
|
|
|
|
|
/* 3. <20><><EFBFBD><EFBFBD>LPTimer1 */
|
2026-03-20 21:19:04 +08:00
|
|
|
|
LHL_LPTIM_Start(LPTIM1, uploadCounter); // LPTIMER1 = (Period+1)/Clock = 32768/32768 = 1S
|
2026-03-20 21:16:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**------------------------------------------------------------------------
|
2026-03-20 21:19:04 +08:00
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı䶨ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>
|
|
|
|
|
|
* @note LPTimer ʱ<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>32768Hz
|
|
|
|
|
|
* @param uploadCounter : <EFBFBD><EFBFBD><EFBFBD>㷽<EFBFBD><EFBFBD>(uploadCounter=32.768 ->t=1ms)
|
2026-03-20 21:16:58 +08:00
|
|
|
|
**/
|
|
|
|
|
|
void ResetLPTimer1(u16 uploadCounter)
|
|
|
|
|
|
{
|
|
|
|
|
|
LPTIM1->CSR &= ~LPTIM_CSR_TEN_Msk;// 1. <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
|
LPTIM1->CSR |= LPTIM_CSR_TCF_Msk; // 2. <20><><EFBFBD><EFBFBD><EFBFBD>Ƚ<EFBFBD><C8BD>жϱ<D0B6>־
|
|
|
|
|
|
LPTIM1->CMR = uploadCounter; // 3. <20><><EFBFBD><EFBFBD><EFBFBD>µıȽ<C4B1>ֵ
|
|
|
|
|
|
LPTIM1->CSR |= LPTIM_CSR_TEN_Msk; // 4. <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 <20><>ʼ
|
|
|
|
|
|
}
|
|
|
|
|
|
/*==================================================================================*/
|
2026-03-20 21:19:04 +08:00
|
|
|
|
/*LPTimer1==========================================================================*/
|
2026-03-20 21:16:58 +08:00
|
|
|
|
/*==================================================================================*/
|
|
|
|
|
|
/**------------------------------------------------------------------------
|
2026-03-20 21:19:04 +08:00
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ӳ<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
* @note LPTimer ʱ<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>32768Hz
|
|
|
|
|
|
* @param uploadCounter : <EFBFBD><EFBFBD><EFBFBD>㷽<EFBFBD><EFBFBD>(uploadCounter=32.768 ->t=1ms)
|
2026-03-20 21:16:58 +08:00
|
|
|
|
**/
|
|
|
|
|
|
void StartLPTimer2(u16 uploadCounter)//125ms 250ms ......
|
|
|
|
|
|
{
|
2026-03-20 21:19:04 +08:00
|
|
|
|
LPTIM_InitTypeDef LPTIM_InitStructure;
|
|
|
|
|
|
|
|
|
|
|
|
/* 1. <20><>ʼ<EFBFBD><CABC>LPTimer Base */
|
|
|
|
|
|
LPTIM_InitStructure.Mode = LPTIM_MODE_TIMER_COUNTER; // <20><>ʱ<EFBFBD><CAB1>ģʽ
|
|
|
|
|
|
#if 1
|
|
|
|
|
|
LHL_RCC_LSEConfig(ENABLE);
|
|
|
|
|
|
LPTIM_InitStructure.Clock = LPTIM_CLOCKSOURCE_LSI; // LPTIM0ʱ<30><CAB1>ԴLSI
|
|
|
|
|
|
#else
|
|
|
|
|
|
LPTIM_InitStructure.Clock = LPTIM_CLOCKSOURCE_LSI; // LPTIM0ʱ<30><CAB1>ԴLSI
|
|
|
|
|
|
#endif
|
|
|
|
|
|
LPTIM_InitStructure.Prescaler = LPTIM_PRESCALER_DIV1; // Ԥ<><D4A4>Ƶϵ<C6B5><CFB5>2
|
|
|
|
|
|
LPTIM_InitStructure.FreeRunning = DISABLE; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
|
|
|
|
|
LHL_LPTIM_Init(pLPTIM2, &LPTIM_InitStructure);
|
|
|
|
|
|
/* 2. <20><><EFBFBD><EFBFBD>LPTimer<65>ж<EFBFBD> */
|
|
|
|
|
|
LHL_LPTIM_ITConfig(pLPTIM2, ENABLE);
|
2026-03-20 21:16:58 +08:00
|
|
|
|
NVIC_EnableIRQ(LPTIM2_IRQn);
|
|
|
|
|
|
/* 3. <20><><EFBFBD><EFBFBD>LPTimer1<72><31>2 */
|
2026-03-20 21:19:04 +08:00
|
|
|
|
LHL_LPTIM_Start(pLPTIM2, uploadCounter); // LPTIMER1 = (Period+1)/Clock = 32768/32768 = 1S
|
2026-03-20 21:16:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**------------------------------------------------------------------------
|
2026-03-20 21:19:04 +08:00
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
* @note LPTimer ʱ<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>32768Hz
|
|
|
|
|
|
* @param uploadCounter : <EFBFBD><EFBFBD><EFBFBD>㷽<EFBFBD><EFBFBD>(uploadCounter=32.768 ->t=1ms)
|
2026-03-20 21:16:58 +08:00
|
|
|
|
**/
|
|
|
|
|
|
void ResetLPTimer2(u16 uploadCounter)
|
|
|
|
|
|
{
|
|
|
|
|
|
LPTIM2->CSR &= ~LPTIM_CSR_TEN_Msk;// 1. <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
|
LPTIM2->CSR |= LPTIM_CSR_TCF_Msk; // 2. <20><><EFBFBD><EFBFBD><EFBFBD>Ƚ<EFBFBD><C8BD>жϱ<D0B6>־
|
|
|
|
|
|
LPTIM2->CMR = uploadCounter; // 3. <20><><EFBFBD><EFBFBD><EFBFBD>µıȽ<C4B1>ֵ
|
|
|
|
|
|
LPTIM2->CSR |= LPTIM_CSR_TEN_Msk; // 4. <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 <20><>ʼ
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*==================================================================================*/
|
2026-03-20 21:19:04 +08:00
|
|
|
|
/*<2A><EFBFBD><CDB9>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>====================================================================*/
|
2026-03-20 21:16:58 +08:00
|
|
|
|
/*==================================================================================*/
|
|
|
|
|
|
|
|
|
|
|
|
/**------------------------------------------------------------------------
|
2026-03-20 21:19:04 +08:00
|
|
|
|
* @brief <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD>
|
|
|
|
|
|
* @note
|
|
|
|
|
|
* @param LPTIM_TypeDef *lptimer<EFBFBD><EFBFBD>LPTIM1 LPTIM2 <EFBFBD><EFBFBD> lptimer_irq_callback_t lptim_irq_callback <EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
* @example: SHAL_timer_register_irq_callback(pTIM1,callback1);
|
2026-03-20 21:16:58 +08:00
|
|
|
|
**/
|
|
|
|
|
|
static lptimer_irq_callback_t lptim1_irq_callback,lptim2_irq_callback ;
|
|
|
|
|
|
|
|
|
|
|
|
void lptimer_register_irq_callback(LPTIM_TypeDef *lptimer ,lptimer_irq_callback_t lptim_irq_callback)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(lptimer == LPTIM1)
|
|
|
|
|
|
{
|
|
|
|
|
|
lptim1_irq_callback = lptim_irq_callback;//<2F><>ֵ<EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
LHL_LPTIM_ClearPending(LPTIM1);// <20><><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־
|
|
|
|
|
|
NVIC_EnableIRQ(LPTIM1_IRQn);//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(lptimer == LPTIM2)
|
|
|
|
|
|
{
|
|
|
|
|
|
lptim2_irq_callback = lptim_irq_callback;
|
|
|
|
|
|
LHL_LPTIM_ClearPending(LPTIM2);// <20><><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־
|
|
|
|
|
|
NVIC_EnableIRQ(LPTIM2_IRQn);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 21:19:04 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief
|
|
|
|
|
|
* @param
|
|
|
|
|
|
* @retval
|
|
|
|
|
|
*/
|
2026-03-20 21:16:58 +08:00
|
|
|
|
void LPTIM1_IRQHandler(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD>˻ص<CBBB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
if (lptim1_irq_callback != NULL) lptim1_irq_callback();// <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ע<EFBFBD><D7A2><EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
LHL_LPTIM_ClearPending(LPTIM1); // <20><><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2026-03-20 21:19:04 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief
|
|
|
|
|
|
* @param
|
|
|
|
|
|
* @retval
|
|
|
|
|
|
*/
|
2026-03-20 21:16:58 +08:00
|
|
|
|
void LPTIM2_IRQHandler(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD>˻ص<CBBB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
if (lptim2_irq_callback != NULL) lptim2_irq_callback();// <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ע<EFBFBD><D7A2><EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
LHL_LPTIM_ClearPending(LPTIM2); // <20><><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־
|
|
|
|
|
|
}
|