173 lines
3.5 KiB
C
Raw Normal View History

2022-03-26 20:51:40 +08:00
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_SYS.h
* Author : WCH
* Version : V1.2
* Date : 2021/11/17
* Description
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
#ifndef __CH58x_SYS_H__
#define __CH58x_SYS_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief rtc interrupt event define
*/
typedef enum
{
RST_STATUS_SW = 0, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
RST_STATUS_RPOR, // <20>ϵ縴λ
RST_STATUS_WTR, // <20><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ʱ<EFBFBD><CAB1>λ
RST_STATUS_MR, // <20>ⲿ<EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>λ
RST_STATUS_LRM0, // <20><><EFBFBD>Ѹ<EFBFBD>λ-<2D><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
RST_STATUS_GPWSM, // <20>µ<EFBFBD>ģʽ<C4A3><CABD><EFBFBD>Ѹ<EFBFBD>λ
RST_STATUS_LRM1, // <09><><EFBFBD>Ѹ<EFBFBD>λ-<2D><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD><EFBFBD><EFBFBD>
RST_STATUS_LRM2, // <09><><EFBFBD>Ѹ<EFBFBD>λ-<2D>ֶ<EFBFBD><D6B6><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
} SYS_ResetStaTypeDef;
/**
* @brief rtc interrupt event define
*/
typedef enum
{
INFO_ROM_READ = 0, // FlashROM <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ƿ<EFBFBD><C7B7>ɶ<EFBFBD>
INFO_RESET_EN = 2, // RST#<23>ⲿ<EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EBB9A6><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
INFO_BOOT_EN, // ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> BootLoader <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
INFO_DEBUG_EN, // ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խӿ<D4BD><D3BF>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
INFO_LOADER, // <20><>ǰϵͳ<CFB5>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>Bootloader <20><>
STA_SAFEACC_ACT, // <20><>ǰϵͳ<CFB5>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڰ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RWA<57><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򲻿ɷ<F2B2BBBF><C9B7><EFBFBD>
} SYS_InfoStaTypeDef;
/**
* @brief <EFBFBD><EFBFBD>ȡоƬID<EFBFBD>һ<EFBFBD><EFBFBD>Ϊ<EFBFBD>̶<EFBFBD>ֵ
*/
#define SYS_GetChipID() R8_CHIP_ID
/**
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>Ϊ<EFBFBD>̶<EFBFBD>ֵ
*/
#define SYS_GetAccessID() R8_SAFE_ACCESS_ID
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
*
* @param sc - ϵͳʱ<EFBFBD><EFBFBD>Դѡ<EFBFBD><EFBFBD> refer to SYS_CLKTypeDef
*/
void SetSysClock(SYS_CLKTypeDef sc);
/**
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ǰϵͳʱ<EFBFBD><EFBFBD>
*
* @return Hz
*/
uint32_t GetSysClock(void);
/**
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ǰϵͳ<EFBFBD><EFBFBD>Ϣ״̬
*
* @param i - refer to SYS_InfoStaTypeDef
*
* @return <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t SYS_GetInfoSta(SYS_InfoStaTypeDef i);
/**
* @brief <EFBFBD><EFBFBD>ȡϵͳ<EFBFBD>ϴθ<EFBFBD>λ״̬
*
* @return refer to SYS_ResetStaTypeDef
*/
#define SYS_GetLastResetSta() (R8_RESET_STATUS & RB_RESET_FLAG)
/**
* @brief ִ<EFBFBD><EFBFBD>ϵͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
*/
void SYS_ResetExecute(void);
/**
* @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><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>
*
* @param i - refer to SYS_InfoStaTypeDef
*/
#define SYS_ResetKeepBuf(d) (R8_GLOB_RESET_KEEP = d)
/**
* @brief <EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ж<EFBFBD>ֵ
*
* @param pirqv - <EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ֵ
*/
void SYS_DisableAllIrq(uint32_t *pirqv);
/**
* @brief <EFBFBD>ָ<EFBFBD>֮ǰ<EFBFBD>رյ<EFBFBD><EFBFBD>ж<EFBFBD>ֵ
*
* @param irq_status - <EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ֵ
*/
void SYS_RecoverIrq(uint32_t irq_status);
/**
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ǰϵͳ(SYSTICK)<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
*
* @return <EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
*/
uint32_t SYS_GetSysTickCnt(void);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD>ؿ<EFBFBD><EFBFBD>Ź<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param c - <EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
*/
#define WWDG_SetCounter(c) (R8_WDOG_COUNT = c)
/**
* @brief <EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><EFBFBD>
*
* @param s - <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ж<EFBFBD>
*/
void WWDG_ITCfg(FunctionalState s);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param s - <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>λ
*/
void WWDG_ResetCfg(FunctionalState s);
/**
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
*
* @return <EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
*/
#define WWDG_GetFlowFlag() (R8_RST_WDOG_CTRL & RB_WDOG_INT_FLAG)
/**
* @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>
*/
void WWDG_ClearFlag(void);
/**
* @brief uS <EFBFBD><EFBFBD>ʱ
*
* @param t - ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
void mDelayuS(uint16_t t);
/**
* @brief mS <EFBFBD><EFBFBD>ʱ
*
* @param t - ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
void mDelaymS(uint16_t t);
#ifdef __cplusplus
}
#endif
#endif // __CH58x_SYS_H__