送样江西
This commit is contained in:
parent
28eeb4d4f2
commit
f01da795ed
|
@ -145,7 +145,7 @@ void app_task_handler(TeAppEvtType app_evt_type)
|
|||
// tmos_set_event(led_task_id, LED_SHOW_START_EVT);
|
||||
BSP_BlockSleep();
|
||||
BSP_RequestBoost();
|
||||
DelayMs(1);;
|
||||
DelayMs(1);
|
||||
ShowLed();
|
||||
// tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT);
|
||||
// tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000);
|
||||
|
|
|
@ -110,18 +110,20 @@ __HIGH_CODE
|
|||
// 由按键中断唤醒后开启按键扫描
|
||||
void BSP_KEY_EnterLowpower(void)
|
||||
{
|
||||
// https://www.cnblogs.com/frontier/p/18743204
|
||||
#if 1
|
||||
// TODO:按键电平触发设置
|
||||
// GPIOB_ModeCfg( KEY_B_PIN, GPIO_ModeIN_PU );
|
||||
// 下降沿触发
|
||||
GPIOB_ITModeCfg(KEY_B_PIN, GPIO_ITMode_FallEdge);
|
||||
|
||||
// 开启GPIOB中断
|
||||
PFIC_EnableIRQ(GPIO_B_IRQn);
|
||||
|
||||
// 开启GPIO的睡眠唤醒,如果需要的话
|
||||
// PWR_PeriphWakeUpCfg(ENABLE, RB_SLP_GPIO_WAKE, Long_Delay);
|
||||
PWR_PeriphWakeUpCfg(ENABLE, RB_GPIO_WAKE_MODE | RB_SLP_GPIO_WAKE, Long_Delay);
|
||||
|
||||
// 开启GPIOB中断
|
||||
PFIC_EnableIRQ(GPIO_B_IRQn);
|
||||
|
||||
BSP_RequestSleep();
|
||||
#endif
|
||||
}
|
||||
|
@ -265,13 +267,13 @@ void BSP_KEY_Init(app_task_evt_handler_t handler)
|
|||
GPIOB_ITModeCfg(GPIO_Pin_0, GPIO_ITMode_FallEdge);
|
||||
// GPIOB_ITModeCfg(GPIO_Pin_1, GPIO_ITMode_FallEdge);
|
||||
|
||||
// 开启GPIOB中断
|
||||
PFIC_EnableIRQ(GPIO_B_IRQn);
|
||||
|
||||
// 开启GPIO的睡眠唤醒,如果需要的话
|
||||
// PWR_PeriphWakeUpCfg(ENABLE, RB_SLP_GPIO_WAKE, Long_Delay);
|
||||
PWR_PeriphWakeUpCfg(ENABLE, RB_GPIO_WAKE_MODE | RB_SLP_GPIO_WAKE, Long_Delay);
|
||||
|
||||
// 开启GPIOB中断
|
||||
PFIC_EnableIRQ(GPIO_B_IRQn);
|
||||
|
||||
tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(KEY_SACN_MS));
|
||||
#endif
|
||||
logDebug("BSP_KEY_Init=%d", IS_KEY_Vaild());
|
||||
|
@ -313,7 +315,7 @@ void GPIOB_IRQHandler(void)
|
|||
// PRINT("KEY IRQ\n");
|
||||
|
||||
// GPIOB_ClearITFlagBit(KEY_B_PIN);
|
||||
GPIOB_ClearITFlagBit(GPIO_Pin_0);
|
||||
GPIOB_ClearITFlagBit(KEY_B_PIN);
|
||||
// GPIOB_ClearITFlagBit(GPIO_Pin_1);
|
||||
|
||||
// tmos_set_event(key_task_id, KEY_SCAN_EVT);
|
||||
|
|
10
HAL/KEY.c
10
HAL/KEY.c
|
@ -1,3 +1,13 @@
|
|||
/*
|
||||
* @Author : stark1898y 1658608470@qq.com
|
||||
* @Date : 2024-12-30 10:11:28
|
||||
* @LastEditors : stark1898y 1658608470@qq.com
|
||||
* @LastEditTime : 2025-04-08 16:39:05
|
||||
* @FilePath : \BLE_TYQ_CH584M\HAL\KEY.c
|
||||
* @Description :
|
||||
*
|
||||
* Copyright (c) 2025 by yzy, All Rights Reserved.
|
||||
*/
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : KEY.c
|
||||
* Author : WCH
|
||||
|
|
10
HAL/LED.c
10
HAL/LED.c
|
@ -1,13 +1,3 @@
|
|||
/*
|
||||
* @Author : stark1898y 1658608470@qq.com
|
||||
* @Date : 2024-12-30 10:11:28
|
||||
* @LastEditors : stark1898y 1658608470@qq.com
|
||||
* @LastEditTime : 2025-03-27 10:11:31
|
||||
* @FilePath : \BLE_TYQ_CH584M\HAL\LED.c
|
||||
* @Description :
|
||||
*
|
||||
* Copyright (c) 2025 by yzy, All Rights Reserved.
|
||||
*/
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : LED.c
|
||||
* Author : WCH
|
||||
|
|
10
HAL/MCU.c
10
HAL/MCU.c
|
@ -1,13 +1,3 @@
|
|||
/*
|
||||
* @Author : stark1898y 1658608470@qq.com
|
||||
* @Date : 2024-12-30 10:11:28
|
||||
* @LastEditors : stark1898y 1658608470@qq.com
|
||||
* @LastEditTime : 2025-03-27 10:11:40
|
||||
* @FilePath : \BLE_TYQ_CH584M\HAL\MCU.c
|
||||
* @Description :
|
||||
*
|
||||
* Copyright (c) 2025 by yzy, All Rights Reserved.
|
||||
*/
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : MCU.c
|
||||
* Author : WCH
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @Author : stark1898y 1658608470@qq.com
|
||||
* @Date : 2024-12-30 10:11:28
|
||||
* @LastEditors : stark1898y 1658608470@qq.com
|
||||
* @LastEditTime : 2025-03-27 10:11:52
|
||||
* @LastEditTime : 2025-04-08 16:40:29
|
||||
* @FilePath : \BLE_TYQ_CH584M\HAL\RTC.c
|
||||
* @Description :
|
||||
*
|
||||
|
@ -107,6 +107,7 @@ static void SYS_SetTignOffest( int32_t val )
|
|||
*
|
||||
* @return None.
|
||||
*/
|
||||
__HIGH_CODE
|
||||
void RTC_SetTignTime(uint32_t time)
|
||||
{
|
||||
sys_safe_access_enable();
|
||||
|
|
38
HAL/SLEEP.c
38
HAL/SLEEP.c
|
@ -55,7 +55,8 @@ void BSP_NoNeedBoost(void)
|
|||
block_boost_flag = true;
|
||||
}
|
||||
|
||||
#include "bsp_uart.h"
|
||||
|
||||
pfnLowPowerGapProcessCB_t LowPowerGapProcess;
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn CH58x_LowPower
|
||||
|
@ -149,11 +150,23 @@ uint32_t CH58x_LowPower(uint32_t time)
|
|||
}
|
||||
BSP_KEY_EnterLowpower();
|
||||
|
||||
LowPower_Sleep(RB_PWR_RAM32K | RB_PWR_RAM96K | RB_PWR_EXTEND | RB_XT_PRE_EN);
|
||||
LowPower_Sleep(RB_PWR_RAM32K | RB_PWR_RAM96K | RB_PWR_EXTEND);
|
||||
R8_RTC_FLAG_CTRL = (RB_RTC_TMR_CLR | RB_RTC_TRIG_CLR);
|
||||
RTC_SetTignTime(time);
|
||||
sys_safe_access_enable();
|
||||
R8_HFCK_PWR_CTRL |= RB_CLK_XT32M_KEEP;
|
||||
sys_safe_access_disable();
|
||||
|
||||
|
||||
if(!RTCTigFlag)
|
||||
{
|
||||
LowPower_Halt();
|
||||
}
|
||||
R8_RTC_FLAG_CTRL = (RB_RTC_TMR_CLR | RB_RTC_TRIG_CLR);
|
||||
HSECFG_Current(HSE_RCur_100); // 降为额定电流(低功耗函数中提升了HSE偏置电流)
|
||||
|
||||
i = RTC_GetCycle32k();
|
||||
while (i == RTC_GetCycle32k());
|
||||
// i = RTC_GetCycle32k();
|
||||
// while (i == RTC_GetCycle32k());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -161,6 +174,23 @@ uint32_t CH58x_LowPower(uint32_t time)
|
|||
return 3;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn LowPowerGapProcess_Register
|
||||
*
|
||||
* @brief 注册低功耗唤醒间隙执行回调
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void LowPowerGapProcess_Register(pfnLowPowerGapProcessCB_t cb)
|
||||
{
|
||||
if((uint32_t)cb & 0x20000000)
|
||||
{
|
||||
LowPowerGapProcess = cb;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn HAL_SleepInit
|
||||
*
|
||||
|
|
|
@ -140,7 +140,7 @@
|
|||
#define PERIPHERAL_MAX_CONNECTION 1
|
||||
#endif
|
||||
#ifndef CENTRAL_MAX_CONNECTION
|
||||
#define CENTRAL_MAX_CONNECTION 2
|
||||
#define CENTRAL_MAX_CONNECTION 3
|
||||
#endif
|
||||
|
||||
extern uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];
|
||||
|
|
|
@ -23,12 +23,11 @@ extern "C" {
|
|||
*/
|
||||
|
||||
/* LEDS - The LED number is the same as the bit position */
|
||||
#define HAL_LED_R 0x01
|
||||
#define HAL_LED_G 0x02
|
||||
#define HAL_LED_Y 0x04
|
||||
// BEEP
|
||||
#define HAL_LED_BEEP 0x08
|
||||
#define HAL_LED_ALL (HAL_LED_R | HAL_LED_G | HAL_LED_Y | HAL_LED_BEEP)
|
||||
#define HAL_LED_1 0x01
|
||||
#define HAL_LED_2 0x02
|
||||
#define HAL_LED_3 0x04
|
||||
#define HAL_LED_4 0x08
|
||||
#define HAL_LED_ALL (HAL_LED_1 | HAL_LED_2 | HAL_LED_3 | HAL_LED_4)
|
||||
|
||||
/* Modes */
|
||||
#define HAL_LED_MODE_OFF 0x00
|
||||
|
@ -50,42 +49,33 @@ extern "C" {
|
|||
/* 连接一个LED用于监控演示程序的进度,低电平LED亮 */
|
||||
|
||||
/* 1 - LED */
|
||||
#define LEDR_BV BV(4) // PA4
|
||||
#define LEDG_BV BV(5) // PA5
|
||||
#define LEDY_BV BV(15) // PA15
|
||||
#define LED1_BV BV(15)
|
||||
#define LED2_BV
|
||||
#define LED3_BV
|
||||
|
||||
#define BEEP_BV BV(14) // PA14
|
||||
#define LED1_OUT (R32_PB_OUT)
|
||||
#define LED2_OUT 0
|
||||
#define LED3_OUT 0
|
||||
#define LED4_OUT 0
|
||||
|
||||
#define LEDR_OUT (R32_PA_OUT)
|
||||
#define LEDG_OUT (R32_PA_OUT)
|
||||
#define LEDY_OUT (R32_PA_OUT)
|
||||
#define LED1_DDR (R32_PB_DIR |= LED1_BV)
|
||||
#define LED2_DDR 0
|
||||
#define LED3_DDR 0
|
||||
|
||||
#define BEEP_OUT (R32_PA_OUT)
|
||||
#define HAL_TURN_OFF_LED1() (LED1_OUT |= LED1_BV)
|
||||
#define HAL_TURN_OFF_LED2()
|
||||
#define HAL_TURN_OFF_LED3()
|
||||
#define HAL_TURN_OFF_LED4()
|
||||
|
||||
#define LEDR_DDR (R32_PA_DIR |= LEDR_BV)
|
||||
#define LEDG_DDR (R32_PA_DIR |= LEDG_BV)
|
||||
#define LEDY_DDR (R32_PA_DIR |= LEDY_BV)
|
||||
#define HAL_TURN_ON_LED1() (LED1_OUT &= (~LED1_BV))
|
||||
#define HAL_TURN_ON_LED2()
|
||||
#define HAL_TURN_ON_LED3()
|
||||
#define HAL_TURN_ON_LED4()
|
||||
|
||||
#define BEEP_DDR (R32_PA_DIR |= BEEP_BV)
|
||||
|
||||
|
||||
#define HAL_TURN_OFF_LEDR() (LEDR_OUT &= (~LEDR_BV))
|
||||
#define HAL_TURN_OFF_LEDG() (LEDG_OUT &= (~LEDG_BV))
|
||||
#define HAL_TURN_OFF_LEDY() (LEDY_OUT &= (~LEDY_BV))
|
||||
|
||||
#define HAL_TURN_OFF_BEEP() (BEEP_OUT |= BEEP_BV)
|
||||
|
||||
#define HAL_TURN_ON_LEDR() (LEDR_OUT |= LEDR_BV)
|
||||
#define HAL_TURN_ON_LEDG() (LEDG_OUT |= LEDG_BV)
|
||||
#define HAL_TURN_ON_LEDY() (LEDY_OUT |= LEDY_BV)
|
||||
|
||||
#define HAL_TURN_ON_BEEP() (BEEP_OUT |= BEEP_BV)
|
||||
|
||||
#define HAL_STATE_LEDR() GPIOA_ReadPortPin(LEDR_BV)
|
||||
#define HAL_STATE_LEDG() GPIOA_ReadPortPin(LEDG_BV)
|
||||
#define HAL_STATE_LEDY() GPIOA_ReadPortPin(LEDY_BV)
|
||||
|
||||
#define HAL_STATE_BEEP() GPIOA_ReadPortPin(BEEP_BV)
|
||||
#define HAL_STATE_LED1() 0
|
||||
#define HAL_STATE_LED2() 0
|
||||
#define HAL_STATE_LED3() 0
|
||||
#define HAL_STATE_LED4() 0
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
|
|
|
@ -28,7 +28,10 @@ void BSP_BlockSleep(void);
|
|||
void BSP_RequestBoost(void);
|
||||
void BSP_NoNeedBoost(void);
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
typedef void (*pfnLowPowerGapProcessCB_t)( void );
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
|
@ -47,6 +50,7 @@ extern void HAL_SleepInit(void);
|
|||
* @return state.
|
||||
*/
|
||||
extern uint32_t CH58x_LowPower(uint32_t time);
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
|
|
22961
LIB/CH584BLE_ROMx.hex
22961
LIB/CH584BLE_ROMx.hex
File diff suppressed because it is too large
Load Diff
22961
LIB/CH585BLE_ROMx.hex
22961
LIB/CH585BLE_ROMx.hex
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
71
LIB/wchrf.h
71
LIB/wchrf.h
|
@ -1,7 +1,7 @@
|
|||
/********************************** (C) COPYRIGHT ******************************
|
||||
* File Name : wchrf.h
|
||||
* Author : WCH
|
||||
* Version : V1.20
|
||||
* Version : V1.33
|
||||
* Date : 2024/9/27
|
||||
* Description : head file(CH585/CH584)
|
||||
*
|
||||
|
@ -84,6 +84,18 @@ typedef struct
|
|||
#define RF_ROLE_BOUND_MAX (0x07)
|
||||
#define RF_ROLE_BOUND_ID RF_ROLE_ID_INVALD
|
||||
#define RF_ROLE_DISCARDED_EN (1<<3)
|
||||
|
||||
/* bound status */
|
||||
#define BOUND_STA_SUCCESS 0x00 //!< Success
|
||||
#define BOUND_STA_FAILURE 0x01 //!< Failure
|
||||
#define BOUND_STA_INVALIDPARM 0x02 //!< Invalid request field
|
||||
#define BOUND_STA_TIMEOUT 0x17 //!< timeout
|
||||
|
||||
/* bound request */
|
||||
#define BOUNG_REQ_TYPE 0x01 //!< 4k mode
|
||||
#define BOUNG_FAST_REQ_TYPE 0x02 //!< 8k mode
|
||||
#define BOUNG_UNACK_REQ_TYPE 0x03 //!< unack mode
|
||||
|
||||
/* package type */
|
||||
typedef struct
|
||||
{
|
||||
|
@ -106,6 +118,7 @@ typedef struct
|
|||
uint16_t rxMaxLen; //!< The maximum length of data received
|
||||
uint16_t sendInterval; //!< Resend interval N*0.5us
|
||||
uint16_t sendTime; //!< Time to switch from Rx t0 Tx (N*0.5us)+24us
|
||||
uint8_t mapCheckCount; //!< Set the threshold of continuous packet loss to determine the quality of the channel.(default 2)
|
||||
} rfRoleParam_t;
|
||||
|
||||
/* rfip tx parameter */
|
||||
|
@ -142,9 +155,10 @@ typedef struct
|
|||
typedef struct
|
||||
{
|
||||
bStatus_t status; //!< Status for the connection
|
||||
/* SUCESS
|
||||
* bleTimeout:When the connection times out, it automatically switches to the bindable state
|
||||
* FAILURE:If the device binding fails on the device side, the application layer needs to restart the binding */
|
||||
/* SUCCESS
|
||||
* BOUND_STA_FAILURE: If the device binding fails on the device side, the application layer needs to restart the binding
|
||||
* BOUND_STA_INVALIDPARM: When the host receives a mismatched connection request, devType indicates the bound request type of the peer side
|
||||
* BOUND_STA_TIMEOUT: When the connection times out, it automatically switches to the bind state */
|
||||
uint8_t role; //!< the role of the binding
|
||||
uint8_t devId; //!< The ID number of the binding
|
||||
uint8_t devType; //!< The device type of the binding
|
||||
|
@ -258,6 +272,24 @@ void RFIP_Calibration( void );
|
|||
*/
|
||||
void RFIP_WakeUpRegInit( void );
|
||||
|
||||
/**
|
||||
* @brief rf mode single channel mode.
|
||||
*
|
||||
* @param ch - rf channel,f=2402+ch*2 MHz, ch=0,...,39
|
||||
*
|
||||
* @return 0 - success, 1- phy busy
|
||||
*/
|
||||
bStatus_t RFIP_SingleChannel( uint8_t ch );
|
||||
|
||||
/**
|
||||
* @brief used to stop single channel mode.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void RFIP_TestEnd( void );
|
||||
|
||||
/**
|
||||
* @brief library-fast initial
|
||||
*
|
||||
|
@ -303,6 +335,15 @@ bStatus_t RFRole_SetParam( rfRoleParam_t *pParam );
|
|||
*/
|
||||
bStatus_t RFBound_SetSpeedType( rfRoleSpeed_t *pList_t );
|
||||
|
||||
/**
|
||||
* @brief Stop binding, disconnect the connection, and clear the sending and receiving data status.
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFBound_Stop( void );
|
||||
|
||||
/**
|
||||
* @brief start host mode(8k)
|
||||
*
|
||||
|
@ -396,6 +437,28 @@ bStatus_t RFRole_SwitchMode( uint8_t mode );
|
|||
*/
|
||||
bStatus_t RFRole_MapCheck( int8_t rssi,uint8_t id );
|
||||
|
||||
/**
|
||||
* @brief Set a lower power consumption mode.
|
||||
*
|
||||
* note: only the device role can be called
|
||||
*
|
||||
* @param level - 0:disable(Slightly improve the transmission efficiency.) others: lower power level
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void RFRole_LowPower( uint8_t level );
|
||||
|
||||
/**
|
||||
* @brief start phy update.
|
||||
*
|
||||
* note: supported in version 1.3 and above.
|
||||
*
|
||||
* @param phy - 0:1M 1:2M
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFRole_PHYUpdate( uint8_t dev_id, uint8_t phy );
|
||||
|
||||
/**
|
||||
* @brief library-basic initial
|
||||
*
|
||||
|
|
|
@ -3,7 +3,7 @@ ENTRY( _start )
|
|||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 448K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
|
|
|
@ -158,8 +158,8 @@ __attribute__((always_inline)) RV_STATIC_INLINE uint32_t __risc_v_disable_irq(vo
|
|||
|
||||
/* ########################## PFIC functions #################################### */
|
||||
|
||||
#define PFIC_EnableAllIRQ() {write_csr(0x800, 0x88);__nop();__nop();}
|
||||
#define PFIC_DisableAllIRQ() {write_csr(0x800, 0x80);__nop();__nop();}
|
||||
#define PFIC_EnableAllIRQ() {write_csr(0x800, 0x88);}
|
||||
#define PFIC_DisableAllIRQ() {write_csr(0x800, 0x80);asm volatile("fence.i");}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn PFIC_EnableIRQ
|
||||
|
@ -183,8 +183,7 @@ __attribute__((always_inline)) RV_STATIC_INLINE void PFIC_EnableIRQ(IRQn_Type IR
|
|||
__attribute__((always_inline)) RV_STATIC_INLINE void PFIC_DisableIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
PFIC->IRER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F));
|
||||
__nop();
|
||||
__nop();
|
||||
asm volatile("fence.i");
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
|
|
|
@ -347,7 +347,7 @@ void LowPower_Halt(void)
|
|||
|
||||
/*******************************************************************************
|
||||
* Function Name : LowPower_Sleep
|
||||
* Description : 低功耗-Sleep模式。
|
||||
* Description : 低功耗-Sleep模式,注意唤醒后到flash稳定还需要300us
|
||||
* Input : rm:
|
||||
RB_PWR_RAM32K - 32K retention SRAM ¹©µç
|
||||
RB_PWR_RAM96K - 96K main SRAM ¹©µç
|
||||
|
@ -414,14 +414,16 @@ void LowPower_Sleep(uint16_t rm)
|
|||
R16_CLK_SYS_CFG = CLK_SOURCE_HSI_4MHz;
|
||||
sys_safe_access_disable();
|
||||
}
|
||||
// sys_safe_access_enable();
|
||||
// R8_PLL_CONFIG |= (1 << 5);
|
||||
// sys_safe_access_disable();
|
||||
|
||||
__WFI();
|
||||
__nop();
|
||||
__nop();
|
||||
|
||||
if(rm & RB_PWR_EXTEND)
|
||||
{
|
||||
R32_U2H_BC_CTRL = 0;
|
||||
(*((PUINT32V)0x4000C254)) = 0;
|
||||
}
|
||||
if((!(clk_sys_cfg & RB_OSC32M_SEL)) && (clk_sys_cfg & 0x100)) //ʹÓÃÄÚ²¿16M
|
||||
{
|
||||
i = 40;
|
||||
|
@ -441,10 +443,7 @@ void LowPower_Sleep(uint16_t rm)
|
|||
R16_POWER_PLAN &= ~RB_PWR_PLAN_EN;
|
||||
sys_safe_access_disable();
|
||||
|
||||
// sys_safe_access_enable();
|
||||
// R8_PLL_CONFIG &= ~(1 << 5);
|
||||
// sys_safe_access_disable();
|
||||
// DelayUs(40);
|
||||
// DelayUs(100); //如果rm & RB_XT_PRE_EN == 0, 且退出函数后运行flash代码,则需要延时100us后退出
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
|
|
@ -345,6 +345,7 @@ void SYS_DisableAllIrq(uint32_t *pirqv)
|
|||
*pirqv = (PFIC->ISR[0] >> 8) | (PFIC->ISR[1] << 24);
|
||||
PFIC->IRER[0] = 0xffffffff;
|
||||
PFIC->IRER[1] = 0xffffffff;
|
||||
asm volatile("fence.i");
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
@ -607,3 +608,49 @@ void *__wrap_memcpy(void *dst, void *src, size_t size)
|
|||
__MCPY(dst, src, (void *)((uint32_t)src+size));
|
||||
return dst;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn IWDG_KR_Set
|
||||
*
|
||||
* @brief 启动看门狗/解除读保护/喂狗/重装载计数值
|
||||
*
|
||||
* @param pr - IWDG_PR
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void IWDG_KR_Set(IWDG_KR_Key kr)
|
||||
{
|
||||
R32_IWDG_KR = kr;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn IWDG_PR_Set
|
||||
*
|
||||
* @brief 配置预分频,关闭写保护位生效
|
||||
*
|
||||
* @param pr
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void IWDG_PR_Set(IWDG_32K_PR pr)
|
||||
{
|
||||
R32_IWDG_CFG |= (pr << 12);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn IWDG_RLR_Set
|
||||
*
|
||||
* @brief 配置计数器重装载值,关闭写保护位生效
|
||||
*
|
||||
* @param rlr
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void IWDG_RLR_Set(uint16_t rlr)
|
||||
{
|
||||
uint32_t cfg;
|
||||
|
||||
cfg = R32_IWDG_CFG;
|
||||
cfg = (R32_IWDG_CFG & ~0xFFF) | (rlr & 0xFFF);
|
||||
R32_IWDG_CFG = cfg;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
#endif
|
||||
|
||||
#ifndef SAFEOPERATE
|
||||
#define SAFEOPERATE __nop();__nop()
|
||||
#define SAFEOPERATE asm volatile("fence.i")
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,6 +49,31 @@ typedef enum
|
|||
|
||||
} SYS_InfoStaTypeDef;
|
||||
|
||||
/**
|
||||
* @brief IWDG_KR_Key
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
KEY_UNPROTECT = 0x5555, //解除保护
|
||||
KEY_RELOADING_COUNT = 0xAAAA, //重装载计数值
|
||||
KEY_START_IWDG = 0xCCCC //启动看门狗
|
||||
} IWDG_KR_Key;
|
||||
|
||||
/**
|
||||
* @brief IWDG Prescaler factor
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
IWDG_PR_4 = 0, // 4分频
|
||||
IWDG_PR_8, // 8分频
|
||||
IWDG_PR_16, // 16分频
|
||||
IWDG_PR_32, // 32分频
|
||||
IWDG_PR_64, // 64分频
|
||||
IWDG_PR_128, // 128分频
|
||||
IWDG_PR_256, // 256分频
|
||||
IWDG_PR_512 // 512分频
|
||||
} IWDG_32K_PR;
|
||||
|
||||
/**
|
||||
* @brief 获取芯片ID类,一般为固定值
|
||||
*/
|
||||
|
@ -181,6 +206,48 @@ void mDelayuS(uint16_t t);
|
|||
*/
|
||||
void mDelaymS(uint16_t t);
|
||||
|
||||
/**
|
||||
* @brief 获取写保护状态
|
||||
*
|
||||
* @return 1:禁止操作相应字段; 0:解除保护
|
||||
*/
|
||||
#define IWDG_WR_Protect() (R32_IWDG_CFG >> 30 & 0x01)
|
||||
|
||||
/**
|
||||
* @brief 获取看门狗计数器
|
||||
*
|
||||
* @return COUNT
|
||||
*/
|
||||
#define IWDG_Count_Get() ((R32_IWDG_CFG >> 16) & 0xFFF)
|
||||
|
||||
/**
|
||||
* @brief 获取配置寄存器更新标志,关闭写保护位生效
|
||||
*
|
||||
* @return 1:寄存器更新; 0:寄存器不更新
|
||||
*/
|
||||
#define IWDG_PVU_Get() (R32_IWDG_CFG >> 15 & 0x01)
|
||||
|
||||
/**
|
||||
* @brief 启动看门狗/解除读保护/喂狗/重装载计数值
|
||||
*
|
||||
* @param kr - 控制值
|
||||
*/
|
||||
void IWDG_KR_Set(IWDG_KR_Key kr);
|
||||
|
||||
/**
|
||||
* @brief 配置预分频,关闭写保护位生效
|
||||
*
|
||||
* @param pr - 分频系数
|
||||
*/
|
||||
void IWDG_PR_Set(IWDG_32K_PR pr);
|
||||
|
||||
/**
|
||||
* @brief 配置计数器重装载值,关闭写保护位生效
|
||||
*
|
||||
* @param rlr - 计数器重装载值
|
||||
*/
|
||||
void IWDG_RLR_Set(uint16_t rlr);
|
||||
|
||||
/**
|
||||
* @brief Enter safe access mode.
|
||||
*
|
||||
|
|
|
@ -60,8 +60,8 @@
|
|||
*
|
||||
* @param cmd - CMD_* for caller from FlashROM or RAM.
|
||||
* @param StartAddr - Address of the data to be process.
|
||||
* @param Buffer - Pointer to the buffer where data should be process, Must be aligned to 4 bytes.
|
||||
* @param Length - Size of data to be process, in bytes.
|
||||
|
||||
* @param Buffer - Pointer to the buffer where data should be process, Must in RAM and be aligned to 4 bytes. * @param Length - Size of data to be process, in bytes.
|
||||
*
|
||||
* @return 0-SUCCESS (!0)-FAILURE
|
||||
*/
|
||||
|
@ -84,7 +84,7 @@ extern uint32_t FLASH_EEPROM_CMD( uint8_t cmd, uint32_t StartAddr, void *Buffer,
|
|||
/**
|
||||
* @brief get 6 bytes MAC address
|
||||
*
|
||||
* @param Buffer - Pointer to the buffer where data should be stored, Must be aligned to 4 bytes.
|
||||
* @param Buffer - Pointer to the buffer where data should be stored, Must in RAM and be aligned to 4 bytes.
|
||||
*
|
||||
* @return 0-SUCCESS (!0)-FAILURE
|
||||
*/
|
||||
|
@ -93,7 +93,7 @@ extern uint32_t FLASH_EEPROM_CMD( uint8_t cmd, uint32_t StartAddr, void *Buffer,
|
|||
/**
|
||||
* @brief get 8 bytes BOOT information
|
||||
*
|
||||
* @param Buffer - Pointer to the buffer where data should be stored, Must be aligned to 4 bytes.
|
||||
* @param Buffer - Pointer to the buffer where data should be stored, Must in RAM and be aligned to 4 bytes.
|
||||
*
|
||||
* @return 0-SUCCESS (!0)-FAILURE
|
||||
*/
|
||||
|
@ -117,7 +117,7 @@ extern uint32_t FLASH_EEPROM_CMD( uint8_t cmd, uint32_t StartAddr, void *Buffer,
|
|||
* @brief read Data-Flash data block
|
||||
*
|
||||
* @param StartAddr - Address of the data to be read.
|
||||
* @param Buffer - Pointer to the buffer where data should be stored, Must be aligned to 4 bytes.
|
||||
* @param Buffer - Pointer to the buffer where data should be stored, Must in RAM and be aligned to 4 bytes.
|
||||
* @param Length - Size of data to be read, in bytes.
|
||||
*
|
||||
* @return 0-SUCCESS (!0)-FAILURE
|
||||
|
@ -137,7 +137,7 @@ extern uint32_t FLASH_EEPROM_CMD( uint8_t cmd, uint32_t StartAddr, void *Buffer,
|
|||
* @brief write Data-Flash data block
|
||||
*
|
||||
* @param StartAddr - Address of the data to be written.
|
||||
* @param Buffer - Pointer to the source buffer, Must be aligned to 4 bytes.
|
||||
* @param Buffer - Pointer to the source buffer, Must in RAM and be aligned to 4 bytes.
|
||||
* @param Length - Size of data to be written, in bytes.
|
||||
*
|
||||
* @return 0-SUCCESS (!0)-FAILURE
|
||||
|
@ -158,7 +158,7 @@ extern uint32_t FLASH_EEPROM_CMD( uint8_t cmd, uint32_t StartAddr, void *Buffer,
|
|||
* @brief write FlashROM data block, minimal block is dword.
|
||||
*
|
||||
* @param StartAddr - Address of the data to be written.
|
||||
* @param Buffer - Pointer to the source buffer, Must be aligned to 4 bytes.
|
||||
* @param Buffer - Pointer to the source buffer, Must in RAM and be aligned to 4 bytes.
|
||||
* @param Length - Size of data to be written, in bytes.
|
||||
*
|
||||
* @return 0-SUCCESS (!0)-FAILURE
|
||||
|
@ -169,7 +169,7 @@ extern uint32_t FLASH_EEPROM_CMD( uint8_t cmd, uint32_t StartAddr, void *Buffer,
|
|||
* @brief verify FlashROM data block, minimal block is dword.
|
||||
*
|
||||
* @param StartAddr - Address of the data to verify.
|
||||
* @param Buffer - Pointer to the source buffer, Must be aligned to 4 bytes.
|
||||
* @param Buffer - Pointer to the source buffer, Must in RAM and be aligned to 4 bytes.
|
||||
* @param Length - Size of data to verify, in bytes.
|
||||
*
|
||||
* @return 0-SUCCESS (!0)-FAILURE
|
||||
|
|
Loading…
Reference in New Issue