150 lines
4.7 KiB
C
150 lines
4.7 KiB
C
/*!
|
|
* \file xc_drv_clock.h
|
|
*
|
|
* \brief The header of xc_drv_clock.c
|
|
*
|
|
* \copyright Revised BSD License, see section \ref LICENSE.
|
|
*
|
|
* \code
|
|
*
|
|
* _ __ _ ________ _
|
|
* | |/ /(_)___ / ____/ /_ (_)___
|
|
* | // / __ \/ / / __ \/ / __ \
|
|
* / |/ / / / / /___/ / / / / /_/ /
|
|
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
|
* /_/
|
|
* (C) 2022-2025 XinChip
|
|
*
|
|
* \endcode
|
|
*
|
|
* \author ( XinChip ) Alex-J
|
|
*
|
|
* \author ( XinChip )
|
|
*/
|
|
|
|
#ifndef _XC_DRV_CLOCK_H_
|
|
#define _XC_DRV_CLOCK_H_
|
|
|
|
/*-----------------------------------------------------------------------------------
|
|
INCLUDE HEADE FILES
|
|
------------------------------------------------------------------------------------*/
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
|
|
#include "xc6xxx.h"
|
|
/*------------------------------------------------------------------------------------
|
|
Macros
|
|
-------------------------------------------------------------------------------------*/
|
|
#define CLOCK_SRC_OSC32M 0x00
|
|
#define CLOCK_SRC_OSC 0x00
|
|
#define CLOCK_SRC_BBPLL 0x01
|
|
#define CLOCK_SRC_BBPLL_DIV 0x02
|
|
#if !defined(NO_SUPPORT_HFCLK_RC_16M)
|
|
#define CLOCK_SRC_RC16M 0x03
|
|
#endif //NO_SUPPORT_HFCLK_RC_16M
|
|
|
|
#define LOOPDIV_BBPLL_RES_LEVEL_0 6
|
|
#define LOOPDIV_BBPLL_RES_LEVEL_1 7
|
|
#define LOOPDIV_BBPLL_RES_LEVEL_2 8
|
|
#define LOOPDIV_BBPLL_RES_LEVEL_3 9
|
|
#define LOOPDIV_BBPLL_RES_LEVEL_4 10
|
|
#define LOOPDIV_BBPLL_RES_LEVEL_5 11
|
|
#define LOOPDIV_BBPLL_RES_LEVEL_6 12
|
|
|
|
#define BBPLL_LOCK_DELAY 100
|
|
#define AON_RF_AONREG_DA_LDO_EN_DELAY 100
|
|
|
|
#define ANA2_REG (*(volatile uint32_t *)(0x53021008))
|
|
#define ANA17_REG (*(volatile uint32_t *)(0x53021044))
|
|
#define ANA24_REG (*(volatile uint32_t *)(0x53021060))
|
|
|
|
/*------------------------------------------------------------------------------------
|
|
TypeDef
|
|
-------------------------------------------------------------------------------------*/
|
|
|
|
typedef enum
|
|
{
|
|
CLOCK_LFCLK_SRC_RC = 0, /* Internal 32 KHz RC oscillator. */
|
|
CLOCK_LFCLK_SRC_XTAL = 1, /* External 32 KHz crystal oscillator. */
|
|
} CLOCK_LFCLK_Src_Typedef;
|
|
|
|
typedef enum
|
|
{
|
|
CLOCK_LFCLK_IN_32K = 32000,
|
|
CLOCK_LFCLK_IN_32768 = 32768,
|
|
} CLOCK_LFCLK_In_Typedef;
|
|
|
|
typedef enum
|
|
{
|
|
#if !defined(NO_SUPPORT_HFCLK_RC_16M)
|
|
CLOCK_HFCLK_SRC_RC = 0, /* Internal 16 MHz RC oscillator. */
|
|
#endif
|
|
CLOCK_HFCLK_SRC_XTAL = 1, /* External 32 MHz crystal oscillator. */
|
|
} CLOCK_HFCLK_Src_Typedef;
|
|
|
|
typedef enum
|
|
{
|
|
CLOCK_HFCLK_IN_16M = 16000000,
|
|
CLOCK_HFCLK_IN_24M = 24000000,
|
|
CLOCK_HFCLK_IN_32M = 32000000,
|
|
CLOCK_HFCLK_IN_48M = 48000000,
|
|
CLOCK_HFCLK_IN_64M = 64000000,
|
|
#if !defined(NO_SUPPORT_HFCLK_BBPLL_96M)
|
|
CLOCK_HFCLK_IN_96M = 96000000,
|
|
#endif //NO_SUPPORT_HFCLK_BBPLL_96M
|
|
#if !defined(NO_SUPPORT_HFCLK_BBPLL_128M)
|
|
CLOCK_HFCLK_IN_128M = 128000000,
|
|
#endif //NO_SUPPORT_HFCLK_BBPLL_128M
|
|
} CLOCK_HFCLK_In_Typedef;
|
|
|
|
typedef enum
|
|
{
|
|
SYSTICK_UNIT_IN_16M = 16,
|
|
SYSTICK_UNIT_IN_24M = 24,
|
|
SYSTICK_UNIT_IN_32M = 32,
|
|
SYSTICK_UNIT_IN_48M = 48,
|
|
SYSTICK_UNIT_IN_64M = 64,
|
|
#if !defined(NO_SUPPORT_HFCLK_BBPLL_96M)
|
|
SYSTICK_UNIT_IN_96M = 96
|
|
#endif //NO_SUPPORT_HFCLK_BBPLL_96M
|
|
} Systick_Unit_Typedef;
|
|
|
|
typedef struct
|
|
{
|
|
CLOCK_HFCLK_Src_Typedef hfclk_src;
|
|
CLOCK_HFCLK_In_Typedef hfclk_in;
|
|
|
|
CLOCK_LFCLK_Src_Typedef lfclk_src;
|
|
CLOCK_LFCLK_In_Typedef lfclk_in;
|
|
|
|
Systick_Unit_Typedef systick_unit;
|
|
|
|
} CLOCK_InitCfg_t;
|
|
|
|
typedef struct
|
|
{
|
|
CLOCK_InitCfg_t *cb;
|
|
uint8_t bbpll_loopdiv;
|
|
uint8_t bbpll_clkdiv;
|
|
uint8_t mclk_src;
|
|
} Hfclk_InitCfg_t;
|
|
|
|
/*------------------------------------------------------------------------------------
|
|
Global Variables
|
|
-------------------------------------------------------------------------------------*/
|
|
extern CLOCK_InitCfg_t clock_cb;
|
|
/*------------------------------------------------------------------------------------
|
|
Exported Functions
|
|
-------------------------------------------------------------------------------------*/
|
|
void xc_clock_bbpll_common_cfg(void);
|
|
void xc_clock_init_cfg(CLOCK_InitCfg_t *clock_cfg);
|
|
CLOCK_HFCLK_In_Typedef xc_clock_hfclk_in_get(void);
|
|
CLOCK_LFCLK_In_Typedef xc_clock_lfclk_in_get(void);
|
|
CLOCK_HFCLK_Src_Typedef xc_clock_hfclk_src_get(void);
|
|
CLOCK_LFCLK_Src_Typedef xc_clock_lfclk_src_get(void);
|
|
Systick_Unit_Typedef xc_systick_unit_get(void);
|
|
void xc_system_param_check(void);
|
|
void xc_system_param_check_rf24g(void);
|
|
|
|
#endif // _XC_DRV_CLOCK_H_
|