stm32_ota/SYSTEM/PVD/pvd.c

116 lines
4.1 KiB
C
Raw Normal View History

2023-12-15 06:28:06 +00:00
#include "pvd.h"
#include "sysport.h"
#include "stm32f10x_pwr.h"
#include "stm32f10x_bkp.h"
/********************************************************************************
* @file pvd.c
* @author <EFBFBD>̳ϿƼ<EFBFBD> Mr.Wang
* @version V1.0.0
* @date 11-Dec-2018
* @brief pvd<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
******************************************************************************
*******************************************************************************/
/*****************************************
*<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ʹ<EFBFBD>õij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
****************************************/
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void Delay_Us(u32 nus)
* <EFBFBD><EFBFBD> <EFBFBD>ܣ<EFBFBD> <EFBFBD><EFBFBD>ʱnus
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param nus Ҫ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>us<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD>ϵͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> nus:0~59652323(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>2^32/fac_us@fac_us=72) 59652323
*************************************************************************************************/
void Pvd_Init( EXTITrigger_TypeDef exitTrigger, IntPriority_e ePriority)
{
/*<2A><><EFBFBD><EFBFBD>EXIT<49><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ <20><><EFBFBD><EFBFBD>AFIOʱ<4F><CAB1><EFBFBD>ҳ<EFBFBD>ʼ<EFBFBD><CABC> EXIT<49><54>NVIC*/
EXTI_InitTypeDef EXTI_InitStructure ; //EXIT<49><54><EFBFBD><EFBFBD> <20><EFBFBD><EFBFBD><E5B6A8>
NVIC_InitTypeDef NVIC_InitStructure ; //NVIC<49><43><EFBFBD><EFBFBD> <20><EFBFBD><EFBFBD><E5B6A8>
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //GPIO EXIT<49><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>AFIOʱ<4F><CAB1>
EXTI_InitStructure.EXTI_Line = EXTI_Line16 ; //<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt ; //<2F>ж<EFBFBD>ģʽ
EXTI_InitStructure.EXTI_Trigger = exitTrigger ; //IO<49>ⲿ<EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD>ʽ
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init( &EXTI_InitStructure );
/*<2A><><EFBFBD>жϱ<D0B6>־λ<D6BE><CEBB><EFBFBD>ٿ<EFBFBD><D9BF>ж<EFBFBD>*/
EXTI_ClearITPendingBit( EXTI_Line16);
NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQn ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = ePriority ; //<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD>
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0 ; //freertos<6F><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE ; //ʧ<><CAA7><EFBFBD>ⲿ<EFBFBD>ж<EFBFBD>ͨ<EFBFBD><CDA8>
NVIC_Init(&NVIC_InitStructure); //<2F>ж<EFBFBD>NVIC<49><43><EFBFBD><EFBFBD>
NVIC_EnableIRQ(PVD_IRQn) ;
PWR_PVDLevelConfig(PWR_PVDLevel_2V8) ;
PWR_PVDCmd(ENABLE) ;
}
//void PVD_IRQHandler(void)
//{
//if( EXTI_GetFlagStatus(EXTI_Line16) != RESET )
// {
// EXTI_ClearITPendingBit(EXTI_Line16);
// WriteLogToFlash("Pvd Irq!") ;
// SysErr("Pvd Irq!") ;
// }
//}
void PWR_PVD_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);//ʹ<><CAB9>PWRʱ<52><CAB1>
NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQn; //ʹ<><CAB9>PVD<56><44><EFBFBD>ڵ<EFBFBD><DAB5>ⲿ<EFBFBD>ж<EFBFBD>ͨ<EFBFBD><CDA8>
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;//<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹ<><CAB9><EFBFBD>ⲿ<EFBFBD>ж<EFBFBD>ͨ<EFBFBD><CDA8>
NVIC_Init(&NVIC_InitStructure); EXTI_StructInit(&EXTI_InitStructure);
EXTI_InitStructure.EXTI_Line = EXTI_Line16; //PVD<56><44><EFBFBD>ӵ<EFBFBD><D3B5>ж<EFBFBD><D0B6><EFBFBD>16<31><36>
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //ʹ<><CAB9><EFBFBD>ж<EFBFBD>ģʽ
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //<2F><>ѹ<EFBFBD><D1B9><EFBFBD>ڷ<EFBFBD>ֵʱ<D6B5><CAB1><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //ʹ<><CAB9><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>
EXTI_Init(&EXTI_InitStructure); //<2F><>ʼ
PWR_PVDLevelConfig(PWR_PVDLevel_2V8);//<2F><EFBFBD><E8B6A8><EFBFBD>ط<EFBFBD>ֵ
PWR_PVDCmd(ENABLE);//ʹ<><CAB9>PVD
}
u16 num = 0 ;
void PVD_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line16);//<2F><><EFBFBD>ж<EFBFBD>
// num = BKP_ReadBackupRegister(BKP_DR10);
// num++; //<2F>û<EFBFBD><C3BB><EFBFBD><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);//ʹ<><CAB9>PWR<57><52>BKP<4B><50><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
// PWR_BackupAccessCmd(ENABLE);//ʹ<>ܺ󱸼Ĵ<F3B1B8BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// BKP_WriteBackupRegister(BKP_DR1, num);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
//uint16_t power_time = 0 ;
//void PVD_IRQHandler(void)
//{
// EXTI_ClearITPendingBit(EXTI_Line16);//<2F><><EFBFBD>ж<EFBFBD>
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR , ENABLE);//ʹ<><CAB9>PWR<57><52>BKP<4B><50><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
// PWR_BackupAccessCmd(ENABLE); //ʹ<>ܺ󱸼Ĵ<F3B1B8BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// while(1)
// {
// power_time++;
// BKP_WriteBackupRegister(BKP_DR14, power_time) ;
// }
//}