From 04a99f2c8d26644500fe6120a6bd179274414a7b Mon Sep 17 00:00:00 2001
From: czq <860517298@qq.com>
Date: Thu, 20 Mar 2025 11:26:08 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B0=94=E5=8E=8B=E4=BC=A0=E6=84=9F=E5=99=A8BM?=
=?UTF-8?q?P390=E4=BD=8E=E5=8A=9F=E8=80=97=E8=B0=83=E8=AF=95=E5=AE=8C?=
=?UTF-8?q?=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.cproject | 774 +++++++++++++++-----
.mrs/IoT_SCV_CH584M1.mrs-workspace | 26 +
.mrs/launch.json | 65 ++
.project | 67 +-
.settings/language.settings.xml | 2 +-
.settings/org.eclipse.core.resources.prefs | 1 +
.template | 23 +
.vscode/c_cpp_properties.json | 15 +
APP/peripheral.c | 10 +-
APP/peripheral_main.c | 63 +-
HAL/SLEEP.c | 28 +-
HAL/include/SLEEP.h | 2 +
IoT_SCV_CH584M.wvproj | Bin 202 -> 0 bytes
IoT_SCV_CH584M1.launch | 62 ++
IoT_SCV_CH584M1.wvproj | 776 ++++++++++++++++++++
LIB/CH58xBLE_LIB.h | 2 +-
README.md | 4 +-
StdPeriphDriver/CH58x_sys.c | 52 +-
bsp/inc/{bsp_wf5803.h => bsp_bmp390.h} | 19 +-
bsp/inc/bsp_key.h | 40 +
bsp/inc/bsp_led.h | 41 ++
bsp/inc/bsp_ml307r.h | 16 -
bsp/inc/bsp_motor.h | 20 +-
bsp/inc/bsp_timkey.h | 13 +
bsp/src/bsp_adc.c | 20 +-
bsp/src/bsp_bmp390.c | 805 +++++++++++++++++++++
bsp/src/bsp_key.c | 344 +++++++++
bsp/src/bsp_led.c | 20 +
bsp/src/bsp_ml307r.c | 211 +++---
bsp/src/bsp_motor.c | 48 +-
bsp/src/bsp_timkey.c | 8 +
bsp/src/bsp_uart.c | 14 +-
bsp/src/bsp_wf5803.c | 756 -------------------
33 files changed, 3181 insertions(+), 1166 deletions(-)
create mode 100644 .mrs/IoT_SCV_CH584M1.mrs-workspace
create mode 100644 .mrs/launch.json
create mode 100644 .vscode/c_cpp_properties.json
delete mode 100644 IoT_SCV_CH584M.wvproj
create mode 100644 IoT_SCV_CH584M1.launch
create mode 100644 IoT_SCV_CH584M1.wvproj
rename bsp/inc/{bsp_wf5803.h => bsp_bmp390.h} (88%)
create mode 100644 bsp/inc/bsp_key.h
create mode 100644 bsp/inc/bsp_led.h
create mode 100644 bsp/inc/bsp_timkey.h
create mode 100644 bsp/src/bsp_bmp390.c
create mode 100644 bsp/src/bsp_key.c
create mode 100644 bsp/src/bsp_led.c
create mode 100644 bsp/src/bsp_timkey.c
delete mode 100644 bsp/src/bsp_wf5803.c
diff --git a/.cproject b/.cproject
index 9529184..317b301 100644
--- a/.cproject
+++ b/.cproject
@@ -1,179 +1,599 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.mrs/IoT_SCV_CH584M1.mrs-workspace b/.mrs/IoT_SCV_CH584M1.mrs-workspace
new file mode 100644
index 0000000..fb1ef29
--- /dev/null
+++ b/.mrs/IoT_SCV_CH584M1.mrs-workspace
@@ -0,0 +1,26 @@
+{
+ "folders": [
+ {
+ "path": "."
+ },
+ {
+ "name": "IoT_SCV_CH584M1",
+ "path": "../"
+ }
+ ],
+ "settings": {
+ "mrs.workspace.type": "project",
+ "files.associations": {
+ "*.c": "c",
+ "*.h": "cpp",
+ "*.hxx": "cpp",
+ "*.hpp": "cpp",
+ "*.c++": "cpp",
+ "*.cpp": "cpp",
+ "*.cxx": "cpp",
+ "*.cc": "cpp",
+ "*.hh": "cpp",
+ "*.h++": "cpp"
+ }
+ }
+}
\ No newline at end of file
diff --git a/.mrs/launch.json b/.mrs/launch.json
new file mode 100644
index 0000000..8595f7b
--- /dev/null
+++ b/.mrs/launch.json
@@ -0,0 +1,65 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "type": "mrs-debugger",
+ "request": "launch",
+ "name": "IoT_SCV_CH584M1",
+ "cwd": "c:\\Users\\123\\Desktop\\物联网自闭阀",
+ "openOCDCfg": {
+ "useLocalOpenOCD": true,
+ "executable": "d:/MounRiverV2/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/openocd.exe",
+ "configOptions": [
+ "-f \"d:/MounRiverV2/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/wch-riscv.cfg\" -c \"chip_id CH32L10x\""
+ ],
+ "gdbport": 3333,
+ "telnetport": 4444,
+ "tclport": 6666,
+ "host": "localhost",
+ "port": 3333,
+ "skipDownloadBeforeDebug": false,
+ "enablePageEraser": false,
+ "enableNoZeroWaitingAreaFlash": false
+ },
+ "gdbCfg": {
+ "executable": "d:/MounRiverV2/MounRiver_Studio2/resources/app/resources/win32/components/WCH/Toolchain/RISC-V Embedded GCC12/bin/riscv-wch-elf-gdb.exe",
+ "commands": [
+ "set mem inaccessible-by-default off",
+ "set architecture riscv:rv32",
+ "set remotetimeout unlimited",
+ "set disassembler-options xw"
+ ],
+ "options": []
+ },
+ "startup": {
+ "initCommands": {
+ "initReset": true,
+ "initResetType": "init",
+ "armSemihosting": false,
+ "additionalCommands": []
+ },
+ "loadedFiles": {
+ "executableFile": "c:\\Users\\123\\Desktop\\物联网自闭阀\\obj\\IoT_SCV_CH584M1.elf",
+ "symbolFile": "c:\\Users\\123\\Desktop\\物联网自闭阀\\obj\\IoT_SCV_CH584M1.elf",
+ "executableFileOffset": 0,
+ "symbolFileOffset": 0
+ },
+ "runCommands": {
+ "runReset": true,
+ "runResetType": "halt",
+ "additionalCommands": [],
+ "setBreakAt": "handle_reset",
+ "continue": true,
+ "setProgramCounterAt": 0
+ },
+ "debugInRAM": false
+ },
+ "svdpath": "",
+ "output": {
+ "showDebugGDBTrace": true,
+ "saveDebugOutputToFile": false,
+ "showDebugOutputTimestamps": true
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/.project b/.project
index 75fa798..6afa436 100644
--- a/.project
+++ b/.project
@@ -1,37 +1,34 @@
- IoT_SCV_CH584M
-
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.genmakebuilder
- clean,full,incremental,
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
- full,incremental,
-
-
-
-
-
- org.eclipse.cdt.core.cnature
- org.eclipse.cdt.managedbuilder.core.managedBuildNature
- org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
-
-
-
- 1602468250279
-
- 22
-
- org.eclipse.ui.ide.multiFilter
- 1.0-name-matches-false-false-*.wvproj
-
-
-
-
+ IoT_SCV_CH584M1
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.genmakebuilder
+ clean,full,incremental,
+
+
+
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
+ full,incremental,
+
+
+
+
+ org.eclipse.cdt.core.cnature
+ org.eclipse.cdt.managedbuilder.core.managedBuildNature
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+
+
+
+
+ 6
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-*.wvproj
+
+
+
+
\ No newline at end of file
diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml
index d06d393..c4b6599 100644
--- a/.settings/language.settings.xml
+++ b/.settings/language.settings.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
index 63a0542..c261454 100644
--- a/.settings/org.eclipse.core.resources.prefs
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -13,6 +13,7 @@ encoding//StdPeriphDriver/CH58x_uart1.c=GBK
encoding//StdPeriphDriver/inc/CH585SFR.h=GBK
encoding//bsp/inc/bsp_ml307r.h=GBK
encoding//bsp/inc/bsp_uart.h=GBK
+encoding//bsp/src/bsp_key.c=UTF-8
encoding//bsp/src/bsp_ml307r.c=GBK
encoding//bsp/src/bsp_tim.c=GBK
encoding//bsp/src/bsp_uart.c=GBK
diff --git a/.template b/.template
index e69de29..b20a2f1 100644
--- a/.template
+++ b/.template
@@ -0,0 +1,23 @@
+Vendor=WCH
+Toolchain=RISC-V
+Series=CH32L103
+RTOS=NoneOS
+MCU=CH32L103C8T6
+Link=WCH-Link
+PeripheralVersion=1.0
+Description=
+Mcu Type=CH32L10x
+Address=0x08000000
+Target Path=
+Exe Path=
+Exe Arguments=
+CLKSpeed=1
+DebugInterfaceMode=0
+Erase All=false
+Program=false
+Verify=false
+Reset=false
+SDIPrintf=false
+Disable Power Output=false
+Clear CodeFlash=false
+Disable Code-Protect=false
\ No newline at end of file
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
new file mode 100644
index 0000000..15bad55
--- /dev/null
+++ b/.vscode/c_cpp_properties.json
@@ -0,0 +1,15 @@
+{
+ "configurations": [
+ {
+ "name": "Win32",
+ "includePath": ["${workspaceFolder}/**"],
+ "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
+ "windowsSdkVersion": "10.0.19041.0",
+ "compilerPath": "C:\\msys64\\mingw64\\bin\\gcc.exe",
+ "cStandard": "c17",
+ "cppStandard": "c++17",
+ "intelliSenseMode": "gcc-x64"
+ }
+ ],
+ "version": 4
+ }
\ No newline at end of file
diff --git a/APP/peripheral.c b/APP/peripheral.c
index 75ebacf..90e6daf 100644
--- a/APP/peripheral.c
+++ b/APP/peripheral.c
@@ -40,23 +40,23 @@
#define SBP_PHY_UPDATE_DELAY 2400
// What is the advertising interval when device is discoverable (units of 625us, 80=50ms)
-#define DEFAULT_ADVERTISING_INTERVAL (160 * 10)
+#define DEFAULT_ADVERTISING_INTERVAL (160 * 20) //160 * 10
// Limited discoverable mode advertises for 30.72s, and then stops
// General discoverable mode advertises indefinitely
#define DEFAULT_DISCOVERABLE_MODE GAP_ADTYPE_FLAGS_GENERAL
// Minimum connection interval (units of 1.25ms, 6=7.5ms)
-#define DEFAULT_DESIRED_MIN_CONN_INTERVAL (100)
+#define DEFAULT_DESIRED_MIN_CONN_INTERVAL (200) //100
// Maximum connection interval (units of 1.25ms, 100=125ms)
-#define DEFAULT_DESIRED_MAX_CONN_INTERVAL (400)
+#define DEFAULT_DESIRED_MAX_CONN_INTERVAL (800) //400
// Slave latency to use parameter update
-#define DEFAULT_DESIRED_SLAVE_LATENCY 5
+#define DEFAULT_DESIRED_SLAVE_LATENCY 10 //5
// Supervision timeout value (units of 10ms, 100=1s)
-#define DEFAULT_DESIRED_CONN_TIMEOUT 200
+#define DEFAULT_DESIRED_CONN_TIMEOUT 400 //200
// Company Identifier: WCH
#define WCH_COMPANY_ID 0x07D7
diff --git a/APP/peripheral_main.c b/APP/peripheral_main.c
index 7921917..4e14786 100644
--- a/APP/peripheral_main.c
+++ b/APP/peripheral_main.c
@@ -16,18 +16,20 @@
#include "HAL.h"
#include "gattprofile.h"
#include "peripheral.h"
-#include "bsp_wf5803.h"
+#include "bsp_bmp390.h"
#include "bsp_ml307r.h"
#include "bsp_uart.h"
#include "bsp_adc.h"
#include "bsp_motor.h"
+#include "bsp_led.h"
+#include "bsp_key.h"
#include "log.h"
#undef LOG_ENABLE
#define LOG_ENABLE 1
#define SYSTICK_INTERVAL (1)
-
+#define PB3_PIN GPIO_Pin_3
uint8_t TxBuff[] = "This is a uart3 tx example\r\n";
/*********************************************************************
@@ -39,6 +41,29 @@ __attribute__((aligned(4))) uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];
const uint8_t MacAddr[6] = {0x84, 0xC2, 0xE4, 0x03, 0x02, 0x02};
#endif
+void app_task_handler(TeAppEvtType app_evt_type)
+{
+ switch(app_evt_type)
+ {
+ case kKeyShort:{
+ logDebug("button short press");
+ break;
+ }
+ case kKeyLong:
+ logDebug("button long press");
+
+ break;
+ case kKeyRelease:
+ BSP_KEY_EnterLowpower();
+ // DelayMs(10);
+ BSP_RequestSleep();
+ logDebug("gpio relase;BSP_RequestSleep");
+
+ break;
+ default:
+ break;
+ }
+}
/*********************************************************************
* @fn Main_Circulation
*
@@ -54,6 +79,7 @@ void Main_Circulation()
while(1)
{
TMOS_SystemProcess();
+// KEY_ProcessLoop();
}
}
@@ -72,18 +98,16 @@ int main(void)
HSECFG_Capacitance(HSECap_18p);
SetSysClock(CLK_SOURCE_HSE_PLL_62_4MHz);
SysTick_Config( GetSysClock() / 1000 * SYSTICK_INTERVAL); //趨ʱ1ms
-#if(defined(HAL_SLEEP)) && (HAL_SLEEP == FALSE)
+#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU);
GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU);
#endif
-#ifdef DEBUG
- BSP_UART3_Init();
+#ifdef DEBUG
+ BSP_UART3_Init();
logDebug("%s", TxBuff);
-
#endif
-
logDebug("Start @ChipID=%02X\n", R8_CHIP_ID);
logDebug("%s\n", VER_LIB);
@@ -96,13 +120,24 @@ int main(void)
Peripheral_Init();
logDebug("Peripheral init ok\n");
- BSP_PRESS_Init();
- logDebug("BSP init ok\n");
-
- BSP_VBAT_Init();
- logDebug("VBAT init ok\n");
-
- BSP_Ml307r_Init();
+// BSP_MOTOR_Init();
+//
+// VALVE_OPEN();
+//
+// BSP_LED_Init();
+//
+// BSP_VBAT_Init();
+// logDebug("VBAT init ok\n");
+//
+// BSP_Ml307r_Init();
+// logDebug("BSP_M1307r ok\n");
+//
+// BSP_KEY_Init(app_task_handler);
+//
+ BSP_PRESS_Init();
+// logDebug("BSP init ok\n");
+//
+// Function_Check();
Main_Circulation();
logDebug("Main_Circulation\n");
diff --git a/HAL/SLEEP.c b/HAL/SLEEP.c
index c89a07b..b0ce265 100644
--- a/HAL/SLEEP.c
+++ b/HAL/SLEEP.c
@@ -13,10 +13,23 @@
/******************************************************************************/
/* ͷļ */
#include "HAL.h"
+#include "stdbool.h"
+#include "bsp_bmp390.h"
-#include "bsp_wf5803.h"
+static volatile bool block_sleep_flag = false;
+
+void BSP_RequestSleep(void)
+{
+ block_sleep_flag = false;
+}
+
+void BSP_BlockSleep(void)
+{
+ block_sleep_flag = true;
+}
/*******************************************************************************
+ *
* @fn CH58x_LowPower
*
* @brief ˯
@@ -28,7 +41,12 @@
__HIGH_CODE
uint32_t CH58x_LowPower(uint32_t time)
{
-#if(defined(HAL_SLEEP)) && (HAL_SLEEP == FALSE)
+ if( true == block_sleep_flag)
+ {
+ // logDebug("block_sleep");
+ return 0;
+ }
+#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
volatile uint32_t i;
uint32_t time_tign, time_sleep, time_curr;
unsigned long irq_status;
@@ -59,8 +77,8 @@ uint32_t CH58x_LowPower(uint32_t time)
RTC_SetTignTime(time_tign);
SYS_RecoverIrq(irq_status);
-#if(DEBUG == Debug_UART0) // ʹӡϢҪд
- while((R8_UART0_LSR & RB_LSR_TX_ALL_EMP) == 0)
+#if(DEBUG == Debug_UART3) // ʹӡϢҪд
+ while((R8_UART3_LSR & RB_LSR_TX_ALL_EMP) == 0)
{
__nop();
}
@@ -72,7 +90,7 @@ uint32_t CH58x_LowPower(uint32_t time)
LowPower_Sleep(RB_PWR_RAM32K | RB_PWR_RAM96K | RB_PWR_EXTEND |RB_XT_PRE_EN );
HSECFG_Current(HSE_RCur_100); // Ϊ(ĺHSEƫõ)
-
+
return 0;
}
#endif
diff --git a/HAL/include/SLEEP.h b/HAL/include/SLEEP.h
index 868a4a8..208dc73 100644
--- a/HAL/include/SLEEP.h
+++ b/HAL/include/SLEEP.h
@@ -43,6 +43,8 @@ extern uint32_t CH58x_LowPower(uint32_t time);
/*********************************************************************
*********************************************************************/
+void BSP_RequestSleep(void);
+void BSP_BlockSleep(void);
#ifdef __cplusplus
}
diff --git a/IoT_SCV_CH584M.wvproj b/IoT_SCV_CH584M.wvproj
deleted file mode 100644
index 02d84e695ff5691ab6b468e95a367d3f08c81b78..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 202
zcmV;*05$&zW0R4mN*`eo!Y&tKE2k4$T|ZEBq7D&UmNb7*U1_0`se+k(zIcxdwK_x>
ziGp38F(rz3O0)tTDX7IrdMkz)sF4z{DGVtZG>;%kT0+5RFHJD9bBF?}IWI&2M1vKU
zxk8~5Edj$(i=fB93Nu+FSt$jsfSz=eZEIgMKQ&Z|LQ?{2S5X>%S5YJ}jY*3vEe~EA
zJ)x{^22xW_rjLaKPB)msqac|abWaSuZikvEm!n^grM7N>s;6u$A4^toDsym$1&q8u
EymtRf-v9sr
diff --git a/IoT_SCV_CH584M1.launch b/IoT_SCV_CH584M1.launch
new file mode 100644
index 0000000..3e3f2f6
--- /dev/null
+++ b/IoT_SCV_CH584M1.launch
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/IoT_SCV_CH584M1.wvproj b/IoT_SCV_CH584M1.wvproj
new file mode 100644
index 0000000..80b2667
--- /dev/null
+++ b/IoT_SCV_CH584M1.wvproj
@@ -0,0 +1,776 @@
+{
+ "version": "1.0",
+ "isNormalMRSProject": true,
+ "basic": {
+ "chipInfo": {
+ "vendor": "WCH",
+ "toolchain": "RISC-V",
+ "series": "CH32L103",
+ "rtos": "NoneOS",
+ "mcu": "CH32L103C8T6",
+ "description": "",
+ "link": "WCH-Link",
+ "peripheral_version": "1.0"
+ },
+ "linkedFolders": [],
+ "removedResources": [
+ {
+ "parentLogicPath": "",
+ "type": "file",
+ "name": "*.wvproj"
+ }
+ ],
+ "projectName": "IoT_SCV_CH584M1",
+ "architecture": "RISC-V",
+ "projectType": "c"
+ },
+ "buildConfig": {
+ "configurations": [
+ {
+ "buildArtifact": {
+ "artifact_name": "${ProjName}",
+ "artifact_extension": "elf",
+ "output_prefix": "",
+ "artifact_type": "Executable"
+ },
+ "parallelizationNumber": "optimal",
+ "stop_on_first_build_error": true,
+ "pre_script": "",
+ "pre_script_description": "",
+ "post_script": "",
+ "post_script_description": "",
+ "excludeResources": [
+ "${project}/APP/simpleBLEPeripheral.c",
+ "${project}/APP/simpleBLEPeripheral_main.c",
+ "${project}/HAL/Profile",
+ "${project}/HAL/KEY.c",
+ "${project}/HAL/LED.c",
+ "${project}/StdPeriphDriver/CH59x_pwm.c",
+ "${project}/StdPeriphDriver/CH59x_usbdev.c",
+ "${project}/StdPeriphDriver/CH59x_usbhostClass.c",
+ "${project}/StdPeriphDriver/CH59x_usbhostBase.c",
+ "${project}/StdPeriphDriver/CH59x_spi0.c",
+ "${project}/StdPeriphDriver/CH59x_timer0.c",
+ "${project}/StdPeriphDriver/CH59x_timer1.c",
+ "${project}/StdPeriphDriver/CH59x_timer2.c",
+ "${project}/StdPeriphDriver/CH59x_timer3.c",
+ "${project}/StdPeriphDriver/CH59x_uart0.c",
+ "${project}/StdPeriphDriver/CH59x_uart2.c",
+ "${project}/StdPeriphDriver/CH59x_uart3.c"
+ ],
+ "riscvTargetProcessor": {
+ "architecture": "rv32i",
+ "multiply_extension": true,
+ "atomic_extension": false,
+ "floating_point": "none",
+ "compressed_extension": true,
+ "extra_compressed_extension": true,
+ "bit_extension": true,
+ "multiplication_subset_of_the_M_extension": false,
+ "integer_ABI": "ilp32",
+ "floating_point_ABI": "none",
+ "tuning": "default",
+ "code_model": "any",
+ "small_data_limit": 8,
+ "align": "default",
+ "save_restore": false,
+ "other_target_flags": ""
+ },
+ "optimization": {
+ "level": "size",
+ "message_length": true,
+ "char_is_signed": true,
+ "function_sections": true,
+ "data_sections": true,
+ "no_common_unitialized": true,
+ "do_not_inline_functions": false,
+ "assume_freestanding_environment": false,
+ "disable_builtin": false,
+ "single_precision_constants": false,
+ "position_independent_code": false,
+ "link_time_optimizer": false,
+ "disable_loop_invariant_move": false,
+ "optimize_unused_sections_declared_as_high_code": true,
+ "code_generation_without_hardware_floating": false,
+ "use_pipelines": false,
+ "show_caret_indicating_the_column": false,
+ "other_optimization_flags": ""
+ },
+ "warnings": {
+ "check_syntax_only": false,
+ "pedantic": false,
+ "pedantic_warnings_as_errors": false,
+ "inhibit_all_warnings": false,
+ "warn_on_various_unused_elements": false,
+ "warn_on_uninitialized_variables": false,
+ "enable_all_common_warnings": false,
+ "enable_extra_warnings": false,
+ "warn_on_undeclared_global_function": false,
+ "warn_on_implicit_conversions": false,
+ "warn_if_pointer_arthmetic": false,
+ "warn_if_padding_is_included": false,
+ "warn_if_shadowed_variable": false,
+ "warn_if_suspicious_logical_ops": false,
+ "warn_if_struct_is_returned": false,
+ "warn_if_floats_are_compared_as_equal": false,
+ "generate_errors_instead_of_warnings": false,
+ "other_warning_flags": ""
+ },
+ "debugging": {
+ "debug_level": "default",
+ "debug_format": "default",
+ "generate_prof_information": false,
+ "generate_gprof_information": false,
+ "other_debugging_flags": ""
+ },
+ "assembler": {
+ "preprocessor": {
+ "use_preprocessor": true,
+ "do_not_search_system_directories": false,
+ "preprocess_only": false,
+ "defined_symbols": [],
+ "undefined_symbols": []
+ },
+ "includes": {
+ "include_paths": [],
+ "include_system_paths": [],
+ "include_files": []
+ },
+ "other_warning_flags": "",
+ "miscellaneous": {
+ "assembler_flags": [],
+ "generate_assembler_listing": false,
+ "save_temporary_files": false,
+ "verbose": false,
+ "other_assembler_flags": ""
+ }
+ },
+ "ccompiler": {
+ "preprocessor": {
+ "do_not_search_system_directories": false,
+ "preprocess_only": false,
+ "defined_symbols": [
+ "CLK_OSC32K=0",
+ "DEBUG=3"
+ ],
+ "undefined_symbols": []
+ },
+ "includes": {
+ "include_paths": [
+ "${project}/Startup",
+ "${project}/Profile/include",
+ "${project}/common/AT-Command-master/include",
+ "${project}/common/letter-shell-master/src",
+ "${project}/common/LwUtil",
+ "${project}/common/lwrb",
+ "${project}/StdPeriphDriver/inc",
+ "${project}/HAL/include",
+ "${project}/Ld",
+ "${project}/LIB",
+ "${project}/RVMSIS",
+ "${project}/bsp/inc",
+ "${project}/APP/include"
+ ],
+ "include_system_paths": [],
+ "include_files": []
+ },
+ "optimization": {
+ "language_standard": "gnu99",
+ "other_optimization_flags": ""
+ },
+ "warnings": {
+ "warn_if_a_global_function_has_no_prototype": false,
+ "warn_if_a_function_has_no_arg_type": false,
+ "warn_if_wrong_cast": false,
+ "other_warning_flags": ""
+ },
+ "miscellaneous": {
+ "generate_assembler_listing": false,
+ "save_temporary_files": false,
+ "verbose": false,
+ "other_compiler_flags": ""
+ }
+ },
+ "cppcompiler": {
+ "preprocessor": {
+ "do_not_search_system_directories": false,
+ "do_not_search_system_cpp_directories": false,
+ "preprocess_only": false,
+ "defined_symbols": [],
+ "undefined_symbols": []
+ },
+ "includes": {
+ "include_paths": [],
+ "include_system_paths": [],
+ "include_files": []
+ },
+ "optimization": {
+ "cpp_language_standard": "gnucpp11",
+ "abi_version": "0",
+ "do_not_use_exceptions": false,
+ "do_not_use_rtti": false,
+ "do_not_use__cxa_atexit": false,
+ "do_not_use_thread_safe_statics": false,
+ "other_optimization_flags": ""
+ },
+ "warnings": {
+ "warn_on_abi_violations": false,
+ "warn_on_class_privacy": false,
+ "warn_on_no_except_expressions": false,
+ "warn_on_virtual_destructors": false,
+ "warn_on_uncast_null": false,
+ "warn_on_sign_promotion": false,
+ "warn_about_effictive_cpp_violcations": false,
+ "other_warning_flags": ""
+ },
+ "miscellaneous": {
+ "generate_assembler_listing": false,
+ "save_temporary_files": false,
+ "verbose": false,
+ "other_compiler_flags": ""
+ }
+ },
+ "clinker": {
+ "general": {
+ "scriptFiles": [
+ "${project}/Ld/Link.ld"
+ ],
+ "do_not_use_standard_start_files": true,
+ "do_not_use_default_libraries": false,
+ "no_startup_or_default_libs": false,
+ "remove_unused_sections": true,
+ "print_removed_sections": false,
+ "omit_all_symbol_information": false
+ },
+ "libraries": {
+ "libraries": [
+ "ISP585",
+ "CH58xBLE"
+ ],
+ "library_search_path": [
+ "../",
+ "${project}/LIB",
+ "${project}/StdPeriphDriver"
+ ]
+ },
+ "miscellaneous": {
+ "picolibc": "disabled",
+ "linker_flags": [
+ "--print-memory-usage"
+ ],
+ "other_objects": [],
+ "generate_map": "\"${BuildArtifactFileBaseName}.map\"",
+ "cross_reference": false,
+ "print_link_map": false,
+ "use_newlib_nano": false,
+ "use_float_with_nano_printf": false,
+ "use_float_with_nano_scanf": false,
+ "do_not_use_syscalls": true,
+ "verbose": false,
+ "use_wch_printffloat": false,
+ "use_wch_printf": false,
+ "use_iqmath": false,
+ "other_linker_flags": ""
+ }
+ },
+ "cpplinker": {
+ "general": {
+ "scriptFiles": [
+ "${project}/Ld/Link.ld"
+ ],
+ "do_not_use_standard_start_files": true,
+ "do_not_use_default_libraries": false,
+ "no_startup_or_default_libs": false,
+ "remove_unused_sections": true,
+ "print_removed_sections": false,
+ "omit_all_symbol_information": false
+ },
+ "libraries": {
+ "libraries": [
+ "ISP585",
+ "CH58xBLE"
+ ],
+ "library_search_path": [
+ "../",
+ "${project}/LIB",
+ "${project}/StdPeriphDriver"
+ ]
+ },
+ "miscellaneous": {
+ "picolibc": "disabled",
+ "linker_flags": [
+ "--print-memory-usage"
+ ],
+ "other_objects": [],
+ "generate_map": "\"${BuildArtifactFileBaseName}.map\"",
+ "cross_reference": false,
+ "print_link_map": false,
+ "use_newlib_nano": false,
+ "use_float_with_nano_printf": false,
+ "use_float_with_nano_scanf": false,
+ "do_not_use_syscalls": true,
+ "verbose": false,
+ "use_wch_printffloat": false,
+ "use_wch_printf": false,
+ "use_iqmath": false,
+ "other_linker_flags": ""
+ }
+ },
+ "archiver": {
+ "archiver_flags": "-r"
+ },
+ "createFlash": {
+ "enabled": true,
+ "outputFileFormat": "binary",
+ "copy_only_section_text": false,
+ "copy_only_section_data": false,
+ "copy_only_sections": [],
+ "other_flags": ""
+ },
+ "createList": {
+ "enabled": true,
+ "display_source": true,
+ "display_all_headers": true,
+ "demangle_names": true,
+ "display_debug_info": false,
+ "disassemble": false,
+ "display_file_headers": false,
+ "display_line_numbers": true,
+ "display_relocation_info": false,
+ "display_symbols": false,
+ "wide_lines": true,
+ "other_flags": ""
+ },
+ "printSize": {
+ "enabled": true,
+ "size_format": "berkeley",
+ "hex": false,
+ "show_totals": false,
+ "other_flags": ""
+ },
+ "component_toolchain": "${WCH:Toolchain:GCC12}",
+ "name": "obj",
+ "configVariables": []
+ },
+ {
+ "buildArtifact": {
+ "artifact_name": "${ProjName}",
+ "artifact_extension": "elf",
+ "output_prefix": "",
+ "artifact_type": "Executable"
+ },
+ "parallelizationNumber": "optimal",
+ "stop_on_first_build_error": true,
+ "pre_script": "",
+ "pre_script_description": "",
+ "post_script": "",
+ "post_script_description": "",
+ "excludeResources": [
+ "${project}/APP/simpleBLEPeripheral.c",
+ "${project}/APP/simpleBLEPeripheral_main.c",
+ "${project}/HAL/Profile",
+ "${project}/HAL/KEY.c",
+ "${project}/HAL/LED.c",
+ "${project}/StdPeriphDriver/CH59x_pwm.c",
+ "${project}/StdPeriphDriver/CH59x_usbdev.c",
+ "${project}/StdPeriphDriver/CH59x_usbhostClass.c",
+ "${project}/StdPeriphDriver/CH59x_usbhostBase.c",
+ "${project}/StdPeriphDriver/CH59x_spi0.c",
+ "${project}/StdPeriphDriver/CH59x_timer0.c",
+ "${project}/StdPeriphDriver/CH59x_timer1.c",
+ "${project}/StdPeriphDriver/CH59x_timer2.c",
+ "${project}/StdPeriphDriver/CH59x_timer3.c",
+ "${project}/StdPeriphDriver/CH59x_uart0.c",
+ "${project}/StdPeriphDriver/CH59x_uart2.c",
+ "${project}/StdPeriphDriver/CH59x_uart3.c"
+ ],
+ "riscvTargetProcessor": {
+ "architecture": "rv32i",
+ "multiply_extension": true,
+ "atomic_extension": false,
+ "floating_point": "none",
+ "compressed_extension": true,
+ "extra_compressed_extension": true,
+ "bit_extension": true,
+ "multiplication_subset_of_the_M_extension": false,
+ "integer_ABI": "ilp32",
+ "floating_point_ABI": "none",
+ "tuning": "default",
+ "code_model": "any",
+ "small_data_limit": 8,
+ "align": "default",
+ "save_restore": false,
+ "other_target_flags": ""
+ },
+ "optimization": {
+ "level": "size",
+ "message_length": true,
+ "char_is_signed": true,
+ "function_sections": true,
+ "data_sections": true,
+ "no_common_unitialized": true,
+ "do_not_inline_functions": false,
+ "assume_freestanding_environment": false,
+ "disable_builtin": false,
+ "single_precision_constants": false,
+ "position_independent_code": false,
+ "link_time_optimizer": false,
+ "disable_loop_invariant_move": false,
+ "optimize_unused_sections_declared_as_high_code": true,
+ "code_generation_without_hardware_floating": false,
+ "use_pipelines": false,
+ "show_caret_indicating_the_column": false,
+ "other_optimization_flags": ""
+ },
+ "warnings": {
+ "check_syntax_only": false,
+ "pedantic": false,
+ "pedantic_warnings_as_errors": false,
+ "inhibit_all_warnings": false,
+ "warn_on_various_unused_elements": false,
+ "warn_on_uninitialized_variables": false,
+ "enable_all_common_warnings": false,
+ "enable_extra_warnings": false,
+ "warn_on_undeclared_global_function": false,
+ "warn_on_implicit_conversions": false,
+ "warn_if_pointer_arthmetic": false,
+ "warn_if_padding_is_included": false,
+ "warn_if_shadowed_variable": false,
+ "warn_if_suspicious_logical_ops": false,
+ "warn_if_struct_is_returned": false,
+ "warn_if_floats_are_compared_as_equal": false,
+ "generate_errors_instead_of_warnings": false,
+ "other_warning_flags": ""
+ },
+ "debugging": {
+ "debug_level": "default",
+ "debug_format": "default",
+ "generate_prof_information": false,
+ "generate_gprof_information": false,
+ "other_debugging_flags": ""
+ },
+ "assembler": {
+ "preprocessor": {
+ "use_preprocessor": true,
+ "do_not_search_system_directories": false,
+ "preprocess_only": false,
+ "defined_symbols": [],
+ "undefined_symbols": []
+ },
+ "includes": {
+ "include_paths": [],
+ "include_system_paths": [],
+ "include_files": []
+ },
+ "other_warning_flags": "",
+ "miscellaneous": {
+ "assembler_flags": [],
+ "generate_assembler_listing": false,
+ "save_temporary_files": false,
+ "verbose": false,
+ "other_assembler_flags": ""
+ }
+ },
+ "ccompiler": {
+ "preprocessor": {
+ "do_not_search_system_directories": false,
+ "preprocess_only": false,
+ "defined_symbols": [
+ "CLK_OSC32K=0",
+ "DEBUG=3"
+ ],
+ "undefined_symbols": []
+ },
+ "includes": {
+ "include_paths": [
+ "${project}/Startup",
+ "${project}/Profile/include",
+ "${project}/common/AT-Command-master/include",
+ "${project}/common/letter-shell-master/src",
+ "${project}/common/LwUtil",
+ "${project}/common/lwrb",
+ "${project}/StdPeriphDriver/inc",
+ "${project}/HAL/include",
+ "${project}/Ld",
+ "${project}/LIB",
+ "${project}/RVMSIS",
+ "${project}/bsp/inc",
+ "${project}/APP/include"
+ ],
+ "include_system_paths": [],
+ "include_files": []
+ },
+ "optimization": {
+ "language_standard": "gnu99",
+ "other_optimization_flags": ""
+ },
+ "warnings": {
+ "warn_if_a_global_function_has_no_prototype": false,
+ "warn_if_a_function_has_no_arg_type": false,
+ "warn_if_wrong_cast": false,
+ "other_warning_flags": ""
+ },
+ "miscellaneous": {
+ "generate_assembler_listing": false,
+ "save_temporary_files": false,
+ "verbose": false,
+ "other_compiler_flags": ""
+ }
+ },
+ "cppcompiler": {
+ "preprocessor": {
+ "do_not_search_system_directories": false,
+ "do_not_search_system_cpp_directories": false,
+ "preprocess_only": false,
+ "defined_symbols": [],
+ "undefined_symbols": []
+ },
+ "includes": {
+ "include_paths": [],
+ "include_system_paths": [],
+ "include_files": []
+ },
+ "optimization": {
+ "cpp_language_standard": "gnucpp11",
+ "abi_version": "0",
+ "do_not_use_exceptions": false,
+ "do_not_use_rtti": false,
+ "do_not_use__cxa_atexit": false,
+ "do_not_use_thread_safe_statics": false,
+ "other_optimization_flags": ""
+ },
+ "warnings": {
+ "warn_on_abi_violations": false,
+ "warn_on_class_privacy": false,
+ "warn_on_no_except_expressions": false,
+ "warn_on_virtual_destructors": false,
+ "warn_on_uncast_null": false,
+ "warn_on_sign_promotion": false,
+ "warn_about_effictive_cpp_violcations": false,
+ "other_warning_flags": ""
+ },
+ "miscellaneous": {
+ "generate_assembler_listing": false,
+ "save_temporary_files": false,
+ "verbose": false,
+ "other_compiler_flags": ""
+ }
+ },
+ "clinker": {
+ "general": {
+ "scriptFiles": [
+ "${project}/Ld/Link.ld"
+ ],
+ "do_not_use_standard_start_files": true,
+ "do_not_use_default_libraries": false,
+ "no_startup_or_default_libs": false,
+ "remove_unused_sections": true,
+ "print_removed_sections": false,
+ "omit_all_symbol_information": false
+ },
+ "libraries": {
+ "libraries": [
+ "ISP585",
+ "CH58xBLE"
+ ],
+ "library_search_path": [
+ "../",
+ "${project}/LIB",
+ "${project}/StdPeriphDriver"
+ ]
+ },
+ "miscellaneous": {
+ "picolibc": "disabled",
+ "linker_flags": [
+ "--print-memory-usage"
+ ],
+ "other_objects": [],
+ "generate_map": "\"${BuildArtifactFileBaseName}.map\"",
+ "cross_reference": false,
+ "print_link_map": false,
+ "use_newlib_nano": false,
+ "use_float_with_nano_printf": false,
+ "use_float_with_nano_scanf": false,
+ "do_not_use_syscalls": true,
+ "verbose": false,
+ "use_wch_printffloat": false,
+ "use_wch_printf": false,
+ "use_iqmath": false,
+ "other_linker_flags": ""
+ }
+ },
+ "cpplinker": {
+ "general": {
+ "scriptFiles": [
+ "${project}/Ld/Link.ld"
+ ],
+ "do_not_use_standard_start_files": true,
+ "do_not_use_default_libraries": false,
+ "no_startup_or_default_libs": false,
+ "remove_unused_sections": true,
+ "print_removed_sections": false,
+ "omit_all_symbol_information": false
+ },
+ "libraries": {
+ "libraries": [
+ "ISP585",
+ "CH58xBLE"
+ ],
+ "library_search_path": [
+ "../",
+ "${project}/LIB",
+ "${project}/StdPeriphDriver"
+ ]
+ },
+ "miscellaneous": {
+ "picolibc": "disabled",
+ "linker_flags": [
+ "--print-memory-usage"
+ ],
+ "other_objects": [],
+ "generate_map": "\"${BuildArtifactFileBaseName}.map\"",
+ "cross_reference": false,
+ "print_link_map": false,
+ "use_newlib_nano": false,
+ "use_float_with_nano_printf": false,
+ "use_float_with_nano_scanf": false,
+ "do_not_use_syscalls": true,
+ "verbose": false,
+ "use_wch_printffloat": false,
+ "use_wch_printf": false,
+ "use_iqmath": false,
+ "other_linker_flags": ""
+ }
+ },
+ "archiver": {
+ "archiver_flags": "-r"
+ },
+ "createFlash": {
+ "enabled": true,
+ "outputFileFormat": "binary",
+ "copy_only_section_text": false,
+ "copy_only_section_data": false,
+ "copy_only_sections": [],
+ "other_flags": ""
+ },
+ "createList": {
+ "enabled": true,
+ "display_source": true,
+ "display_all_headers": true,
+ "demangle_names": true,
+ "display_debug_info": false,
+ "disassemble": false,
+ "display_file_headers": false,
+ "display_line_numbers": true,
+ "display_relocation_info": false,
+ "display_symbols": false,
+ "wide_lines": true,
+ "other_flags": ""
+ },
+ "printSize": {
+ "enabled": true,
+ "size_format": "berkeley",
+ "hex": false,
+ "show_totals": false,
+ "other_flags": ""
+ },
+ "component_toolchain": "${WCH:Toolchain:GCC12}",
+ "name": "dbg",
+ "configVariables": []
+ }
+ ]
+ },
+ "flashConfig": {
+ "mcutype": "CH32L10x",
+ "address": "0x08000000",
+ "target_path": "",
+ "clkSpeed": "High",
+ "debug_interface_mode": "1-wire serial",
+ "erase": false,
+ "program": false,
+ "verify": false,
+ "reset": false,
+ "sdiPrintf": false,
+ "disablepowerout": false,
+ "clearcodeflash": false,
+ "disablecodeprotect": false,
+ "exepath": "",
+ "exearguments": ""
+ },
+ "debugConfigurations": {
+ "openOCDCfg": {
+ "useLocalOpenOCD": true,
+ "executable": "${WCH:OpenOCD:default}",
+ "gdbport": 3333,
+ "telnetport": 4444,
+ "tclport": 6666,
+ "configOptions": [
+ "-f \"${WCH:OpenOCD:default}/bin/wch-riscv.cfg\""
+ ],
+ "host": "localhost",
+ "port": 3333,
+ "skipDownloadBeforeDebug": false,
+ "enablePageEraser": false,
+ "enableNoZeroWaitingAreaFlash": false
+ },
+ "gdbCfg": {
+ "executable": "${WCH:Toolchain:GCC12}",
+ "options": [],
+ "commands": [
+ "set mem inaccessible-by-default off",
+ "set architecture riscv:rv32",
+ "set remotetimeout unlimited",
+ "set disassembler-options xw"
+ ]
+ },
+ "startup": {
+ "initCommands": {
+ "initReset": true,
+ "initResetType": "init",
+ "additionalCommands": [],
+ "armSemihosting": false,
+ "armSemihosting_old": false
+ },
+ "loadedFiles": {
+ "loadSymbols": true,
+ "useProjBinaryForSymbols": true,
+ "useFileForSymbols": false,
+ "symbolFile": "",
+ "symbolFileOffset": "",
+ "loadImage": true,
+ "useProjBinaryForImage": true,
+ "useFileForImage": false,
+ "executableFile": "",
+ "executableFileOffset": ""
+ },
+ "runCommands": {
+ "runReset": true,
+ "runResetType": "halt",
+ "additionalCommands": [],
+ "setBreakAt": "handle_reset",
+ "continue": true,
+ "setBreak": true,
+ "setProgramCounter": false,
+ "setProgramCounterAddress": ""
+ },
+ "debugInRAM": false
+ },
+ "svdpath": null,
+ "output": {
+ "showDebugGDBTrace": true,
+ "saveDebugOutputToFile": false,
+ "showDebugOutputTimestamps": true
+ },
+ "reserve": {
+ "PROGRAM_NAME": "obj/IoT_SCV_CH584M1.elf",
+ "PROJECT_ATTR": "IoT_SCV_CH584M1",
+ "PROJECT_BUILD_CONFIG_AUTO_ATTR": true,
+ "PROJECT_BUILD_CONFIG_ID_ATTR": "",
+ "ATTR_BUILD_BEFORE_LAUNCH_ATTR": 2,
+ "GdbServerAllocateConsole": true,
+ "GdbServerAllocateTelnetConsole": false,
+ "StartGdbCLient": true,
+ "UPDATE_THREADLIST_ON_SUSPEND": false
+ }
+ }
+}
\ No newline at end of file
diff --git a/LIB/CH58xBLE_LIB.h b/LIB/CH58xBLE_LIB.h
index a9fca14..3b5e938 100644
--- a/LIB/CH58xBLE_LIB.h
+++ b/LIB/CH58xBLE_LIB.h
@@ -137,7 +137,7 @@ typedef struct tag_ble_pa_control_config
uint32_t rxEnableGPIO; // rx enable gpio register
uint32_t rxDisableGPIO; // rx disable gpio register
uint32_t rx_pin; // tx pin define
-} blePaControlConfig_t;
+}blePaControlConfig_t;
// defined for all task
#define SYS_EVENT_MSG (0x8000) // A message is waiting event
diff --git a/README.md b/README.md
index db3d990..b06f22e 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,2 @@
-
-# [IoT_SCV_CH584M](https://gitee.com/SXDT-Embedded/iot_-scv_-ch584-m "IoT_SCV_CH584M")
+不开启睡眠正常
+开启睡眠不初始化任何外设的情况下letter shell卡死,只有初始化4G后正常
diff --git a/StdPeriphDriver/CH58x_sys.c b/StdPeriphDriver/CH58x_sys.c
index ec954a6..bcf92b0 100644
--- a/StdPeriphDriver/CH58x_sys.c
+++ b/StdPeriphDriver/CH58x_sys.c
@@ -545,37 +545,37 @@ void mDelaymS(uint16_t t)
}while(--t);
}
-//#ifdef DEBUG
-//int _write(int fd, char *buf, int size)
-//{
-// int i;
-// for(i = 0; i < size; i++)
-// {
-//#if DEBUG == Debug_UART0
-// while(R8_UART0_TFC == UART_FIFO_SIZE); /* ȴݷ */
-// R8_UART0_THR = *buf++; /* */
-//#elif DEBUG == Debug_UART1
-// while(R8_UART1_TFC == UART_FIFO_SIZE); /* ȴݷ */
-// R8_UART1_THR = *buf++; /* */
-//#elif DEBUG == Debug_UART2
-// while(R8_UART2_TFC == UART_FIFO_SIZE); /* ȴݷ */
-// R8_UART2_THR = *buf++; /* */
-//#elif DEBUG == Debug_UART3
-// while(R8_UART3_TFC == UART_FIFO_SIZE); /* ȴݷ */
-// R8_UART3_THR = *buf++; /* */
-//#endif
-// }
-// return size;
-//}
-
-//#endif
-
+#ifdef DEBUG
int _write(int fd, char *buf, int size)
{
- BSP_Uart3_Send_Data(buf, size);
+ int i;
+ for(i = 0; i < size; i++)
+ {
+#if DEBUG == Debug_UART0
+ while(R8_UART0_TFC == UART_FIFO_SIZE); /* ȴݷ */
+ R8_UART0_THR = *buf++; /* */
+#elif DEBUG == Debug_UART1
+ while(R8_UART1_TFC == UART_FIFO_SIZE); /* ȴݷ */
+ R8_UART1_THR = *buf++; /* */
+#elif DEBUG == Debug_UART2
+ while(R8_UART2_TFC == UART_FIFO_SIZE); /* ȴݷ */
+ R8_UART2_THR = *buf++; /* */
+#elif DEBUG == Debug_UART3
+ while(R8_UART3_TFC == UART_FIFO_SIZE); /* ȴݷ */
+ R8_UART3_THR = *buf++; /* */
+#endif
+ }
return size;
}
+#endif
+
+//int _write(int fd, char *buf, int size)
+//{
+// BSP_Uart3_Send_Data(buf, size);
+// return size;
+//}
+
/*********************************************************************
* @fn _sbrk
*
diff --git a/bsp/inc/bsp_wf5803.h b/bsp/inc/bsp_bmp390.h
similarity index 88%
rename from bsp/inc/bsp_wf5803.h
rename to bsp/inc/bsp_bmp390.h
index 9567510..fa6bd43 100644
--- a/bsp/inc/bsp_wf5803.h
+++ b/bsp/inc/bsp_bmp390.h
@@ -1,16 +1,23 @@
-#ifndef __BSP_WF5803_H
-#define __BSP_WF5803_H
+#ifndef __BSP_BMP390_H
+#define __BSP_BMP390_H
#include "CH58x_common.h"
-#define WF5803_EVT_START (0x0001 << 0)
-#define WF5803_EVT_READ (0x0001 << 1)
+#define BMP390_IN_START (0x0001 << 0)
+#define BMP390_OUT_START (0x0001 << 1)
+#define BMP390_ATOM_START (0x0001 << 2)
+#define BMP390_EVT_READ (0x0001 << 3)
+#define BMP390_IN_READ (0x0001 << 4)
+#define BMP390_OUT_READ (0x0001 << 5)
+#define BMP390_ATOM_READ (0x0001 << 6)
+#define CHECK_EVT_START (0x0001 << 0)
+#define MOTOR_STOP_EVT (0x0001 << 1)
void PRESS_LowPower(void);
void BSP_PRESS_Init(void);
-
+void Function_Check(void);
#include "bmp3.h"
@@ -109,6 +116,4 @@ void bmp3_delay_us(uint32_t period, void *intf_ptr);
void bmp3_check_rslt(const char api_name[], int8_t rslt);
-void BMP390_IN_IRQ(void);
-
#endif
diff --git a/bsp/inc/bsp_key.h b/bsp/inc/bsp_key.h
new file mode 100644
index 0000000..eed2472
--- /dev/null
+++ b/bsp/inc/bsp_key.h
@@ -0,0 +1,40 @@
+#ifndef __BSP_KEY_H__
+#define __BSP_KEY_H__
+
+#include "CONFIG.h"
+
+#include
+#include
+
+#define KEY_TIMOUT_MS 1000
+#define KEY_LONG_PRESS_MS 5000
+#define KEY_SACN_MS 40
+
+#define KEY_SCAN_EVT (0x0001 << 0)
+#define KEY_WAKEUP_EVT (0x0001 << 1)
+#define KEY_RELEASE_EVT (0x0001 << 2)
+#define KEY_IDLE_TIMEOUT_EVT (0x0001 << 2)
+
+// KEY_B_PIN at PB7,low->active
+#define KEY_B_PIN GPIO_Pin_0
+
+#define IS_KEY_Vaild() ((GPIOB_ReadPortPin(KEY_B_PIN) ? 0 : 1))
+
+typedef enum
+{
+ kKeyShort = 0,
+ kKeyLong,
+ kKeyRelease,
+} TeAppEvtType;
+
+typedef void (*app_task_evt_handler_t)(TeAppEvtType app_task_evt_type);
+
+void BSP_KEY_EnterLowpower(void);
+void BSP_KEY_ExitLowpower(void);
+
+void BSP_KEY_Init(app_task_evt_handler_t handler);
+
+void KEY_ProcessLoop(void);
+
+
+#endif // !__BSP_KEY_H__
diff --git a/bsp/inc/bsp_led.h b/bsp/inc/bsp_led.h
new file mode 100644
index 0000000..6d91a6b
--- /dev/null
+++ b/bsp/inc/bsp_led.h
@@ -0,0 +1,41 @@
+/*
+ * bsp_led.h
+ *
+ * Created on: 20241216
+ * Author: 123
+ */
+
+#ifndef INC_BSP_LED_H_
+#define INC_BSP_LED_H_
+
+#include "CH58x_common.h"
+
+#define LED_VALVE_R_PIN GPIO_Pin_7
+#define LED_VALVE_G_PIN GPIO_Pin_8
+#define LED_VALVE_Y_PIN GPIO_Pin_9
+#define LED_ALARM_PIN GPIO_Pin_9
+#define LED_VBAT_PIN GPIO_Pin_4
+
+#define LED_VALVE_OPEN {GPIOA_ResetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
+ GPIOA_SetBits(LED_VALVE_G_PIN);}
+
+#define LED_VALVE_CLOSE {GPIOA_ResetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
+ GPIOA_SetBits(LED_VALVE_R_PIN);}
+
+#define LED_ALARM_OPEN GPIOB_SetBits(LED_ALARM_PIN)
+
+#define LED_ALARM_CLOSE GPIOB_ResetBits(LED_ALARM_PIN)
+
+#define LED_VBAT_OPEN GPIOB_SetBits(LED_VBAT_PIN)
+
+#define LED_VBAT_CLOSE GPIOB_ResetBits(LED_VBAT_PIN)
+
+#define LED_ALL_OPEN {GPIOA_SetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
+ GPIOB_SetBits(LED_ALARM_PIN | LED_VBAT_PIN);}
+
+#define LED_ALL_CLOSE {GPIOA_ResetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
+ GPIOA_ResetBits(LED_ALARM_PIN | LED_VBAT_PIN);}
+
+void BSP_LED_Init(void);
+
+#endif /* INC_BSP_LED_H_ */
diff --git a/bsp/inc/bsp_ml307r.h b/bsp/inc/bsp_ml307r.h
index 9fddfdf..e63790c 100644
--- a/bsp/inc/bsp_ml307r.h
+++ b/bsp/inc/bsp_ml307r.h
@@ -17,22 +17,6 @@
void BSP_Ml307r_Init(void);
void Ml307r_Loop(void);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
#endif //!@__BSP_ML307R_H__
diff --git a/bsp/inc/bsp_motor.h b/bsp/inc/bsp_motor.h
index 8b8f92f..ee3f60f 100644
--- a/bsp/inc/bsp_motor.h
+++ b/bsp/inc/bsp_motor.h
@@ -9,8 +9,22 @@
#define INC_BSP_MOTOR_H_
#include "CH58x_common.h"
-void MOTOR_FORWARD_TURN(void);
-void MOTOR_RESERVE_TURN(void);
-void MOTOR_STOP(void);
+
+//extern uint8_t motor_state;
+
+typedef struct state{
+ uint8_t motor_state; //״̬
+ uint8_t dot_state; //״̬
+ uint8_t off_state; //ѹ״̬
+}valve_state;
+extern valve_state valve_status;
+#define NSLEEP_PIN GPIO_Pin_8
+#define COIL_A GPIO_Pin_17
+#define COIL_B GPIO_Pin_16
+
+void BSP_MOTOR_Init(void);
+void VALVE_OPEN(void);
+void VALVE_CLOSE(void);
+void VALVE_STOP(void);
#endif /* INC_BSP_MOTOR_H_ */
diff --git a/bsp/inc/bsp_timkey.h b/bsp/inc/bsp_timkey.h
new file mode 100644
index 0000000..ec75bc1
--- /dev/null
+++ b/bsp/inc/bsp_timkey.h
@@ -0,0 +1,13 @@
+/*
+ * bsp_timkey.h
+ *
+ * Created on: 20241219
+ * Author: 123
+ */
+
+#ifndef INC_BSP_TIMKEY_H_
+#define INC_BSP_TIMKEY_H_
+
+#include "CH58x_common.h"
+
+#endif /* INC_BSP_TIMKEY_H_ */
diff --git a/bsp/src/bsp_adc.c b/bsp/src/bsp_adc.c
index 86f809a..47d663e 100644
--- a/bsp/src/bsp_adc.c
+++ b/bsp/src/bsp_adc.c
@@ -12,37 +12,39 @@ signed short RoughCalib_Value = 0; // ADC
static tmosTaskID vbat_task_id = INVALID_TASK_ID;
void VBAT_ADC_Init(void)
{
- //ADC_CTRL
-// GPIOA_SetBits(GPIO_Pin_0);
-// GPIOA_ModeCfg(GPIO_Pin_0, GPIO_ModeOut_PP_5mA);
-
//ADCʼ
- /* ͨѡadcͨ8Ӧ PA1ţ У */
- GPIOA_ModeCfg(GPIO_Pin_1, GPIO_ModeIN_Floating);
+ /* ͨѡadcͨ0Ӧ PA4ţ У */
+ GPIOA_ModeCfg(GPIO_Pin_4, GPIO_ModeIN_Floating);
// 8M
ADC_ExtSingleChSampInit(SampleFreq_8_or_4, ADC_PGA_1_2);
RoughCalib_Value = ADC_DataCalib_Rough(); // ڼADCڲƫ¼ȫֱ RoughCalib_Value
logDebug("RoughCalib_Value =%d \n", RoughCalib_Value);
- ADC_ChannelCfg(8);
+ ADC_ChannelCfg(0);
ADC_ExcutSingleConver();//ʱ㹻ʱٴת״ADC
DelayMs(10);
}
+void ADC_GPIO_Init(void)
+{
+ GPIOA_ModeCfg(GPIO_Pin_4, GPIO_ModeIN_Floating);
+}
+
uint16_t VBAT_ProcessEvent(uint8_t task_id, uint16_t events)
{
if (events & VBAT_EVT_START)
{
uint16_t adc_vbat = 0;
float vbat = 0;
+ ADC_GPIO_Init();
- ADC_ChannelCfg(8);
+ ADC_ChannelCfg(0);
adc_vbat = ADC_ExcutSingleConver() + RoughCalib_Value;
logDebug("adc_vbat =%d \n", adc_vbat);
vbat = (adc_vbat/1024.0-1)*1.05;
logDebug("vbat =%f \n", vbat);
- tmos_start_task(vbat_task_id, VBAT_EVT_START, MS1_TO_SYSTEM_TIME(1000));
+ tmos_start_task(vbat_task_id, VBAT_EVT_START, MS1_TO_SYSTEM_TIME(1000*60));
return (events ^ VBAT_EVT_START);
}
return 0;
diff --git a/bsp/src/bsp_bmp390.c b/bsp/src/bsp_bmp390.c
new file mode 100644
index 0000000..56c60b1
--- /dev/null
+++ b/bsp/src/bsp_bmp390.c
@@ -0,0 +1,805 @@
+#include "bsp_bmp390.h"
+#include "bsp_motor.h"
+#include "bsp_led.h"
+#include "CONFIG.h"
+#include "log.h"
+#include "bsp_ml307r.h"
+
+uint8_t flag, fault_state;
+extern uint8_t motor_flag;
+
+static tmosTaskID check_task_id = INVALID_TASK_ID;
+typedef enum
+{
+ kPressIn = 0,
+ kPressOut = 1,
+ kPressAtom = 2,
+ kPressMaxIndex
+} TePressSensorIndex;
+
+static tmosTaskID press_task_id = INVALID_TASK_ID;
+
+#define PRESS_IN_CS_HIGH() GPIOA_SetBits(GPIO_Pin_5)
+#define PRESS_IN_CS_LOW() GPIOA_ResetBits(GPIO_Pin_5)
+
+#define PRESS_OUT_CS_HIGH() GPIOA_SetBits(GPIO_Pin_0)
+#define PRESS_OUT_CS_LOW() GPIOA_ResetBits(GPIO_Pin_0)
+
+#define PRESS_ATOM_CS_HIGH() GPIOA_SetBits(GPIO_Pin_3)
+#define PRESS_ATOM_CS_LOW() GPIOA_ResetBits(GPIO_Pin_3)
+
+uint8_t volatile press_done_flag = 0;
+
+uint8_t SPI0_SendByte(uint8_t data);
+void SPI_CsStart(TePressSensorIndex index);
+void SPI_CsStop(TePressSensorIndex index);
+
+/* Variable to store the device address */
+static uint8_t dev_in_addr;
+static uint8_t dev_out_addr;
+static uint8_t dev_atom_addr;
+
+uint8_t Bmp_ReadData(uint8_t *reg_data, uint32_t len)
+{
+ while (len--)
+ {
+ *reg_data = SPI0_SendByte(0x00);
+ reg_data++;
+ }
+ return BMP3_INTF_RET_SUCCESS;
+}
+
+BMP3_INTF_RET_TYPE Bmp_WriteData(const uint8_t *reg_data, uint32_t len)
+{
+ uint8_t i = 0;
+ for (i = 0; i < len; i++)
+ {
+ SPI0_SendByte(reg_data[i]);
+ }
+ return BMP3_INTF_RET_SUCCESS;
+}
+
+BMP3_INTF_RET_TYPE BMP390_IN_SPI_Read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
+{
+ BMP3_INTF_RET_TYPE rslt = 0;
+
+ uint8_t reg_spi[1] = {(reg_addr & 0x7F) | 0x80};
+ SPI_CsStart(kPressIn); // Ƭѡ
+ Bmp_WriteData(reg_spi, 1); // дֽ
+ rslt = Bmp_ReadData(reg_data, len);
+ SPI_CsStop(kPressIn);
+ return rslt;
+}
+
+/*!
+ * SPI write function map to COINES platform
+ */
+BMP3_INTF_RET_TYPE BMP390_IN_SPI_Write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
+{
+ uint8_t reg_spi[1] = {reg_addr & 0x7f};
+ BMP3_INTF_RET_TYPE rslt = 0;
+
+ SPI_CsStart(kPressIn);
+ Bmp_WriteData(reg_spi, 1);
+ rslt = Bmp_WriteData(reg_data, len);
+ SPI_CsStop(kPressIn);
+ // printf("BMP390_OUT_SPI_Write: %d" , rslt);
+
+ return rslt;
+}
+
+/*!
+ * SPI read function map to COINES platform
+ */
+BMP3_INTF_RET_TYPE BMP390_OUT_SPI_Read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
+{
+ BMP3_INTF_RET_TYPE rslt = 0;
+
+ uint8_t reg_spi[1] = {(reg_addr & 0x7F) | 0x80};
+ SPI_CsStart(kPressOut); // Ƭѡ
+ Bmp_WriteData(reg_spi, 1); // дֽ
+ rslt = Bmp_ReadData(reg_data, len);
+ SPI_CsStop(kPressOut);
+ return rslt;
+}
+
+/*!
+ * SPI write function map to COINES platform
+ */
+BMP3_INTF_RET_TYPE BMP390_OUT_SPI_Write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
+{
+ uint8_t reg_spi[1] = {reg_addr & 0x7f};
+ BMP3_INTF_RET_TYPE rslt = 0;
+
+ SPI_CsStart(kPressOut);
+ Bmp_WriteData(reg_spi, 1);
+ rslt = Bmp_WriteData(reg_data, len);
+ SPI_CsStop(kPressOut);
+ // printf("BMP390_OUT_SPI_Write: %d" , rslt);
+
+ return rslt;
+}
+
+BMP3_INTF_RET_TYPE BMP390_ATOM_SPI_Read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
+{
+ BMP3_INTF_RET_TYPE rslt = 0;
+
+ uint8_t reg_spi[1] = {(reg_addr & 0x7F) | 0x80};
+ SPI_CsStart(kPressAtom); // Ƭѡ
+ Bmp_WriteData(reg_spi, 1); // дֽ
+ rslt = Bmp_ReadData(reg_data, len);
+ SPI_CsStop(kPressAtom);
+ return rslt;
+}
+
+/*!
+ * SPI write function map to COINES platform
+ */
+BMP3_INTF_RET_TYPE BMP390_ATOM_SPI_Write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
+{
+ uint8_t reg_spi[1] = {reg_addr & 0x7f};
+ BMP3_INTF_RET_TYPE rslt = 0;
+
+ SPI_CsStart(kPressAtom);
+ Bmp_WriteData(reg_spi, 1);
+ rslt = Bmp_WriteData(reg_data, len);
+ SPI_CsStop(kPressAtom);
+ // printf("BMP390_OUT_SPI_Write: %d" , rslt);
+
+ return rslt;
+}
+
+void bmp3_delay_us(uint32_t period, void *intf_ptr)
+{
+ DelayUs(period);
+}
+
+void bmp3_check_rslt(const char api_name[], int8_t rslt)
+{
+ switch (rslt)
+ {
+ case BMP3_OK:
+
+ /* Do nothing */
+ break;
+ case BMP3_E_NULL_PTR:
+ printf("API [%s] Error [%d] : Null pointer\r\n", api_name, rslt);
+ break;
+ case BMP3_E_COMM_FAIL:
+ printf("API [%s] Error [%d] : Communication failure\r\n", api_name, rslt);
+ break;
+ case BMP3_E_INVALID_LEN:
+ printf("API [%s] Error [%d] : Incorrect length parameter\r\n", api_name, rslt);
+ break;
+ case BMP3_E_DEV_NOT_FOUND:
+ printf("API [%s] Error [%d] : Device not found\r\n", api_name, rslt);
+ break;
+ case BMP3_E_CONFIGURATION_ERR:
+ printf("API [%s] Error [%d] : Configuration Error\r\n", api_name, rslt);
+ break;
+ case BMP3_W_SENSOR_NOT_ENABLED:
+ printf("API [%s] Error [%d] : Warning when Sensor not enabled\r\n", api_name, rslt);
+ break;
+ case BMP3_W_INVALID_FIFO_REQ_FRAME_CNT:
+ printf("API [%s] Error [%d] : Warning when Fifo watermark level is not in limit\r\n", api_name, rslt);
+ break;
+ default:
+ printf("API [%s] Error [%d] : Unknown error code\r\n", api_name, rslt);
+ break;
+ }
+}
+
+BMP3_INTF_RET_TYPE BMP390_IN_InterfaceInit(struct bmp3_dev *bmp3, uint8_t intf)
+{
+ int8_t rslt = BMP3_OK;
+
+ /* Bus configuration : SPI */
+ if (intf == BMP3_SPI_INTF)
+ {
+ printf("SPI Interface\n");
+ bmp3->read = BMP390_IN_SPI_Read;
+ bmp3->write = BMP390_IN_SPI_Write;
+ bmp3->intf = BMP3_SPI_INTF;
+ printf("spi init ok\r\n");
+ }
+
+ DelayMs(100);
+ bmp3->delay_us = bmp3_delay_us;
+ bmp3->intf_ptr = &dev_in_addr;
+
+ return rslt;
+}
+
+BMP3_INTF_RET_TYPE BMP390_OUT_InterfaceInit(struct bmp3_dev *bmp3, uint8_t intf)
+{
+ int8_t rslt = BMP3_OK;
+
+ /* Bus configuration : SPI */
+ if (intf == BMP3_SPI_INTF)
+ {
+ printf("SPI Interface\n");
+ bmp3->read = BMP390_OUT_SPI_Read;
+ bmp3->write = BMP390_OUT_SPI_Write;
+ bmp3->intf = BMP3_SPI_INTF;
+ printf("spi init ok\r\n");
+ }
+
+ DelayMs(100);
+ bmp3->delay_us = bmp3_delay_us;
+ bmp3->intf_ptr = &dev_out_addr;
+
+ return rslt;
+}
+
+BMP3_INTF_RET_TYPE BMP390_ATOM_InterfaceInit(struct bmp3_dev *bmp3, uint8_t intf)
+{
+ int8_t rslt = BMP3_OK;
+
+ /* Bus configuration : SPI */
+ if (intf == BMP3_SPI_INTF)
+ {
+ printf("SPI Interface\n");
+ bmp3->read = BMP390_ATOM_SPI_Read;
+ bmp3->write = BMP390_ATOM_SPI_Write;
+ bmp3->intf = BMP3_SPI_INTF;
+ printf("spi init ok\r\n");
+ }
+
+ DelayMs(100);
+ bmp3->delay_us = bmp3_delay_us;
+ bmp3->intf_ptr = &dev_atom_addr;
+
+ return rslt;
+}
+
+void SPI_CsStart(TePressSensorIndex index)
+{
+ switch (index)
+ {
+ case kPressIn:
+ PRESS_IN_CS_LOW();
+ break;
+ case kPressOut:
+ PRESS_OUT_CS_LOW();
+ break;
+ case kPressAtom:
+ PRESS_ATOM_CS_LOW();
+ break;
+
+ default:
+ break;
+ }
+}
+
+void SPI_CsStop(TePressSensorIndex index)
+{
+ switch (index)
+ {
+ case kPressIn:
+ PRESS_IN_CS_HIGH();
+ break;
+ case kPressOut:
+ PRESS_OUT_CS_HIGH();
+ break;
+ case kPressAtom:
+ PRESS_ATOM_CS_HIGH();
+ break;
+
+ default:
+ break;
+ }
+}
+
+uint8_t SPI0_SendByte(uint8_t data)
+{
+ R8_SPI0_BUFFER = data;
+ while (!(R8_SPI0_INT_FLAG & RB_SPI_FREE));
+ return (R8_SPI0_BUFFER);
+}
+
+void PRESS_IO_SPI_Init(void)
+{
+ /**
+ * CSB1: PA3
+ * CSB2: PA5
+ * CSB3: PA0
+ * SCL: PA13
+ * SDA: PA14
+ * SDO: PA15
+ */
+
+ // SDA: MOSI
+ // SDO: MISO
+ GPIOA_SetBits(GPIO_Pin_0);
+ GPIOA_ModeCfg(GPIO_Pin_0, GPIO_ModeOut_PP_5mA);
+
+ GPIOA_SetBits(GPIO_Pin_5);
+ GPIOA_ModeCfg(GPIO_Pin_5, GPIO_ModeOut_PP_5mA);
+
+ GPIOA_SetBits(GPIO_Pin_3);
+ GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeOut_PP_5mA);
+
+ SPI_CsStop(kPressIn);
+ SPI_CsStop(kPressOut);
+ SPI_CsStop(kPressAtom);
+
+ // spiʼģʽ0
+ GPIOA_ModeCfg(GPIO_Pin_13 | GPIO_Pin_14, GPIO_ModeOut_PP_5mA);
+ GPIOA_ModeCfg(GPIO_Pin_15, GPIO_ModeIN_PU);
+
+ SPI0_MasterDefInit();
+}
+
+void PRESS_LowerIO_Init(void)
+{
+ // BMP390ĬϹʱIOǸߵƽ,INTΪ͵ƽ
+ // SPI
+ GPIOA_SetBits(GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
+ GPIOA_ModeCfg(GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15, GPIO_ModeIN_PU);
+
+ // CSB3: PA0
+ GPIOA_SetBits(GPIO_Pin_0);
+ GPIOA_ModeCfg(GPIO_Pin_0, GPIO_ModeIN_PU);
+
+ // CSB2: PA5
+ GPIOA_SetBits(GPIO_Pin_5);
+ GPIOA_ModeCfg(GPIO_Pin_5, GPIO_ModeIN_PU);
+
+ // CSB1: PA3
+ GPIOA_SetBits(GPIO_Pin_3);
+ GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeIN_PU);
+}
+
+void Lower_IO_Deinit(void)
+{
+ // LED
+ GPIOA_ResetBits(GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9);
+ GPIOA_ModeCfg(GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9, GPIO_ModeIN_PD);
+ GPIOB_ResetBits(GPIO_Pin_4 | GPIO_Pin_9);
+ GPIOB_ModeCfg(GPIO_Pin_4 | GPIO_Pin_9, GPIO_ModeIN_PD);
+
+ // KEY | RESET KEY | boot KEY
+ GPIOB_ResetBits(GPIO_Pin_0 | GPIO_Pin_23 | GPIO_Pin_22);
+ GPIOB_ModeCfg(GPIO_Pin_0 | GPIO_Pin_23 | GPIO_Pin_22, GPIO_ModeIN_PD);
+
+ // ADC
+ GPIOA_ResetBits(GPIO_Pin_4);
+ GPIOA_ModeCfg(GPIO_Pin_4, GPIO_ModeIN_PD);
+ ADC_DisablePower();
+
+ // BMP390
+ //Ƭѡ͵ƽЧʼΪ
+ // CSB3: PA0 | CSB2: PA3 | CSB1: PA5
+ GPIOA_SetBits(GPIO_Pin_0 | GPIO_Pin_3 | GPIO_Pin_5);
+ GPIOA_ModeCfg(GPIO_Pin_0 | GPIO_Pin_3 | GPIO_Pin_5, GPIO_ModeOut_PP_5mA);
+ //жߵƽЧģʽ
+ // INT1: PA2 | INT2: PA6 | INT3: PA12
+ GPIOA_ModeCfg(GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_12, GPIO_ModeIN_PD);
+ // spiʼ
+ GPIOA_ModeCfg(GPIO_Pin_13 | GPIO_Pin_14, GPIO_ModeOut_PP_5mA);
+ GPIOA_ModeCfg(GPIO_Pin_15, GPIO_ModeIN_PU);
+
+ //4G
+ // ر3.8V
+ GPIOB_ResetBits(ENABLE_3_8_V);
+ GPIOB_ModeCfg(ENABLE_3_8_V, GPIO_ModeIN_PD);
+ // Ϊ©
+ GPIOB_ModeCfg(ML307_PWR_PIN | ML307_RST_PIN, GPIO_ModeIN_PD);
+ // UARTΪ
+ GPIOB_ModeCfg(ML307_UART_TX_PIN | ML307_UART_RX_PIN, GPIO_ModeIN_PD);
+ // SIMΪ
+ GPIOB_ModeCfg(USIM_DECT_PIN, GPIO_ModeIN_PD);
+
+ //motor
+ GPIOB_ResetBits(NSLEEP_PIN);
+ GPIOB_ModeCfg(NSLEEP_PIN, GPIO_ModeIN_PD);
+ //IN1 + ; IN2 +
+ //GPIOB_SetBits(COIL_A);
+ //GPIOB_SetBits(COIL_B);
+ GPIOB_ModeCfg(COIL_A | COIL_B, GPIO_ModeIN_PD);
+}
+
+void PRESS_LowPower(void)
+{
+ Lower_IO_Deinit();
+ if (press_done_flag == 1)
+ {
+ PRESS_LowerIO_Init();
+ }
+}
+
+int8_t ret = 0;
+uint8_t loop = 0;
+struct bmp3_dev DevIn;
+struct bmp3_dev DevOut;
+struct bmp3_dev DevAtom;
+uint16_t settings_sel;
+struct bmp3_data data = {0};
+struct bmp3_settings settings = {0};
+struct bmp3_status status = {{0}};
+
+//T,P
+int32_t T[3] = {0};
+int32_t P[3] = {0};
+
+__HIGH_CODE
+__attribute__((noinline))
+uint16_t
+BMP390_ProcessEvent(uint8_t task_id, uint16_t events)
+{
+ if (events & BMP390_IN_START)
+ {
+ press_done_flag = 0;
+ PRESS_IO_SPI_Init();
+
+ settings.op_mode = BMP3_MODE_FORCED;
+ ret = bmp3_set_op_mode(&settings, &DevIn);
+ bmp3_check_rslt("bmp3_set_op_mode", ret);
+
+ return (events ^ BMP390_IN_START);
+ }
+ else if(events & BMP390_OUT_START)
+ {
+ press_done_flag = 0;
+ PRESS_IO_SPI_Init();
+
+ settings.op_mode = BMP3_MODE_FORCED;
+ ret = bmp3_set_op_mode(&settings, &DevOut);
+ bmp3_check_rslt("bmp3_set_op_mode", ret);
+ return (events ^ BMP390_OUT_START);
+ }
+ else if(events & BMP390_ATOM_START)
+ {
+ press_done_flag = 0;
+ PRESS_IO_SPI_Init();
+
+ settings.op_mode = BMP3_MODE_FORCED;
+ ret = bmp3_set_op_mode(&settings, &DevAtom);
+ bmp3_check_rslt("bmp3_set_op_mode", ret);
+
+ return (events ^ BMP390_ATOM_START);
+ }
+ else if (events & BMP390_EVT_READ)
+ {
+ PRESS_IO_SPI_Init();
+#if 0
+ PRESS_IO_SPI_Init();
+
+ // IN
+ ret = bmp3_get_status(&status, &DevIn);
+ bmp3_check_rslt("bmp3_get_status", ret);
+
+ /* Read temperature and pressure data iteratively based on data ready interrupt */
+ if ((ret == BMP3_OK) && (status.intr.drdy == BMP3_ENABLE))
+ {
+ /*
+ * First parameter indicates the type of data to be read
+ * BMP3_PRESS_TEMP : To read pressure and temperature data
+ * BMP3_TEMP : To read only temperature data
+ * BMP3_PRESS : To read only pressure data
+ */
+ ret = bmp3_get_sensor_data(BMP3_PRESS_TEMP, &data, &DevIn);
+ bmp3_check_rslt("bmp3_get_sensor_data", ret);
+
+ /* NOTE : Read status register again to clear data ready interrupt status */
+ ret = bmp3_get_status(&status, &DevIn);
+ bmp3_check_rslt("bmp3_get_status", ret);
+
+ #ifdef BMP3_FLOAT_COMPENSATION
+ printf("IN[%d] T: %.2f deg C, P: %.2f Pa\n", loop, (data.temperature), (data.pressure));
+ #else
+ printf("IN[%d] T: %ld deg C, P: %lu Pa\n", loop, (long int)(int32_t)(data.temperature / 100),
+ (long unsigned int)(uint32_t)(data.pressure / 100));
+ #endif
+ }
+
+ // OUT
+ ret = bmp3_get_status(&status, &DevOut);
+ bmp3_check_rslt("bmp3_get_status", ret);
+
+ /* Read temperature and pressure data iteratively based on data ready interrupt */
+ if ((ret == BMP3_OK) && (status.intr.drdy == BMP3_ENABLE))
+ {
+ /*
+ * First parameter indicates the type of data to be read
+ * BMP3_PRESS_TEMP : To read pressure and temperature data
+ * BMP3_TEMP : To read only temperature data
+ * BMP3_PRESS : To read only pressure data
+ */
+ ret = bmp3_get_sensor_data(BMP3_PRESS_TEMP, &data, &DevOut);
+ bmp3_check_rslt("bmp3_get_sensor_data", ret);
+
+ /* NOTE : Read status register again to clear data ready interrupt status */
+ ret = bmp3_get_status(&status, &DevOut);
+ bmp3_check_rslt("bmp3_get_status", ret);
+
+ #ifdef BMP3_FLOAT_COMPENSATION
+ printf("OUT[%d] T: %.2f deg C, P: %.2f Pa\n", loop, (data.temperature), (data.pressure));
+ #else
+ printf("OUT[%d] T: %ld deg C, P: %lu Pa\n", loop, (long int)(int32_t)(data.temperature / 100),
+ (long unsigned int)(uint32_t)(data.pressure / 100));
+ #endif
+ loop = loop + 1;
+ }
+ tmos_start_task(press_task_id, WF5803_EVT_START, MS1_TO_SYSTEM_TIME(2000));
+#endif
+ if(flag == 1)
+ {
+ ret = bmp3_get_status(&status, &DevIn); // жΪģʽҪȡint_status.drdyλж״̬־
+ bmp3_check_rslt("bmp3_get_status", ret);
+
+ if (status.intr.drdy == BMP3_ENABLE)
+ {
+ /*
+ * First parameter indicates the type of data to be read
+ * BMP3_PRESS_TEMP : To read pressure and temperature data
+ * BMP3_TEMP : To read only temperature data
+ * BMP3_PRESS : To read only pressure data
+ */
+ ret = bmp3_get_sensor_data(BMP3_PRESS_TEMP, &data, &DevIn);
+ bmp3_check_rslt("bmp3_get_sensor_data", ret);
+
+ /* NOTE : Read status register again to clear data ready interrupt status */
+ ret = bmp3_get_status(&status, &DevIn);
+ bmp3_check_rslt("bmp3_get_status", ret);
+
+// printf("IN[%d] T: %ld deg C, P: %lu Pa\r\n", loop, (long int)(int32_t)(data.temperature / 100),
+// (long unsigned int)(uint32_t)(data.pressure / 100));
+ T[0] = (int32_t)(data.temperature / 100);
+ P[0] = (uint32_t)(data.pressure / 100);
+ }
+ //tmos_start_task(press_task_id, BMP390_ATOM_START, MS1_TO_SYSTEM_TIME(100));
+ tmos_start_task(press_task_id, BMP390_OUT_START, MS1_TO_SYSTEM_TIME(500)); //100
+ //tmos_start_task(press_task_id, BMP390_IN_START, MS1_TO_SYSTEM_TIME(1000));
+ }
+ else if(flag == 2)
+ {
+ ret = bmp3_get_status(&status, &DevOut); // жΪģʽҪȡint_status.drdyλж״̬־
+ bmp3_check_rslt("bmp3_get_status", ret);
+
+ if (status.intr.drdy == BMP3_ENABLE)
+ {
+ /*
+ * First parameter indicates the type of data to be read
+ * BMP3_PRESS_TEMP : To read pressure and temperature data
+ * BMP3_TEMP : To read only temperature data
+ * BMP3_PRESS : To read only pressure data
+ */
+ ret = bmp3_get_sensor_data(BMP3_PRESS_TEMP, &data, &DevOut);
+ bmp3_check_rslt("bmp3_get_sensor_data", ret);
+
+ /* NOTE : Read status register again to clear data ready interrupt status */
+ ret = bmp3_get_status(&status, &DevOut);
+ bmp3_check_rslt("bmp3_get_status", ret);
+
+// printf("OUT[%d] T: %ld deg C, P: %lu Pa\r\n", loop, (long int)(int32_t)(data.temperature / 100),
+// (long unsigned int)(uint32_t)(data.pressure / 100));
+ T[1] = (int32_t)(data.temperature / 100);
+ P[1] = (uint32_t)(data.pressure / 100);
+ }
+ tmos_start_task(press_task_id, BMP390_ATOM_START, MS1_TO_SYSTEM_TIME(500)); //100
+ //tmos_start_task(press_task_id, BMP390_OUT_START, MS1_TO_SYSTEM_TIME(1000));
+ }
+ else if(flag == 3)
+ {
+ ret = bmp3_get_status(&status, &DevAtom); // жΪģʽҪȡint_status.drdyλж״̬־
+ bmp3_check_rslt("bmp3_get_status", ret);
+
+ if (status.intr.drdy == BMP3_ENABLE)
+ {
+ /*
+ * First parameter indicates the type of data to be read
+ * BMP3_PRESS_TEMP : To read pressure and temperature data
+ * BMP3_TEMP : To read only temperature data
+ * BMP3_PRESS : To read only pressure data
+ */
+ ret = bmp3_get_sensor_data(BMP3_PRESS_TEMP, &data, &DevAtom);
+ bmp3_check_rslt("bmp3_get_sensor_data", ret);
+
+ /* NOTE : Read status register again to clear data ready interrupt status */
+ ret = bmp3_get_status(&status, &DevAtom);
+ bmp3_check_rslt("bmp3_get_status", ret);
+
+// printf("ATOM[%d] T: %ld deg C, P: %lu Pa\r\n", loop, (long int)(int32_t)(data.temperature / 100),
+// (long unsigned int)(uint32_t)(data.pressure / 100));
+ T[2] = (int32_t)(data.temperature / 100);
+ P[2] = (uint32_t)(data.pressure / 100);
+
+ //printf("%d, %d, %d\r\n",T[0],T[1],T[2]);
+ printf("%d, %d, %d, %d, %d, %d, %d \r\n",T[0],T[1],T[2],P[0],P[1],P[2],P[0]-P[1]);
+ }
+ tmos_start_task(press_task_id, BMP390_IN_START, MS1_TO_SYSTEM_TIME(500)); //100
+ //tmos_start_task(press_task_id, BMP390_ATOM_START, MS1_TO_SYSTEM_TIME(1000));
+ }
+ flag = 0;
+ press_done_flag = 1;
+ loop = loop + 1;
+ return (events ^ BMP390_EVT_READ);
+ }
+ return 0;
+}
+
+void BSP_PRESS_Init(void)
+{
+ PRESS_IO_SPI_Init();
+
+ // жŵ
+ GPIOA_ModeCfg(GPIO_Pin_6, GPIO_ModeIN_PD);
+ GPIOA_ITModeCfg(GPIO_Pin_6, GPIO_ITMode_RiseEdge);
+
+ GPIOA_ModeCfg(GPIO_Pin_12, GPIO_ModeIN_PD);
+ GPIOA_ITModeCfg(GPIO_Pin_12, GPIO_ITMode_RiseEdge);
+
+ GPIOA_ModeCfg(GPIO_Pin_2, GPIO_ModeIN_PD);
+ GPIOA_ITModeCfg(GPIO_Pin_2, GPIO_ITMode_RiseEdge);
+
+ PWR_PeriphWakeUpCfg(ENABLE, RB_GPIO_WAKE_MODE | RB_SLP_GPIO_WAKE, Long_Delay);
+ PFIC_EnableIRQ(GPIO_A_IRQn);
+
+ // IN
+ ret = BMP390_IN_InterfaceInit(&DevIn, BMP3_SPI_INTF);
+ bmp3_check_rslt("BMP390_OUT_InterfaceInit", ret);
+
+ ret = bmp3_init(&DevIn);
+ bmp3_check_rslt("bmp3_init", ret);
+ settings.int_settings.drdy_en = BMP3_ENABLE;
+ settings.int_settings.latch = BMP3_INT_PIN_LATCH;
+ settings.int_settings.level = BMP3_INT_PIN_ACTIVE_HIGH;
+ settings.int_settings.output_mode = BMP3_INT_PIN_PUSH_PULL;
+
+ settings.press_en = BMP3_ENABLE;
+ settings.temp_en = BMP3_ENABLE;
+
+ settings.odr_filter.press_os = BMP3_OVERSAMPLING_2X; //BMP3_OVERSAMPLING_2X
+ settings.odr_filter.temp_os = BMP3_OVERSAMPLING_2X; //BMP3_OVERSAMPLING_2X
+ settings.odr_filter.odr = BMP3_ODR_0_78_HZ; //BMP3_ODR_1_5_HZ
+ settings.odr_filter.iir_filter = BMP3_IIR_FILTER_COEFF_1; //BMP3_IIR_FILTER_COEFF_3
+
+ settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_TEMP_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR | BMP3_SEL_DRDY_EN | BMP3_SEL_IIR_FILTER | BMP3_SEL_OUTPUT_MODE | BMP3_SEL_LEVEL | BMP3_SEL_LATCH;
+
+ ret = bmp3_set_sensor_settings(settings_sel, &settings, &DevIn);
+ bmp3_check_rslt("bmp3_set_sensor_settings", ret);
+
+ // OUT
+ ret = BMP390_OUT_InterfaceInit(&DevOut, BMP3_SPI_INTF);
+ bmp3_check_rslt("BMP390_OUT_InterfaceInit", ret);
+
+ ret = bmp3_init(&DevOut);
+ bmp3_check_rslt("bmp3_init", ret);
+ settings.int_settings.drdy_en = BMP3_ENABLE;
+ settings.int_settings.latch = BMP3_INT_PIN_LATCH;
+ settings.int_settings.level = BMP3_INT_PIN_ACTIVE_HIGH;
+ settings.int_settings.output_mode = BMP3_INT_PIN_PUSH_PULL;
+ settings.press_en = BMP3_ENABLE;
+ settings.temp_en = BMP3_ENABLE;
+
+ settings.odr_filter.press_os = BMP3_OVERSAMPLING_2X;
+ settings.odr_filter.temp_os = BMP3_OVERSAMPLING_2X;
+ settings.odr_filter.odr = BMP3_ODR_0_78_HZ;
+ settings.odr_filter.iir_filter = BMP3_IIR_FILTER_COEFF_1;
+
+ settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_TEMP_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR | BMP3_SEL_DRDY_EN | BMP3_SEL_IIR_FILTER | BMP3_SEL_OUTPUT_MODE | BMP3_SEL_LEVEL | BMP3_SEL_LATCH;
+
+ ret = bmp3_set_sensor_settings(settings_sel, &settings, &DevOut);
+ bmp3_check_rslt("bmp3_set_sensor_settings", ret);
+
+ // ATOM
+ ret = BMP390_ATOM_InterfaceInit(&DevAtom, BMP3_SPI_INTF);
+ bmp3_check_rslt("BMP390_ATOM_InterfaceInit", ret);
+
+ ret = bmp3_init(&DevAtom);
+ bmp3_check_rslt("bmp3_init", ret);
+ settings.int_settings.drdy_en = BMP3_ENABLE;
+ settings.int_settings.latch = BMP3_INT_PIN_LATCH;
+ settings.int_settings.level = BMP3_INT_PIN_ACTIVE_HIGH;
+ settings.int_settings.output_mode = BMP3_INT_PIN_PUSH_PULL;
+
+ settings.press_en = BMP3_ENABLE;
+ settings.temp_en = BMP3_ENABLE;
+
+ settings.odr_filter.press_os = BMP3_OVERSAMPLING_2X;
+ settings.odr_filter.temp_os = BMP3_OVERSAMPLING_2X;
+ settings.odr_filter.odr = BMP3_ODR_0_78_HZ;
+ settings.odr_filter.iir_filter = BMP3_IIR_FILTER_COEFF_1;
+
+ settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_TEMP_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR | BMP3_SEL_DRDY_EN | BMP3_SEL_IIR_FILTER | BMP3_SEL_OUTPUT_MODE | BMP3_SEL_LEVEL | BMP3_SEL_LATCH;
+
+ ret = bmp3_set_sensor_settings(settings_sel, &settings, &DevAtom);
+ bmp3_check_rslt("bmp3_set_sensor_settings", ret);
+
+ press_task_id = TMOS_ProcessEventRegister(BMP390_ProcessEvent);
+ tmos_set_event(press_task_id, BMP390_IN_START);
+ //tmos_set_event(press_task_id, BMP390_OUT_START);
+ //tmos_set_event(press_task_id, BMP390_ATOM_START);
+}
+
+uint16_t Check_ProcessEvent(uint8_t task_id, uint16_t events)
+{
+ if (events & CHECK_EVT_START)
+ {
+ if(!fault_state)
+ {
+ //ѹ
+ if(P[0] - P[2] >= 8000)
+ {
+ VALVE_CLOSE();
+ fault_state = 1;
+ tmos_start_task(check_task_id, MOTOR_STOP_EVT, MS1_TO_SYSTEM_TIME(1000));
+ logDebug("motor high close");
+ }
+ //Ƿѹ
+ if(P[0] - P[2] <= 800)
+ {
+ VALVE_CLOSE();
+ fault_state = 2;
+ tmos_start_task(check_task_id, MOTOR_STOP_EVT, MS1_TO_SYSTEM_TIME(1000));
+ logDebug("motor low close");
+ }
+ //
+ if( P[0] - P[1] >= 700)
+ {
+ VALVE_CLOSE();
+ fault_state = 3;
+ tmos_start_task(check_task_id, MOTOR_STOP_EVT, MS1_TO_SYSTEM_TIME(1000));
+ logDebug("motor ver close");
+ }
+ }
+ //ֶط
+ if(motor_flag == 1)
+ {
+ motor_flag = 0;
+ VALVE_OPEN();
+ fault_state = 0;
+ tmos_start_task(check_task_id, MOTOR_STOP_EVT, MS1_TO_SYSTEM_TIME(1000));
+ //LED_VALVE_OPEN;
+ }
+ else if(motor_flag == 2)
+ {
+ motor_flag = 0;
+ VALVE_CLOSE();
+ tmos_start_task(check_task_id, MOTOR_STOP_EVT, MS1_TO_SYSTEM_TIME(1000));
+ //LED_VALVE_CLOSE;
+ }
+ tmos_start_task(check_task_id, CHECK_EVT_START, MS1_TO_SYSTEM_TIME(500)); //100
+ return (events ^ CHECK_EVT_START);
+ }
+ if (events & MOTOR_STOP_EVT)
+ {
+ VALVE_STOP();
+ logDebug("motor STOP");
+ return (events ^ MOTOR_STOP_EVT);
+ }
+ return 0;
+}
+void Function_Check(void)
+{
+ check_task_id = TMOS_ProcessEventRegister(Check_ProcessEvent);
+ tmos_set_event(check_task_id, CHECK_EVT_START);
+}
+
+__INTERRUPT
+__HIGH_CODE
+void GPIOA_IRQHandler(void)
+{
+ if (R16_PA_INT_IF & GPIO_Pin_6)
+ {
+ R16_PA_INT_IF = GPIO_Pin_6;
+ flag = 1;
+ tmos_set_event(press_task_id, BMP390_EVT_READ);
+ //printf("interrupt1\r\n");
+ }
+ else if (R16_PA_INT_IF & GPIO_Pin_12)
+ {
+ R16_PA_INT_IF = GPIO_Pin_12;
+ flag = 2;
+ tmos_set_event(press_task_id, BMP390_EVT_READ);
+ //printf("interrupt2\r\n");
+ }
+ else if (R16_PA_INT_IF & GPIO_Pin_2)
+ {
+ R16_PA_INT_IF = GPIO_Pin_2;
+ flag = 3;
+ tmos_set_event(press_task_id, BMP390_EVT_READ);
+ //printf("interrupt3\r\n");
+ }
+}
diff --git a/bsp/src/bsp_key.c b/bsp/src/bsp_key.c
new file mode 100644
index 0000000..11c6feb
--- /dev/null
+++ b/bsp/src/bsp_key.c
@@ -0,0 +1,344 @@
+#include "bsp_key.h"
+#include "bsp_motor.h"
+#include "bsp_uart.h"
+#include "bsp_led.h"
+#include "log.h"
+#include "SLEEP.h"
+
+// https://www.cnblogs.com/iot-fan/p/14304943.html
+
+#undef LOG_ENABLE
+#define LOG_ENABLE 1
+
+#undef LOG_TAG
+#define LOG_TAG "key"
+
+uint8_t motor_flag;
+tmosTaskID key_task_id = INVALID_TASK_ID;
+
+volatile uint8_t key_wakeup_flag = 0;
+volatile uint8_t key_timeout_flag = 0;
+
+static app_task_evt_handler_t p_handler = NULL;
+
+static volatile uint8_t key_timeout_cnt = 0;
+
+static void KEY_Task_ProcessTmosMsg(tmos_event_hdr_t *pMsg)
+{
+ switch (pMsg->event)
+ {
+ default:
+ logDebug("pMsg->event %04x", pMsg->event);
+ break;
+ }
+}
+
+#if 1
+static uint16_t KEY_Task_ProcessEvent(uint8_t task_id, uint16_t events)
+{
+ if (events & SYS_EVENT_MSG)
+ {
+ uint8_t *pMsg;
+ if ((pMsg = tmos_msg_receive(key_task_id)) != NULL)
+ {
+ KEY_Task_ProcessTmosMsg((tmos_event_hdr_t *)pMsg);
+ // Release the TMOS message
+ tmos_msg_deallocate(pMsg);
+ }
+ // return unprocessed events
+ return (events ^ SYS_EVENT_MSG);
+ }
+
+ if (events & KEY_SCAN_EVT)
+ {
+ static volatile uint8_t key_vaild_times = 0;
+ static volatile bool key_vaild_for_long_press = false;
+ if (IS_KEY_Vaild())
+ {
+ if (key_vaild_times > (KEY_LONG_PRESS_MS / KEY_SACN_MS))
+ { //> 20ms*100=2000ms
+ if (false == key_vaild_for_long_press)
+ {
+ if (NULL != p_handler)
+ {
+ p_handler(kKeyLong);
+ }
+ // PRINT("WE should power switch here\r\n");
+ key_vaild_for_long_press = true;
+ }
+ }
+ else
+ {
+ key_vaild_times++;
+ }
+ key_timeout_cnt = 10;
+ }
+ else
+ { // button release
+
+ if (key_vaild_times)
+ {
+ if ((key_vaild_times) < (KEY_LONG_PRESS_MS / KEY_SACN_MS))
+ {
+ p_handler(kKeyShort);
+ }
+ key_vaild_times = 0;
+ // PRINT("KEY VAILED\r\n");
+ }
+
+ key_vaild_for_long_press = false;
+ }
+ if (key_timeout_cnt)
+ {
+ key_timeout_cnt--;
+ logDebug("key_timeout_cnt %d", key_timeout_cnt);
+ tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(KEY_SACN_MS)); // 40ms
+ }
+ else
+ {
+ p_handler(kKeyRelease);
+ }
+ return (events ^ KEY_SCAN_EVT);
+ }
+
+ // Discard unknown events
+ return 0;
+}
+
+#endif
+
+// 由按键中断唤醒后开启按键扫描
+void BSP_KEY_EnterLowpower(void)
+{
+ // key_wakeup_flag = 0;
+ // tmos_stop_task(key_task_id, KEY_SCAN_EVT);
+
+ // R16_PB_INT_MODE |= KEY_B_PIN; // edge mode
+ // GPIOB_ResetBits(KEY_B_PIN); // edge fall
+ // R16_PB_INT_IF = KEY_B_PIN;
+ // R16_PB_INT_EN |= KEY_B_PIN;
+
+ // 由外部上拉电阻了
+ // 设置为浮空输入模式
+ // GPIOB_SetBits(KEY_B_PIN);
+ // GPIOB_ModeCfg(KEY_B_PIN, GPIO_ModeIN_PU);
+
+ // TODO:按键电平触发设置
+ // 下降沿触发
+ GPIOB_ITModeCfg(KEY_B_PIN, GPIO_ITMode_FallEdge);
+
+ // 开启GPIO的睡眠唤醒,如果需要的话
+ // PWR_PeriphWakeUpCfg(ENABLE, RB_SLP_GPIO_WAKE, Long_Delay);
+ PWR_PeriphWakeUpCfg(ENABLE, RB_GPIO_WAKE_MODE | RB_SLP_GPIO_WAKE, Long_Delay);
+
+ // 开启GPIOB中断
+ PFIC_EnableIRQ(GPIO_B_IRQn);
+
+ BSP_RequestSleep();
+}
+
+void BSP_KEY_ExitLowpower(void)
+{
+ BSP_BlockSleep();
+
+ // 关闭GPIOB中断
+ PFIC_DisableIRQ(GPIO_B_IRQn);
+ PWR_PeriphWakeUpCfg(DISABLE, RB_GPIO_WAKE_MODE | RB_SLP_GPIO_WAKE, Long_Delay);
+}
+
+#if 0
+uint8_t read_button_GPIO(uint8_t button_id)
+{
+ // you can share the GPIO read function with multiple Buttons
+ switch(button_id)
+ {
+ case btn1_id:
+ return (uint8_t)GPIOB_ReadPortPin(KEY_B_PIN);
+ default:
+ // logAssert(0, while (1));
+ return 0;
+ }
+}
+
+void BTN1_PRESS_DOWN_Handler(void* btn)
+{
+ logDebug("BTN1_PRESS_DOWN_Handler");
+ // BSP_KEY_EnterLowpower();
+}
+
+void BTN1_PRESS_UP_Handler(void* btn)
+{
+ logDebug("BTN1_PRESS_UP_Handler");
+ tmos_stop_task(key_task_id, KEY_IDLE_TIMEOUT_EVT);
+ tmos_start_task(key_task_id, KEY_IDLE_TIMEOUT_EVT, MS1_TO_SYSTEM_TIME(1000 * 5));
+ logDebug("tmos_start_task KEY_IDLE_TIMEOUT_EVT");
+ // BSP_KEY_EnterLowpower();
+}
+
+void BTN1_SINGLE_Click_Handler(void* btn)
+{
+ logDebug("BTN1_SINGLE_Click_Handler");
+ // BSP_KEY_EnterLowpower();
+}
+
+void BTN1_DOUBLE_Click_Handler(void* btn)
+{
+ logDebug("BTN1_DOUBLE_Click_Handler");
+ // BSP_KEY_EnterLowpower();
+}
+
+void BTN1_LONG_PRESS_START_Handler(void* btn)
+{
+ logDebug("BTN1_LONG_PRESS_START_Handler");
+ // BSP_KEY_EnterLowpower();
+}
+
+static uint16_t KEY_Task_ProcessEvent(uint8_t task_id, uint16_t events)
+{
+ if (events & SYS_EVENT_MSG)
+ {
+ uint8_t *pMsg;
+ if ((pMsg = tmos_msg_receive(key_task_id)) != NULL)
+ {
+ KEY_Task_ProcessTmosMsg((tmos_event_hdr_t *)pMsg);
+ // Release the TMOS message
+ tmos_msg_deallocate(pMsg);
+ }
+ // return unprocessed events
+ return (events ^ SYS_EVENT_MSG);
+ }
+ // if (events & KEY_WAKEUP_EVT)
+ // {
+ // logDebug("KEY_WAKEUP_EVT");
+
+ // BSP_KEY_ExitLowpower();
+ // return (events ^ KEY_WAKEUP_EVT);
+ // }
+ if (events & KEY_SCAN_EVT)
+ {
+ // 按键没抬起来就继续扫描
+ if (0 == key_timeout_flag)
+ {
+ tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(5));
+ }
+ else
+ {
+ logDebug("KEY_SCAN_EVT timeout");
+ BSP_KEY_EnterLowpower();
+ }
+ // logDebug("KEY_SCAN_EVT");
+ button_ticks();
+
+ return (events ^ KEY_SCAN_EVT);
+ }
+ if (events & KEY_IDLE_TIMEOUT_EVT)
+ {
+ tmos_stop_task(key_task_id, KEY_SCAN_EVT);
+ BSP_KEY_EnterLowpower();
+ logDebug("KEY_IDLE_TIMEOUT_EVT");
+ key_timeout_flag = 1;
+ return (events ^ KEY_IDLE_TIMEOUT_EVT);
+ }
+
+
+ // Discard unknown events
+ return 0;
+}
+#endif
+
+void BSP_KEY_Init(app_task_evt_handler_t handler)
+{
+ p_handler = handler;
+ key_task_id = TMOS_ProcessEventRegister(KEY_Task_ProcessEvent);
+
+ // 由外部上拉电阻了
+ // 设置为浮空输入模式
+ // GPIOB_SetBits(KEY_B_PIN);
+ GPIOB_ModeCfg(KEY_B_PIN, GPIO_ModeIN_PU);
+
+ // 下降沿触发
+ GPIOB_ITModeCfg(KEY_B_PIN, GPIO_ITMode_FallEdge);
+
+ // 开启GPIO的睡眠唤醒,如果需要的话
+ // PWR_PeriphWakeUpCfg(ENABLE, RB_SLP_GPIO_WAKE, Long_Delay);
+ PWR_PeriphWakeUpCfg(ENABLE, RB_GPIO_WAKE_MODE | RB_SLP_GPIO_WAKE, Long_Delay);
+
+ // 开启GPIOB中断
+ PFIC_EnableIRQ(GPIO_B_IRQn);
+
+ tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(KEY_SACN_MS));
+
+ // tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(5));
+
+ //开始一个定时事件,不断的执行,除非运行tmos_stop_task关掉,
+ //tmosTimer具体是 1600 = 1s
+ // BSP_KEY_EnterLowpower();
+}
+
+__HIGH_CODE
+__attribute__((noinline))
+void KEY_ProcessLoop(void)
+{
+ static uint8_t key_flag = 0;
+ // {
+ // if (R16_PB_INT_IF & KEY_B_PIN)
+ // {
+ // R16_PB_INT_IF = KEY_B_PIN;
+ // tmos_set_event(key_task_id, KEY_SCAN_EVT);
+ // logDebug("KEY_ProcessLoop");
+ // }
+ // }
+ if (key_wakeup_flag)
+ {
+ key_wakeup_flag = 0;
+ key_flag = !key_flag;
+ if(key_flag)
+ {
+ motor_flag = 1;
+ logDebug("motor open");
+ }
+ else {
+ motor_flag = 2;
+ logDebug("motor close");
+ }
+ tmos_set_event(key_task_id, KEY_SCAN_EVT);
+ logDebug("KEY_ProcessLoop");
+ }
+
+ // if (key_wakeup_flag)
+ // {
+ // key_wakeup_flag = 0;
+ // tmos_set_event(key_task_id, KEY_SCAN_EVT);
+ // // tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(20));
+ // // tmos_start_task(key_task_id, KEY_IDLE_TIMEOUT_EVT, MS1_TO_SYSTEM_TIME(1000 * 10));
+ // logDebug("key_wakeup_flag");
+ // }
+}
+
+
+__INTERRUPT // 告诉编译器使用硬件压栈
+__HIGH_CODE // 放到RAM里
+void GPIOB_IRQHandler(void)
+{
+ // 阻止睡眠
+ BSP_BlockSleep();
+ // 关按键中断
+ BSP_KEY_ExitLowpower();
+
+ logDebug("KEY IRQ");
+
+ GPIOB_ClearITFlagBit(KEY_B_PIN);
+
+ key_wakeup_flag = 1;
+ // key_timeout_flag = 0;
+
+ // BSP_BlockSleep();
+
+ // if (R16_PB_INT_IF & KEY_B_PIN)
+ // {
+ // R16_PB_INT_IF = KEY_B_PIN;
+ // // tmos_set_event(key_task_id, KEY_SCAN_EVT);
+ // BSP_KEY_ExitLowpower();
+ // }
+ // tmos_set_event(key_task_id,KEY_SCAN_EVT);
+}
diff --git a/bsp/src/bsp_led.c b/bsp/src/bsp_led.c
new file mode 100644
index 0000000..3fa8d0f
--- /dev/null
+++ b/bsp/src/bsp_led.c
@@ -0,0 +1,20 @@
+/*
+ * bsp_led.c
+ *
+ * Created on: 20241216
+ * Author: 123
+ */
+#include "bsp_led.h"
+
+void BSP_LED_Init(void)
+{
+ GPIOA_ResetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);
+ GPIOA_ModeCfg(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN, GPIO_ModeOut_PP_5mA);
+
+ GPIOB_ResetBits(LED_ALARM_PIN);
+ GPIOB_ModeCfg(LED_ALARM_PIN, GPIO_ModeOut_PP_5mA);
+
+ GPIOB_ResetBits(LED_VBAT_PIN);
+ GPIOB_ModeCfg(LED_VBAT_PIN, GPIO_ModeOut_PP_5mA);
+}
+
diff --git a/bsp/src/bsp_ml307r.c b/bsp/src/bsp_ml307r.c
index 7b34ef3..167d4d8 100644
--- a/bsp/src/bsp_ml307r.c
+++ b/bsp/src/bsp_ml307r.c
@@ -6,8 +6,6 @@
#include "stdio.h"
#include "CONFIG.h"
-
-
#undef LOG_ENABLE
#define LOG_ENABLE 1
@@ -16,6 +14,7 @@
static tmosTaskID ml307_task_id = INVALID_TASK_ID;
at_obj_t *ml307r_obj;
+uint8_t databuf[5] = {0x01,0xaa,0x12,0xde,0x39};
void At_Debug(const char *fmt, ...)
{
@@ -127,107 +126,144 @@ static int Module_Read_State(at_env_t *e)
return 0;
}
-static void Module_Get_Imei_Cb(at_response_t *r)
-{
- char imei[16] = {0};
- if (r->code == AT_RESP_OK)
- {
- if (sscanf(r->prefix, "+GSN:%s", imei) == 1)
- {
- r->obj->adap->debug("imei: %s\r\n", r->prefix);
- }
- }
- else
- {
- r->obj->adap->debug("'AT+GSN=1' command response failed!\r\n");
- }
-}
-
-/*
- * @brief ȡIMEI
- * @return
- */
-static void Module_Get_Imei(void)
-{
- at_attr_t attr;
- at_attr_deinit(&attr);
- attr.prefix = "+GSN:";
- attr.cb = Module_Get_Imei_Cb;
- at_send_singlline(ml307r_obj, &attr, "AT+GSN=1");
-}
static void BSP_Read_Module(void)
{
at_do_work(ml307r_obj, NULL, Module_Read_State); // Ч
}
-static void Module_Get_Imsi_Cb(at_response_t *r)
+
+/**
+* @brief Ӧ
+*/
+static void simcom_init_callback(at_response_t *r)
{
- char imsi[60] = {0};
- if (r->code == AT_RESP_OK)
- {
- if (sscanf(r->prefix, "%s\r\n", imsi) == 1)
- {
- r->obj->adap->debug("imsi:%s\r\n", imsi);
- }
- }
- else
- {
- r->obj->adap->debug("'AT+CIMI' command response failed!\r\n");
- }
+ printf("SIM800C Init %s!\r\n",r->code == AT_RESP_OK ? "ok" : "error");
+}
+/*
+* @brief ģʼ
+*/
+static void simcom_init(void)
+{
+ at_attr_t attr;
+ static const char *cmds[] = {
+ "AT+GSN=1",
+ "AT+CIMI",
+ "AT+MCCID",
+ "AT+CPIN?",
+ "AT+CEREG?",
+ "AT+CSQ",
+ NULL,
+ };
+ at_attr_deinit(&attr);
+ attr.cb = simcom_init_callback; //ص
+ at_send_multiline(ml307r_obj, &attr, cmds);
}
/*
- * @brief ȡIMSI
+ * @brief 豸
* @return
*/
-static void Module_Get_Imsi(void)
+static int BSP_Module_Connect_CtWing_Handle(at_env_t *e)
{
- at_attr_t attr;
- at_attr_deinit(&attr);
- attr.prefix = "46";
- attr.suffix = "\r\n";
- attr.cb = Module_Get_Imsi_Cb;
- at_send_singlline(ml307r_obj, &attr, "AT+CIMI");
-}
-
-static void Module_Get_Iccid_Cb(at_response_t *r)
-{
- char iccid[21] = {0};
-
- if (r->code == AT_RESP_OK)
+ switch (e->state)
{
- if (sscanf(r->prefix, "+MCCID: %s\r\n", iccid) == 1)
- {
- r->obj->adap->debug("iccid: %s\r\n", iccid);
+ case 0:
+ logDebug("create device...\r\n");
+ e->println(e, "AT+MIPOPEN=0,\"TCP\",\"8.135.10.183\",32994,,1");
+ e->reset_timer(e);
+ e->state++;
+ break;
+ case 1:
+ if (e->contains(e, "CONNECT"))
+ {
+ logDebug("create device complete\r\n");
+ e->finish(e, AT_RESP_OK);
+ }
+ else if (e->is_timeout(e, 5000))
+ {
+ e->state--;
+ if (++e->i > 3)
+ {
+ logDebug("create device error\r\n");
+ e->finish(e, AT_RESP_ERROR);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+//ӷ
+static void BSP_Module_Connect_CtWing(void)
+{
+ at_do_work(ml307r_obj, NULL, BSP_Module_Connect_CtWing_Handle);//豸
+}
+static int Module_Restart_Work(at_env_t *e)
+{
+ switch (e->state)
+ {
+ case 0:
+ logDebug("restart module...\r\n");
+ e->println(e, "AT+CFUN=1,1");//ģ
+ e->reset_timer(e);
+ e->state++;
+ break;
+ case 1:
+ if (e->contains(e, "OK"))
+ {
+ logDebug("restart module complete\r\n");
+ e->reset_timer(e);
+ e->state++;
+ }
+ if (e->is_timeout(e, 5000))
+ {
+ e->state--;
+ if (++e->i > 3)
+ {
+ logDebug("Module restart error\r\n");
+ e->finish(e, AT_RESP_ERROR);
+ }
+ }
+ break;
+ case 2:
+ logDebug("Check if the Module is ready\r\n");
+ e->println(e, "AT");
+ e->reset_timer(e);
+ e->state++;
+ break;
+ case 3:
+ if (e->contains(e, "OK"))
+ {
+ e->recvclr(e);
+ e->finish(e, AT_RESP_OK);
+ logDebug("Module is ready\r\n");
+ }
+ if (e->is_timeout(e, 5000))
+ {
+ e->state--;
+ if (++e->i > 3)
+ {
+ logDebug("Module error\r\n");
+ e->finish(e, AT_RESP_ERROR);
+ }
+ }
+ break;
}
- }
- else
- {
- r->obj->adap->debug("'AT+QCCID' command response failed!\r\n");
- }
+ return 0;
}
-
-/*
- * @brief ȡICCID
- * @return
- */
-static void Module_Get_Iccid(void)
+//ģ
+static void BSP_Restart_Module(void)
{
- at_attr_t attr;
- at_attr_deinit(&attr);
- attr.prefix = "+MCCID:";
- attr.cb = Module_Get_Iccid_Cb;
- at_send_singlline(ml307r_obj, &attr, "AT+MCCID");
+ at_do_work(ml307r_obj, NULL, Module_Restart_Work);//Ч
}
-
void Ml307r_Loop(void)
{
at_obj_process(ml307r_obj);
}
-
__HIGH_CODE
__attribute__((noinline))
uint16_t Ml307r_Handle(uint8_t task_id, uint16_t events)
@@ -237,11 +273,15 @@ uint16_t Ml307r_Handle(uint8_t task_id, uint16_t events)
Ml307r_Loop();
tmos_start_task(ml307_task_id, ML307_PERIODIC_EVT, MS1_TO_SYSTEM_TIME(5));
return (events ^ ML307_PERIODIC_EVT);
-
}
return 0;
}
-
+//
+void BSP_Module_Send_Data(uint8_t* data, uint8_t len)
+{
+ at_attr_t attr;
+ at_send_data(ml307r_obj, &attr, data, len);
+}
void BSP_Ml307r_Init(void)
{
@@ -256,11 +296,8 @@ void BSP_Ml307r_Init(void)
tmos_set_event(ml307_task_id, ML307_PERIODIC_EVT);
BSP_Read_Module();
- Module_Get_Imei();
- Module_Get_Imsi();
- Module_Get_Iccid();
-
+ simcom_init();
+ BSP_Module_Connect_CtWing();
+ BSP_Module_Send_Data(databuf, 5);
}
-
-
diff --git a/bsp/src/bsp_motor.c b/bsp/src/bsp_motor.c
index c30e0d7..693d03a 100644
--- a/bsp/src/bsp_motor.c
+++ b/bsp/src/bsp_motor.c
@@ -6,33 +6,45 @@
*/
#include "bsp_motor.h"
-void MOTOR_FORWARD_TURN(void)
+//uint8_t motor_state = 0;
+valve_state valve_status = {0};
+void BSP_MOTOR_Init(void)
{
+ GPIOB_ResetBits(NSLEEP_PIN);
+ GPIOB_ModeCfg(NSLEEP_PIN, GPIO_ModeOut_PP_5mA);
+
+ GPIOB_ResetBits(COIL_A);
+ GPIOB_ModeCfg(COIL_A, GPIO_ModeOut_PP_5mA);
+
+ GPIOB_ResetBits(COIL_B);
+ GPIOB_ModeCfg(COIL_B, GPIO_ModeOut_PP_5mA);
+
+ //VALVE_CLOSE();
+}
+void VALVE_OPEN(void)
+{
+ GPIOB_SetBits(NSLEEP_PIN);
//IN1 + ; IN2 -
- GPIOA_SetBits(GPIO_Pin_8);
- GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeOut_PP_5mA);
-
- GPIOA_ResetBits(GPIO_Pin_9);
- GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA);
+ GPIOB_SetBits(COIL_A);
+ GPIOB_ResetBits(COIL_B);
+ valve_status.motor_state = 1;
}
-void MOTOR_RESERVE_TURN(void)
+void VALVE_CLOSE(void)
{
+ GPIOB_SetBits(NSLEEP_PIN);
//IN1 - ; IN2 +
- GPIOA_ResetBits(GPIO_Pin_8);
- GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeOut_PP_5mA);
-
- GPIOA_SetBits(GPIO_Pin_9);
- GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA);
+ GPIOB_ResetBits(COIL_A);
+ GPIOB_SetBits(COIL_B);
+ valve_status.motor_state = 0;
}
-void MOTOR_STOP(void)
+void VALVE_STOP(void)
{
+ GPIOB_ResetBits(NSLEEP_PIN);
//IN1 + ; IN2 +
- GPIOA_SetBits(GPIO_Pin_8);
- GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeOut_PP_5mA);
-
- GPIOA_SetBits(GPIO_Pin_9);
- GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA);
+ GPIOB_SetBits(COIL_A);
+ GPIOB_SetBits(COIL_B);
}
+
diff --git a/bsp/src/bsp_timkey.c b/bsp/src/bsp_timkey.c
new file mode 100644
index 0000000..36b0f06
--- /dev/null
+++ b/bsp/src/bsp_timkey.c
@@ -0,0 +1,8 @@
+/*
+ * bsp_timkey.c
+ *
+ * Created on: 20241219
+ * Author: 123
+ */
+
+
diff --git a/bsp/src/bsp_uart.c b/bsp/src/bsp_uart.c
index 209a1d1..6d67339 100644
--- a/bsp/src/bsp_uart.c
+++ b/bsp/src/bsp_uart.c
@@ -85,7 +85,7 @@ void UART3_FifoInit(void)
lwrb_init(&uart3_tx_t, uart3_tx_buf, sizeof(uart3_tx_buf));
lwrb_init(&uart3_rx_t, uart3_rx_buf, sizeof(uart3_rx_buf));
- lwrb_set_evt_fn(&uart1_rx_t, Uart1_evt_fn);
+ //lwrb_set_evt_fn(&uart1_rx_t, Uart1_evt_fn);
}
@@ -94,7 +94,7 @@ void BSP_UART1_Init(void)
GPIOPinRemap(ENABLE, RB_PIN_UART1);
/* ô1IOģʽô */
- GPIOB_SetBits(ML307_UART_RX_PIN);
+ GPIOB_SetBits(ML307_UART_TX_PIN);
GPIOB_ModeCfg(ML307_UART_RX_PIN, GPIO_ModeIN_PU); // RXD-
GPIOB_ModeCfg(ML307_UART_TX_PIN, GPIO_ModeOut_PP_5mA); // TXD-עIOߵƽ
UART1_DefInit();
@@ -136,7 +136,9 @@ __INTERRUPT
__HIGH_CODE
void UART1_IRQHandler(void)
{
- uint8_t data;
+ uint8_t data,q;
+// q = UART1_GetITFlag();
+// printf("q1 = %#x\r\n", q);
switch(UART1_GetITFlag())
{
case UART_II_LINE_STAT: // ·״̬
@@ -146,7 +148,9 @@ void UART1_IRQHandler(void)
}
case UART_II_RECV_RDY:
data = UART1_RecvByte();
+ UART3_SendByte(data);
lwrb_write(&uart1_rx_t, &data, 1);
+
break;
case UART_II_RECV_TOUT: //
break;
@@ -182,7 +186,9 @@ __INTERRUPT
__HIGH_CODE
void UART3_IRQHandler(void)
{
- uint8_t data;
+ uint8_t data,q;
+// q = UART3_GetITFlag();
+// printf("q3 = %#x\r\n", q);
switch(UART3_GetITFlag())
{
case UART_II_LINE_STAT: // ·״̬
diff --git a/bsp/src/bsp_wf5803.c b/bsp/src/bsp_wf5803.c
deleted file mode 100644
index 3d62382..0000000
--- a/bsp/src/bsp_wf5803.c
+++ /dev/null
@@ -1,756 +0,0 @@
-#include "bsp_wf5803.h"
-#include "CONFIG.h"
-
-uint8_t flag;
-
-typedef enum
-{
- kPressIn = 0,
- kPressOut = 1,
- kPressAtom = 2,
- kPressMaxIndex
-} TePressSensorIndex;
-
-static tmosTaskID press_task_id = INVALID_TASK_ID;
-
-#define PRESS_IN_CS_HIGH() GPIOB_SetBits(GPIO_Pin_9)
-#define PRESS_IN_CS_LOW() GPIOB_ResetBits(GPIO_Pin_9)
-
-#define PRESS_OUT_CS_HIGH() GPIOB_SetBits(GPIO_Pin_4)
-#define PRESS_OUT_CS_LOW() GPIOB_ResetBits(GPIO_Pin_4)
-
-#define PRESS_ATOM_CS_HIGH() GPIOB_SetBits(GPIO_Pin_17)
-#define PRESS_ATOM_CS_LOW() GPIOB_ResetBits(GPIO_Pin_17)
-
-uint8_t volatile press_done_flag = 0;
-
-uint8_t press_raw_data[kPressMaxIndex][5];
-
-// 1 pa
-uint32_t press_value[kPressMaxIndex];
-
-// 0.1 C
-int16_t temp_value[kPressMaxIndex];
-
-uint8_t SPI0_SendByte(uint8_t data);
-void SPI_CsStart(TePressSensorIndex index);
-void SPI_CsStop(TePressSensorIndex index);
-
-/* Variable to store the device address */
-static uint8_t dev_in_addr;
-static uint8_t dev_out_addr;
-
-uint8_t Bmp_ReadData(uint8_t *reg_data, uint32_t len)
-{
- while (len--)
- {
- *reg_data = SPI0_SendByte(0x00);
- reg_data++;
- }
- return BMP3_INTF_RET_SUCCESS;
-}
-
-BMP3_INTF_RET_TYPE Bmp_WriteData(const uint8_t *reg_data, uint32_t len)
-{
- uint8_t i = 0;
- for (i = 0; i < len; i++)
- {
- SPI0_SendByte(reg_data[i]);
- }
- return BMP3_INTF_RET_SUCCESS;
-}
-
-BMP3_INTF_RET_TYPE BMP390_IN_SPI_Read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
-{
- BMP3_INTF_RET_TYPE rslt = 0;
-
- uint8_t reg_spi[1] = {(reg_addr & 0x7F) | 0x80};
- SPI_CsStart(kPressIn); // Ƭѡ
- Bmp_WriteData(reg_spi, 1); // дֽ
- rslt = Bmp_ReadData(reg_data, len);
- SPI_CsStop(kPressIn);
- return rslt;
-}
-
-/*!
- * SPI write function map to COINES platform
- */
-BMP3_INTF_RET_TYPE BMP390_IN_SPI_Write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
-{
- uint8_t reg_spi[1] = {reg_addr & 0x7f};
- BMP3_INTF_RET_TYPE rslt = 0;
-
- SPI_CsStart(kPressIn);
- Bmp_WriteData(reg_spi, 1);
- rslt = Bmp_WriteData(reg_data, len);
- SPI_CsStop(kPressIn);
- // printf("BMP390_OUT_SPI_Write: %d" , rslt);
-
- return rslt;
-}
-
-/*!
- * SPI read function map to COINES platform
- */
-BMP3_INTF_RET_TYPE BMP390_OUT_SPI_Read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
-{
- BMP3_INTF_RET_TYPE rslt = 0;
-
- uint8_t reg_spi[1] = {(reg_addr & 0x7F) | 0x80};
- SPI_CsStart(kPressOut); // Ƭѡ
- Bmp_WriteData(reg_spi, 1); // дֽ
- rslt = Bmp_ReadData(reg_data, len);
- SPI_CsStop(kPressOut);
- return rslt;
-}
-
-/*!
- * SPI write function map to COINES platform
- */
-BMP3_INTF_RET_TYPE BMP390_OUT_SPI_Write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
-{
- uint8_t reg_spi[1] = {reg_addr & 0x7f};
- BMP3_INTF_RET_TYPE rslt = 0;
-
- SPI_CsStart(kPressOut);
- Bmp_WriteData(reg_spi, 1);
- rslt = Bmp_WriteData(reg_data, len);
- SPI_CsStop(kPressOut);
- // printf("BMP390_OUT_SPI_Write: %d" , rslt);
-
- return rslt;
-}
-
-void bmp3_delay_us(uint32_t period, void *intf_ptr)
-{
- DelayUs(period);
-}
-
-void bmp3_check_rslt(const char api_name[], int8_t rslt)
-{
- switch (rslt)
- {
- case BMP3_OK:
-
- /* Do nothing */
- break;
- case BMP3_E_NULL_PTR:
- printf("API [%s] Error [%d] : Null pointer\r\n", api_name, rslt);
- break;
- case BMP3_E_COMM_FAIL:
- printf("API [%s] Error [%d] : Communication failure\r\n", api_name, rslt);
- break;
- case BMP3_E_INVALID_LEN:
- printf("API [%s] Error [%d] : Incorrect length parameter\r\n", api_name, rslt);
- break;
- case BMP3_E_DEV_NOT_FOUND:
- printf("API [%s] Error [%d] : Device not found\r\n", api_name, rslt);
- break;
- case BMP3_E_CONFIGURATION_ERR:
- printf("API [%s] Error [%d] : Configuration Error\r\n", api_name, rslt);
- break;
- case BMP3_W_SENSOR_NOT_ENABLED:
- printf("API [%s] Error [%d] : Warning when Sensor not enabled\r\n", api_name, rslt);
- break;
- case BMP3_W_INVALID_FIFO_REQ_FRAME_CNT:
- printf("API [%s] Error [%d] : Warning when Fifo watermark level is not in limit\r\n", api_name, rslt);
- break;
- default:
- printf("API [%s] Error [%d] : Unknown error code\r\n", api_name, rslt);
- break;
- }
-}
-
-BMP3_INTF_RET_TYPE BMP390_IN_InterfaceInit(struct bmp3_dev *bmp3, uint8_t intf)
-{
- int8_t rslt = BMP3_OK;
-
- /* Bus configuration : SPI */
- if (intf == BMP3_SPI_INTF)
- {
- printf("SPI Interface\n");
- bmp3->read = BMP390_IN_SPI_Read;
- bmp3->write = BMP390_IN_SPI_Write;
- bmp3->intf = BMP3_SPI_INTF;
- printf("spi init ok\r\n");
- }
-
- DelayMs(100);
- bmp3->delay_us = bmp3_delay_us;
- bmp3->intf_ptr = &dev_in_addr;
-
- return rslt;
-}
-
-BMP3_INTF_RET_TYPE BMP390_OUT_InterfaceInit(struct bmp3_dev *bmp3, uint8_t intf)
-{
- int8_t rslt = BMP3_OK;
-
- /* Bus configuration : SPI */
- if (intf == BMP3_SPI_INTF)
- {
- printf("SPI Interface\n");
- bmp3->read = BMP390_OUT_SPI_Read;
- bmp3->write = BMP390_OUT_SPI_Write;
- bmp3->intf = BMP3_SPI_INTF;
- printf("spi init ok\r\n");
- }
-
- DelayMs(100);
- bmp3->delay_us = bmp3_delay_us;
- bmp3->intf_ptr = &dev_out_addr;
-
- return rslt;
-}
-
-void SPI_CsStart(TePressSensorIndex index)
-{
- switch (index)
- {
- case kPressIn:
- PRESS_IN_CS_LOW();
- break;
- case kPressOut:
- PRESS_OUT_CS_LOW();
- break;
- case kPressAtom:
- PRESS_ATOM_CS_LOW();
- break;
-
- default:
- break;
- }
-}
-
-void SPI_CsStop(TePressSensorIndex index)
-{
- switch (index)
- {
- case kPressIn:
- PRESS_IN_CS_HIGH();
- break;
- case kPressOut:
- PRESS_OUT_CS_HIGH();
- break;
- case kPressAtom:
- PRESS_ATOM_CS_HIGH();
- break;
-
- default:
- break;
- }
-}
-
-uint8_t SPI0_SendByte(uint8_t data)
-{
- R8_SPI0_BUFFER = data;
- while (!(R8_SPI0_INT_FLAG & RB_SPI_FREE));
- return (R8_SPI0_BUFFER);
-}
-
-void WF5803_WriteReg(uint8_t Address, uint8_t value, TePressSensorIndex index)
-{
- SPI_CsStart(index);
- SPI0_SendByte(0x00);
- SPI0_SendByte(Address);
- SPI0_SendByte(value);
- SPI_CsStop(index);
-}
-
-uint8_t WF5803_ReadReg(uint8_t addr, TePressSensorIndex index)
-{
- uint8_t value;
- SPI_CsStart(index);
- SPI0_SendByte(0x80);
- SPI0_SendByte(addr);
- value = SPI0_SendByte(0xFF);
- SPI_CsStop(index);
- return value;
-}
-
-void PRESS_IO_SPI_Init(void)
-{
- /**
- * CSB: PB17
- * SCL: PA13
- * SDA: PA14
- * SDO: PA15
- */
- // SDA: MOSI
- // SDO: MISO
-
- // CSB1: PA3
- // GPIOA_SetBits(GPIO_Pin_3);
- // GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeOut_PP_5mA);
-
- // CSB2: PB9
- GPIOB_SetBits(GPIO_Pin_9);
- GPIOB_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA);
-
- // CSB3: PB4
- GPIOB_SetBits(GPIO_Pin_4);
- GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeOut_PP_5mA);
-
- // CSB4: PB17
- GPIOB_SetBits(GPIO_Pin_17);
- GPIOB_ModeCfg(GPIO_Pin_17, GPIO_ModeOut_PP_5mA);
-
- SPI_CsStop(kPressIn);
- SPI_CsStop(kPressOut);
- SPI_CsStop(kPressAtom);
-
- // spiʼģʽ0
- GPIOA_ModeCfg(GPIO_Pin_13 | GPIO_Pin_14, GPIO_ModeOut_PP_5mA);
- GPIOA_ModeCfg(GPIO_Pin_15, GPIO_ModeIN_PU);
-
- SPI0_MasterDefInit();
-}
-
-void WF5803_Init(void)
-{
- PRESS_IO_SPI_Init();
- WF5803_WriteReg(0x00, 0x81, kPressIn); // spiΪģʽ
- WF5803_WriteReg(0x00, 0x81, kPressOut); // spiΪģʽ
- WF5803_WriteReg(0x00, 0x81, kPressAtom); // spiΪģʽ
-}
-
-void PRESS_LowerIO_Init(void)
-{
- // WF5803ĬϹʱIOǸߵƽ
- // SPI
- GPIOA_SetBits(GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
- GPIOA_ModeCfg(GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15, GPIO_ModeIN_PU);
-
- // CSB1: PA3
- // GPIOA_SetBits(GPIO_Pin_3);
- // GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeIN_PU);
- // CSB1: PA3
- // GPIOA_SetBits(GPIO_Pin_3);
- // GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeOut_PP_5mA);
-
- // CSB2: PB9
- GPIOB_SetBits(GPIO_Pin_9);
- GPIOB_ModeCfg(GPIO_Pin_9, GPIO_ModeIN_PU);
-
- // CSB3: PB4
- GPIOB_SetBits(GPIO_Pin_4);
- GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeIN_PU);
-
- // CSB4: PB17
- GPIOB_SetBits(GPIO_Pin_17);
- GPIOB_ModeCfg(GPIO_Pin_17, GPIO_ModeIN_PU);
-}
-
-void Lower_IO_Deinit(void)
-{
- // LED
- GPIOA_ResetBits(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12);
- GPIOA_ModeCfg(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12, GPIO_ModeIN_PD);
-
- // KEY
- GPIOA_ResetBits(GPIO_Pin_7);
- GPIOA_ModeCfg(GPIO_Pin_7, GPIO_ModeIN_PU);
-
- // RESET KEY
- GPIOB_ResetBits(GPIO_Pin_7);
- GPIOB_ModeCfg(GPIO_Pin_7, GPIO_ModeIN_PU);
-
- // motor
- GPIOB_ResetBits(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2);
- GPIOB_ModeCfg(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2, GPIO_ModeIN_PD);
-
- // COIL_ADC
- GPIOA_ResetBits(GPIO_Pin_6);
- GPIOA_ModeCfg(GPIO_Pin_6, GPIO_ModeIN_PD);
-
- // ADC_CTRL,ADC_VBAT
- GPIOA_ResetBits(GPIO_Pin_0 | GPIO_Pin_1);
- GPIOA_ModeCfg(GPIO_Pin_0 | GPIO_Pin_1, GPIO_ModeIN_PD);
-}
-
-void PRESS_LowPower(void)
-{
- Lower_IO_Deinit();
- if (press_done_flag == 1)
- {
- PRESS_LowerIO_Init();
- }
-}
-
-uint8_t GetSensorData(TePressSensorIndex index)
-{
- memset(press_raw_data[index], 0, 5);
-
- if (WF5803_ReadReg(0x02, index) != 0x01)
- {
- PRINT("Status = %02x\r\n", WF5803_ReadReg(0x02, index));
- return 1;
- }
-
- // ѹ
- // ¶
- for (uint8_t i = 0; i < 5; i++)
- {
- press_raw_data[index][i] = WF5803_ReadReg(0x06 + i, index);
- }
-
- return 0;
-}
-
-__HIGH_CODE
-__attribute__((noinline)) void SensorData_Process(TePressSensorIndex index)
-{
- long reading = 0;
- float fDat = 0;
- float press = 0;
- float temp = 0;
-
- GetSensorData(index);
-
- reading = press_raw_data[index][0];
- reading = reading << 8;
- reading |= press_raw_data[index][1];
- reading = reading << 8;
- reading |= press_raw_data[index][2];
- if (reading >= 8388608)
- {
- fDat = (int32_t)(reading - 16777216) / 8388608.0f;
- }
- else
- {
- fDat = reading / 8388608.0f;
- }
-
- press = fDat * 125 + 17.5; // WF5803_1BAR ʹ10mʹ
- press_value[index] = (uint32_t)(press * 1000); // pa
-
- reading = press_raw_data[index][3];
- reading = reading << 8;
- reading |= press_raw_data[index][4];
- if (reading > 32768)
- {
- temp = (reading - 65844) / 256.0f;
- temp_value[index] = (int16_t)(temp * 10); // .1 C
- }
- else
- {
- temp = (reading - 308) / 256.0f;
- temp_value[index] = (int16_t)(temp * 10); // .1 C
- }
-
- // PRINT("P[%d] = %d.%d pa\r\n", index, (int)(press * 1000), ((int)(press * 10000000.0f) % 10000));
- // PRINT("T[%d] = %d.%d \r\n", index, (int)temp, ((int)(temp * 100.0f) % 100));
-}
-
-int8_t ret = 0;
-uint8_t loop = 0;
-struct bmp3_dev DevIn;
-struct bmp3_dev DevOut;
-uint16_t settings_sel;
-struct bmp3_data data = {0};
-struct bmp3_settings settings = {0};
-struct bmp3_status status = {{0}};
-
-__HIGH_CODE
-__attribute__((noinline))
-uint16_t
-WF5803_ProcessEvent(uint8_t task_id, uint16_t events)
-{
- if (events & WF5803_EVT_START)
- {
- press_done_flag = 0;
-
-#if 0
- WF5803_Init();
-
- WF5803_WriteReg(0x30, 0x0A, kPressIn);
- WF5803_WriteReg(0x30, 0x0A, kPressOut);
- WF5803_WriteReg(0x30, 0x0A, kPressAtom);
-#endif
- PRESS_IO_SPI_Init();
- DelayMs(2);
-
- settings.op_mode = BMP3_MODE_FORCED;
- ret = bmp3_set_op_mode(&settings, &DevIn);
- bmp3_check_rslt("bmp3_set_op_mode", ret);
-
- settings.op_mode = BMP3_MODE_FORCED;
- ret = bmp3_set_op_mode(&settings, &DevOut);
- bmp3_check_rslt("bmp3_set_op_mode", ret);
-
- // tmos_start_task(press_task_id, WF5803_EVT_READ, MS1_TO_SYSTEM_TIME(5));
- return (events ^ WF5803_EVT_START);
- }
- else if (events & WF5803_EVT_READ)
- {
-#if 0
- SensorData_Process(kPressIn);
- SensorData_Process(kPressOut);
- SensorData_Process(kPressAtom);
-
- press_value[kPressIn];
- press_value[kPressOut];
- press_value[kPressAtom];
-
- PRINT("%d %d %d pa\r\n", press_value[kPressIn], press_value[kPressOut], press_value[kPressAtom]);
- PRINT("%d %d %d C\r\n", temp_value[kPressIn], temp_value[kPressOut], temp_value[kPressAtom]);
-
- if (press_value[kPressIn] > press_value[kPressOut])
- {
- PRINT("> %d\r\n", press_value[kPressIn] - press_value[kPressOut]);
- }
- else
- {
- PRINT("< %d\r\n", press_value[kPressOut] - press_value[kPressIn]);
- }
-
-#endif
-
-#if 0
- PRESS_IO_SPI_Init();
-
- // IN
- ret = bmp3_get_status(&status, &DevIn);
- bmp3_check_rslt("bmp3_get_status", ret);
-
- /* Read temperature and pressure data iteratively based on data ready interrupt */
- if ((ret == BMP3_OK) && (status.intr.drdy == BMP3_ENABLE))
- {
- /*
- * First parameter indicates the type of data to be read
- * BMP3_PRESS_TEMP : To read pressure and temperature data
- * BMP3_TEMP : To read only temperature data
- * BMP3_PRESS : To read only pressure data
- */
- ret = bmp3_get_sensor_data(BMP3_PRESS_TEMP, &data, &DevIn);
- bmp3_check_rslt("bmp3_get_sensor_data", ret);
-
- /* NOTE : Read status register again to clear data ready interrupt status */
- ret = bmp3_get_status(&status, &DevIn);
- bmp3_check_rslt("bmp3_get_status", ret);
-
- #ifdef BMP3_FLOAT_COMPENSATION
- printf("IN[%d] T: %.2f deg C, P: %.2f Pa\n", loop, (data.temperature), (data.pressure));
- #else
- printf("IN[%d] T: %ld deg C, P: %lu Pa\n", loop, (long int)(int32_t)(data.temperature / 100),
- (long unsigned int)(uint32_t)(data.pressure / 100));
- #endif
- }
-
- // OUT
- ret = bmp3_get_status(&status, &DevOut);
- bmp3_check_rslt("bmp3_get_status", ret);
-
- /* Read temperature and pressure data iteratively based on data ready interrupt */
- if ((ret == BMP3_OK) && (status.intr.drdy == BMP3_ENABLE))
- {
- /*
- * First parameter indicates the type of data to be read
- * BMP3_PRESS_TEMP : To read pressure and temperature data
- * BMP3_TEMP : To read only temperature data
- * BMP3_PRESS : To read only pressure data
- */
- ret = bmp3_get_sensor_data(BMP3_PRESS_TEMP, &data, &DevOut);
- bmp3_check_rslt("bmp3_get_sensor_data", ret);
-
- /* NOTE : Read status register again to clear data ready interrupt status */
- ret = bmp3_get_status(&status, &DevOut);
- bmp3_check_rslt("bmp3_get_status", ret);
-
- #ifdef BMP3_FLOAT_COMPENSATION
- printf("OUT[%d] T: %.2f deg C, P: %.2f Pa\n", loop, (data.temperature), (data.pressure));
- #else
- printf("OUT[%d] T: %ld deg C, P: %lu Pa\n", loop, (long int)(int32_t)(data.temperature / 100),
- (long unsigned int)(uint32_t)(data.pressure / 100));
- #endif
- loop = loop + 1;
- }
- tmos_start_task(press_task_id, WF5803_EVT_START, MS1_TO_SYSTEM_TIME(2000));
-#endif
- if(flag == 1)
- {
- PRESS_IO_SPI_Init();
- ret = bmp3_get_status(&status, &DevIn); // жΪģʽҪȡint_status.drdyλж״̬־
- bmp3_check_rslt("bmp3_get_status", ret);
-
- if (status.intr.drdy == BMP3_ENABLE)
- {
- /*
- * First parameter indicates the type of data to be read
- * BMP3_PRESS_TEMP : To read pressure and temperature data
- * BMP3_TEMP : To read only temperature data
- * BMP3_PRESS : To read only pressure data
- */
- ret = bmp3_get_sensor_data(BMP3_PRESS_TEMP, &data, &DevIn);
- bmp3_check_rslt("bmp3_get_sensor_data", ret);
-
- /* NOTE : Read status register again to clear data ready interrupt status */
- ret = bmp3_get_status(&status, &DevIn);
- bmp3_check_rslt("bmp3_get_status", ret);
-
- printf("IN[%d] T: %ld deg C, P: %lu Pa\n", loop, (long int)(int32_t)(data.temperature / 100),
- (long unsigned int)(uint32_t)(data.pressure / 100));
- }
- }
- if(flag == 2)
- {
- PRESS_IO_SPI_Init();
-
- ret = bmp3_get_status(&status, &DevOut); // жΪģʽҪȡint_status.drdyλж״̬־
- bmp3_check_rslt("bmp3_get_status", ret);
-
- if (status.intr.drdy == BMP3_ENABLE)
- {
- /*
- * First parameter indicates the type of data to be read
- * BMP3_PRESS_TEMP : To read pressure and temperature data
- * BMP3_TEMP : To read only temperature data
- * BMP3_PRESS : To read only pressure data
- */
- ret = bmp3_get_sensor_data(BMP3_PRESS_TEMP, &data, &DevOut);
- bmp3_check_rslt("bmp3_get_sensor_data", ret);
-
- /* NOTE : Read status register again to clear data ready interrupt status */
- ret = bmp3_get_status(&status, &DevOut);
- bmp3_check_rslt("bmp3_get_status", ret);
-
- printf("OUT[%d] T: %ld deg C, P: %lu Pa\n", loop, (long int)(int32_t)(data.temperature / 100),
- (long unsigned int)(uint32_t)(data.pressure / 100));
- }
- }
- loop = loop + 1;
- press_done_flag = 1;
- tmos_start_task(press_task_id, WF5803_EVT_START, MS1_TO_SYSTEM_TIME(1000));
- return (events ^ WF5803_EVT_READ);
- }
- return 0;
-}
-
-void BSP_PRESS_Init(void)
-{
- PRESS_IO_SPI_Init();
-
- // жŵ PB2 PB3
- GPIOB_ModeCfg(GPIO_Pin_2, GPIO_ModeIN_PD);
- GPIOB_ITModeCfg(GPIO_Pin_2, GPIO_ITMode_RiseEdge);
-
- GPIOB_ModeCfg(GPIO_Pin_3, GPIO_ModeIN_PD);
- GPIOB_ITModeCfg(GPIO_Pin_3, GPIO_ITMode_RiseEdge);
-
- PWR_PeriphWakeUpCfg(ENABLE, RB_GPIO_WAKE_MODE | RB_SLP_GPIO_WAKE, Long_Delay);
- PFIC_EnableIRQ(GPIO_B_IRQn);
-
- // IN
- ret = BMP390_IN_InterfaceInit(&DevIn, BMP3_SPI_INTF);
- bmp3_check_rslt("BMP390_OUT_InterfaceInit", ret);
-
- ret = bmp3_init(&DevIn);
- bmp3_check_rslt("bmp3_init", ret);
- settings.int_settings.drdy_en = BMP3_ENABLE;
- settings.int_settings.latch = BMP3_INT_PIN_LATCH;
- settings.int_settings.level = BMP3_INT_PIN_ACTIVE_HIGH;
- settings.int_settings.output_mode = BMP3_INT_PIN_PUSH_PULL;
-
- settings.press_en = BMP3_ENABLE;
- settings.temp_en = BMP3_ENABLE;
-
- settings.odr_filter.press_os = BMP3_OVERSAMPLING_2X;
- settings.odr_filter.temp_os = BMP3_OVERSAMPLING_2X;
- settings.odr_filter.odr = BMP3_ODR_1_5_HZ;
- settings.odr_filter.iir_filter = BMP3_IIR_FILTER_COEFF_3;
-
- settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_TEMP_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR | BMP3_SEL_DRDY_EN | BMP3_SEL_IIR_FILTER | BMP3_SEL_OUTPUT_MODE | BMP3_SEL_LEVEL | BMP3_SEL_LATCH;
-
- ret = bmp3_set_sensor_settings(settings_sel, &settings, &DevIn);
- bmp3_check_rslt("bmp3_set_sensor_settings", ret);
-
- // settings.op_mode = BMP3_MODE_NORMAL;
- // ret = bmp3_set_op_mode(&settings, &DevIn);
- // bmp3_check_rslt("bmp3_set_op_mode", ret);
-
- // OUT
- ret = BMP390_OUT_InterfaceInit(&DevOut, BMP3_SPI_INTF);
- bmp3_check_rslt("BMP390_OUT_InterfaceInit", ret);
-
- ret = bmp3_init(&DevOut);
- bmp3_check_rslt("bmp3_init", ret);
- settings.int_settings.drdy_en = BMP3_ENABLE;
- settings.int_settings.latch = BMP3_INT_PIN_LATCH;
- settings.int_settings.level = BMP3_INT_PIN_ACTIVE_HIGH;
- settings.int_settings.output_mode = BMP3_INT_PIN_PUSH_PULL;
- settings.press_en = BMP3_ENABLE;
- settings.temp_en = BMP3_ENABLE;
-
- settings.odr_filter.press_os = BMP3_OVERSAMPLING_2X;
- settings.odr_filter.temp_os = BMP3_OVERSAMPLING_2X;
- settings.odr_filter.odr = BMP3_ODR_1_5_HZ;
- settings.odr_filter.iir_filter = BMP3_IIR_FILTER_COEFF_3;
-
- settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_TEMP_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR | BMP3_SEL_DRDY_EN | BMP3_SEL_IIR_FILTER | BMP3_SEL_OUTPUT_MODE | BMP3_SEL_LEVEL | BMP3_SEL_LATCH;
-
- ret = bmp3_set_sensor_settings(settings_sel, &settings, &DevOut);
- bmp3_check_rslt("bmp3_set_sensor_settings", ret);
-
- // settings.op_mode = BMP3_MODE_NORMAL;
- // ret = bmp3_set_op_mode(&settings, &DevOut);
- // bmp3_check_rslt("bmp3_set_op_mode", ret);
-
- press_task_id = TMOS_ProcessEventRegister(WF5803_ProcessEvent);
- tmos_set_event(press_task_id, WF5803_EVT_START);
-}
-
-#if 0
-volatile uint8_t flag = 0;
-// __INTERRUPT
-// __HIGH_CODE
-void BMP390_IN_IRQ(void)
-{
- if (flag)
- {
- flag = 0;
- ret = bmp3_get_status(&status, &DevIn); // жΪģʽҪȡint_status.drdyλж״̬־
- bmp3_check_rslt("bmp3_get_status", ret);
-
- if (status.intr.drdy == BMP3_ENABLE)
- {
- printf("interrupt\r\n");
- /*
- * First parameter indicates the type of data to be read
- * BMP3_PRESS_TEMP : To read pressure and temperature data
- * BMP3_TEMP : To read only temperature data
- * BMP3_PRESS : To read only pressure data
- */
- ret = bmp3_get_sensor_data(BMP3_PRESS_TEMP, &data, &DevIn);
- bmp3_check_rslt("bmp3_get_sensor_data", ret);
-
- /* NOTE : Read status register again to clear data ready interrupt status */
- ret = bmp3_get_status(&status, &DevIn);
- bmp3_check_rslt("bmp3_get_status", ret);
-
- printf("IN[%d] T: %ld deg C, P: %lu Pa\n", loop, (long int)(int32_t)(data.temperature / 100),
- (long unsigned int)(uint32_t)(data.pressure / 100));
- loop = loop + 1;
- }
- }
-}
-#endif
-
-__INTERRUPT
-__HIGH_CODE
-void GPIOB_IRQHandler(void)
-{
- if (R16_PB_INT_IF & GPIO_Pin_2)
- {
- R16_PB_INT_IF = GPIO_Pin_2;
- flag = 1;
- tmos_set_event(press_task_id, WF5803_EVT_READ);
- printf("interrupt1\r\n");
- }
- if (R16_PB_INT_IF & GPIO_Pin_3)
- {
- R16_PB_INT_IF = GPIO_Pin_3;
- flag = 2;
- tmos_set_event(press_task_id, WF5803_EVT_READ);
- printf("interrupt2\r\n");
- }
-}