drvsys.c

来自「cortex-m0 LCD1602程序」· C语言 代码 · 共 864 行 · 第 1/5 页

C
864
字号
/*---------------------------------------------------------------------------------------------------------*/
void DrvSYS_ResetIP(E_SYS_IP_RST eIpRst)
{   
    uint32_t u32Reg;

    if (eIpRst == E_SYS_PDMA_RST)
    {
        SYS->IPRSTC1.PDMA_RST = 1;
        SYS->IPRSTC1.PDMA_RST = 0;
    }
    else if (eIpRst == E_SYS_EBI_RST)
    {
        SYS->IPRSTC1.EBI_RST = 1;
        SYS->IPRSTC1.EBI_RST = 0;   
    }
    else
    {
        u32Reg = *((__IO uint32_t *) &SYS->IPRSTC2);
        *((__IO uint32_t *) &SYS->IPRSTC2) = u32Reg | (1<<eIpRst);
        *((__IO uint32_t *) &SYS->IPRSTC2) = u32Reg & ~(1<<eIpRst);
    }
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_ResetCPU                                                                               */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               None                                                                                      */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               None                                                                                      */
/*                                                                                                         */
/* Description:                                                                                            */
/*               Reset CPU                                                                                 */
/*                                                                                                         */
/* Note:                                                                                                   */
/*               Please make sure that Register Write-Protection Function has been disabled before using   */
/*               this function to reset CPU.                                                               */
/*               User can check the status of Register Write-Protection Function                           */
/*               with DrvSYS_IsProtectedRegLocked().                                                       */
/*---------------------------------------------------------------------------------------------------------*/
void DrvSYS_ResetCPU(void)
{
    SYS->IPRSTC1.CPU_RST = 1;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_ResetChip                                                                              */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               None                                                                                      */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               None                                                                                      */
/*                                                                                                         */
/* Description:                                                                                            */
/*               Reset whole chip                                                                          */
/*                                                                                                         */
/* Note:                                                                                                   */
/*               Please make sure that Register Write-Protection Function has been disabled before using   */
/*               this function to reset whole chip .                                                       */
/*               User can check the status of Register Write-Protection Function                           */
/*               with DrvSYS_IsProtectedRegLocked().                                                       */
/*---------------------------------------------------------------------------------------------------------*/
void DrvSYS_ResetChip(void)
{
    SYS->IPRSTC1.CHIP_RST = 1;
}


/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_SelectBODVolt                                                                          */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               u8Volt     - [in]    3:4.5V, 2:3.8V, 1:2.7V, 0:2.2V                                       */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               None                                                                                      */
/*                                                                                                         */
/* Description:                                                                                            */
/*               Select Brown-Out Detector threshold voltage                                               */
/*                                                                                                         */
/* Note:                                                                                                   */
/*               Please make sure that Register Write-Protection Function has been disabled before using   */
/*               this function to select BOD threshold voltage.                                            */
/*               User can check the status of Register Write-Protection Function                           */
/*               with DrvSYS_IsProtectedRegLocked().                                                       */
/*---------------------------------------------------------------------------------------------------------*/
void DrvSYS_SelectBODVolt(uint8_t u8Volt)
{
    SYS->BODCR.BOD_VL = u8Volt;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_SetBODFunction                                                                         */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               i32Enable      - [in]    1: Enable / 0: Disable                                           */
/*               i32Flag        - [in]    1: Enable BOD reset function / 0:Enable BOD interrupt function   */
/*               bodcallbackFn  - [in]    BOD Call back function                                           */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               None                                                                                      */
/*                                                                                                         */
/* Description:                                                                                            */
/*               Enable Brown-Out Detector, and select BOD reset function or interrupt function.           */
/*               And, install call backfunction if interrupt function is selected.                         */
/*                                                                                                         */
/* Note:                                                                                                   */
/*               Please make sure that Register Write-Protection Function has been disabled before using   */
/*               this function.                                                                            */
/*               User can check the status of Register Write-Protection Function                           */
/*               with DrvSYS_IsProtectedRegLocked().                                                       */
/*---------------------------------------------------------------------------------------------------------*/
void DrvSYS_SetBODFunction(int32_t i32Enable, int32_t i32Mode, BOD_CALLBACK bodcallbackFn)
{
    SYS->BODCR.BOD_EN = i32Enable;

    if (i32Enable)
    {
        SYS->BODCR.BOD_RSTEN = i32Mode;
    
        if (i32Mode)
        {       
            NVIC_DisableIRQ(BOD_IRQn);
        }
        else
        { 
            BOD_callbackFn = bodcallbackFn;
            NVIC_SetPriority(BOD_IRQn, (1<<__NVIC_PRIO_BITS) - 2);
            NVIC_EnableIRQ(BOD_IRQn);
        }
    }   
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_EnableBODLowPowerMode                                                                  */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               None                                                                                      */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               None                                                                                      */
/*                                                                                                         */
/* Description:                                                                                            */
/*               Enable Brown-Out Detector low power mode                                                  */
/*                                                                                                         */
/* Note:                                                                                                   */
/*               Please make sure that Register Write-Protection Function has been disabled before using   */
/*               this function to enable BOD low power mode.                                               */
/*               User can check the status of Register Write-Protection Function                           */
/*               with DrvSYS_IsProtectedRegLocked().                                                       */
/*---------------------------------------------------------------------------------------------------------*/
void DrvSYS_EnableBODLowPowerMode(void)
{
    SYS->BODCR.BOD_LPM = 1;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_DisableBODLowPowerMode                                                                 */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               None                                                                                      */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               None                                                                                      */
/*                                                                                                         */
/* Description:                                                                                            */
/*               Disable Brown-Out Detector low power mode                                                 */
/*                                                                                                         */
/* Note:                                                                                                   */
/*               Please make sure that Register Write-Protection Function has been disabled before using   */
/*               this function to disable BOD low power mode.                                              */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?