This commit is contained in:
许晟昊 2026-02-27 11:03:47 +08:00
parent 62321b1294
commit 1c31a9f6dd
27 changed files with 36354 additions and 332 deletions

View File

@ -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 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"> <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="DEBUG=0"/>
<listOptionValue builtIn="false" value="HAL_SLEEP=1"/>
</option> </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.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"> <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="&quot;${workspace_loc:/${ProjName}/FreeRTOS}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/FreeRTOS}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/system/RVMSIS}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/system/RVMSIS}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/system/StdPeriphDriver/inc}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/system/StdPeriphDriver/inc}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/system/HAL/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/system/LIB}&quot;"/>
</option> </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.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"/> <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 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"> <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="ISP585"/>
<listOptionValue builtIn="false" value="CH58xBLE"/>
</option> </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"> <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="../"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/system/StdPeriphDriver}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/system/StdPeriphDriver}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/system/LIB}&quot;"/>
</option> </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"> <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"/> <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 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"> <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="ISP585"/>
<listOptionValue builtIn="false" value="CH58xBLE"/>
</option> </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"> <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="../"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/system/StdPeriphDriver}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/system/StdPeriphDriver}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/system/LIB}&quot;"/>
</option> </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"> <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"/> <listOptionValue builtIn="false" value="--print-memory-usage"/>

View File

@ -131,7 +131,8 @@
"do_not_search_system_directories": false, "do_not_search_system_directories": false,
"preprocess_only": false, "preprocess_only": false,
"defined_symbols": [ "defined_symbols": [
"DEBUG=0" "DEBUG=0",
"HAL_SLEEP=1"
], ],
"undefined_symbols": [] "undefined_symbols": []
}, },
@ -144,7 +145,9 @@
"${project}/FreeRTOS/include", "${project}/FreeRTOS/include",
"${project}/FreeRTOS", "${project}/FreeRTOS",
"${project}/system/RVMSIS", "${project}/system/RVMSIS",
"${project}/system/StdPeriphDriver/inc" "${project}/system/StdPeriphDriver/inc",
"${project}/system/HAL/include",
"${project}/system/LIB"
], ],
"include_system_paths": [], "include_system_paths": [],
"include_files": [] "include_files": []
@ -219,11 +222,13 @@
}, },
"libraries": { "libraries": {
"libraries": [ "libraries": [
"ISP585" "ISP585",
"CH58xBLE"
], ],
"library_search_path": [ "library_search_path": [
"../", "../",
"${project}/system/StdPeriphDriver" "${project}/system/StdPeriphDriver",
"${project}/system/LIB"
] ]
}, },
"miscellaneous": { "miscellaneous": {
@ -260,11 +265,13 @@
}, },
"libraries": { "libraries": {
"libraries": [ "libraries": [
"ISP585" "ISP585",
"CH58xBLE"
], ],
"library_search_path": [ "library_search_path": [
"../", "../",
"${project}/system/StdPeriphDriver" "${project}/system/StdPeriphDriver",
"${project}/system/LIB"
] ]
}, },
"miscellaneous": { "miscellaneous": {

View File

@ -92,7 +92,7 @@
#define configUSE_PREEMPTION 1 #define configUSE_PREEMPTION 1
#define configUSE_TIME_SLICING 0 #define configUSE_TIME_SLICING 0
#define configUSE_IDLE_HOOK 0 #define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 0 #define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ FREQ_SYS #define configCPU_CLOCK_HZ FREQ_SYS
#define configTICK_RATE_HZ ((TickType_t)500) #define configTICK_RATE_HZ ((TickType_t)500)

View File

@ -3,55 +3,27 @@
* Author : WCH * Author : WCH
* Version : V1.0 * Version : V1.0
* Date : 2024/08/13 * Date : 2024/08/13
* Description : FreeRTOS例程使使 * Description : FreeRTOS仅保留任务1
* __attribute__((interrupt("WCH-Interrupt-fast")))
* 使HIGHCODE修饰即可
********************************************************************************* *********************************************************************************
* Copyright (c) 2024 Nanjing Qinheng Microelectronics Co., Ltd. * 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 "CH58x_common.h"
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "task.h" #include "task.h"
#include "semphr.h" #include "semphr.h"
#include "stdarg.h"
/*********************************************************************
* GLOBAL TYPEDEFS
*/
/************************** 任务配置 **************************/
#define TASK1_TASK_PRIO 5 #define TASK1_TASK_PRIO 5
#define TASK1_STK_SIZE 256 /* 因在任务中使用了APP_Printf所以栈空间必须要大于APP_Printf中的buf_str的大小+configMINIMAL_STACK_SIZE */ #define TASK1_STK_SIZE 256
#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
/* Global Variable */ /************************** 全局变量 **************************/
TaskHandle_t Task1Task_Handler; 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 * @fn DebugInit
* * @brief
* @brief ********************************************************************/
*
* @return none
*/
void DebugInit(void) void DebugInit(void)
{ {
GPIOA_SetBits(GPIO_Pin_14); GPIOA_SetBits(GPIO_Pin_14);
@ -61,218 +33,63 @@ void DebugInit(void)
} }
/********************************************************************* /*********************************************************************
* @fn vPortSuppressTicksAndSleep * @fn CH585_EnterSleep
* * @brief CH585进入浅休眠API
* @brief FreeRTOS Tickless Idle回调函数 ********************************************************************/
*
*
* @param xExpectedIdleTime - tick为单位
*
* @return none
*/
__HIGH_CODE __HIGH_CODE
void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime) void CH585_EnterSleep(void)
{ {
uint32_t ulCompleteTickPeriods;
/* 限制最短睡眠时间,避免频繁唤醒 */
if (xExpectedIdleTime < 2)
{
return;
}
/* Idle模式功耗约1.44mA,所有外设正常运行,快速响应 */
LowPower_Idle(); LowPower_Idle();
/* 计算实际睡眠的tick数 */ // LowPower_Halt();
ulCompleteTickPeriods = xExpectedIdleTime - 1; // HSECFG_Current(HSE_RCur_100); // 降为额定电流(低功耗函数中提升了HSE偏置电流)
/* 更新系统时间 */
vTaskStepTick(ulCompleteTickPeriods);
} }
/*********************************************************************
* @fn LowPowerGapProcess
*
* @brief flash未准备好RAM中运行
*
* @return none
*/
__HIGH_CODE __HIGH_CODE
void LowPowerGapProcess() void vApplicationIdleHook(void)
{ {
// 执行对时钟要求不高的处理 // 空函数,兼容原框架
CH585_EnterSleep();
// 可以简单的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);
} }
/********************************************************************* /*********************************************************************
* @fn task1_task * @fn task1_task
* * @brief 1LED翻转
* @brief task1 program. ********************************************************************/
*
* @param *pvParameters - Parameters point of task1
*
* @return none
*/
__HIGH_CODE __HIGH_CODE
void task1_task(void *pvParameters) void task1_task(void *pvParameters)
{ {
// 初始化GPIOA_Pin_0为输出LED控制
GPIOA_ModeCfg(GPIO_Pin_0, GPIO_ModeOut_PP_5mA); GPIOA_ModeCfg(GPIO_Pin_0, GPIO_ModeOut_PP_5mA);
while (1) while (1)
{ {
GPIOA_SetBits(GPIO_Pin_0); // 打开IO高电平 GPIOA_SetBits(GPIO_Pin_0); // IO置高LED亮
vTaskDelay(configTICK_RATE_HZ); vTaskDelay(configTICK_RATE_HZ); // 延时1秒期间系统休眠
GPIOA_ResetBits(GPIO_Pin_0); // 关闭IO低电平 GPIOA_ResetBits(GPIO_Pin_0); // IO置低LED灭
vTaskDelay(configTICK_RATE_HZ / 2); vTaskDelay(configTICK_RATE_HZ / 2); // 延时0.5秒,期间系统休眠
}
}
/*********************************************************************
* @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");
} }
} }
/********************************************************************* /*********************************************************************
* @fn main * @fn main
* * @brief +1+
* @brief main function. ********************************************************************/
*
* @param none
*
* @return none
*/
int main(void) int main(void)
{ {
#if (defined(DCDC_ENABLE)) && (DCDC_ENABLE == TRUE) // 系统初始化
PWR_DCDCCfg(ENABLE);
#endif
HSECFG_Capacitance(HSECap_18p); HSECFG_Capacitance(HSECap_18p);
SetSysClock(SYSCLK_FREQ); SetSysClock(SYSCLK_FREQ);
PWR_DCDCCfg(ENABLE);
/* 注意不能配置GPIO_Pin_All会影响SWD调试引脚PA13/PA14导致无法调试和系统异常 */ GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU);
/* 只配置需要的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);
GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU); GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU);
#ifdef DEBUG #ifdef DEBUG
DebugInit(); DebugInit(); // 调试时开启串口,发布可注释
#endif #endif
PRINT("start.\n"); // 创建任务1唯一任务
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);
xTaskCreate((TaskFunction_t)task1_task, xTaskCreate((TaskFunction_t)task1_task,
(const char *)"task1", (const char *)"task1",
(uint16_t)TASK1_STK_SIZE, (uint16_t)TASK1_STK_SIZE,
@ -280,35 +97,14 @@ int main(void)
(UBaseType_t)TASK1_TASK_PRIO, (UBaseType_t)TASK1_TASK_PRIO,
(TaskHandle_t *)&Task1Task_Handler); (TaskHandle_t *)&Task1Task_Handler);
// 启动FreeRTOS调度器
vTaskStartScheduler(); vTaskStartScheduler();
// 调度器启动失败则死循环
while (1) 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 ******************************/ /******************************** endfile @ main ******************************/

View File

@ -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
}

24
system/HAL/.vscode/launch.json vendored Normal file
View File

@ -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
}
]
}
]
}

59
system/HAL/.vscode/settings.json vendored Normal file
View File

@ -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
}

137
system/HAL/KEY.c Normal file
View File

@ -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 ******************************/

361
system/HAL/LED.c Normal file
View File

@ -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 ******************************/

302
system/HAL/MCU.c Normal file
View File

@ -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 ******************************/

205
system/HAL/RTC.c Normal file
View File

@ -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 ******************************/

149
system/HAL/SLEEP.c Normal file
View File

@ -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
}

151
system/HAL/include/CONFIG.h Normal file
View File

@ -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

80
system/HAL/include/HAL.h Normal file
View File

@ -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

112
system/HAL/include/KEY.h Normal file
View File

@ -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

134
system/HAL/include/LED.h Normal file
View File

@ -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

60
system/HAL/include/RTC.h Normal file
View File

@ -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

View File

@ -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

11901
system/LIB/CH584BLE_ROMx.hex Normal file

File diff suppressed because it is too large Load Diff

11901
system/LIB/CH585BLE_ROMx.hex Normal file

File diff suppressed because it is too large Load Diff

4917
system/LIB/CH58xBLE_LIB.h Normal file

File diff suppressed because it is too large Load Diff

4936
system/LIB/CH58xBLE_ROM.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -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

BIN
system/LIB/libCH58xBLE.a Normal file

Binary file not shown.

Binary file not shown.

589
system/LIB/wchrf.h Normal file
View File

@ -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

View File

@ -539,7 +539,6 @@ void LowPower_Halt_WFE(void)
__WFE(); __WFE();
__nop(); __nop();
__nop(); __nop();
} }
/******************************************************************************* /*******************************************************************************
@ -597,4 +596,3 @@ void LowPower_Sleep_WFE(uint16_t rm)
// DelayUs(100); //如果退出函数后运行flash代码则需要延时100us后退出 // DelayUs(100); //如果退出函数后运行flash代码则需要延时100us后退出
} }