rt-thread/bsp/nv32f100x/lib/inc/ics.h

348 lines
9.8 KiB
C
Raw Normal View History

2017-09-20 14:21:18 +08:00
/******************************************************************************
*
* @brief ICS <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>.
*
******************************************************************************/
#ifndef ICS_H_
#define ICS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "common.h"
/****************************************************************************!
* @brief ʱ<EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
***************************************************************************/
enum
{
ICS_CLK_MODE_FEI = 1, /*!< FEI ģʽ */
ICS_CLK_MODE_FEE, /*!< FEE ģʽ */
ICS_CLK_MODE_FEE_OSC, /*!< FEE ģʽ OSC<53><43><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Դѡ<D4B4><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>EXTAL<41><4C><EFBFBD>ŵ<EFBFBD><C5B5>ⲿʱ<E2B2BF><CAB1>Դ */
ICS_CLK_MODE_FBE, /*!< FBE ģʽ */
ICS_CLK_MODE_FBE_OSC, /*!< FBE ģʽ OSC<53><43><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Դѡ<D4B4><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>EXTAL<41><4C><EFBFBD>ŵ<EFBFBD><C5B5>ⲿʱ<E2B2BF><CAB1>Դ */
ICS_CLK_MODE_FBI, /*!< FBI ģʽ */
ICS_CLK_MODE_FBILP, /*!< FBILP ģʽ */
ICS_CLK_MODE_FBELP, /*!< FBELP ģʽ */
};
/*****************************************************************************//*!
*
* @brief <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ģʽ<EFBFBD>ӵ<EFBFBD>ǰģʽ<EFBFBD>л<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ģʽ.
*
* ʱ<EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD>۶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
* FEI, FBI, FEE, FBE, FBILP, FBELP, FEE_OSC, FBE_OSC
* ע<EFBFBD><EFBFBD>FEE_OSC, FBE_OSC <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰʱ<EFBFBD><EFBFBD>ģʽ. <EFBFBD><EFBFBD>ǰʱ<EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD>Ҫ<EFBFBD>л<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
* < <EFBFBD><EFBFBD>ǰʱ<EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD>Ҫ<EFBFBD>л<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ģʽ>
* <FEI,FEE>, <FEI,FBI>, <FEI,FBE>, <FEI,FBE_OSC>, <FEI,FEE_OSC>, <FEE,FEI>,
* <FEE,FBI>, <FEE,FBE>, <FBI,FBE>, <FBI,FEE>, <FBI,FBILP>, <FBI,FEI>,
* <FBE,FBI>, <FBE,FEE>, <FBE,FEI>, <FBE,FBELP>, <FBELP,FBE>, <FBILP,FBI>.
*
* @param[in] CurMode <EFBFBD><EFBFBD>ǰʱ<EFBFBD><EFBFBD>ģʽ
* @param[in] NewMode Ҫ<EFBFBD>л<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ģʽ
* @param[in] clkFreq <EFBFBD>ο<EFBFBD>ʱ<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>
*
* @return none
* @warning FEE_OSC, FBE_OSC <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰʱ<EFBFBD><EFBFBD>ģʽ.
*
*****************************************************************************/
#define ICS_SwitchMode(CurMode, NewMode, clkFreq) CurMode##_to_##NewMode(clkFreq)
/******************************************************************************
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> OSC <EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><EFBFBD>
*
*******************************************************************************/
typedef struct
{
uint8_t bRange : 1; /*!< 1: <20><>Ƶ<EFBFBD><C6B5>Χ, 0: <20><>Ƶ<EFBFBD><C6B5>Χ */
uint8_t bGain : 1; /*!< 1: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 0:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
uint8_t bEnable : 1; /*!< 1: ʹ<><CAB9>OSC, 0: <20><><EFBFBD><EFBFBD>OSC */
uint8_t bStopEnable : 1; /*!< 1: ֹͣģʽ<C4A3><CABD>OSCʹ<43><CAB9>, 0: ֹͣģʽ<C4A3><CABD>OSC<53><43><EFBFBD><EFBFBD> */
uint8_t bIsCryst : 1; /*!< 1: OSC<53><43><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>, 0: OSC<53><43><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>extal<61><6C><EFBFBD>ŵ<EFBFBD><C5B5>ⲿʱ<E2B2BF><CAB1> */
uint8_t bWaitInit : 1; /*!< 1: <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 0: <20><><EFBFBD>ȴ<EFBFBD> */
} OSC_ConfigType, *OSC_ConfigPtr;
/******************************************************************************
*
* ICS<EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><EFBFBD>
*
*******************************************************************************/
typedef struct
{
uint8_t u8ClkMode; /*!< ѡ<><D1A1>ʱ<EFBFBD><CAB1>ģʽ*/
uint8_t bLPEnable; /*!< <20>͹<EFBFBD><CDB9><EFBFBD>ģʽ<C4A3><CABD>ʹ<EFBFBD><CAB9> */
uint32_t u32ClkFreq; /*!< <20>ο<EFBFBD>ʱ<EFBFBD><CAB1>Ƶ<EFBFBD><C6B5> */
OSC_ConfigType oscConfig; /*!< OSC <20><><EFBFBD><EFBFBD> */
} ICS_ConfigType ;
/*****************************************************************************//*!
*
* @brief ʹ<EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>.
*
* @param none
*
* @return none
*
* @see ICS_DisableInt
*****************************************************************************/
__STATIC_INLINE void ICS_EnableInt(void)
{
ICS->C4 |= (ICS_C4_LOLIE_MASK);
}
/*****************************************************************************//*!
*
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
*
* @param none
*
* @return none
*
* @see ICS_EnableInt
*****************************************************************************/
__STATIC_INLINE void ICS_DisableInt(void)
{
ICS->C4 &= ~(ICS_C4_LOLIE_MASK);
}
/*****************************************************************************//*!
*
* @brief ʹ<EFBFBD><EFBFBD>ʱ<EFBFBD>Ӽ<EFBFBD><EFBFBD><EFBFBD>
*
* @param none
*
* @return none
*
* @see ICS_DisableClockMonitor
*****************************************************************************/
__STATIC_INLINE void ICS_EnableClockMonitor(void)
{
ICS->C4 |= (ICS_C4_CME_MASK);
}
/*****************************************************************************//*!
*
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ӽ<EFBFBD><EFBFBD><EFBFBD>
*
* @param none
*
* @return none
*
* @see ICS_EnableClockMonitor
*****************************************************************************/
__STATIC_INLINE void ICS_DisableClockMonitor(void)
{
ICS->C4 &= ~(ICS_C4_CME_MASK);
}
/*****************************************************************************//*!
*
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ICS<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD>Ƶ
*
* @param[in] busDivide -- <EFBFBD><EFBFBD>Ƶֵ
*
* @return depends on commands
*****************************************************************************/
__STATIC_INLINE void ICS_SetBusDivider(uint8_t u8BusDivide)
{
ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(u8BusDivide);
}
/*****************************************************************************//*!
*
* @brief ʹ<EFBFBD><EFBFBD>OSC
*
* @param none
*
* @return none
*
*****************************************************************************/
__STATIC_INLINE void OSC_Enable(void)
{
OSC->CR |= (OSC_CR_OSCEN_MASK);
}
/*****************************************************************************//*!
*
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>OSC
*
* @param none
*
* @return none
*
*****************************************************************************/
__STATIC_INLINE void OSC_Disable(void)
{
OSC->CR &= ~(OSC_CR_OSCEN_MASK);
}
/*****************************************************************************//*!
*
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>OSCģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ʷ<EFBFBD>ΧΪ<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>Χ
*
* @param none
*
* @return none
*
*****************************************************************************/
__STATIC_INLINE void OSC_SetLowRange(void)
{
OSC->CR &= ~(OSC_CR_RANGE_MASK);
}
/*!***************************************************************************//*!
+FUNCTION----------------------------------------------------------------
*
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>OSCģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ʷ<EFBFBD>ΧΪ<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>Χ
*
* @param none
*
* @return none
*
*****************************************************************************/
__STATIC_INLINE void OSC_SetHighRange(void)
{
OSC->CR |= (OSC_CR_RANGE_MASK);
}
/*****************************************************************************//*!
*
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>OSC<EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD>ģʽΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
*
* @param none
*
* @return none
*
*****************************************************************************/
__STATIC_INLINE void OSC_SetHighGain(void)
{
OSC->CR |= (OSC_CR_HGO_MASK);
}
/*****************************************************************************//*!
*
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>OSC<EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD>ģʽΪ<EFBFBD>͹<EFBFBD><EFBFBD><EFBFBD>ģʽ
*
* @param none
*
* @return none
*
*****************************************************************************/
__STATIC_INLINE void OSC_SetLowGain(void)
{
OSC->CR &= ~(OSC_CR_HGO_MASK);
}
/*****************************************************************************//*!
*
* @brief ѡ<EFBFBD><EFBFBD>OSCģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ԴΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Դ
*
* @param none
*
* @return none
*
*****************************************************************************/
__STATIC_INLINE void OSC_SelectCrystal(void)
{
OSC->CR |= (OSC_CR_OSCOS_MASK);
}
/*****************************************************************************//*!
*
* @brief OSC<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>extal<EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD>ⲿʱ<EFBFBD><EFBFBD>
*
* @param none
*
* @return none
*
*****************************************************************************/
__STATIC_INLINE void OSC_SelectClock(void)
{
OSC->CR &= ~(OSC_CR_OSCOS_MASK);
}
/*****************************************************************************//*!
*
* @brief <EFBFBD><EFBFBD>ֹͣģʽ<EFBFBD><EFBFBD>OSCģ<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>
*
* @param none
*
* @return none
*
*****************************************************************************/
__STATIC_INLINE void OSC_ActiveInStop(void)
{
OSC->CR |= (OSC_CR_OSCSTEN_MASK);
}
/*****************************************************************************//*!
*
* @brief <EFBFBD><EFBFBD>ֹͣģʽ<EFBFBD><EFBFBD>OSCģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param none
*
* @return none
*
*****************************************************************************/
__STATIC_INLINE void OSC_InactiveInStop(void)
{
OSC->CR &= ~(OSC_CR_OSCSTEN_MASK);
}
/******************************************************************************/
void ICS_Init(ICS_ConfigType *pConfig);
void ICS_DeInit(void);
void ICS_SetClkDivider(uint32_t u32ClkFreqKHz);
void ICS_Trim(uint16 u16TrimValue);
void OSC_Init(OSC_ConfigType *pConfig);
void OSC_DeInit(void);
/************** <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ******************/
void ICS_DisableClockMonitor(void);
void ICS_DisableInt(void);
void ICS_EnableClockMonitor(void);
void ICS_EnableInt(void);
void ICS_SetBusDivider(uint8_t u8BusDivide);
void OSC_ActiveInStop(void);
void OSC_Enable(void);
void OSC_Disable(void);
void OSC_InactiveInStop(void);
void OSC_SelectClock(void);
void OSC_SelectCrystal(void);
void OSC_SetHighGain(void);
void OSC_SetHighRange(void);
void OSC_SetLowGain(void);
void OSC_SetLowRange(void);
/* do not touch the following functions */
void FEI_to_FEE(ICS_ConfigType *pConfig);
void FEI_to_FBI(ICS_ConfigType *pConfig);
void FEI_to_FBE(ICS_ConfigType *pConfig);
void FEE_to_FBI(ICS_ConfigType *pConfig);
void FEE_to_FEI(ICS_ConfigType *pConfig);
void FEE_to_FBE(ICS_ConfigType *pConfig);
void FBE_to_FEE(ICS_ConfigType *pConfig);
void FBE_to_FEI(ICS_ConfigType *pConfig);
void FBE_to_FBI(ICS_ConfigType *pConfig);
void FBE_to_FBELP(ICS_ConfigType *pConfig);
void FBI_to_FEI(ICS_ConfigType *pConfig);
void FBI_to_FBE(ICS_ConfigType *pConfig);
void FBI_to_FEE(ICS_ConfigType *pConfig);
void FBI_to_FBILP(ICS_ConfigType *pConfig);
void FBILP_to_FBI(ICS_ConfigType *pConfig);
void FBELP_to_FBE(ICS_ConfigType *pConfig);
void FEI_to_FBE_OSC(ICS_ConfigType *pConfig);
void FEI_to_FEE_OSC(ICS_ConfigType *pConfig);
#ifdef __cplusplus
}
#endif
#endif