/**
  ******************************************************************************
  * @file     PVD_CFG.c
  * @author   SINOMCU-AE
  * @brief    PVD config
  *    
  *          This file provides functions to PVD config.
  *         
  ******************************************************************************
  * @attention 
  *                           DISCLAIMER
  * The present firmware which is for guidance only aims at providing customers
  * with coding information regarding their products in order for them to save
  * time. As a result, SinoMCU shall not be held liable for any direct,indirect
  * or consequential damages with respect to any claims arising from the content 
  * of such firmware and/or the use made by customers of the coding information 
  * contained herein in connection with their products.
  *
  * <h2><center>&copy; Copyright (c) 2021 sinomcu All rights reserved.</center></h2>
  *
  ******************************************************************************
  */
    
#include "PVD_CFG.h"

/**
  * @brief  PVD config Function
  * @param  None
  * @retval None
  */
void pvd_init(void) {
  MS32_PWR_InitTypeDef PwrInitStr = {0};
  MS32_EXTI_InitTypeDef ExitInitStruct = {0};

  MS32_PWR_StructInit(&PwrInitStr);
  PwrInitStr.BackupAccessStatus  = MS32_PWR_BKUPACC_DIS;
  PwrInitStr.WakeupPin           = MS32_PWR_WAKEUP_NONE;
  PwrInitStr.PowerVoltDetectSel  = MS32_PWR_PVDON_LEVEL6;  // level 6:datasheet 1.0.1,typical rising 2.78V falling 2.68V
  PwrInitStr.PowerVoltDetectLock = MS32_SYSCFG_PVD_UNLOCK;
  MS32_PWR_Init(&PwrInitStr);                              // init function had enable clock

  MS32_EXTI_StructInit(&ExitInitStruct);
  ExitInitStruct.Line_0_31   = MS32_EXTI_LINE_16;          // PVD interrupt
  ExitInitStruct.LineCommand = ENABLE;
  ExitInitStruct.Mode        = MS32_EXTI_MODE_IT;
  ExitInitStruct.Trigger     = MS32_EXTI_TRIGGER_RISING;
  MS32_EXTI_Init(&ExitInitStruct);
  MS32_EXTI_ClearFlag_0_31(MS32_EXTI_LINE_16);  

  MS32_PWR_ITConfig(MS32_PWR_PVDIT_ENABLE , 0);            // Cortex-M0,Priority:0-3
}

/******************************** END OF FILE *********************************/
