2025-04-26 16:03:23 +08:00

198 lines
6.0 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** ##########################################################################
** Filename :
** Project :
** Module :
** Processor :
** Version :
** Compiler :
** Date/Time :
** Abstract :
** Contents :
** Note :
**
** (c) Copyright dmdz Co.,Ltd
** --------------------------------------------------------------------------
** R E V I S I O N H I S T O R Y
** --------------------------------------------------------------------------
** Date Ver Author Description
** -20230602- --V1.0-- --mingyea--- --修改--
** #########################################################################*/
/*---------------------------------------------------------------------------
- I N C L U D E F I L E S
----------------------------------------------------------------------------*/
#include "svd.h"
#include "nvic.h"
/*---------------------------------------------------------------------------
- D E F I N E S / M A C R O S
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
- T Y P E D E F I N I T I O N S
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
- S T A T I C V A R I A B L E S
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
* G L O B A L V A R I A B L E S
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
- C O N S T A N T S
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
- F U N C T I O N P R O T O T Y P E
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
|Prototype :
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description : SVD初始化
----------------------------------------------------------------------------*/
void svd_init(void)
{
//FL_GPIO_InitTypeDef GPIO_InitStruct;
FL_NVIC_ConfigTypeDef InterruptConfigStruct;
FL_SVD_InitTypeDef SVD_InitStruct;
#if 0
GPIO_InitStruct.pin = FL_GPIO_PIN_15;
GPIO_InitStruct.mode = FL_GPIO_MODE_ANALOG;
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.pull = FL_DISABLE;
GPIO_InitStruct.remapPin = FL_DISABLE;
GPIO_InitStruct.analogSwitch = FL_DISABLE;
FL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif
SVD_InitStruct.SVSChannel = FL_DISABLE;
SVD_InitStruct.digitalFilter = FL_ENABLE;
SVD_InitStruct.referenceVoltage = FL_SVD_REFERENCE_1P0V;
SVD_InitStruct.workMode = FL_SVD_WORK_MODE_CONTINUOUS;
SVD_InitStruct.enablePeriod = FL_SVD_ENABLE_PERIOD_62P5MS;
SVD_InitStruct.warningThreshold = FL_SVD_WARNING_THRESHOLD_GROUP11; //必须4.2以上
FL_SVD_Init(SVD, &SVD_InitStruct);
/* 清除欠压标志 */
FL_SVD_ClearFlag_PowerFall(SVD);
/* 使能欠压中断 */
FL_SVD_EnableIT_PowerFall(SVD);
/* 清除过压标志 */
FL_SVD_ClearFlag_PowerRise(SVD);
/* 使能过压中断 */
FL_SVD_EnableIT_PowerRise(SVD);
InterruptConfigStruct.preemptPriority = NVIC_PRIORITY_SVD; //优先级改为最高
FL_NVIC_Init(&InterruptConfigStruct, SVD_IRQn);
FL_SVD_Enable(SVD);
}
/*---------------------------------------------------------------------------
|Prototype :
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description :
----------------------------------------------------------------------------*/
void svd_task(void)
{
//SVD锁存判断
if(FL_RESET == FL_SVD_GetLatchedPowerStatus(SVD)) // SVD内部滤波后的电压检测标志仅在使能数字滤波时有意义软件避免写此寄存器。
{
// SVD检测到欠压
// ...
}
#if 0
if(SVDState == SPOWEROFF)
{
// SVD检测到欠压
}
else
{
// SVD检测到欠压恢复
}
#endif
}
/*---------------------------------------------------------------------------
|Prototype :
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description : SVD中断配置
----------------------------------------------------------------------------*/
void SVD_Interrupt_Init(void)
{
FL_NVIC_ConfigTypeDef InterruptConfigStruct;
/* 使能过压和欠压中断 */
FL_SVD_ClearFlag_PowerRise(SVD);
FL_SVD_ClearFlag_PowerFall(SVD);
FL_SVD_EnableIT_PowerRise(SVD);
FL_SVD_EnableIT_PowerFall(SVD);
/* 配置NVIC中断 */
InterruptConfigStruct.preemptPriority = NVIC_PRIORITY_SVD;
FL_NVIC_Init(&InterruptConfigStruct, SVD_IRQn);
/* 基于SVD监测结果初始赋值 */
/* 注意如果有使能数字滤波应使用SVDR查询如未使能数字滤波应使用SVDO查询 */
//eSVDResult = SVD_SVDO_POLL();
}
/*---------------------------------------------------------------------------
|Prototype :
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description : SVD中断反初始化
----------------------------------------------------------------------------*/
void SVD_Interrupt_DeInit(void)
{
/* 禁能过压和欠压中断 */
FL_SVD_ClearFlag_PowerRise(SVD);
FL_SVD_ClearFlag_PowerFall(SVD);
FL_SVD_DisableIT_PowerRise(SVD);
FL_SVD_DisableIT_PowerFall(SVD);
/* 清除NVIC Pending位 */
NVIC_ClearPendingIRQ(SVD_IRQn);
/* 禁能NVIC中断 */
NVIC_DisableIRQ(SVD_IRQn);
}