⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drvsys.c

📁 cortex-m0 LCD1602程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2009 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/
#include <stdio.h>
#include "DrvSYS.h"


#define FREQ_25MHZ         25000000
#define FREQ_50MHZ         50000000
#define FREQ_100MHZ       100000000
#define FREQ_200MHZ       200000000

/*---------------------------------------------------------------------------------------------------------*/
/* Global file scope (static) variables                                                                    */
/*---------------------------------------------------------------------------------------------------------*/
static BOD_CALLBACK BOD_callbackFn;
static PWRWU_CALLBACK PWRWU_callbackFn;

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_GetVersion                                                                             */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               None                                                                                      */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               The DrvSYS version number                                                                 */
/*                                                                                                         */
/* Description:                                                                                            */
/*               This function is used to get the DrvSYS version number                                    */
/*---------------------------------------------------------------------------------------------------------*/
uint32_t DrvSYS_GetVersion(void)
{
    return DRVSYS_VERSION_NUM;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_ReadProductID                                                                          */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               None                                                                                      */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               Product ID                                                                                */
/* Description:                                                                                            */
/*               Read Product ID                                                                           */
/*---------------------------------------------------------------------------------------------------------*/
uint32_t DrvSYS_ReadProductID(void)
{   
    return SYS->PDID;
}


/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_UnlockProtectedReg                                                                     */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               None                                                                                      */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               0      Success                                                                            */
/*              <0      Failed                                                                             */
/* Description:                                                                                            */
/*               Unlock protected registers                                                                */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvSYS_UnlockProtectedReg(void)
{
    uint32_t lockbit;
    
    SYS->REGWRPROT = 0x59;
    SYS->REGWRPROT = 0x16;
    SYS->REGWRPROT = 0x88;

    lockbit = SYS->REGWRPROT & 0x01;
    return (lockbit)? 0 : E_DRVSYS_ERR_UNLOCK_FAIL;
} 
 
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_LockProtectedReg                                                                       */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               None                                                                                      */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               0      Success                                                                            */
/*              <0      Failed                                                                             */
/* Description:                                                                                            */
/*               Re-Lock protected registers                                                               */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvSYS_LockProtectedReg(void)
{
    uint32_t lockbit;
    
    SYS->REGWRPROT = 0x00;

    lockbit = SYS->REGWRPROT & 0x01;
    return (lockbit)? E_DRVSYS_ERR_LOCK_FAIL : 0;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_IsProtectedRegLocked                                                                   */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               None                                                                                      */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               1: The protected Registers are unlocked                                                   */
/*               0: The protected Registers are locked                                                     */
/* Description:                                                                                            */
/*               This function is used to check the protected registers are locked or not                  */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvSYS_IsProtectedRegLocked(void)
{
    return (SYS->REGWRPROT & 0x01);
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_GetResetSource                                                                         */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               None                                                                                      */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               Reset source                                                                              */
/*                                                                                                         */
/* Description:                                                                                            */
/*               Get reset source from last operation                                                      */
/*---------------------------------------------------------------------------------------------------------*/
uint32_t DrvSYS_GetResetSource(void)
{
    return *((__IO uint32_t *) &SYS->RSTSRC);
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_ClearResetSource                                                                       */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               u32Src     - [in]    The corresponding bit of reset source                                */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               0                                                                                         */
/* Description:                                                                                            */
/*               Clear reset source by write 1                                                             */
/*---------------------------------------------------------------------------------------------------------*/
uint32_t DrvSYS_ClearResetSource(uint32_t u32Src)
{
    *((__IO uint32_t *) &SYS->RSTSRC) = u32Src;
    return 0;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvSYS_ResetIP                                                                                */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               eIpRst  - [in]     E_SYS_GPIO_RST  / E_SYS_TMR0_RST / E_SYS_TMR1_RST / E_SYS_TMR2_RST     */
/*                                  E_SYS_TMR3_RST  / E_SYS_I2C0_RST / E_SYS_I2C1_RST / E_SYS_SPI0_RST     */
/*                                  E_SYS_SPI1_RST  / E_SYS_SPI2_RST / E_SYS_SPI3_RST / E_SYS_UART0_RST    */
/*                                  E_SYS_UART1_RST / E_SYS_UART2_RST/ E_SYS_PWM03_RST/ E_SYS_PWM47_RST    */
/*                                  E_SYS_ACMP_RST  / E_SYS_PS2_RST  / E_SYS_CAN0_RST / E_SYS_USBD_RST     */
/*                                  E_SYS_ADC_RST   / E_SYS_I2S_RST  / E_SYS_PDMA_RST / E_SYS_EBI_RST      */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               None                                                                                      */
/*                                                                                                         */
/* Description:                                                                                            */
/*               Reset coresponding IP                                                                     */
/*                                                                                                         */
/* Note:                                                                                                   */
/*               Please make sure that Register Write-Protection Function has been disabled before using   */
/*               this function to reset EBI or PDMA.                                                       */
/*               User can check the status of Register Write-Protection Function                           */
/*               with DrvSYS_IsProtectedRegLocked().                                                       */

⌨️ 快捷键说明

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