This commit is contained in:
parent
62321b1294
commit
1c31a9f6dd
|
|
@ -121,6 +121,7 @@
|
|||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.preprocessonly.208069239" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.preprocessonly" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs.177116515" name="Defined symbols (-D)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs" useByScannerDiscovery="true" valueType="definedSymbols">
|
||||
<listOptionValue builtIn="false" value="DEBUG=0"/>
|
||||
<listOptionValue builtIn="false" value="HAL_SLEEP=1"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.undef.1820512625" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.undef" useByScannerDiscovery="true" valueType="undefDefinedSymbols"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths.1567947810" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths" useByScannerDiscovery="true" valueType="includePath">
|
||||
|
|
@ -132,6 +133,8 @@
|
|||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/FreeRTOS}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/system/RVMSIS}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/system/StdPeriphDriver/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/system/HAL/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/system/LIB}""/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.systempaths.2011720354" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.systempaths" useByScannerDiscovery="true" valueType="includePath"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.files.542153928" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.files" useByScannerDiscovery="true" valueType="includeFiles"/>
|
||||
|
|
@ -189,10 +192,12 @@
|
|||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.strip.1802601885" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.strip" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.libs.813115939" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.libs" useByScannerDiscovery="false" valueType="libs">
|
||||
<listOptionValue builtIn="false" value="ISP585"/>
|
||||
<listOptionValue builtIn="false" value="CH58xBLE"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.paths.2057340378" name="Library search path (-L)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.paths" useByScannerDiscovery="false" valueType="libPaths">
|
||||
<listOptionValue builtIn="false" value="../"/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/system/StdPeriphDriver}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/system/LIB}""/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags.1125808200" name="Linker flags (-Xlinker [option])" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags" useByScannerDiscovery="false" valueType="stringList">
|
||||
<listOptionValue builtIn="false" value="--print-memory-usage"/>
|
||||
|
|
@ -228,10 +233,12 @@
|
|||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.strip.679063538" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.strip" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.libs.579700779" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.libs" useByScannerDiscovery="false" valueType="libs">
|
||||
<listOptionValue builtIn="false" value="ISP585"/>
|
||||
<listOptionValue builtIn="false" value="CH58xBLE"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.paths.1029177148" name="Library search path (-L)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.paths" useByScannerDiscovery="false" valueType="libPaths">
|
||||
<listOptionValue builtIn="false" value="../"/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/system/StdPeriphDriver}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/system/LIB}""/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.flags.1251620602" name="Linker flags (-Xlinker [option])" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.flags" useByScannerDiscovery="false" valueType="stringList">
|
||||
<listOptionValue builtIn="false" value="--print-memory-usage"/>
|
||||
|
|
|
|||
|
|
@ -131,7 +131,8 @@
|
|||
"do_not_search_system_directories": false,
|
||||
"preprocess_only": false,
|
||||
"defined_symbols": [
|
||||
"DEBUG=0"
|
||||
"DEBUG=0",
|
||||
"HAL_SLEEP=1"
|
||||
],
|
||||
"undefined_symbols": []
|
||||
},
|
||||
|
|
@ -144,7 +145,9 @@
|
|||
"${project}/FreeRTOS/include",
|
||||
"${project}/FreeRTOS",
|
||||
"${project}/system/RVMSIS",
|
||||
"${project}/system/StdPeriphDriver/inc"
|
||||
"${project}/system/StdPeriphDriver/inc",
|
||||
"${project}/system/HAL/include",
|
||||
"${project}/system/LIB"
|
||||
],
|
||||
"include_system_paths": [],
|
||||
"include_files": []
|
||||
|
|
@ -219,11 +222,13 @@
|
|||
},
|
||||
"libraries": {
|
||||
"libraries": [
|
||||
"ISP585"
|
||||
"ISP585",
|
||||
"CH58xBLE"
|
||||
],
|
||||
"library_search_path": [
|
||||
"../",
|
||||
"${project}/system/StdPeriphDriver"
|
||||
"${project}/system/StdPeriphDriver",
|
||||
"${project}/system/LIB"
|
||||
]
|
||||
},
|
||||
"miscellaneous": {
|
||||
|
|
@ -260,11 +265,13 @@
|
|||
},
|
||||
"libraries": {
|
||||
"libraries": [
|
||||
"ISP585"
|
||||
"ISP585",
|
||||
"CH58xBLE"
|
||||
],
|
||||
"library_search_path": [
|
||||
"../",
|
||||
"${project}/system/StdPeriphDriver"
|
||||
"${project}/system/StdPeriphDriver",
|
||||
"${project}/system/LIB"
|
||||
]
|
||||
},
|
||||
"miscellaneous": {
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@
|
|||
|
||||
#define configUSE_PREEMPTION 1
|
||||
#define configUSE_TIME_SLICING 0
|
||||
#define configUSE_IDLE_HOOK 0
|
||||
#define configUSE_IDLE_HOOK 1
|
||||
#define configUSE_TICK_HOOK 0
|
||||
#define configCPU_CLOCK_HZ FREQ_SYS
|
||||
#define configTICK_RATE_HZ ((TickType_t)500)
|
||||
|
|
|
|||
272
src/main.c
272
src/main.c
|
|
@ -3,55 +3,27 @@
|
|||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2024/08/13
|
||||
* Description : FreeRTOS例程,使用硬件压栈,中断嵌套可选,中断函数不再使用修饰
|
||||
* __attribute__((interrupt("WCH-Interrupt-fast"))),
|
||||
* 中断函数直接按照普通函数定义,只使用HIGHCODE修饰即可。
|
||||
* Description : FreeRTOS仅保留任务1,延时期间自动进入低功耗休眠
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2024 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* 头文件包含 */
|
||||
#include "CH58x_common.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
#include "stdarg.h"
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL TYPEDEFS
|
||||
*/
|
||||
|
||||
/************************** 任务配置 **************************/
|
||||
#define TASK1_TASK_PRIO 5
|
||||
#define TASK1_STK_SIZE 256 /* 因在任务中使用了APP_Printf所以栈空间必须要大于APP_Printf中的buf_str的大小+configMINIMAL_STACK_SIZE */
|
||||
#define TASK2_TASK_PRIO 5
|
||||
#define TASK2_STK_SIZE 256
|
||||
#define TASK3_TASK_PRIO configMAX_PRIORITIES - 1
|
||||
#define TASK3_STK_SIZE 256
|
||||
#define TASK4_TASK_PRIO 4
|
||||
#define TASK4_STK_SIZE 512
|
||||
#define TASK1_STK_SIZE 256
|
||||
|
||||
/* Global Variable */
|
||||
/************************** 全局变量 **************************/
|
||||
TaskHandle_t Task1Task_Handler;
|
||||
TaskHandle_t Task2Task_Handler;
|
||||
TaskHandle_t Task3Task_Handler;
|
||||
TaskHandle_t Task4Task_Handler;
|
||||
SemaphoreHandle_t printMutex;
|
||||
SemaphoreHandle_t xBinarySem;
|
||||
SemaphoreHandle_t xRTCSem;
|
||||
|
||||
/* Function declarations */
|
||||
void LowPowerGapProcess(void);
|
||||
|
||||
/*********************************************************************
|
||||
* @fn DebugInit
|
||||
*
|
||||
* @brief 调试初始化
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
* @brief 调试初始化
|
||||
********************************************************************/
|
||||
void DebugInit(void)
|
||||
{
|
||||
GPIOA_SetBits(GPIO_Pin_14);
|
||||
|
|
@ -61,218 +33,63 @@ void DebugInit(void)
|
|||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn vPortSuppressTicksAndSleep
|
||||
*
|
||||
* @brief FreeRTOS Tickless Idle回调函数,当所有任务等待时自动调用
|
||||
* 实现在任务等待期间自动进入低功耗模式
|
||||
*
|
||||
* @param xExpectedIdleTime - 预计的空闲时间(以tick为单位)
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
* @fn CH585_EnterSleep
|
||||
* @brief CH585进入浅休眠(适配原生API,关闭无用外设降低功耗)
|
||||
********************************************************************/
|
||||
__HIGH_CODE
|
||||
void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime)
|
||||
void CH585_EnterSleep(void)
|
||||
{
|
||||
uint32_t ulCompleteTickPeriods;
|
||||
|
||||
/* 限制最短睡眠时间,避免频繁唤醒 */
|
||||
if (xExpectedIdleTime < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Idle模式:功耗约1.44mA,所有外设正常运行,快速响应 */
|
||||
LowPower_Idle();
|
||||
|
||||
/* 计算实际睡眠的tick数 */
|
||||
ulCompleteTickPeriods = xExpectedIdleTime - 1;
|
||||
|
||||
/* 更新系统时间 */
|
||||
vTaskStepTick(ulCompleteTickPeriods);
|
||||
// LowPower_Halt();
|
||||
// HSECFG_Current(HSE_RCur_100); // 降为额定电流(低功耗函数中提升了HSE偏置电流)
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn LowPowerGapProcess
|
||||
*
|
||||
* @brief 外部时钟不稳定期间执行,可用于执行对时钟要求不高的处理,且flash未准备好,需要在RAM中运行
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
__HIGH_CODE
|
||||
void LowPowerGapProcess()
|
||||
void vApplicationIdleHook(void)
|
||||
{
|
||||
// 执行对时钟要求不高的处理
|
||||
|
||||
// 可以:简单的GPIO操作
|
||||
// 可以:LED指示
|
||||
// 可以:计数、标志位更新
|
||||
|
||||
// 不可以:从Flash读取代码/数据
|
||||
// 不可以:精确定时操作(时钟不稳定)
|
||||
// 不可以:复杂计算(时钟慢,功耗高)
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn App_Printf
|
||||
*
|
||||
* @brief printf can be used within freertos.
|
||||
*
|
||||
* @param *fmt - printf params.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
__HIGH_CODE
|
||||
void App_Printf(const char *fmt, ...)
|
||||
{
|
||||
char buf_str[128]; /* 需要注意在这里的内存空间是否足够打印 */
|
||||
va_list v_args;
|
||||
|
||||
va_start(v_args, fmt);
|
||||
(void)vsnprintf((char *)&buf_str[0],
|
||||
(size_t)sizeof(buf_str),
|
||||
(char const *)fmt,
|
||||
v_args);
|
||||
va_end(v_args);
|
||||
|
||||
/* 互斥量操作,不可在中断中使用 */
|
||||
xSemaphoreTake(printMutex, portMAX_DELAY);
|
||||
printf("%s", buf_str);
|
||||
xSemaphoreGive(printMutex);
|
||||
// 空函数,兼容原框架
|
||||
CH585_EnterSleep();
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn task1_task
|
||||
*
|
||||
* @brief task1 program.
|
||||
*
|
||||
* @param *pvParameters - Parameters point of task1
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
* @brief 仅保留任务1:LED翻转,延时期间系统自动休眠
|
||||
********************************************************************/
|
||||
__HIGH_CODE
|
||||
void task1_task(void *pvParameters)
|
||||
{
|
||||
// 初始化GPIOA_Pin_0为输出(LED控制)
|
||||
GPIOA_ModeCfg(GPIO_Pin_0, GPIO_ModeOut_PP_5mA);
|
||||
|
||||
while (1)
|
||||
{
|
||||
GPIOA_SetBits(GPIO_Pin_0); // 打开IO(高电平)
|
||||
vTaskDelay(configTICK_RATE_HZ);
|
||||
GPIOA_SetBits(GPIO_Pin_0); // IO置高(LED亮)
|
||||
vTaskDelay(configTICK_RATE_HZ); // 延时1秒,期间系统休眠
|
||||
|
||||
GPIOA_ResetBits(GPIO_Pin_0); // 关闭IO(低电平)
|
||||
vTaskDelay(configTICK_RATE_HZ / 2);
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn task2_task
|
||||
*
|
||||
* @brief task2 program.
|
||||
*
|
||||
* @param *pvParameters - Parameters point of task2
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
__HIGH_CODE
|
||||
void task2_task(void *pvParameters)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
App_Printf("task2 running!\n");
|
||||
vTaskDelay(configTICK_RATE_HZ);
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn task3_task
|
||||
*
|
||||
* @brief task3 program - GPIO唤醒测试.
|
||||
*
|
||||
* @param *pvParameters - Parameters point of task3
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
__HIGH_CODE
|
||||
void task3_task(void *pvParameters)
|
||||
{
|
||||
xBinarySem = xSemaphoreCreateBinary();
|
||||
if (xBinarySem != NULL)
|
||||
{
|
||||
GPIOA_ModeCfg(GPIO_Pin_12, GPIO_ModeIN_PU);
|
||||
GPIOA_ITModeCfg(GPIO_Pin_12, GPIO_ITMode_FallEdge);
|
||||
PFIC_EnableIRQ(GPIO_A_IRQn);
|
||||
while (1)
|
||||
{
|
||||
if (xSemaphoreTake(xBinarySem, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
App_Printf("task3 GPIO wake up!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
App_Printf("task3 sem get failed\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
App_Printf("task3 sem init failed\n");
|
||||
GPIOA_ResetBits(GPIO_Pin_0); // IO置低(LED灭)
|
||||
vTaskDelay(configTICK_RATE_HZ / 2); // 延时0.5秒,期间系统休眠
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn main
|
||||
*
|
||||
* @brief main function.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
* @brief 主函数:仅初始化+创建任务1+启动调度器
|
||||
********************************************************************/
|
||||
int main(void)
|
||||
{
|
||||
#if (defined(DCDC_ENABLE)) && (DCDC_ENABLE == TRUE)
|
||||
PWR_DCDCCfg(ENABLE);
|
||||
#endif
|
||||
// 系统初始化
|
||||
HSECFG_Capacitance(HSECap_18p);
|
||||
SetSysClock(SYSCLK_FREQ);
|
||||
|
||||
/* 注意:不能配置GPIO_Pin_All,会影响SWD调试引脚PA13/PA14,导致无法调试和系统异常 */
|
||||
/* 只配置需要的GPIO为上拉输入,排除调试引脚 */
|
||||
GPIOA_ModeCfg(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
|
||||
GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 |
|
||||
GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 |
|
||||
GPIO_Pin_12 | GPIO_Pin_15,
|
||||
GPIO_ModeIN_PU);
|
||||
PWR_DCDCCfg(ENABLE);
|
||||
GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU);
|
||||
GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU);
|
||||
|
||||
#ifdef DEBUG
|
||||
DebugInit();
|
||||
DebugInit(); // 调试时开启串口,发布可注释
|
||||
#endif
|
||||
|
||||
PRINT("start.\n");
|
||||
|
||||
printMutex = xSemaphoreCreateMutex();
|
||||
if (printMutex == NULL)
|
||||
{
|
||||
PRINT("printMutex error\n");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
/* create tasks */
|
||||
xTaskCreate((TaskFunction_t)task3_task,
|
||||
(const char *)"task3",
|
||||
(uint16_t)TASK3_STK_SIZE,
|
||||
(void *)NULL,
|
||||
(UBaseType_t)TASK3_TASK_PRIO,
|
||||
(TaskHandle_t *)&Task3Task_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t)task2_task,
|
||||
(const char *)"task2",
|
||||
(uint16_t)TASK2_STK_SIZE,
|
||||
(void *)NULL,
|
||||
(UBaseType_t)TASK2_TASK_PRIO,
|
||||
(TaskHandle_t *)&Task2Task_Handler);
|
||||
|
||||
// 创建任务1(唯一任务)
|
||||
xTaskCreate((TaskFunction_t)task1_task,
|
||||
(const char *)"task1",
|
||||
(uint16_t)TASK1_STK_SIZE,
|
||||
|
|
@ -280,35 +97,14 @@ int main(void)
|
|||
(UBaseType_t)TASK1_TASK_PRIO,
|
||||
(TaskHandle_t *)&Task1Task_Handler);
|
||||
|
||||
// 启动FreeRTOS调度器
|
||||
vTaskStartScheduler();
|
||||
|
||||
// 调度器启动失败则死循环
|
||||
while (1)
|
||||
{
|
||||
PRINT("shouldn't run at here!!\n");
|
||||
// 理论上不会执行到这里
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn GPIOA_IRQHandler
|
||||
*
|
||||
* @brief GPIOA_IRQHandler.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
__HIGH_CODE
|
||||
void GPIOA_IRQHandler(void)
|
||||
{
|
||||
/* 本函数可以作为在本工程FreeRTOS中的中断函数写法示例 */
|
||||
uint16_t flag;
|
||||
portBASE_TYPE xHigherPriorityTaskWoken;
|
||||
flag = GPIOA_ReadITFlagPort();
|
||||
if ((flag & GPIO_Pin_12) != 0)
|
||||
{
|
||||
xSemaphoreGiveFromISR(xBinarySem, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken); /* 根据需要发起切换请求 */
|
||||
}
|
||||
GPIOA_ClearITFlagBit(flag); /* 清除中断标志 */
|
||||
}
|
||||
|
||||
/******************************** endfile @ main ******************************/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "windows-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "C:/TDM-GCC-64/bin/gcc.exe",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "windows-gcc-x64",
|
||||
"compilerArgs": [
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"cwd": "c:/Users/Administrator/Desktop/CH585EVT/EVT/EXAM/BLE/HAL",
|
||||
"program": "c:/Users/Administrator/Desktop/CH585EVT/EVT/EXAM/BLE/HAL/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wcast-align",
|
||||
"-Wconversion",
|
||||
"-Wsign-conversion",
|
||||
"-Wnull-dereference"
|
||||
],
|
||||
"C_Cpp_Runner.msvcWarnings": [
|
||||
"/W4",
|
||||
"/permissive-",
|
||||
"/w14242",
|
||||
"/w14287",
|
||||
"/w14296",
|
||||
"/w14311",
|
||||
"/w14826",
|
||||
"/w44062",
|
||||
"/w44242",
|
||||
"/w14905",
|
||||
"/w14906",
|
||||
"/w14263",
|
||||
"/w44265",
|
||||
"/w14928"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false
|
||||
}
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : KEY.c
|
||||
* Author : WCH
|
||||
* Version : V1.2
|
||||
* Date : 2022/01/18
|
||||
* Description :
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* 头文件包含 */
|
||||
#include "HAL.h"
|
||||
|
||||
/**************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
**************************************************************************************************/
|
||||
|
||||
static uint8_t halKeySavedKeys; /* 保留按键最后的状态,用于查询是否有键值变化 */
|
||||
|
||||
/**************************************************************************************************
|
||||
* FUNCTIONS - Local
|
||||
**************************************************************************************************/
|
||||
static halKeyCBack_t pHalKeyProcessFunction; /* callback function */
|
||||
|
||||
/**************************************************************************************************
|
||||
* @fn HAL_KeyInit
|
||||
*
|
||||
* @brief Initilize Key Service
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return None
|
||||
**************************************************************************************************/
|
||||
void HAL_KeyInit(void)
|
||||
{
|
||||
/* Initialize previous key to 0 */
|
||||
halKeySavedKeys = 0;
|
||||
/* Initialize callback function */
|
||||
pHalKeyProcessFunction = NULL;
|
||||
KEY1_DIR;
|
||||
KEY1_PU;
|
||||
KEY2_DIR;
|
||||
KEY2_PU;
|
||||
}
|
||||
|
||||
/**************************************************************************************************
|
||||
* @fn HalKeyConfig
|
||||
*
|
||||
* @brief Configure the Key serivce
|
||||
*
|
||||
* @param cback - pointer to the CallBack function
|
||||
*
|
||||
* @return None
|
||||
**************************************************************************************************/
|
||||
void HalKeyConfig(halKeyCBack_t cback)
|
||||
{
|
||||
/* Register the callback fucntion */
|
||||
pHalKeyProcessFunction = cback;
|
||||
tmos_start_task(halTaskID, HAL_KEY_EVENT, HAL_KEY_POLLING_VALUE); /* Kick off polling */
|
||||
}
|
||||
|
||||
/**************************************************************************************************
|
||||
* @fn HalKeyRead
|
||||
*
|
||||
* @brief Read the current value of a key
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return keys - current keys status
|
||||
**************************************************************************************************/
|
||||
uint8_t HalKeyRead(void)
|
||||
{
|
||||
uint8_t keys = 0;
|
||||
|
||||
if(HAL_PUSH_BUTTON1())
|
||||
{ //读按键1
|
||||
keys |= HAL_KEY_SW_1;
|
||||
}
|
||||
if(HAL_PUSH_BUTTON2())
|
||||
{ //读按键1
|
||||
keys |= HAL_KEY_SW_2;
|
||||
}
|
||||
if(HAL_PUSH_BUTTON3())
|
||||
{ //读按键1
|
||||
keys |= HAL_KEY_SW_3;
|
||||
}
|
||||
if(HAL_PUSH_BUTTON4())
|
||||
{ //读按键1
|
||||
keys |= HAL_KEY_SW_4;
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**************************************************************************************************
|
||||
* @fn HAL_KeyPoll
|
||||
*
|
||||
* @brief Called by hal_driver to poll the keys
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return None
|
||||
**************************************************************************************************/
|
||||
void HAL_KeyPoll(void)
|
||||
{
|
||||
uint8_t keys = 0;
|
||||
if(HAL_PUSH_BUTTON1())
|
||||
{
|
||||
keys |= HAL_KEY_SW_1;
|
||||
}
|
||||
if(HAL_PUSH_BUTTON2())
|
||||
{
|
||||
keys |= HAL_KEY_SW_2;
|
||||
}
|
||||
if(HAL_PUSH_BUTTON3())
|
||||
{
|
||||
keys |= HAL_KEY_SW_3;
|
||||
}
|
||||
if(HAL_PUSH_BUTTON4())
|
||||
{
|
||||
keys |= HAL_KEY_SW_4;
|
||||
}
|
||||
if(keys == halKeySavedKeys)
|
||||
{ /* Exit - since no keys have changed */
|
||||
return;
|
||||
}
|
||||
halKeySavedKeys = keys; /* Store the current keys for comparation next time */
|
||||
/* Invoke Callback if new keys were depressed */
|
||||
if(keys && (pHalKeyProcessFunction))
|
||||
{
|
||||
(pHalKeyProcessFunction)(keys);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************** endfile @ key ******************************/
|
||||
|
|
@ -0,0 +1,361 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : LED.c
|
||||
* Author : WCH
|
||||
* Version : V1.2
|
||||
* Date : 2022/01/18
|
||||
* Description :
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Í·Îļþ°üº¬ */
|
||||
#include "HAL.h"
|
||||
|
||||
/* LED control structure */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t mode; /* Operation mode */
|
||||
uint8_t todo; /* Blink cycles left */
|
||||
uint8_t onPct; /* On cycle percentage */
|
||||
uint16_t time; /* On/off cycle time (msec) */
|
||||
uint32_t next; /* Time for next change */
|
||||
} HalLedControl_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
HalLedControl_t HalLedControlTable[HAL_LED_DEFAULT_MAX_LEDS];
|
||||
uint8_t sleepActive;
|
||||
} HalLedStatus_t;
|
||||
|
||||
/***************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
***************************************************************************************************/
|
||||
static uint8_t HalLedState; // LED state at last set/clr/blink update
|
||||
|
||||
static uint8_t preBlinkState; // Original State before going to blink mode
|
||||
// bit 0, 1, 2, 3 represent led 0, 1, 2, 3
|
||||
static HalLedStatus_t HalLedStatusControl;
|
||||
|
||||
/***************************************************************************************************
|
||||
* LOCAL FUNCTION
|
||||
***************************************************************************************************/
|
||||
void HalLedOnOff(uint8_t leds, uint8_t mode);
|
||||
|
||||
/***************************************************************************************************
|
||||
* FUNCTIONS - API
|
||||
***************************************************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
* @fn HAL_LedInit
|
||||
*
|
||||
* @brief Initialize LED Service
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void HAL_LedInit(void)
|
||||
{
|
||||
/* Initialize all LEDs to OFF */
|
||||
LED1_DDR;
|
||||
HalLedSet(HAL_LED_ALL, HAL_LED_MODE_OFF);
|
||||
// just test
|
||||
HalLedBlink(HAL_LED_1, 10, 30, 4000);
|
||||
/* Initialize sleepActive to FALSE */
|
||||
HalLedStatusControl.sleepActive = FALSE;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn HalLedSet
|
||||
*
|
||||
* @brief Turn ON/OFF/TOGGLE given LEDs
|
||||
*
|
||||
* @param led - bit mask value of leds to be turned ON/OFF/TOGGLE
|
||||
* @param mode - BLINK, FLASH, TOGGLE, ON, OFF
|
||||
*
|
||||
* @return 0
|
||||
*/
|
||||
uint8_t HalLedSet(uint8_t leds, uint8_t mode)
|
||||
{
|
||||
uint8_t led;
|
||||
HalLedControl_t *sts;
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case HAL_LED_MODE_BLINK:
|
||||
{
|
||||
/* Default blink, 1 time, D% duty cycle */
|
||||
HalLedBlink(leds, 1, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME);
|
||||
break;
|
||||
}
|
||||
|
||||
case HAL_LED_MODE_FLASH:
|
||||
{
|
||||
/* Default flash, N times, D% duty cycle */
|
||||
HalLedBlink(leds, HAL_LED_DEFAULT_FLASH_COUNT, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME);
|
||||
break;
|
||||
}
|
||||
|
||||
case HAL_LED_MODE_ON:
|
||||
case HAL_LED_MODE_OFF:
|
||||
case HAL_LED_MODE_TOGGLE:
|
||||
{
|
||||
led = HAL_LED_1;
|
||||
leds &= HAL_LED_ALL;
|
||||
sts = HalLedStatusControl.HalLedControlTable;
|
||||
while(leds)
|
||||
{
|
||||
if(leds & led)
|
||||
{
|
||||
if(mode != HAL_LED_MODE_TOGGLE)
|
||||
{
|
||||
sts->mode = mode; /* ON or OFF */
|
||||
}
|
||||
else
|
||||
{
|
||||
sts->mode ^= HAL_LED_MODE_ON; /* Toggle */
|
||||
}
|
||||
HalLedOnOff(led, sts->mode);
|
||||
leds ^= led;
|
||||
}
|
||||
led <<= 1;
|
||||
sts++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn HalLedBlink
|
||||
*
|
||||
* @brief Blink the leds
|
||||
*
|
||||
* @param led - bit mask value of leds to be turned ON/OFF/TOGGLE
|
||||
* @param numBlinks - number of blinks
|
||||
* @param percent - the percentage in each period where the led will be on
|
||||
* @param period - length of each cycle in milliseconds
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void HalLedBlink(uint8_t leds, uint8_t numBlinks, uint8_t percent, uint16_t period)
|
||||
{
|
||||
uint8_t led;
|
||||
HalLedControl_t *sts;
|
||||
|
||||
if(leds && percent && period)
|
||||
{
|
||||
if(percent < 100)
|
||||
{
|
||||
led = HAL_LED_1;
|
||||
leds &= HAL_LED_ALL;
|
||||
sts = HalLedStatusControl.HalLedControlTable;
|
||||
while(leds)
|
||||
{
|
||||
if(leds & led)
|
||||
{
|
||||
/* Store the current state of the led before going to blinking */
|
||||
preBlinkState |= (led & HalLedState);
|
||||
sts->mode = HAL_LED_MODE_OFF; /* Stop previous blink */
|
||||
sts->time = period; /* Time for one on/off cycle */
|
||||
sts->onPct = percent; /* % of cycle LED is on */
|
||||
sts->todo = numBlinks; /* Number of blink cycles */
|
||||
if(!numBlinks)
|
||||
{
|
||||
sts->mode |= HAL_LED_MODE_FLASH; /* Continuous */
|
||||
}
|
||||
sts->next = TMOS_GetSystemClock(); /* Start now */
|
||||
sts->mode |= HAL_LED_MODE_BLINK; /* Enable blinking */
|
||||
leds ^= led;
|
||||
}
|
||||
led <<= 1;
|
||||
sts++;
|
||||
}
|
||||
tmos_start_task(halTaskID, LED_BLINK_EVENT, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
HalLedSet(leds, HAL_LED_MODE_ON); /* >= 100%, turn on */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HalLedSet(leds, HAL_LED_MODE_OFF); /* No on time, turn off */
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn HalLedUpdate
|
||||
*
|
||||
* @brief Update leds to work with blink
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void HalLedUpdate(void)
|
||||
{
|
||||
uint8_t led, pct, leds;
|
||||
uint16_t next, wait;
|
||||
uint32_t time;
|
||||
HalLedControl_t *sts;
|
||||
|
||||
next = 0;
|
||||
led = HAL_LED_1;
|
||||
leds = HAL_LED_ALL;
|
||||
sts = HalLedStatusControl.HalLedControlTable;
|
||||
|
||||
/* Check if sleep is active or not */
|
||||
if(!HalLedStatusControl.sleepActive)
|
||||
{
|
||||
while(leds)
|
||||
{
|
||||
if(leds & led)
|
||||
{
|
||||
if(sts->mode & HAL_LED_MODE_BLINK)
|
||||
{
|
||||
time = TMOS_GetSystemClock();
|
||||
if(time >= sts->next)
|
||||
{
|
||||
if(sts->mode & HAL_LED_MODE_ON)
|
||||
{
|
||||
pct = 100 - sts->onPct; /* Percentage of cycle for off */
|
||||
sts->mode &= ~HAL_LED_MODE_ON; /* Say it's not on */
|
||||
HalLedOnOff(led, HAL_LED_MODE_OFF); /* Turn it off */
|
||||
if(!(sts->mode & HAL_LED_MODE_FLASH))
|
||||
{
|
||||
if(sts->todo != 0xff)
|
||||
{
|
||||
sts->todo--; /* Not continuous, reduce count */
|
||||
}
|
||||
if(!sts->todo)
|
||||
{
|
||||
sts->mode ^= HAL_LED_MODE_BLINK; /* No more blinks */
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pct = sts->onPct; /* Percentage of cycle for on */
|
||||
sts->mode |= HAL_LED_MODE_ON; /* Say it's on */
|
||||
HalLedOnOff(led, HAL_LED_MODE_ON); /* Turn it on */
|
||||
}
|
||||
if(sts->mode & HAL_LED_MODE_BLINK)
|
||||
{
|
||||
wait = (((uint32_t)pct * (uint32_t)sts->time) / 100);
|
||||
sts->next = time + wait;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no more blink, no more wait */
|
||||
wait = 0;
|
||||
/* After blinking, set the LED back to the state before it blinks */
|
||||
HalLedSet(led, ((preBlinkState & led) != 0) ? HAL_LED_MODE_ON : HAL_LED_MODE_OFF);
|
||||
/* Clear the saved bit */
|
||||
preBlinkState &= (led ^ 0xFF);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wait = sts->next - time; /* Time left */
|
||||
}
|
||||
if(!next || (wait && (wait < next)))
|
||||
{
|
||||
next = wait;
|
||||
}
|
||||
}
|
||||
leds ^= led;
|
||||
}
|
||||
led <<= 1;
|
||||
sts++;
|
||||
}
|
||||
if(next)
|
||||
{
|
||||
tmos_start_task(halTaskID, LED_BLINK_EVENT, next); /* Schedule event */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn HalLedOnOff
|
||||
*
|
||||
* @brief Turns specified LED ON or OFF
|
||||
*
|
||||
* @param led - LED bit mask
|
||||
* @param mode - LED_ON,LED_OFF,
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void HalLedOnOff(uint8_t leds, uint8_t mode)
|
||||
{
|
||||
if(leds & HAL_LED_1)
|
||||
{
|
||||
if(mode == HAL_LED_MODE_ON)
|
||||
{
|
||||
HAL_TURN_ON_LED1();
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_TURN_OFF_LED1();
|
||||
}
|
||||
}
|
||||
if(leds & HAL_LED_2)
|
||||
{
|
||||
if(mode == HAL_LED_MODE_ON)
|
||||
{
|
||||
HAL_TURN_ON_LED2();
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_TURN_OFF_LED2();
|
||||
}
|
||||
}
|
||||
if(leds & HAL_LED_3)
|
||||
{
|
||||
if(mode == HAL_LED_MODE_ON)
|
||||
{
|
||||
HAL_TURN_ON_LED3();
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_TURN_OFF_LED3();
|
||||
}
|
||||
}
|
||||
if(leds & HAL_LED_4)
|
||||
{
|
||||
if(mode == HAL_LED_MODE_ON)
|
||||
{
|
||||
HAL_TURN_ON_LED4();
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_TURN_OFF_LED4();
|
||||
}
|
||||
}
|
||||
/* Remember current state */
|
||||
if(mode)
|
||||
{
|
||||
HalLedState |= leds;
|
||||
}
|
||||
else
|
||||
{
|
||||
HalLedState &= (leds ^ 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
* @fn HalGetLedState
|
||||
*
|
||||
* @brief Dim LED2 - Dim (set level) of LED2
|
||||
*
|
||||
* @return led state
|
||||
*/
|
||||
uint8_t HalLedGetState()
|
||||
{
|
||||
return HalLedState;
|
||||
}
|
||||
|
||||
/******************************** endfile @ led ******************************/
|
||||
|
|
@ -0,0 +1,302 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : MCU.c
|
||||
* Author : WCH
|
||||
* Version : V1.2
|
||||
* Date : 2022/01/18
|
||||
* Description : 硬件任务处理函数及BLE和硬件初始化
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* 头文件包含 */
|
||||
#include "HAL.h"
|
||||
|
||||
tmosTaskID halTaskID;
|
||||
uint32_t g_LLE_IRQLibHandlerLocation;
|
||||
/*******************************************************************************
|
||||
* @fn Lib_Calibration_LSI
|
||||
*
|
||||
* @brief 内部32k校准
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void Lib_Calibration_LSI(void)
|
||||
{
|
||||
Calibration_LSI(Level_64);
|
||||
}
|
||||
|
||||
#if(defined(BLE_SNV)) && (BLE_SNV == TRUE)
|
||||
/*******************************************************************************
|
||||
* @fn Lib_Read_Flash
|
||||
*
|
||||
* @brief Callback function used for BLE lib.
|
||||
*
|
||||
* @param addr - Read start address
|
||||
* @param num - Number of units to read (unit: 4 bytes)
|
||||
* @param pBuf - Buffer to store read data
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
uint32_t Lib_Read_Flash(uint32_t addr, uint32_t num, uint32_t *pBuf)
|
||||
{
|
||||
EEPROM_READ(addr, pBuf, num * 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn Lib_Write_Flash_584X
|
||||
*
|
||||
* @brief Callback function used for BLE lib.
|
||||
*
|
||||
* @param addr - Write start address
|
||||
* @param num - Number of units to write (unit: 4 bytes)
|
||||
* @param pBuf - Buffer with data to be written
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void Lib_Write_Flash_584X(uint32_t addr, uint32_t num, uint32_t *pBuf)
|
||||
{
|
||||
__attribute__((aligned(4))) uint32_t FLASH_BUF[(BLE_SNV_BLOCK*BLE_SNV_NUM) / 4];
|
||||
EEPROM_READ(addr&0xFFFFF000, FLASH_BUF, BLE_SNV_BLOCK*BLE_SNV_NUM);
|
||||
tmos_memcpy(&FLASH_BUF[addr&0xFFF], pBuf, num * 4);
|
||||
EEPROM_ERASE(addr&0xFFFFF000, ((BLE_SNV_BLOCK*BLE_SNV_NUM+EEPROM_BLOCK_SIZE-1)/EEPROM_BLOCK_SIZE)*EEPROM_BLOCK_SIZE);
|
||||
EEPROM_WRITE(addr&0xFFFFF000, FLASH_BUF, BLE_SNV_BLOCK*BLE_SNV_NUM);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn Lib_Write_Flash
|
||||
*
|
||||
* @brief Callback function used for BLE lib.
|
||||
*
|
||||
* @param addr - Write start address
|
||||
* @param num - Number of units to write (unit: 4 bytes)
|
||||
* @param pBuf - Buffer with data to be written
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
uint32_t Lib_Write_Flash(uint32_t addr, uint32_t num, uint32_t *pBuf)
|
||||
{
|
||||
if((chip_info&0x0F) == DEF_CHIP_ID_CH584X)
|
||||
{
|
||||
Lib_Write_Flash_584X(addr, num, pBuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
EEPROM_ERASE(addr, num * 4);
|
||||
EEPROM_WRITE(addr, pBuf, num * 4);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn CH58x_BLEInit
|
||||
*
|
||||
* @brief BLE 库初始化
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void CH58x_BLEInit(void)
|
||||
{
|
||||
uint8_t i;
|
||||
bleConfig_t cfg;
|
||||
if(tmos_memcmp(VER_LIB, VER_FILE, strlen(VER_FILE)) == FALSE)
|
||||
{
|
||||
PRINT("head file error...\n");
|
||||
while(1);
|
||||
}
|
||||
|
||||
__SysTick_Config(SysTick_LOAD_RELOAD_Msk);// 配置SysTick并打开中断
|
||||
PFIC_DisableIRQ(SysTick_IRQn);
|
||||
|
||||
g_LLE_IRQLibHandlerLocation = (uint32_t)LLE_IRQLibHandler;
|
||||
PFIC_SetPriority(BLEL_IRQn, 0xF0);
|
||||
tmos_memset(&cfg, 0, sizeof(bleConfig_t));
|
||||
cfg.MEMAddr = (uint32_t)MEM_BUF;
|
||||
cfg.MEMLen = (uint32_t)BLE_MEMHEAP_SIZE;
|
||||
cfg.BufMaxLen = (uint32_t)BLE_BUFF_MAX_LEN;
|
||||
cfg.BufNumber = (uint32_t)BLE_BUFF_NUM;
|
||||
cfg.TxNumEvent = (uint32_t)BLE_TX_NUM_EVENT;
|
||||
cfg.TxPower = (uint32_t)BLE_TX_POWER;
|
||||
#if(defined(BLE_SNV)) && (BLE_SNV == TRUE)
|
||||
if((BLE_SNV_ADDR + BLE_SNV_BLOCK * BLE_SNV_NUM) > (0x78000 - FLASH_ROM_MAX_SIZE))
|
||||
{
|
||||
PRINT("SNV config error...\n");
|
||||
while(1);
|
||||
}
|
||||
cfg.SNVAddr = (uint32_t)BLE_SNV_ADDR;
|
||||
cfg.SNVBlock = (uint32_t)BLE_SNV_BLOCK;
|
||||
cfg.SNVNum = (uint32_t)BLE_SNV_NUM;
|
||||
cfg.readFlashCB = Lib_Read_Flash;
|
||||
cfg.writeFlashCB = Lib_Write_Flash;
|
||||
#endif
|
||||
cfg.ConnectNumber = (PERIPHERAL_MAX_CONNECTION & 3) | (CENTRAL_MAX_CONNECTION << 2);
|
||||
cfg.srandCB = SYS_GetSysTickCnt;
|
||||
#if(defined TEM_SAMPLE) && (TEM_SAMPLE == TRUE)
|
||||
cfg.tsCB = HAL_GetInterTempValue; // 根据温度变化校准RF和内部RC( 大于7摄氏度 )
|
||||
#if(CLK_OSC32K)
|
||||
cfg.rcCB = Lib_Calibration_LSI; // 内部32K时钟校准
|
||||
#endif
|
||||
#endif
|
||||
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
||||
cfg.idleCB = CH58x_LowPower; // 启用睡眠
|
||||
#endif
|
||||
#if(defined(BLE_MAC)) && (BLE_MAC == TRUE)
|
||||
for(i = 0; i < 6; i++)
|
||||
{
|
||||
cfg.MacAddr[i] = MacAddr[5 - i];
|
||||
}
|
||||
#else
|
||||
{
|
||||
uint8_t MacAddr[6];
|
||||
GetMACAddress(MacAddr);
|
||||
for(i = 0; i < 6; i++)
|
||||
{
|
||||
cfg.MacAddr[i] = MacAddr[i]; // 使用芯片mac地址
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if(!cfg.MEMAddr || cfg.MEMLen < 4 * 1024)
|
||||
{
|
||||
while(1);
|
||||
}
|
||||
// BLE_Lib 占用了VTF Interrupt 2号和3号
|
||||
i = BLE_LibInit(&cfg);
|
||||
if(i)
|
||||
{
|
||||
PRINT("LIB init error code: %x ...\n", i);
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn HAL_ProcessEvent
|
||||
*
|
||||
* @brief 硬件层事务处理
|
||||
*
|
||||
* @param task_id - The TMOS assigned task ID.
|
||||
* @param events - events to process. This is a bit map and can
|
||||
* contain more than one event.
|
||||
*
|
||||
* @return events.
|
||||
*/
|
||||
tmosEvents HAL_ProcessEvent(tmosTaskID task_id, tmosEvents events)
|
||||
{
|
||||
uint8_t *msgPtr;
|
||||
|
||||
if(events & SYS_EVENT_MSG)
|
||||
{ // 处理HAL层消息,调用tmos_msg_receive读取消息,处理完成后删除消息。
|
||||
msgPtr = tmos_msg_receive(task_id);
|
||||
if(msgPtr)
|
||||
{
|
||||
/* De-allocate */
|
||||
tmos_msg_deallocate(msgPtr);
|
||||
}
|
||||
return events ^ SYS_EVENT_MSG;
|
||||
}
|
||||
if(events & LED_BLINK_EVENT)
|
||||
{
|
||||
#if(defined HAL_LED) && (HAL_LED == TRUE)
|
||||
HalLedUpdate();
|
||||
#endif // HAL_LED
|
||||
return events ^ LED_BLINK_EVENT;
|
||||
}
|
||||
if(events & HAL_KEY_EVENT)
|
||||
{
|
||||
#if(defined HAL_KEY) && (HAL_KEY == TRUE)
|
||||
HAL_KeyPoll(); /* Check for keys */
|
||||
tmos_start_task(halTaskID, HAL_KEY_EVENT, MS1_TO_SYSTEM_TIME(100));
|
||||
return events ^ HAL_KEY_EVENT;
|
||||
#endif
|
||||
}
|
||||
if(events & HAL_REG_INIT_EVENT)
|
||||
{
|
||||
uint8_t x32Kpw;
|
||||
#if(defined BLE_CALIBRATION_ENABLE) && (BLE_CALIBRATION_ENABLE == TRUE) // 校准任务,单次校准耗时小于10ms
|
||||
#ifndef RF_8K
|
||||
BLE_RegInit(); // 校准RF,会关闭RF并改变RF相关寄存器,如果使用了RF收发函数需注意校准后再重新启用
|
||||
#endif
|
||||
#if(CLK_OSC32K)
|
||||
Lib_Calibration_LSI(); // 校准内部RC
|
||||
#elif(HAL_SLEEP)
|
||||
x32Kpw = (R8_XT32K_TUNE & 0xfc) | 0x01;
|
||||
sys_safe_access_enable();
|
||||
R8_XT32K_TUNE = x32Kpw; // LSE驱动电流降低到额定电流
|
||||
sys_safe_access_disable();
|
||||
#endif
|
||||
tmos_start_task(halTaskID, HAL_REG_INIT_EVENT, MS1_TO_SYSTEM_TIME(BLE_CALIBRATION_PERIOD));
|
||||
return events ^ HAL_REG_INIT_EVENT;
|
||||
#endif
|
||||
}
|
||||
if(events & HAL_TEST_EVENT)
|
||||
{
|
||||
PRINT("* \n");
|
||||
tmos_start_task(halTaskID, HAL_TEST_EVENT, MS1_TO_SYSTEM_TIME(1000));
|
||||
return events ^ HAL_TEST_EVENT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn HAL_Init
|
||||
*
|
||||
* @brief 硬件初始化
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void HAL_Init()
|
||||
{
|
||||
halTaskID = TMOS_ProcessEventRegister(HAL_ProcessEvent);
|
||||
HAL_TimeInit();
|
||||
#if(defined HAL_SLEEP) && (HAL_SLEEP == TRUE)
|
||||
HAL_SleepInit();
|
||||
#endif
|
||||
#if(defined HAL_LED) && (HAL_LED == TRUE)
|
||||
HAL_LedInit();
|
||||
#endif
|
||||
#if(defined HAL_KEY) && (HAL_KEY == TRUE)
|
||||
HAL_KeyInit();
|
||||
#endif
|
||||
#if(defined BLE_CALIBRATION_ENABLE) && (BLE_CALIBRATION_ENABLE == TRUE)
|
||||
tmos_start_task(halTaskID, HAL_REG_INIT_EVENT, 800); // 添加校准任务,500ms启动,单次校准耗时小于10ms
|
||||
#endif
|
||||
// tmos_start_task( halTaskID, HAL_TEST_EVENT, 1600 ); // 添加一个测试任务
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn HAL_GetInterTempValue
|
||||
*
|
||||
* @brief 获取内部温感采样值,如果使用了ADC中断采样,需在此函数中暂时屏蔽中断.
|
||||
*
|
||||
* @return 内部温感采样值.
|
||||
*/
|
||||
uint16_t HAL_GetInterTempValue(void)
|
||||
{
|
||||
uint8_t sensor, channel, config, tkey_cfg;
|
||||
uint16_t adc_data;
|
||||
|
||||
tkey_cfg = R8_TKEY_CFG;
|
||||
sensor = R8_TEM_SENSOR;
|
||||
channel = R8_ADC_CHANNEL;
|
||||
config = R8_ADC_CFG;
|
||||
ADC_InterTSSampInit();
|
||||
R8_ADC_CONVERT |= RB_ADC_START;
|
||||
while(R8_ADC_CONVERT & RB_ADC_START);
|
||||
adc_data = R16_ADC_DATA;
|
||||
R8_TEM_SENSOR = sensor;
|
||||
R8_ADC_CHANNEL = channel;
|
||||
R8_ADC_CFG = config;
|
||||
R8_TKEY_CFG = tkey_cfg;
|
||||
return (adc_data);
|
||||
}
|
||||
|
||||
/******************************** endfile @ mcu ******************************/
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : RTC.c
|
||||
* Author : WCH
|
||||
* Version : V1.2
|
||||
* Date : 2022/01/18
|
||||
* Description : RTC配置及其初始化
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* 头文件包含 */
|
||||
#include "HAL.h"
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
#define RTC_INIT_TIME_HOUR 0
|
||||
#define RTC_INIT_TIME_MINUTE 0
|
||||
#define RTC_INIT_TIME_SECEND 0
|
||||
|
||||
/***************************************************
|
||||
* Global variables
|
||||
*/
|
||||
volatile uint32_t RTCTigFlag;
|
||||
|
||||
#if RF_8K
|
||||
|
||||
/*********************************************************************
|
||||
* @fn TMR3_IRQHandler
|
||||
*
|
||||
* @brief TMR0中断函数
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
__INTERRUPT
|
||||
__HIGH_CODE
|
||||
void TMR3_IRQHandler(void) // TMR3
|
||||
{
|
||||
uint32_t trig_time;
|
||||
|
||||
TMR3_ClearITFlag(TMR0_3_IT_CYC_END); // 清除中断标志
|
||||
if( !TMOS_TimerIRQHandler( &trig_time ) )
|
||||
{
|
||||
if( trig_time )
|
||||
{
|
||||
R32_TMR3_CNT_END = trig_time;
|
||||
R8_TMR3_CTRL_MOD = RB_TMR_ALL_CLEAR;
|
||||
R8_TMR3_CTRL_MOD = RB_TMR_COUNT_EN;
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT("!!!!!!!!!!!!!!!!!! warn \n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
__HIGH_CODE
|
||||
static uint32_t SYS_GetClock1Value(void)
|
||||
{
|
||||
return SysTick->CNT;
|
||||
}
|
||||
__HIGH_CODE
|
||||
static void SYS_SetClock1PendingIRQ(void)
|
||||
{
|
||||
PFIC_SetPendingIRQ( TMR3_IRQn );
|
||||
}
|
||||
__HIGH_CODE
|
||||
static void SYS_SetTignOffest( int32_t val )
|
||||
{
|
||||
R32_TMR3_CNT_END += (val);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn RTC_SetTignTime
|
||||
*
|
||||
* @brief 配置RTC触发时间
|
||||
*
|
||||
* @param time - 触发时间.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
__HIGH_CODE
|
||||
void RTC_SetTignTime(uint32_t time)
|
||||
{
|
||||
sys_safe_access_enable();
|
||||
R32_RTC_TRIG = time;
|
||||
sys_safe_access_disable();
|
||||
RTCTigFlag = 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn RTC_IRQHandler
|
||||
*
|
||||
* @brief RTC中断处理
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
__INTERRUPT
|
||||
__HIGH_CODE
|
||||
void RTC_IRQHandler(void)
|
||||
{
|
||||
R8_RTC_FLAG_CTRL = (RB_RTC_TMR_CLR | RB_RTC_TRIG_CLR);
|
||||
RTCTigFlag = 1;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn SYS_GetClockValue
|
||||
*
|
||||
* @brief 获取RTC当前计数值
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
__HIGH_CODE
|
||||
static uint32_t SYS_GetClockValue(void)
|
||||
{
|
||||
volatile uint32_t i;
|
||||
|
||||
do
|
||||
{
|
||||
i = R32_RTC_CNT_32K;
|
||||
} while(i != R32_RTC_CNT_32K);
|
||||
|
||||
return (i);
|
||||
}
|
||||
__HIGH_CODE
|
||||
static void SYS_SetPendingIRQ(void)
|
||||
{
|
||||
PFIC_SetPendingIRQ( RTC_IRQn );
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn HAL_Time0Init
|
||||
*
|
||||
* @brief 系统定时器初始化
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void HAL_TimeInit(void)
|
||||
{
|
||||
bleClockConfig_t conf;
|
||||
#if(CLK_OSC32K)
|
||||
sys_safe_access_enable();
|
||||
R8_CK32K_CONFIG &= ~(RB_CLK_OSC32K_XT | RB_CLK_XT32K_PON);
|
||||
sys_safe_access_disable();
|
||||
sys_safe_access_enable();
|
||||
R8_CK32K_CONFIG |= RB_CLK_INT32K_PON;
|
||||
sys_safe_access_disable();
|
||||
LSECFG_Current(LSE_RCur_100);
|
||||
Lib_Calibration_LSI();
|
||||
#else
|
||||
sys_safe_access_enable();
|
||||
R8_CK32K_CONFIG &= ~RB_CLK_INT32K_PON;
|
||||
sys_safe_access_disable();
|
||||
sys_safe_access_enable();
|
||||
R8_CK32K_CONFIG |= RB_CLK_OSC32K_XT | RB_CLK_XT32K_PON;
|
||||
sys_safe_access_disable();
|
||||
#endif
|
||||
RTC_InitTime(2020, 1, 1, 0, 0, 0); //RTC时钟初始化当前时间
|
||||
|
||||
tmos_memset( &conf, 0, sizeof(bleClockConfig_t) );
|
||||
conf.ClockAccuracy = CLK_OSC32K ? 1000 : 50;
|
||||
conf.ClockFrequency = CAB_LSIFQ;
|
||||
conf.ClockMaxCount = RTC_MAX_COUNT;
|
||||
conf.getClockValue = SYS_GetClockValue;
|
||||
conf.SetPendingIRQ = SYS_SetPendingIRQ;
|
||||
|
||||
#if RF_8K
|
||||
// rf-8k 通信时间相关配置
|
||||
conf.Clock1Frequency = GetSysClock( )/1000;
|
||||
conf.getClock1Value = SYS_GetClock1Value;
|
||||
conf.SetClock1PendingIRQ = SYS_SetClock1PendingIRQ;
|
||||
conf.SetTign = SYS_SetTignOffest;
|
||||
TMR3_ITCfg(ENABLE, TMR0_3_IT_CYC_END); // 开启中断
|
||||
PFIC_EnableIRQ(TMR3_IRQn);
|
||||
#endif
|
||||
|
||||
TMOS_TimerInit( &conf );
|
||||
|
||||
}
|
||||
|
||||
/******************************** endfile @ time ******************************/
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : SLEEP.c
|
||||
* Author : WCH
|
||||
* Version : V1.2
|
||||
* Date : 2022/01/18
|
||||
* Description : 睡眠配置及其初始化
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* 头文件包含 */
|
||||
#include "HAL.h"
|
||||
|
||||
|
||||
pfnLowPowerGapProcessCB_t LowPowerGapProcess;
|
||||
/*******************************************************************************
|
||||
* @fn CH58x_LowPower
|
||||
*
|
||||
* @brief 启动睡眠
|
||||
*
|
||||
* @param time - 唤醒的时间点(RTC绝对值)
|
||||
*
|
||||
* @return state.
|
||||
*/
|
||||
__HIGH_CODE
|
||||
uint32_t CH58x_LowPower(uint32_t time)
|
||||
{
|
||||
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
||||
volatile uint32_t i;
|
||||
uint32_t time_tign, time_sleep, time_curr;
|
||||
unsigned long irq_status;
|
||||
|
||||
// 提前唤醒
|
||||
if (time <= WAKE_UP_RTC_MAX_TIME) {
|
||||
time_tign = time + (RTC_MAX_COUNT - WAKE_UP_RTC_MAX_TIME);
|
||||
} else {
|
||||
time_tign = time - WAKE_UP_RTC_MAX_TIME;
|
||||
}
|
||||
|
||||
SYS_DisableAllIrq(&irq_status);
|
||||
time_curr = RTC_GetCycle32k();
|
||||
// 检测睡眠时间
|
||||
if (time_tign < time_curr) {
|
||||
time_sleep = time_tign + (RTC_MAX_COUNT - time_curr);
|
||||
} else {
|
||||
time_sleep = time_tign - time_curr;
|
||||
}
|
||||
|
||||
// 若睡眠时间小于最小睡眠时间或大于最大睡眠时间,则不睡眠
|
||||
if ((time_sleep < SLEEP_RTC_MIN_TIME) ||
|
||||
(time_sleep > SLEEP_RTC_MAX_TIME)) {
|
||||
SYS_RecoverIrq(irq_status);
|
||||
return 2;
|
||||
}
|
||||
|
||||
RTC_SetTignTime(time_tign);
|
||||
R8_RTC_FLAG_CTRL = (RB_RTC_TMR_CLR | RB_RTC_TRIG_CLR);
|
||||
|
||||
#if(DEBUG == Debug_UART0) // 使用其他串口输出打印信息需要修改这行代码
|
||||
while((R8_UART0_LSR & RB_LSR_TX_ALL_EMP) == 0)
|
||||
{
|
||||
__nop();
|
||||
}
|
||||
#endif
|
||||
// LOW POWER-sleep模式
|
||||
if(!(R8_RTC_FLAG_CTRL&RB_RTC_TRIG_FLAG))
|
||||
{
|
||||
uint8_t x32Mpw;
|
||||
|
||||
LowPower_Sleep_WFE(RB_PWR_RAM32K | RB_PWR_RAM96K | RB_PWR_EXTEND);
|
||||
|
||||
// 切换32M电流
|
||||
x32Mpw = R8_XT32M_TUNE;
|
||||
x32Mpw = (x32Mpw & 0xfc) | 0x03; // 150%额定电流
|
||||
sys_safe_access_enable();
|
||||
R8_XT32M_TUNE = x32Mpw;
|
||||
sys_safe_access_disable();
|
||||
|
||||
if(!(R8_RTC_FLAG_CTRL&RB_RTC_TRIG_FLAG)) //非RTC唤醒
|
||||
{
|
||||
// 注意此时32M还需等待稳定,也可执行一些时钟要求不高的代码
|
||||
DelayUs(1400);
|
||||
SetSysClock( SYSCLK_FREQ );
|
||||
SYS_RecoverIrq(irq_status);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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(!(R8_RTC_FLAG_CTRL&RB_RTC_TRIG_FLAG)) //非RTC唤醒
|
||||
{
|
||||
LowPower_Halt_WFE();
|
||||
}
|
||||
// 恢复时钟
|
||||
SetSysClock( SYSCLK_FREQ );
|
||||
R8_RTC_FLAG_CTRL = (RB_RTC_TMR_CLR | RB_RTC_TRIG_CLR);
|
||||
SYS_RecoverIrq(irq_status);
|
||||
HSECFG_Current(HSE_RCur_100); // 降为额定电流(低功耗函数中提升了HSE偏置电流)
|
||||
return 0;
|
||||
}
|
||||
SYS_RecoverIrq(irq_status);
|
||||
#endif
|
||||
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
|
||||
*
|
||||
* @brief 配置睡眠唤醒的方式 - RTC唤醒,触发模式
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void HAL_SleepInit(void)
|
||||
{
|
||||
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
||||
sys_safe_access_enable();
|
||||
R8_SLP_WAKE_CTRL |= RB_SLP_RTC_WAKE; // RTC唤醒
|
||||
sys_safe_access_disable();
|
||||
sys_safe_access_enable();
|
||||
R8_RTC_MODE_CTRL |= RB_RTC_TRIG_EN; // 触发模式
|
||||
sys_safe_access_disable();
|
||||
PFIC_EnableIRQ(RTC_IRQn);
|
||||
#endif
|
||||
}
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : CONFIG.h
|
||||
* Author : WCH
|
||||
* Version : V1.2
|
||||
* Date : 2022/01/18
|
||||
* Description : 配置说明及默认值,建议在工程配置里的预处理中修改当前值
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef __CONFIG_H
|
||||
#define __CONFIG_H
|
||||
|
||||
|
||||
#define CHIP_ID ID_CH585
|
||||
|
||||
#ifdef CH58xBLE_ROM
|
||||
#include "CH58xBLE_ROM.h"
|
||||
#else
|
||||
#include "CH58xBLE_LIB.h"
|
||||
#endif
|
||||
|
||||
#include "CH58x_common.h"
|
||||
|
||||
/*********************************************************************
|
||||
【MAC】
|
||||
BLE_MAC - 是否自定义蓝牙Mac地址 ( 默认:FALSE - 使用芯片Mac地址 ),需要在main.c修改Mac地址定义
|
||||
|
||||
【DCDC】
|
||||
DCDC_ENABLE - 是否使能DCDC ( 默认:FALSE )
|
||||
|
||||
【SLEEP】
|
||||
HAL_SLEEP - 是否开启睡眠功能 ( 默认:FALSE )
|
||||
SLEEP_RTC_MIN_TIME - 非空闲模式下睡眠的最小时间(单位:一个RTC周期)
|
||||
SLEEP_RTC_MAX_TIME - 非空闲模式下睡眠的最大时间(单位:一个RTC周期)
|
||||
WAKE_UP_RTC_MAX_TIME - 等待32M晶振稳定时间(单位:一个RTC周期)
|
||||
根据不同睡眠类型取值可分为: 睡眠模式/下电模式 - 45 (默认)
|
||||
暂停模式 - 45
|
||||
空闲模式 - 5
|
||||
【TEMPERATION】
|
||||
TEM_SAMPLE - 是否打开根据温度变化校准的功能,单次校准耗时小于10ms( 默认:TRUE )
|
||||
|
||||
【CALIBRATION】
|
||||
BLE_CALIBRATION_ENABLE - 是否打开定时校准的功能,单次校准耗时小于10ms( 默认:TRUE )
|
||||
BLE_CALIBRATION_PERIOD - 定时校准的周期,单位ms( 默认:120000 )
|
||||
|
||||
【SNV】
|
||||
BLE_SNV - 是否开启SNV功能,用于储存绑定信息( 默认:TRUE )
|
||||
BLE_SNV_ADDR - SNV信息保存地址,使用data flash最后512字节( 默认:0x77E00 )
|
||||
BLE_SNV_BLOCK - SNV信息保存块大小( 默认:256 )
|
||||
BLE_SNV_NUM - SNV信息保存数量( 默认:1 )
|
||||
|
||||
【RTC】
|
||||
CLK_OSC32K - RTC时钟选择,如包含主机角色必须使用外部32K( 0 外部(32768Hz),默认:1:内部(32000Hz),2:内部(32768Hz) )
|
||||
|
||||
【MEMORY】
|
||||
BLE_MEMHEAP_SIZE - 蓝牙协议栈使用的RAM大小,不小于6K ( 默认:(1024*6) )
|
||||
|
||||
【DATA】
|
||||
BLE_BUFF_MAX_LEN - 单个连接最大包长度( 默认:27 (ATT_MTU=23),取值范围[27~516] )
|
||||
BLE_BUFF_NUM - 控制器缓存的包数量( 默认:5 )
|
||||
BLE_TX_NUM_EVENT - 单个连接事件最多可以发多少个数据包( 默认:1 )
|
||||
BLE_TX_POWER - 发射功率( 默认:LL_TX_POWEER_0_DBM (0dBm) )
|
||||
|
||||
【MULTICONN】
|
||||
PERIPHERAL_MAX_CONNECTION - 最多可同时做多少从机角色( 默认:1 )
|
||||
CENTRAL_MAX_CONNECTION - 最多可同时做多少主机角色( 默认:3 )
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
* 默认配置值
|
||||
*/
|
||||
#ifndef BLE_MAC
|
||||
#define BLE_MAC FALSE
|
||||
#endif
|
||||
#ifndef DCDC_ENABLE
|
||||
#define DCDC_ENABLE FALSE
|
||||
#endif
|
||||
#ifndef HAL_SLEEP
|
||||
#define HAL_SLEEP FALSE
|
||||
#endif
|
||||
#ifndef SLEEP_RTC_MIN_TIME
|
||||
#define SLEEP_RTC_MIN_TIME US_TO_RTC(1000)
|
||||
#endif
|
||||
#ifndef SLEEP_RTC_MAX_TIME
|
||||
#define SLEEP_RTC_MAX_TIME (RTC_MAX_COUNT - 1000 * 1000 * 30)
|
||||
#endif
|
||||
#ifndef WAKE_UP_RTC_MAX_TIME
|
||||
#define WAKE_UP_RTC_MAX_TIME US_TO_RTC(1600)
|
||||
#endif
|
||||
#ifndef HAL_KEY
|
||||
#define HAL_KEY FALSE
|
||||
#endif
|
||||
#ifndef HAL_LED
|
||||
#define HAL_LED FALSE
|
||||
#endif
|
||||
#ifndef TEM_SAMPLE
|
||||
#define TEM_SAMPLE TRUE
|
||||
#endif
|
||||
#ifndef BLE_CALIBRATION_ENABLE
|
||||
#define BLE_CALIBRATION_ENABLE TRUE
|
||||
#endif
|
||||
#ifndef BLE_CALIBRATION_PERIOD
|
||||
#define BLE_CALIBRATION_PERIOD 120000
|
||||
#endif
|
||||
#ifndef BLE_SNV
|
||||
#define BLE_SNV TRUE
|
||||
#endif
|
||||
#ifndef BLE_SNV_ADDR
|
||||
#define BLE_SNV_ADDR 0x77000-FLASH_ROM_MAX_SIZE
|
||||
#endif
|
||||
#ifndef BLE_SNV_BLOCK
|
||||
#define BLE_SNV_BLOCK 256
|
||||
#endif
|
||||
#ifndef BLE_SNV_NUM
|
||||
#define BLE_SNV_NUM 1
|
||||
#endif
|
||||
#ifndef CLK_OSC32K
|
||||
#define CLK_OSC32K 1 // 该项请勿在此修改,必须在工程配置里的预处理中修改,如包含主机角色必须使用外部32K
|
||||
#endif
|
||||
#ifndef BLE_MEMHEAP_SIZE
|
||||
#define BLE_MEMHEAP_SIZE (1024*6)
|
||||
#endif
|
||||
#ifndef BLE_BUFF_MAX_LEN
|
||||
#define BLE_BUFF_MAX_LEN 27
|
||||
#endif
|
||||
#ifndef BLE_BUFF_NUM
|
||||
#define BLE_BUFF_NUM 5
|
||||
#endif
|
||||
#ifndef BLE_TX_NUM_EVENT
|
||||
#define BLE_TX_NUM_EVENT 1
|
||||
#endif
|
||||
#ifndef BLE_TX_POWER
|
||||
#define BLE_TX_POWER LL_TX_POWEER_0_DBM
|
||||
#endif
|
||||
#ifndef PERIPHERAL_MAX_CONNECTION
|
||||
#define PERIPHERAL_MAX_CONNECTION 1
|
||||
#endif
|
||||
#ifndef CENTRAL_MAX_CONNECTION
|
||||
#define CENTRAL_MAX_CONNECTION 3
|
||||
#endif
|
||||
|
||||
extern uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];
|
||||
extern const uint8_t MacAddr[6];
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : HAL.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2016/05/05
|
||||
* Description :
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef __HAL_H
|
||||
#define __HAL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CONFIG.h"
|
||||
#include "RTC.h"
|
||||
#include "SLEEP.h"
|
||||
#include "LED.h"
|
||||
#include "KEY.h"
|
||||
|
||||
/* hal task Event */
|
||||
#define LED_BLINK_EVENT 0x0001
|
||||
#define HAL_KEY_EVENT 0x0002
|
||||
#define HAL_REG_INIT_EVENT 0x2000
|
||||
#define HAL_TEST_EVENT 0x4000
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
extern tmosTaskID halTaskID;
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief 硬件初始化
|
||||
*/
|
||||
extern void HAL_Init(void);
|
||||
|
||||
/**
|
||||
* @brief 硬件层事务处理
|
||||
*
|
||||
* @param task_id - The TMOS assigned task ID.
|
||||
* @param events - events to process. This is a bit map and can
|
||||
* contain more than one event.
|
||||
*/
|
||||
extern tmosEvents HAL_ProcessEvent(tmosTaskID task_id, tmosEvents events);
|
||||
|
||||
/**
|
||||
* @brief BLE 库初始化
|
||||
*/
|
||||
extern void CH58x_BLEInit(void);
|
||||
|
||||
/**
|
||||
* @brief 获取内部温感采样值,如果使用了ADC中断采样,需在此函数中暂时屏蔽中断.
|
||||
*
|
||||
* @return 内部温感采样值.
|
||||
*/
|
||||
extern uint16_t HAL_GetInterTempValue(void);
|
||||
|
||||
/**
|
||||
* @brief 内部32k校准
|
||||
*/
|
||||
extern void Lib_Calibration_LSI(void);
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : KEY.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2016/04/12
|
||||
* Description :
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef __KEY_H
|
||||
#define __KEY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
* MACROS
|
||||
**************************************************************************************************/
|
||||
#define HAL_KEY_POLLING_VALUE 100
|
||||
|
||||
/* Switches (keys) */
|
||||
#define HAL_KEY_SW_1 0x01 // key1
|
||||
#define HAL_KEY_SW_2 0x02 // key2
|
||||
#define HAL_KEY_SW_3 0x04 // key3
|
||||
#define HAL_KEY_SW_4 0x08 // key4
|
||||
|
||||
/* °´¼ü¶¨Òå */
|
||||
|
||||
/* 1 - KEY */
|
||||
#define KEY1_BV BV(22)
|
||||
#define KEY2_BV BV(4)
|
||||
#define KEY3_BV ()
|
||||
#define KEY4_BV ()
|
||||
|
||||
#define KEY1_PU (R32_PB_PU |= KEY1_BV)
|
||||
#define KEY2_PU (R32_PB_PU |= KEY2_BV)
|
||||
#define KEY3_PU ()
|
||||
#define KEY4_PU ()
|
||||
|
||||
#define KEY1_DIR (R32_PB_DIR &= ~KEY1_BV)
|
||||
#define KEY2_DIR (R32_PB_DIR &= ~KEY2_BV)
|
||||
#define KEY3_DIR ()
|
||||
#define KEY4_DIR ()
|
||||
|
||||
#define KEY1_IN (ACTIVE_LOW(R32_PB_PIN & KEY1_BV))
|
||||
#define KEY2_IN (ACTIVE_LOW(R32_PB_PIN & KEY2_BV))
|
||||
#define KEY3_IN ()
|
||||
#define KEY4_IN ()
|
||||
|
||||
#define HAL_PUSH_BUTTON1() (KEY1_IN) //Ìí¼Ó×Ô¶¨Òå°´¼ü
|
||||
#define HAL_PUSH_BUTTON2() (KEY2_IN)
|
||||
#define HAL_PUSH_BUTTON3() (0)
|
||||
#define HAL_PUSH_BUTTON4() (0)
|
||||
|
||||
/**************************************************************************************************
|
||||
* TYPEDEFS
|
||||
**************************************************************************************************/
|
||||
typedef void (*halKeyCBack_t)(uint8_t keys);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t keys; // keys
|
||||
} keyChange_t;
|
||||
|
||||
/**************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
**************************************************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the Key Service
|
||||
*/
|
||||
void HAL_KeyInit(void);
|
||||
|
||||
/**
|
||||
* @brief This is for internal used by hal_driver
|
||||
*/
|
||||
void HAL_KeyPoll(void);
|
||||
|
||||
/**
|
||||
* @brief Configure the Key serivce
|
||||
*
|
||||
* @param cback - pointer to the CallBack function
|
||||
*/
|
||||
void HalKeyConfig(const halKeyCBack_t cback);
|
||||
|
||||
/**
|
||||
* @brief Read the Key callback
|
||||
*/
|
||||
void HalKeyCallback(uint8_t keys);
|
||||
|
||||
/**
|
||||
* @brief Read the Key status
|
||||
*/
|
||||
uint8_t HalKeyRead(void);
|
||||
|
||||
/**************************************************************************************************
|
||||
**************************************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : LED.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2016/04/12
|
||||
* Description :
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef __LED_H
|
||||
#define __LED_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
/* LEDS - The LED number is the same as the bit position */
|
||||
#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
|
||||
#define HAL_LED_MODE_ON 0x01
|
||||
#define HAL_LED_MODE_BLINK 0x02
|
||||
#define HAL_LED_MODE_FLASH 0x04
|
||||
#define HAL_LED_MODE_TOGGLE 0x08
|
||||
|
||||
/* Defaults */
|
||||
#define HAL_LED_DEFAULT_MAX_LEDS 4
|
||||
#define HAL_LED_DEFAULT_DUTY_CYCLE 5
|
||||
#define HAL_LED_DEFAULT_FLASH_COUNT 50
|
||||
#define HAL_LED_DEFAULT_FLASH_TIME 1000
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
/* 连接一个LED用于监控演示程序的进度,低电平LED亮 */
|
||||
|
||||
/* 1 - LED */
|
||||
#define LED1_BV BV(15)
|
||||
#define LED2_BV
|
||||
#define LED3_BV
|
||||
|
||||
#define LED1_OUT (R32_PB_OUT)
|
||||
#define LED2_OUT 0
|
||||
#define LED3_OUT 0
|
||||
#define LED4_OUT 0
|
||||
|
||||
#define LED1_DDR (R32_PB_DIR |= LED1_BV)
|
||||
#define LED2_DDR 0
|
||||
#define LED3_DDR 0
|
||||
|
||||
#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 HAL_TURN_ON_LED1() (LED1_OUT &= (~LED1_BV))
|
||||
#define HAL_TURN_ON_LED2()
|
||||
#define HAL_TURN_ON_LED3()
|
||||
#define HAL_TURN_ON_LED4()
|
||||
|
||||
#define HAL_STATE_LED1() 0
|
||||
#define HAL_STATE_LED2() 0
|
||||
#define HAL_STATE_LED3() 0
|
||||
#define HAL_STATE_LED4() 0
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize LED Service.
|
||||
*/
|
||||
void HAL_LedInit(void);
|
||||
|
||||
/**
|
||||
* @brief update time LED Service.
|
||||
*/
|
||||
void HalLedUpdate(void);
|
||||
|
||||
/**
|
||||
* @brief Turn ON/OFF/TOGGLE given LEDs
|
||||
*
|
||||
* @param led - bit mask value of leds to be turned ON/OFF/TOGGLE
|
||||
* @param mode - BLINK, FLASH, TOGGLE, ON, OFF
|
||||
*/
|
||||
extern uint8_t HalLedSet(uint8_t led, uint8_t mode);
|
||||
|
||||
/**
|
||||
* @brief Blink the leds
|
||||
*
|
||||
* @param led - bit mask value of leds to be turned ON/OFF/TOGGLE
|
||||
* @param numBlinks - number of blinks
|
||||
* @param percent - the percentage in each period where the led will be on
|
||||
* @param period - length of each cycle in milliseconds
|
||||
*/
|
||||
extern void HalLedBlink(uint8_t leds, uint8_t cnt, uint8_t duty, uint16_t time);
|
||||
|
||||
/**
|
||||
* @brief Put LEDs in sleep state - store current values
|
||||
*/
|
||||
extern void HalLedEnterSleep(void);
|
||||
|
||||
/**
|
||||
* @brief Retore LEDs from sleep state
|
||||
*/
|
||||
extern void HalLedExitSleep(void);
|
||||
|
||||
/**
|
||||
* @brief Return LED state
|
||||
*/
|
||||
extern uint8_t HalLedGetState(void);
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : RTC.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2016/04/12
|
||||
* Description :
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef __RTC_H
|
||||
#define __RTC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef CLK_OSC32K
|
||||
#if (CLK_OSC32K==1)
|
||||
#define FREQ_RTC 32000
|
||||
#else
|
||||
#define FREQ_RTC 32768
|
||||
#endif
|
||||
#endif /* CLK_OSC32K */
|
||||
|
||||
|
||||
#define CLK_PER_US (1.0 / ((1.0 / FREQ_RTC) * 1000 * 1000))
|
||||
#define CLK_PER_MS (CLK_PER_US * 1000)
|
||||
|
||||
#define US_PER_CLK (1.0 / CLK_PER_US)
|
||||
#define MS_PER_CLK (US_PER_CLK / 1000.0)
|
||||
|
||||
#define RTC_TO_US(clk) ((uint32_t)((clk) * US_PER_CLK + 0.5))
|
||||
#define RTC_TO_MS(clk) ((uint32_t)((clk) * MS_PER_CLK + 0.5))
|
||||
|
||||
#define US_TO_RTC(us) ((uint32_t)((us) * CLK_PER_US + 0.5))
|
||||
#define MS_TO_RTC(ms) ((uint32_t)((ms) * CLK_PER_MS + 0.5))
|
||||
|
||||
extern volatile uint32_t RTCTigFlag;
|
||||
|
||||
/**
|
||||
* @brief Initialize time Service.
|
||||
*/
|
||||
void HAL_TimeInit(void);
|
||||
|
||||
/**
|
||||
* @brief ÅäÖÃRTC´¥·¢Ê±¼ä
|
||||
*
|
||||
* @param time - ´¥·¢Ê±¼ä.
|
||||
*/
|
||||
extern void RTC_SetTignTime(uint32_t time);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : SLEEP.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/11/12
|
||||
* Description :
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef __SLEEP_H
|
||||
#define __SLEEP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
typedef void (*pfnLowPowerGapProcessCB_t)( void );
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief 配置睡眠唤醒的方式 - RTC唤醒,触发模式
|
||||
*/
|
||||
extern void HAL_SleepInit(void);
|
||||
|
||||
/**
|
||||
* @brief 启动睡眠
|
||||
*
|
||||
* @param time - 唤醒的时间点(RTC绝对值)
|
||||
*
|
||||
* @return state.
|
||||
*/
|
||||
extern uint32_t CH58x_LowPower(uint32_t time);
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,127 @@
|
|||
.global Ecall_M_Mode_Handler
|
||||
.global Ecall_U_Mode_Handler
|
||||
.global LLE_IRQHandler
|
||||
|
||||
.extern g_LLE_IRQLibHandlerLocation
|
||||
|
||||
.section .highcode,"ax",@progbits
|
||||
.align 2
|
||||
.func
|
||||
Ecall_M_Mode_Handler:
|
||||
Ecall_U_Mode_Handler:
|
||||
|
||||
addi a1, x0, 0x20
|
||||
csrs 0x804, a1
|
||||
|
||||
lw a1, 0 * 4( sp )
|
||||
csrw mepc, a1
|
||||
|
||||
lw x1, 1 * 4( sp )
|
||||
lw x4, 2 * 4( sp )
|
||||
lw x5, 3 * 4( sp )
|
||||
lw x6, 4 * 4( sp )
|
||||
lw x7, 5 * 4( sp )
|
||||
lw x8, 6 * 4( sp )
|
||||
lw x9, 7 * 4( sp )
|
||||
lw x10, 8 * 4( sp )
|
||||
lw x11, 9 * 4( sp )
|
||||
lw x12, 10 * 4( sp )
|
||||
lw x13, 11 * 4( sp )
|
||||
lw x14, 12 * 4( sp )
|
||||
lw x15, 13 * 4( sp )
|
||||
lw x16, 14 * 4( sp )
|
||||
lw x17, 15 * 4( sp )
|
||||
lw x18, 16 * 4( sp )
|
||||
lw x19, 17 * 4( sp )
|
||||
lw x20, 18 * 4( sp )
|
||||
lw x21, 19 * 4( sp )
|
||||
lw x22, 20 * 4( sp )
|
||||
lw x23, 21 * 4( sp )
|
||||
lw x24, 22 * 4( sp )
|
||||
lw x25, 23 * 4( sp )
|
||||
lw x26, 24 * 4( sp )
|
||||
lw x27, 25 * 4( sp )
|
||||
lw x28, 26 * 4( sp )
|
||||
lw x29, 27 * 4( sp )
|
||||
lw x30, 28 * 4( sp )
|
||||
lw x31, 29 * 4( sp )
|
||||
|
||||
addi sp, sp, 32*4
|
||||
|
||||
mret
|
||||
.endfunc
|
||||
|
||||
.section .highcode.LLE_IRQHandler,"ax",@progbits
|
||||
.align 2
|
||||
.func
|
||||
LLE_IRQHandler:
|
||||
addi sp, sp, -32*4
|
||||
|
||||
sw x1, 1 * 4( sp )
|
||||
sw x4, 2 * 4( sp )
|
||||
sw x5, 3 * 4( sp )
|
||||
sw x6, 4 * 4( sp )
|
||||
sw x7, 5 * 4( sp )
|
||||
sw x8, 6 * 4( sp )
|
||||
sw x9, 7 * 4( sp )
|
||||
sw x10, 8 * 4( sp )
|
||||
sw x11, 9 * 4( sp )
|
||||
sw x12, 10 * 4( sp )
|
||||
sw x13, 11 * 4( sp )
|
||||
sw x14, 12 * 4( sp )
|
||||
sw x15, 13 * 4( sp )
|
||||
sw x16, 14 * 4( sp )
|
||||
sw x17, 15 * 4( sp )
|
||||
sw x18, 16 * 4( sp )
|
||||
sw x19, 17 * 4( sp )
|
||||
sw x20, 18 * 4( sp )
|
||||
sw x21, 19 * 4( sp )
|
||||
sw x22, 20 * 4( sp )
|
||||
sw x23, 21 * 4( sp )
|
||||
sw x24, 22 * 4( sp )
|
||||
sw x25, 23 * 4( sp )
|
||||
sw x26, 24 * 4( sp )
|
||||
sw x27, 25 * 4( sp )
|
||||
sw x28, 26 * 4( sp )
|
||||
sw x29, 27 * 4( sp )
|
||||
sw x30, 28 * 4( sp )
|
||||
sw x31, 29 * 4( sp )
|
||||
|
||||
la a1, g_LLE_IRQLibHandlerLocation
|
||||
lw a0, 0(a1)
|
||||
jalr x1, 0(a0)
|
||||
|
||||
lw x1, 1 * 4( sp )
|
||||
lw x4, 2 * 4( sp )
|
||||
lw x5, 3 * 4( sp )
|
||||
lw x6, 4 * 4( sp )
|
||||
lw x7, 5 * 4( sp )
|
||||
lw x8, 6 * 4( sp )
|
||||
lw x9, 7 * 4( sp )
|
||||
lw x10, 8 * 4( sp )
|
||||
lw x11, 9 * 4( sp )
|
||||
lw x12, 10 * 4( sp )
|
||||
lw x13, 11 * 4( sp )
|
||||
lw x14, 12 * 4( sp )
|
||||
lw x15, 13 * 4( sp )
|
||||
lw x16, 14 * 4( sp )
|
||||
lw x17, 15 * 4( sp )
|
||||
lw x18, 16 * 4( sp )
|
||||
lw x19, 17 * 4( sp )
|
||||
lw x20, 18 * 4( sp )
|
||||
lw x21, 19 * 4( sp )
|
||||
lw x22, 20 * 4( sp )
|
||||
lw x23, 21 * 4( sp )
|
||||
lw x24, 22 * 4( sp )
|
||||
lw x25, 23 * 4( sp )
|
||||
lw x26, 24 * 4( sp )
|
||||
lw x27, 25 * 4( sp )
|
||||
lw x28, 26 * 4( sp )
|
||||
lw x29, 27 * 4( sp )
|
||||
lw x30, 28 * 4( sp )
|
||||
lw x31, 29 * 4( sp )
|
||||
|
||||
addi sp, sp, 32*4
|
||||
|
||||
mret
|
||||
.endfunc
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,589 @@
|
|||
/********************************** (C) COPYRIGHT ******************************
|
||||
* File Name : wchrf.h
|
||||
* Author : WCH
|
||||
* Version : V1.40
|
||||
* Date : 2024/9/27
|
||||
* Description : head file(CH585/CH584)
|
||||
*
|
||||
* Copyright (c) 2023 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef __WCH_RF_H
|
||||
#define __WCH_RF_H
|
||||
|
||||
#include "stdint.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#include "CH58xBLE_LIB.h"
|
||||
|
||||
typedef uint32_t rfRole_States_t;
|
||||
// Define function type that rfRole process callback
|
||||
typedef void (*pfnRfRoleProcess)( rfRole_States_t status, uint8_t id );
|
||||
|
||||
#define RFIP_MODE_BLE 0
|
||||
#define RFIP_MODE_RF_BASIC 1
|
||||
#define RFIP_MODE_RF_FAST 2
|
||||
|
||||
/* RF DMA structure definition */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Status; /* Status */
|
||||
#define STA_DMA_ENABLE 0x80000000
|
||||
#define STA_LEN_MASK 0x00000FFF
|
||||
|
||||
uint32_t BufferSize; /* Buffer lengths */
|
||||
uint32_t BufferAddr; /* address pointer */
|
||||
uint32_t NextDescAddr; /* next descriptor address pointer */
|
||||
} RF_DMADESCTypeDef;
|
||||
|
||||
/* rfRole config structure definition */
|
||||
typedef struct
|
||||
{
|
||||
int8_t TxPower;
|
||||
RF_DMADESCTypeDef *pTx;
|
||||
RF_DMADESCTypeDef *pRx;
|
||||
pfnRfRoleProcess rfProcessCB;
|
||||
uint32_t processMask;
|
||||
#define RF_STATE_RX (1<<0)
|
||||
#define RF_STATE_RBU (1<<1)
|
||||
#define RF_STATE_TIMEOUT (1<<2)
|
||||
#define RF_STATE_RX_CRCERR (1<<3)
|
||||
#define RF_STATE_TX_FINISH (1<<4)
|
||||
#define RF_STATE_TX_IDLE (1<<5)
|
||||
#define RF_STATE_RX_RETRY (1<<6)
|
||||
#define RF_STATE_MAP_UPDATE (1<<7) //!< map update enable
|
||||
} rfRoleConfig_t;
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL MACROS
|
||||
*/
|
||||
#define RF_MAX_DATA_LEN 251
|
||||
|
||||
// defined for properties
|
||||
// whitening off enable
|
||||
#define BB_WHITENING_OFF (1<<0)
|
||||
#define PROP_WAIT_ACK (1<<1)
|
||||
#define BB_WHITENING_CH (1<<2)
|
||||
|
||||
|
||||
/* package type */
|
||||
#define PKT_HEAD_LEN 4
|
||||
#define PKT_ACK_LEN (PKT_HEAD_LEN-2)
|
||||
#define PKT_RESV_LEN PKT_ACK_LEN
|
||||
|
||||
/* device id type */
|
||||
#define RF_ROLE_ID_INVALD (0x07)
|
||||
#define RF_ROLE_ID_MASK (0x07)
|
||||
#define RF_ROLE_BOUND_MAX (0x07)
|
||||
#define RF_ROLE_BOUND_ID RF_ROLE_ID_INVALD
|
||||
#define RF_ROLE_DISCARDED_EN (1<<3)
|
||||
|
||||
#define RF_BOUND_MUTI_MAX 2
|
||||
#define RF_BOUND_4K_MAX 7
|
||||
|
||||
/* 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 BOUND_REQ_TYPE 0x01 //!< 4k mode
|
||||
#define BOUND_FAST_REQ_TYPE 0x02 //!< 8k mode
|
||||
#define BOUND_MUTI_REQ_TYPE 0x04 //!< muti fast mode
|
||||
#define BOUND_LP_REQ_TYPE 0x10 //!< lower power mode
|
||||
|
||||
/* package type */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t type; //!< bit0-2:device id
|
||||
//!< bit3-7:reserved
|
||||
uint8_t length; //!< data length
|
||||
uint8_t seq; //!< reserved
|
||||
uint8_t resv; //!< reserved
|
||||
} rfPackage_t;
|
||||
|
||||
/* rfRole parameter */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t accessAddress; //!< access address,32bit PHY address
|
||||
uint32_t crcInit; //!< crc initial value
|
||||
uint32_t frequency; //!< rf frequency (2400000kHz-2483500kHz)
|
||||
uint32_t properties; //!< bit0: 0-whitening on 1-whitening off
|
||||
//!< bit1: 0- 1-wait ack
|
||||
//!< BIT4-5 00-1M 01-2M
|
||||
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 */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t accessAddress; //!< access address,32bit PHY address
|
||||
uint32_t crcInit; //!< crc initial value
|
||||
uint32_t frequency; //!< rf frequency (2400000kHz-2483500kHz)
|
||||
uint32_t properties; //!< bit0: 0-whitening on 1-whitening off
|
||||
//!< bit1: 0- 1-wait ack
|
||||
//!< bit2: 0- 1-set the channel index of Data whitening
|
||||
//!< BIT4-5 00-1M 01-2M
|
||||
uint32_t txDMA; //!< Tx DMA address
|
||||
uint8_t whiteChannel; //!< white channel(properties bit2 = 1)
|
||||
uint8_t sendTime; //!< Time to switch from Rx t0 Tx (N*0.5us)+24us
|
||||
uint16_t sendCount; //!< resend count
|
||||
} rfipTx_t;
|
||||
|
||||
/* rfip rx parameter */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t accessAddress; //!< access address,32bit PHY address
|
||||
uint32_t crcInit; //!< crc initial value
|
||||
uint32_t frequency; //!< rf frequency (2400000kHz-2483500kHz)
|
||||
uint32_t properties; //!< bit0: 0-whitening on 1-whitening off
|
||||
//!< bit1: 0- 1-send ack
|
||||
//!< BIT4-5 00-1M 01-2M
|
||||
uint32_t rxDMA; //!< Rx DMA address
|
||||
uint8_t whiteChannel; //!< white channel(properties bit2 = 1)
|
||||
uint16_t rxMaxLen; //!< Maximum length of Rx data
|
||||
uint16_t timeOut; //!< Rx wait timeout,0:No timeout others: N*0.5us
|
||||
} rfipRx_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bStatus_t status; //!< Status for the connection
|
||||
/* 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
|
||||
uint8_t periTime; //!< reserved
|
||||
uint8_t hop; //!< Frequency hopping mode
|
||||
uint8_t PeerInfo[6]; //!< Information about the peer device
|
||||
} staBound_t;
|
||||
|
||||
// Define function type that rfRole bound process callback
|
||||
typedef void (*pfnRfRoleBoundCB)( staBound_t * );
|
||||
|
||||
/* Definition of roles */
|
||||
#define RF_ROLE_RX_MOD0 0 //!< host
|
||||
#define RF_ROLE_TX_MOD0 1 //!< device
|
||||
|
||||
/* Definition of frequency hopping mode type */
|
||||
#define RF_HOP_OFF 0 //!< Fixed frequency
|
||||
#define RF_HOP_BLECS2_MODE 1 //!< Frequency Hopping Mode 1 (same as BLE-CS#2)
|
||||
#define RF_HOP_MANUF_MODE 2 //!< Frequency Hopping Mode 2 (Manufacturer-Defined)
|
||||
|
||||
/* DEVICE configuration information */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t devType; //!< the device type, 0:Not specified
|
||||
uint8_t deviceId; //!< the device ID, 7:the ID number is assigned by the host
|
||||
uint8_t calVal; //!< Calibration values
|
||||
uint8_t speed; //!< communication speed(kHz)
|
||||
uint16_t timeout; //!< Connection communication timeout period (in about 1 ms)
|
||||
uint8_t OwnInfo[6]; //!< Local Information
|
||||
uint8_t PeerInfo[6]; //!< Peer information
|
||||
pfnRfRoleBoundCB rfBoundCB;
|
||||
} rfBoundDevice_t;
|
||||
|
||||
/* HOST configuration information */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t hop; //!< Frequency hopping mode
|
||||
int8_t rssi; //!< reserved
|
||||
uint8_t periTime; //!< Fixed value 8
|
||||
uint8_t devType; //!< reserved
|
||||
uint16_t timeout; //!< Connection communication timeout period (in about 1 ms)
|
||||
uint8_t OwnInfo[6]; //!< Local Information
|
||||
uint8_t PeerInfo[6]; //!< resv
|
||||
pfnRfRoleBoundCB rfBoundCB;
|
||||
uint32_t ChannelMap; //!< indicating Used and Unused data channels.Every channel is represented with a
|
||||
//!< bit positioned as per the data channel index,The LSB represents data channel index 0
|
||||
} rfBoundHost_t;
|
||||
|
||||
/* listing information */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t deviceId; //!< The ID number of the list 0-6:Connection 7:binding
|
||||
int8_t rssi; //!< Minimum RSSI threshold for binding, 0 means unlimited (deviceId=7 valid)
|
||||
uint8_t devType; //!< Specify the bound device type, 0 means unlimited (deviceId=7 valid)
|
||||
uint8_t peerInfo[6]; //!< Specify the peer information of the binding, 0 means unlimited (deviceId=7 valid)
|
||||
} rfRoleList_t;
|
||||
|
||||
/* Connection or binding management lists */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t number; //!< Number of lists
|
||||
rfRoleList_t *pList; //!< listing information
|
||||
} rfRoleSpeed_t;
|
||||
|
||||
/* The timing of communication for devices */
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
uint8_t sub1Number;
|
||||
uint8_t sub2Number;
|
||||
uint16_t subInterval[16]; //!< 0.5us
|
||||
} rfDevsTimeing_t;
|
||||
|
||||
/* bound frequency lists */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t number; //!< Number of lists
|
||||
uint32_t *pFrequency; //!< listing information
|
||||
} rfHostBoundFre_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* PUBLIC FUNCTIONS
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief read rssi
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return the value of rssi.
|
||||
*/
|
||||
int8_t RFIP_ReadRssi( void );
|
||||
|
||||
/**
|
||||
* @brief read crc state
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return the value of crc state.
|
||||
*/
|
||||
uint8_t RFIP_ReadCrc( uint8_t *pBuf );
|
||||
|
||||
/**
|
||||
* @brief set output power level@ TxPower
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return the value of crc state.
|
||||
*/
|
||||
void RFIP_SetTxPower( uint8_t val );
|
||||
|
||||
/**
|
||||
* @brief rf calibration
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void RFIP_Calibration( void );
|
||||
|
||||
/**
|
||||
* @brief reinitialize the rfip register after sleep wake-up
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @param pConf - rfRole config
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFRole_FastInit( rfRoleConfig_t *pConf );
|
||||
|
||||
/**
|
||||
* @brief used to stop TX/RX
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFRole_Stop( void );
|
||||
|
||||
/**
|
||||
* @brief used to power off rf
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFRole_Shut(void );
|
||||
|
||||
/**
|
||||
* @brief used to set rf-role parameter
|
||||
*
|
||||
* @param pParam- rfRole parameter
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFRole_SetParam( rfRoleParam_t *pParam );
|
||||
|
||||
/**
|
||||
* @brief set Connection or binding management lists
|
||||
*
|
||||
* @param pList_t - management lists(global variable)
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFBound_SetSpeedType( rfRoleSpeed_t *pList_t );
|
||||
|
||||
/**
|
||||
* @brief the list of communication frequencies for binding purposes
|
||||
*
|
||||
* @param pList_t - the list of binding frequencies lists(global)
|
||||
*
|
||||
* @return 0-success.
|
||||
*
|
||||
* note: The host mode polls the configured frequency at a 1ms cycle.
|
||||
* The device mode polls the configured frequency at an 8ms cycle.
|
||||
*
|
||||
*/
|
||||
bStatus_t RFBound_SetFrequencyList( rfHostBoundFre_t *pList_t );
|
||||
|
||||
/**
|
||||
* @brief set speed of devices(muti fast mode)
|
||||
*
|
||||
* @param pList -
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFRole_SetDevTimeing( rfDevsTimeing_t *pList );
|
||||
|
||||
/**
|
||||
* @brief Start sending
|
||||
*
|
||||
* note: If sending is currently in progress, wait until the previous data packets have been sent before sending.
|
||||
*
|
||||
* @param pList -
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
void RFRole_StartLpTx( void );
|
||||
|
||||
/**
|
||||
* @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(lower power)
|
||||
*
|
||||
* @param pConfig - host configuration information
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFBound_StartLpHost( rfBoundHost_t *pConfig );
|
||||
|
||||
/**
|
||||
* @brief start host mode(muti fast)
|
||||
*
|
||||
* @param pConfig - host configuration information
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFBound_StartMutiHost( rfBoundHost_t *pConfig );
|
||||
|
||||
/**
|
||||
* @brief start host mode(8k)
|
||||
*
|
||||
* @param pConfig - host configuration information
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFBound_Start8kHost( rfBoundHost_t *pConfig );
|
||||
|
||||
/**
|
||||
* @brief start host mode(4k)
|
||||
*
|
||||
* @param pConfig - host configuration information
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFBound_StartHost( rfBoundHost_t *pConfig );
|
||||
|
||||
/**
|
||||
* @brief start device mode(lower power)
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFBound_StartLpDevice( rfBoundDevice_t *pConfig );
|
||||
|
||||
/**
|
||||
* @brief start device mode(muti fast)
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFBound_StartMutiDevice( rfBoundDevice_t *pConfig );
|
||||
|
||||
/**
|
||||
* @brief start device mode(8k)
|
||||
*
|
||||
* @param pConfig - device configuration information
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFBound_Start8kDevice( rfBoundDevice_t *pConfig );
|
||||
|
||||
/**
|
||||
* @brief start device mode(4k)
|
||||
*
|
||||
* @param pConfig - device configuration information
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFBound_StartDevice( rfBoundDevice_t *pConfig );
|
||||
|
||||
/**
|
||||
* @brief clear data list
|
||||
*
|
||||
* @param dev_id
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFRole_ClearTxData( uint8_t dev_id );
|
||||
|
||||
/**
|
||||
* @brief switch rf mode,must idle status.
|
||||
*
|
||||
* @param mode - 0:BLE 1:RF basic 2:RF fast
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFRole_SwitchMode( uint8_t mode );
|
||||
|
||||
/**
|
||||
* @brief channel map detection and start map update
|
||||
*
|
||||
* note: only the host role can be called
|
||||
* lower power mode and 8k mode support
|
||||
*
|
||||
* @param rssi -
|
||||
* @param id -
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
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(4k&8k)
|
||||
*
|
||||
* @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.
|
||||
* 4k mode and 8k mode support
|
||||
*
|
||||
* @param phy - 0:1M 1:2M
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFRole_PHYUpdate( uint8_t dev_id, uint8_t phy );
|
||||
|
||||
/**
|
||||
* @brief get status.
|
||||
*
|
||||
* note: supported in version 1.4 and above.
|
||||
*
|
||||
* @param id -
|
||||
*
|
||||
* @return 0-idle others-busy.
|
||||
*/
|
||||
uint32_t RFRole_GetStatus( uint8_t id );
|
||||
|
||||
/**
|
||||
* @brief library-basic initial
|
||||
*
|
||||
* @param pConf - rfRole config
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFRole_BasicInit( rfRoleConfig_t *pConf );
|
||||
|
||||
/**
|
||||
* @brief set tx delay time
|
||||
*
|
||||
* @param us - delay n*us
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFIP_SetTxDelayTime( uint16_t us );
|
||||
|
||||
/**
|
||||
* @brief tx start
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFIP_SetTxStart( void );
|
||||
|
||||
/**
|
||||
* @brief set tx parameter
|
||||
*
|
||||
* @param pParm - rfip tx parameter
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFIP_SetTxParm( rfipTx_t *pParm );
|
||||
|
||||
/**
|
||||
* @brief set rx parameter and start rx
|
||||
*
|
||||
* @param pParm - rfip rx parameter
|
||||
*
|
||||
* @return 0-success.
|
||||
*/
|
||||
bStatus_t RFIP_SetRx( rfipRx_t *pParm );
|
||||
|
||||
/*
|
||||
* END @ API
|
||||
*/
|
||||
/******************************************************************************/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -26,7 +26,7 @@ void PWR_DCDCCfg(FunctionalState s)
|
|||
uint16_t adj = R16_AUX_POWER_ADJ;
|
||||
uint16_t plan = R16_POWER_PLAN;
|
||||
|
||||
if(s == DISABLE)
|
||||
if (s == DISABLE)
|
||||
{
|
||||
|
||||
adj &= ~RB_DCDC_CHARGE;
|
||||
|
|
@ -40,7 +40,7 @@ void PWR_DCDCCfg(FunctionalState s)
|
|||
{
|
||||
uint32_t HW_Data[2];
|
||||
FLASH_EEPROM_CMD(CMD_GET_ROM_INFO, ROM_CFG_ADR_HW, HW_Data, 0);
|
||||
if((HW_Data[0]) & (1 << 13))
|
||||
if ((HW_Data[0]) & (1 << 13))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -71,11 +71,11 @@ void PWR_UnitModCfg(FunctionalState s, uint8_t unit)
|
|||
{
|
||||
uint8_t ck32k_cfg = R8_CK32K_CONFIG;
|
||||
|
||||
if(s == DISABLE) //关闭
|
||||
if (s == DISABLE) // 关闭
|
||||
{
|
||||
ck32k_cfg &= ~(unit & 0x03);
|
||||
}
|
||||
else //打开
|
||||
else // 打开
|
||||
{
|
||||
ck32k_cfg |= (unit & 0x03);
|
||||
}
|
||||
|
|
@ -99,7 +99,7 @@ void PWR_SafeClkCfg(FunctionalState s, uint16_t perph)
|
|||
{
|
||||
uint32_t sleep_ctrl = R8_SAFE_CLK_CTRL;
|
||||
|
||||
if(s == DISABLE)
|
||||
if (s == DISABLE)
|
||||
{
|
||||
sleep_ctrl |= perph;
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ void PWR_PeriphClkCfg(FunctionalState s, uint16_t perph)
|
|||
{
|
||||
uint32_t sleep_ctrl = R32_SLEEP_CONTROL;
|
||||
|
||||
if(s == DISABLE)
|
||||
if (s == DISABLE)
|
||||
{
|
||||
sleep_ctrl |= perph;
|
||||
}
|
||||
|
|
@ -162,7 +162,7 @@ void PWR_PeriphWakeUpCfg(FunctionalState s, uint8_t perph, WakeUP_ModeypeDef mod
|
|||
{
|
||||
uint8_t m;
|
||||
|
||||
if(s == DISABLE)
|
||||
if (s == DISABLE)
|
||||
{
|
||||
sys_safe_access_enable();
|
||||
R8_SLP_WAKE_CTRL &= ~perph;
|
||||
|
|
@ -170,19 +170,19 @@ void PWR_PeriphWakeUpCfg(FunctionalState s, uint8_t perph, WakeUP_ModeypeDef mod
|
|||
}
|
||||
else
|
||||
{
|
||||
switch(mode)
|
||||
switch (mode)
|
||||
{
|
||||
case Short_Delay:
|
||||
m = 0x01;
|
||||
break;
|
||||
case Short_Delay:
|
||||
m = 0x01;
|
||||
break;
|
||||
|
||||
case Long_Delay:
|
||||
m = 0x00;
|
||||
break;
|
||||
case Long_Delay:
|
||||
m = 0x00;
|
||||
break;
|
||||
|
||||
default:
|
||||
m = 0x01;
|
||||
break;
|
||||
default:
|
||||
m = 0x01;
|
||||
break;
|
||||
}
|
||||
|
||||
sys_safe_access_enable();
|
||||
|
|
@ -212,7 +212,7 @@ void PowerMonitor(FunctionalState s, VolM_LevelypeDef vl)
|
|||
uint8_t ctrl = R8_BAT_DET_CTRL;
|
||||
uint8_t cfg = R8_BAT_DET_CFG;
|
||||
|
||||
if(s == DISABLE)
|
||||
if (s == DISABLE)
|
||||
{
|
||||
sys_safe_access_enable();
|
||||
R8_BAT_DET_CTRL = 0;
|
||||
|
|
@ -220,7 +220,7 @@ void PowerMonitor(FunctionalState s, VolM_LevelypeDef vl)
|
|||
}
|
||||
else
|
||||
{
|
||||
if(vl & 0x80)
|
||||
if (vl & 0x80)
|
||||
{
|
||||
cfg = vl & 0x03;
|
||||
ctrl = RB_BAT_MON_EN | ((vl >> 2) & 1);
|
||||
|
|
@ -256,7 +256,7 @@ __HIGH_CODE
|
|||
void LowPower_Idle(void)
|
||||
{
|
||||
FLASH_ROM_SW_RESET();
|
||||
R8_FLASH_CTRL = 0x04; //flash关闭
|
||||
R8_FLASH_CTRL = 0x04; // flash关闭
|
||||
|
||||
PFIC->SCTLR &= ~(1 << 2); // sleep
|
||||
__WFI();
|
||||
|
|
@ -279,15 +279,15 @@ void LowPower_Halt(void)
|
|||
uint32_t i;
|
||||
uint8_t x32Mpw;
|
||||
uint16_t clk_sys_cfg;
|
||||
uint8_t flash_cfg,flash_sck;
|
||||
uint8_t flash_cfg, flash_sck;
|
||||
|
||||
clk_sys_cfg = R16_CLK_SYS_CFG;
|
||||
flash_cfg = R8_FLASH_CFG;
|
||||
flash_sck = R8_FLASH_SCK;
|
||||
FLASH_ROM_SW_RESET();
|
||||
R8_FLASH_CTRL = 0x04; //flash关闭
|
||||
R8_FLASH_CTRL = 0x04; // flash关闭
|
||||
x32Mpw = R8_XT32M_TUNE;
|
||||
if(!(R8_HFCK_PWR_CTRL&RB_CLK_XT32M_KEEP))
|
||||
if (!(R8_HFCK_PWR_CTRL & RB_CLK_XT32M_KEEP))
|
||||
{
|
||||
x32Mpw = (x32Mpw & 0xfc) | 0x03; // 150%额定电流
|
||||
}
|
||||
|
|
@ -298,43 +298,43 @@ void LowPower_Halt(void)
|
|||
sys_safe_access_enable();
|
||||
R8_XT32M_TUNE = x32Mpw;
|
||||
sys_safe_access_disable();
|
||||
// sys_safe_access_enable();
|
||||
// R8_PLL_CONFIG |= (1 << 5);
|
||||
// sys_safe_access_disable();
|
||||
// sys_safe_access_enable();
|
||||
// R8_PLL_CONFIG |= (1 << 5);
|
||||
// sys_safe_access_disable();
|
||||
|
||||
if(R16_CLK_SYS_CFG & RB_OSC32M_SEL) //使用外部32M
|
||||
if (R16_CLK_SYS_CFG & RB_OSC32M_SEL) // 使用外部32M
|
||||
{
|
||||
sys_safe_access_enable();
|
||||
R8_SLP_POWER_CTRL &= ~(RB_WAKE_DLY_MOD);
|
||||
R8_SLP_POWER_CTRL |= 0x01;
|
||||
R8_FLASH_CFG = 0X57;
|
||||
R8_FLASH_SCK = R8_FLASH_SCK & (~(1<<4));
|
||||
R8_FLASH_SCK = R8_FLASH_SCK & (~(1 << 4));
|
||||
R16_CLK_SYS_CFG = CLK_SOURCE_HSE_4MHz;
|
||||
sys_safe_access_disable();
|
||||
}
|
||||
else//使用内部16M
|
||||
else // 使用内部16M
|
||||
{
|
||||
sys_safe_access_enable();
|
||||
R8_SLP_POWER_CTRL &= ~(RB_WAKE_DLY_MOD);
|
||||
R8_SLP_POWER_CTRL |= 0x01;
|
||||
R8_FLASH_CFG = 0X57;
|
||||
R8_FLASH_SCK = R8_FLASH_SCK & (~(1<<4));
|
||||
R16_CLK_SYS_CFG = CLK_SOURCE_HSI_4MHz;
|
||||
sys_safe_access_disable();
|
||||
sys_safe_access_enable();
|
||||
R8_SLP_POWER_CTRL &= ~(RB_WAKE_DLY_MOD);
|
||||
R8_SLP_POWER_CTRL |= 0x01;
|
||||
R8_FLASH_CFG = 0X57;
|
||||
R8_FLASH_SCK = R8_FLASH_SCK & (~(1 << 4));
|
||||
R16_CLK_SYS_CFG = CLK_SOURCE_HSI_4MHz;
|
||||
sys_safe_access_disable();
|
||||
}
|
||||
|
||||
PFIC->SCTLR |= (1 << 2); //deep sleep
|
||||
PFIC->SCTLR |= (1 << 2); // deep sleep
|
||||
__WFI();
|
||||
__nop();
|
||||
__nop();
|
||||
|
||||
if((!(clk_sys_cfg & RB_OSC32M_SEL)) && (clk_sys_cfg & 0x100)) //使用内部16M
|
||||
if ((!(clk_sys_cfg & RB_OSC32M_SEL)) && (clk_sys_cfg & 0x100)) // 使用内部16M
|
||||
{
|
||||
i = 40;
|
||||
do
|
||||
{
|
||||
__nop();
|
||||
}while(--i);
|
||||
i = 40;
|
||||
do
|
||||
{
|
||||
__nop();
|
||||
} while (--i);
|
||||
}
|
||||
|
||||
sys_safe_access_enable();
|
||||
|
|
@ -343,9 +343,9 @@ void LowPower_Halt(void)
|
|||
R16_CLK_SYS_CFG = clk_sys_cfg;
|
||||
sys_safe_access_disable();
|
||||
|
||||
// sys_safe_access_enable();
|
||||
// R8_PLL_CONFIG &= ~(1 << 5);
|
||||
// sys_safe_access_disable();
|
||||
// sys_safe_access_enable();
|
||||
// R8_PLL_CONFIG &= ~(1 << 5);
|
||||
// sys_safe_access_disable();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
|
|
@ -366,7 +366,7 @@ void LowPower_Sleep(uint16_t rm)
|
|||
uint16_t power_plan;
|
||||
uint16_t clk_sys_cfg;
|
||||
uint16_t hfck_pwr_ctrl;
|
||||
uint8_t flash_cfg,flash_sck;
|
||||
uint8_t flash_cfg, flash_sck;
|
||||
uint32_t i;
|
||||
|
||||
clk_sys_cfg = R16_CLK_SYS_CFG;
|
||||
|
|
@ -383,57 +383,57 @@ void LowPower_Sleep(uint16_t rm)
|
|||
R8_XT32M_TUNE = x32Mpw;
|
||||
sys_safe_access_disable();
|
||||
|
||||
PFIC->SCTLR |= (1 << 2); //deep sleep
|
||||
PFIC->SCTLR |= (1 << 2); // deep sleep
|
||||
|
||||
power_plan = R16_POWER_PLAN & (RB_PWR_DCDC_EN | RB_PWR_DCDC_PRE);
|
||||
power_plan |= RB_PWR_PLAN_EN | RB_PWR_CORE | rm | (2<<11);
|
||||
if(chip_info&0x800000)
|
||||
power_plan |= RB_PWR_PLAN_EN | RB_PWR_CORE | rm | (2 << 11);
|
||||
if (chip_info & 0x800000)
|
||||
{
|
||||
power_plan &= ~RB_XT_PRE_EN; //不支持RB_XT_PRE_EN功能
|
||||
power_plan &= ~RB_XT_PRE_EN; // 不支持RB_XT_PRE_EN功能
|
||||
}
|
||||
|
||||
sys_safe_access_enable();
|
||||
R16_POWER_PLAN = power_plan;
|
||||
R8_HFCK_PWR_CTRL |= RB_CLK_RC16M_PON; //睡眠需要打开内部HSI
|
||||
R8_HFCK_PWR_CTRL |= RB_CLK_RC16M_PON; // 睡眠需要打开内部HSI
|
||||
sys_safe_access_disable();
|
||||
if(R16_CLK_SYS_CFG & RB_OSC32M_SEL) //使用外部32M
|
||||
if (R16_CLK_SYS_CFG & RB_OSC32M_SEL) // 使用外部32M
|
||||
{
|
||||
sys_safe_access_enable();
|
||||
R8_SLP_POWER_CTRL &= ~(RB_WAKE_DLY_MOD);
|
||||
R8_SLP_POWER_CTRL |= 0x01;
|
||||
R8_FLASH_CFG = 0X57;
|
||||
R8_FLASH_SCK = R8_FLASH_SCK & (~(1<<4));
|
||||
R8_FLASH_SCK = R8_FLASH_SCK & (~(1 << 4));
|
||||
R16_CLK_SYS_CFG = CLK_SOURCE_HSE_4MHz;
|
||||
sys_safe_access_disable();
|
||||
}
|
||||
else//使用内部16M
|
||||
else // 使用内部16M
|
||||
{
|
||||
sys_safe_access_enable();
|
||||
R8_SLP_POWER_CTRL &= ~(RB_WAKE_DLY_MOD);
|
||||
R8_SLP_POWER_CTRL |= 0x01;
|
||||
R8_FLASH_CFG = 0X57;
|
||||
R8_FLASH_SCK = R8_FLASH_SCK & (~(1<<4));
|
||||
R16_CLK_SYS_CFG = CLK_SOURCE_HSI_4MHz;
|
||||
sys_safe_access_disable();
|
||||
sys_safe_access_enable();
|
||||
R8_SLP_POWER_CTRL &= ~(RB_WAKE_DLY_MOD);
|
||||
R8_SLP_POWER_CTRL |= 0x01;
|
||||
R8_FLASH_CFG = 0X57;
|
||||
R8_FLASH_SCK = R8_FLASH_SCK & (~(1 << 4));
|
||||
R16_CLK_SYS_CFG = CLK_SOURCE_HSI_4MHz;
|
||||
sys_safe_access_disable();
|
||||
}
|
||||
|
||||
__WFI();
|
||||
__nop();
|
||||
__nop();
|
||||
|
||||
if(rm & RB_PWR_EXTEND)
|
||||
if (rm & RB_PWR_EXTEND)
|
||||
{
|
||||
// 注意:如果使用了高速USB,且睡眠使能RB_PWR_EXTEND,唤醒后需要将所有高速USB寄存器复位
|
||||
R32_U2H_BC_CTRL = 0;
|
||||
(*((PUINT32V)0x4000C254)) = 0;
|
||||
}
|
||||
if((!(clk_sys_cfg & RB_OSC32M_SEL)) && (clk_sys_cfg & 0x100)) //使用内部16M
|
||||
if ((!(clk_sys_cfg & RB_OSC32M_SEL)) && (clk_sys_cfg & 0x100)) // 使用内部16M
|
||||
{
|
||||
i = 40;
|
||||
do
|
||||
{
|
||||
__nop();
|
||||
}while(--i);
|
||||
i = 40;
|
||||
do
|
||||
{
|
||||
__nop();
|
||||
} while (--i);
|
||||
}
|
||||
|
||||
sys_safe_access_enable();
|
||||
|
|
@ -446,7 +446,7 @@ void LowPower_Sleep(uint16_t rm)
|
|||
R16_POWER_PLAN &= ~RB_PWR_PLAN_EN;
|
||||
sys_safe_access_disable();
|
||||
|
||||
// DelayUs(300); //如果退出函数后运行flash代码,则需要延时300us后退出
|
||||
// DelayUs(300); //如果退出函数后运行flash代码,则需要延时300us后退出
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
|
@ -480,7 +480,7 @@ void LowPower_Shutdown(uint16_t rm)
|
|||
R8_XT32K_TUNE = x32Kpw;
|
||||
sys_safe_access_disable();
|
||||
|
||||
PFIC->SCTLR |= (1 << 2); //deep sleep
|
||||
PFIC->SCTLR |= (1 << 2); // deep sleep
|
||||
|
||||
sys_safe_access_enable();
|
||||
R8_SLP_POWER_CTRL |= 0x40;
|
||||
|
|
@ -513,9 +513,9 @@ void LowPower_Halt_WFE(void)
|
|||
uint8_t x32Mpw;
|
||||
|
||||
FLASH_ROM_SW_RESET();
|
||||
R8_FLASH_CTRL = 0x04; //flash关闭
|
||||
R8_FLASH_CTRL = 0x04; // flash关闭
|
||||
x32Mpw = R8_XT32M_TUNE;
|
||||
if(!(R8_HFCK_PWR_CTRL&RB_CLK_XT32M_KEEP))
|
||||
if (!(R8_HFCK_PWR_CTRL & RB_CLK_XT32M_KEEP))
|
||||
{
|
||||
x32Mpw = (x32Mpw & 0xfc) | 0x03; // 150%额定电流
|
||||
}
|
||||
|
|
@ -531,15 +531,14 @@ void LowPower_Halt_WFE(void)
|
|||
R8_SLP_POWER_CTRL &= ~(RB_WAKE_DLY_MOD);
|
||||
R8_SLP_POWER_CTRL |= 0x01;
|
||||
R8_FLASH_CFG = 0X57;
|
||||
R8_FLASH_SCK = R8_FLASH_SCK & (~(1<<4));
|
||||
R8_FLASH_SCK = R8_FLASH_SCK & (~(1 << 4));
|
||||
R16_CLK_SYS_CFG = CLK_SOURCE_HSI_4MHz;
|
||||
sys_safe_access_disable();
|
||||
|
||||
PFIC->SCTLR |= (1 << 2); //deep sleep
|
||||
PFIC->SCTLR |= (1 << 2); // deep sleep
|
||||
__WFE();
|
||||
__nop();
|
||||
__nop();
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
|
|
@ -562,21 +561,21 @@ void LowPower_Sleep_WFE(uint16_t rm)
|
|||
R8_BAT_DET_CTRL = 0; // 关闭电压监控
|
||||
sys_safe_access_disable();
|
||||
|
||||
PFIC->SCTLR |= (1 << 2); //deep sleep
|
||||
PFIC->SCTLR |= (1 << 2); // deep sleep
|
||||
power_plan = R16_POWER_PLAN & (RB_PWR_DCDC_EN | RB_PWR_DCDC_PRE);
|
||||
power_plan |= RB_PWR_PLAN_EN | RB_PWR_CORE | rm | (2<<11);
|
||||
power_plan &= ~0x4000; //不支持RB_XT_PRE_EN功能
|
||||
power_plan |= RB_PWR_PLAN_EN | RB_PWR_CORE | rm | (2 << 11);
|
||||
power_plan &= ~0x4000; // 不支持RB_XT_PRE_EN功能
|
||||
|
||||
sys_safe_access_enable();
|
||||
R16_POWER_PLAN = power_plan;
|
||||
R8_HFCK_PWR_CTRL |= RB_CLK_RC16M_PON; //睡眠需要打开内部HSI
|
||||
R8_HFCK_PWR_CTRL |= RB_CLK_RC16M_PON; // 睡眠需要打开内部HSI
|
||||
sys_safe_access_disable();
|
||||
|
||||
sys_safe_access_enable();
|
||||
R8_SLP_POWER_CTRL &= ~(RB_WAKE_DLY_MOD);
|
||||
R8_SLP_POWER_CTRL |= 0x01;
|
||||
R8_FLASH_CFG = 0X57;
|
||||
R8_FLASH_SCK = R8_FLASH_SCK & (~(1<<4));
|
||||
R8_FLASH_SCK = R8_FLASH_SCK & (~(1 << 4));
|
||||
R16_CLK_SYS_CFG = CLK_SOURCE_HSI_4MHz;
|
||||
sys_safe_access_disable();
|
||||
|
||||
|
|
@ -584,7 +583,7 @@ void LowPower_Sleep_WFE(uint16_t rm)
|
|||
__nop();
|
||||
__nop();
|
||||
|
||||
if(rm & RB_PWR_EXTEND)
|
||||
if (rm & RB_PWR_EXTEND)
|
||||
{
|
||||
// 注意:如果使用了高速USB,且睡眠使能RB_PWR_EXTEND,唤醒后需要将所有高速USB寄存器复位
|
||||
R32_U2H_BC_CTRL = 0;
|
||||
|
|
@ -595,6 +594,5 @@ void LowPower_Sleep_WFE(uint16_t rm)
|
|||
R16_POWER_PLAN &= ~RB_PWR_PLAN_EN;
|
||||
sys_safe_access_disable();
|
||||
|
||||
// DelayUs(100); //如果退出函数后运行flash代码,则需要延时100us后退出
|
||||
// DelayUs(100); //如果退出函数后运行flash代码,则需要延时100us后退出
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue