1、battery_service 去掉部分日志
authorSnickerSun <snickersun@163.com>
Mon, 26 Feb 2024 17:27:07 +0000 (01:27 +0800)
committerSnickerSun <snickersun@163.com>
Mon, 26 Feb 2024 17:27:07 +0000 (01:27 +0800)
2、添加cywee库,编译通过,未使能
3、添加slip+lwip,编译通过,已经使能,cat1 对应固件未能工作,联调未完成。
4、ppg服务重构,at指令测试通过,数据上传UI 还未完成
5、fota配置默认 application查分升级,验证未能通过,生成ota文件失败,提交问题单,解决中。
6、添加SPO2消息,未验证
7、表冠消息添加代码完成,调试未通过,问题分析修复中。
8、alipay休眠后无法恢复问题解决。硬件能力调通,还需切换到本公司阿里账号下

80 files changed:
code/sdk/application/battery/service/battery_service.cpp
code/sdk/application/brandy/brandy_standard/service_init.c
code/sdk/application/brandy/brandy_standard/thread_pri_init.c
code/sdk/application/wearable/alipay/driver_adapt/soc_adapt.c
code/sdk/application/wearable/alipay/driver_adapt/vendor_product.c
code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp
code/sdk/application/wearable/nativeapp/nativeui/heartrate/include/HeartModel.h
code/sdk/application/wearable/ohos_deps/wearable_log.h
code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h
code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c
code/sdk/build/config/target_config/brandy/config.py
code/sdk/build/config/target_config/brandy/fota/fota.cfg
code/sdk/build/script/build_upg_pkg.py
code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h
code/sdk/drivers/chips/brandy/porting/uart/uart_porting.c
code/sdk/drivers/peripheral/CMakeLists.txt
code/sdk/drivers/peripheral/cywee/CMakeLists.txt [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/Inc/CWM_CustomDataStruct.h [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/Inc/CWM_EventStructure.h [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/Inc/OsApi.h [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/Inc/cwm_lib.h [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/Inc/cwm_lib_dml.h [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/Inc/simulate_signal.h [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_DML_clang_riscv.a [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.a [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/doc/CWM lib Sensor Info_Gnt_Fd230_20240222.xlsx [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/doc/Cwm_Dml_Info__LIS2DOC__20230816.xlsx [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/doc/CyweeMotion Driver Manger Lib Porting Guide_v1.0 1.pdf [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/doc/CyweeMotion_Algo Lib_Tutorial_v1.3_20200903 1.pdf [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/doc/CyweeMotion_MotionSensor_Adjust_Guide_v1.6 1.pdf [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/src/board_apollo3.c [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/src/board_nordic.c [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/src/board_yh601s.c [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/src/config.h [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/src/main.c [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/src/main_dml.c [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/src/test_api.c [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/tools/cwm_log_check.py [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/tools/cwm_log_check__readme.txt [new file with mode: 0644]
code/sdk/drivers/peripheral/ppg/CMakeLists.txt
code/sdk/drivers/peripheral/ppg/hx3695/CMakeLists.txt [new file with mode: 0644]
code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c
code/sdk/drivers/peripheral/ppg/hx3695/hx3695.h
code/sdk/drivers/peripheral/ppg/hx3695/hx3695_at_cmd.c [deleted file]
code/sdk/drivers/peripheral/ppg/hx3695/hx3695_factory_test.c
code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c [new file with mode: 0644]
code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.h [new file with mode: 0644]
code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_agc.c
code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_agc.h
code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_custom.c
code/sdk/drivers/peripheral/ppg/hx3695/hx3695_spo2_agc.h
code/sdk/drivers/peripheral/ppg/hx3695/tyhx_hrs_custom.h
code/sdk/drivers/peripheral/ppg/service/CMakeLists.txt [new file with mode: 0644]
code/sdk/drivers/peripheral/ppg/service/ppg_at_cmd.cpp [new file with mode: 0644]
code/sdk/drivers/peripheral/ppg/service/ppg_at_cmd.h [moved from code/sdk/drivers/peripheral/ppg/hx3695/hx3695_at_cmd.h with 90% similarity]
code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp [new file with mode: 0644]
code/sdk/drivers/peripheral/ppg/service/ppg_service.h [new file with mode: 0644]
code/sdk/drivers/peripheral/rotary_encoder/rotary_encoder_drv.c
code/sdk/drivers/peripheral/slip/CMakeLists.txt
code/sdk/drivers/peripheral/slip/asio.c
code/sdk/drivers/peripheral/slip/cat1slip.c [deleted file]
code/sdk/drivers/peripheral/slip/slipif.c
code/sdk/drivers/peripheral/slip/uart_slip.c
code/sdk/drivers/peripheral/slip/uart_slip.h
code/sdk/drivers/peripheral/slip/udp_server.c
code/sdk/drivers/peripheral/utils/custom_utils.c
code/sdk/drivers/peripheral/utils/custom_utils.h
code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c
code/sdk/middleware/chips/brandy/pm/pm_adapt/pm_core.c
code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dock/lite_encoder_device.h
code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/lite_input_distributer.cpp
code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/lite_input_hal.cpp
code/sdk/middleware/services/gui/uikit/proprietary/src/utils/innerkits/hals/lite_input_distributer.h
code/sdk/middleware/services/gui/uikit/utils/interfaces/kits/gfx_utils/input_event_info.h
code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt
code/sdk/open_source/openharmony/third_party/lwip/doc/doxygen/output/index.html [deleted file]
code/sdk/open_source/openharmony/third_party/lwip/port/include/lwipopts.h
code/sdk/open_source/openharmony/third_party/lwip/src/Filelists.cmake
code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/debug.h
code/sdk/open_source/openharmony/third_party/lwip/src/include/netif/slipif.h

index 8b6da74..82f0e8c 100644 (file)
@@ -201,7 +201,7 @@ static void battery_check_task(void const *arg)
             
                 if (g_check_count*CHARGE_CHECK_TIMER_CYCLE_MS  >= ENABLE_CHARGE_TIMEOUT_MS)
                 {
-                    PRINT("BATTERY_CMD_CHECK_VOLTAGE disable_charge \r\n");
+                    // PRINT("BATTERY_CMD_CHECK_VOLTAGE disable_charge \r\n");
 
                     g_check_count = 0 ;
                     //超时交换状态
@@ -213,7 +213,7 @@ static void battery_check_task(void const *arg)
             }else if (last_battery_charge_enable_status == false) {
                 if (g_check_count*CHARGE_CHECK_TIMER_CYCLE_MS  >= DISABLE_CHARGE_CHECK_MS)
                 {
-                    PRINT("BATTERY_CMD_CHECK_VOLTAGE battery_check_and_enable_charge \r\n");
+                    // PRINT("BATTERY_CMD_CHECK_VOLTAGE battery_check_and_enable_charge \r\n");
 
                     g_check_count = 0 ;
                     //超时交换状态
@@ -224,10 +224,10 @@ static void battery_check_task(void const *arg)
                 
             }
         }else if (mail.comm.event == BATTERY_CMD_CHARGE_PLUG) {
-            PRINT("[battery][service] charger_plug_event_ui_sendmsg_toUI plugged \n");
+            // PRINT("[battery][service] charger_plug_event_ui_sendmsg_toUI plugged \n");
             charger_plug_event_ui_sendmsg_toUI(1);
         }else if (mail.comm.event == BATTERY_CMD_CHARGE_UNPLUG) {
-            PRINT("[battery][service] charger_plug_event_ui_sendmsg_toUI unplugged \n");
+            // PRINT("[battery][service] charger_plug_event_ui_sendmsg_toUI unplugged \n");
             charger_plug_event_ui_sendmsg_toUI(0);
         }
     }
@@ -307,9 +307,6 @@ errcode_t charger_plug_event_ui_sendmsg_toUI(uint8_t plugged)
     /**通过UI事件发送Notify*/
     GraphicService::GetInstance()->PostGraphicEvent(std::bind(charger_plug_event_notify, plugged));
 
-    // /**直接发送Notify , 会直接挂掉。*/
-    // charger_plug_event_notify(plugged);
-
     return ERRCODE_SUCC;
 }
 
index 14a3975..cfd1582 100755 (executable)
@@ -38,8 +38,8 @@
 #include "media_cmd_manager.h"\r
 #endif\r
 \r
-#ifdef SUPPORT_AT_HX3695\r
-#include "hx3695_at_cmd.h"\r
+#ifdef SUPPORT_AT_PPG\r
+#include "ppg_at_cmd.h"\r
 #endif\r
 \r
 #ifdef SUPPORT_AT_VIBRATOR\r
@@ -105,9 +105,9 @@ static void register_at_service(void)
     at_cmd_add_moudle(media_table, media_cmd_count);\r
 #endif\r
 \r
-#ifdef SUPPORT_AT_HX3695\r
+#ifdef SUPPORT_AT_PPG\r
     uint32_t hx3695_cmd_count;\r
-    at_cmd_table_t *hx3695_table = get_hx3695_cmd_table(&hx3695_cmd_count);\r
+    at_cmd_table_t *hx3695_table = get_ppg_cmd_table(&hx3695_cmd_count);\r
     at_cmd_add_moudle(hx3695_table, hx3695_cmd_count);\r
 #endif\r
 \r
index 2958163..44b6ad1 100755 (executable)
 #endif\r
 #include "clocks_config.h"\r
 \r
+#ifdef ENABLE_SLIP\r
+#include "uart_slip.h"\r
+#endif\r
+\r
 #define EMMC_BASE_ADDR              0x52062000\r
 #define TASK_PRIORITY_APP           (osPriority_t)(17)\r
 #define TICK_TEN_MS                 (10U)\r
@@ -329,6 +333,15 @@ static void thread_main(const void *unused)
 #ifdef SUPPORT_ALIPAY_SEC\r
     uapi_alipay_svr_init();\r
 #endif\r
+\r
+#ifdef SUPPORT_PPG_SERVICE\r
+    uapi_ppg_service_init();\r
+#endif\r
+\r
+#ifdef ENABLE_SLIP\r
+    slip_uart_init();\r
+#endif\r
+\r
     set_startup_finish_flag();\r
 }\r
 \r
index 3ace855..60b4096 100755 (executable)
@@ -92,7 +92,7 @@ void IIC_Master_Receive(unsigned char byAddr, unsigned char *pData, unsigned sho
     }\r
 \r
     if (ret != ERRCODE_SUCC) {\r
-        MyPrintf("se i2c data read fail! ret=0x%x", ret);\r
+        if (ret != ERRCODE_I2C_TIMEOUT) MyPrintf("se i2c data read fail! and not equal ERRCODE_I2C_TIMEOUT , ret=0x%x", ret);\r
     }\r
 #if PRINT_I2C_LOG\r
     char printbuf[128*3]={0};\r
@@ -120,3 +120,15 @@ void Set_GPIO_State(unsigned char byState)
 {\r
     uapi_gpio_set_val(ALIPAY_SEC_GPIO, byState);\r
 }\r
+\r
+void alipay_suspend(void)\r
+{\r
+    i2c_save_reg(ALIPAY_SEC_I2C_INDEX);\r
+\r
+}\r
+\r
+void alipay_resume(void)\r
+{\r
+\r
+    i2c_recovery_reg(ALIPAY_SEC_I2C_INDEX);\r
+}
\ No newline at end of file
index ee186f2..fbf289d 100755 (executable)
@@ -19,6 +19,8 @@
 extern void Ble_SendDataSimple(uint16_t handle, uint8_t *data, uint16_t len);
 extern uint32_t Unix_time;
 
+// #define ALIPAY_CSI_LOG_EXT_ON
+
 #define ALIPAY_BLE_MAC_ADDR_NUM 6
 #define ALIPAY_ADAPT_LOG_MAX_NUM 300
 
index 79a4c1c..a56deb9 100644 (file)
@@ -175,7 +175,7 @@ void HeartModel::HandleMaxHeart(uint16 coord, uint16 value)
 {\r
     healthDatas.heartRateMax.x = coord;\r
     healthDatas.heartRateMax.y = value;\r
-    // 插入最大心率\r
+    // 插入最大心率 countMax 数据个数\r
     if (preMaxValue != healthDatas.heartRateMax.y && aveCount < HEART_AVE_NUM) {\r
         if (preMaxX == healthDatas.heartRateMax.x && countMax < HEART_AVE_NUM) {\r
             healthDatas.heartRateAvg[countMax].y = healthDatas.heartRateMax.y;\r
@@ -206,16 +206,26 @@ void HeartModel::HandleMinHeart(uint16 coord, uint16 value)
     healthDatas.heartRateMin.x = coord;\r
     healthDatas.heartRateMin.y = value;\r
     // 插入最小心率\r
+    //avecount 当下有效数据个数,在MaxHeart中也用到,看起来似乎有问题???\r
+    //preMinValue 上一个心率最小值\r
+    //preMinX 上一个最小值对应的坐标\r
+    //当上一个值与当前值不等,且没有超过总数限制,则进行数据处理\r
     if (preMinValue != healthDatas.heartRateMin.y && aveCount < HEART_AVE_NUM) {\r
+\r
+        \r
         if (preMinX == healthDatas.heartRateMin.x && countMin < HEART_AVE_NUM) {\r
+            // 上一个最小坐标和当前值一致,且数据没超过限制,则直接赋值给有效数据 countMin 即可\r
             healthDatas.heartRateAvg[countMin].y = healthDatas.heartRateMin.y;\r
         } else if (aveCount > NUM_2 && (healthDatas.heartRateMin.x == healthDatas.heartRateAvg[aveCount - 1].x)) {\r
+            //有效数据大于2,且当前x值与原始数据最后一个x一致,最后一个数据赋值\r
             healthDatas.heartRateAvg[aveCount - 1].y = healthDatas.heartRateMin.y;\r
         } else {\r
             healthDatas.heartRateAvg[aveCount] = healthDatas.heartRateMin;\r
             countMin = aveCount;\r
             aveCount++;\r
         }\r
+\r
+        //最初的值一直是0 ,则只显示1个 ,不会在后面增加数据。\r
         if (healthDatas.heartRateMin.x != 0) {\r
             if (healthDatas.heartRateAvg[0].x == 0 && healthDatas.heartRateAvg[1].x == 0) {\r
                 for (int i = 0; i < (aveCount - 1); i++) {\r
index e073bce..1a97e8e 100755 (executable)
@@ -31,14 +31,14 @@ typedef struct {
 } HeartPoint;\r
 \r
 typedef struct {\r
-    uint16_t perSec;\r
-    uint16_t rest;\r
-    uint16_t minX;\r
-    uint16_t minValue;\r
-    uint16_t maxX;\r
-    uint16_t maxValue;\r
-    uint16_t index;\r
-    Point value[HEART_ALL_POINTS];\r
+    uint16_t perSec;  //每秒心率\r
+    uint16_t rest;  //静息心率\r
+    uint16_t minX;  //最小坐标(实际上是时间)\r
+    uint16_t minValue;  //最小值?\r
+    uint16_t maxX; //最大值时X坐标,相当于第几个测量值\r
+    uint16_t maxValue; //最大值 心率测量值\r
+    uint16_t index;  //value 有效值个数\r
+    Point value[HEART_ALL_POINTS]; //\r
 } HeartInfo;\r
 \r
 #pragma pack(4)\r
index bca0132..1311b1f 100755 (executable)
@@ -69,12 +69,12 @@ typedef enum {
 #if __cplusplus
 
 /* -------------------------------------------------------------------------- */
-#define DEBUG 1  // 1表示开启打印,0表示关闭打印
-#if DEBUG
-#define DEBUG_PRINT(msg)  printf("File: %s, Line: %d - %s\n", __FILE__, __LINE__, msg)
-#else
-#define PRINT_DEBUG() // 空语句,即关闭打印
-#endif
+// #define DEBUG 1  // 1表示开启打印,0表示关闭打印
+// #if DEBUG
+// #define PRINT_DEBUG(msg)  printf("File: %s, Line: %d - %s\n", __FILE__, __LINE__, msg)
+// #else
+// #define PRINT_DEBUG() // 空语句,即关闭打印
+// #endif
 /* -------------------------------------------------------------------------- */
 }
 #endif
index 96bdf46..c016d5d 100755 (executable)
@@ -46,6 +46,9 @@ typedef enum {
 #ifdef SUPPORT_CHARGER_PLUG_DETECTION_NOTIFICATION
     TOPIC_EVENT_CHARGE_PLUG,
     TOPIC_EVENT_CHARGE_UNPLUG,
+#endif
+#ifdef SUPPORT_SPO2_NOTIFICATION
+    TOPIC_EVENT_SPO2_UPDATE,
 #endif
     TOPIC_END_NUM = 20000,
 } TopicNum;
index 5bd4a5c..9ce572d 100755 (executable)
@@ -26,6 +26,9 @@ static const TopicToCore topicToCoreArray[] = {
     {TOPIC_EVENT_STEPDATA_UPDATE, A_CORE_MASK, 1},
     {TOPIC_EVENT_SHUTDOWN, A_CORE_MASK, 1},
     {TOPIC_EVENT_HEARTRATE_UPDATA, A_CORE_MASK, 1},
+#ifdef SUPPORT_SPO2_NOTIFICATION
+    {TOPIC_EVENT_SPO2_UPDATE, A_CORE_MASK, 1},
+#endif
     {TOPIC_EVENT_HFP_INCOMMING, A_CORE_MASK, 1},
     {TOPIC_EVENT_HFP_PHONE_ACTIVE, A_CORE_MASK, 1},
     {TOPIC_EVENT_HFP_WATCH_ACTIVE, A_CORE_MASK, 1},
index 5bc3fcb..6754e2e 100755 (executable)
@@ -123,12 +123,15 @@ target = {
                     'ENABLE_VIBRATOR',
                     'ENABLE_SLIP',
                     'ENCODER_SUPPORT',
+                    'SUPPORT_SPO2_NOTIFICATION',
+                    'SUPPORT_SPO2_NOTIFICATION_TEST',
                     #'CONFIG_ADC_SUPPORT_AUTO_SCAN','CONFIG_ADC_SUPPORT_LONG_SAMPLE',
                     'MIPI_ULPS_SUPPORT', 
                     'ENABLE_FONT_VECTOR_GLOBAL', 
                     'ENABLE_SHAPING',
                     'TPTYPE_FT6X46',
                     'SUPPORT_CHARGER_PLUG_DETECTION_NOTIFICATION',
+                    'SUPPORT_AT_CUSTOMUTILS',
                     'SUPPORT_ALIPAY_SEC'
                     ],
         'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite",
@@ -151,12 +154,13 @@ target = {
                           "vibrator",
                           "vibrator_service",
                           "lwIP",
-                        #   "slip",
+                          "slip",
                           "audio_manager",
                           "custom_utils",
                           "rotary_encoder",
                           #"nativelauncher",
                            "fd230launcher",
+                           "ppg_service",
                           "batterry_service"
                                                  ],
         'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_uikit', 'bgh_audio', 'dfx_set', 'ohos_set', 'wearable_set', 'alipay_set'],
index 02a9707..a282d98 100755 (executable)
@@ -239,7 +239,7 @@ ImageId=0x4B0F2D2D
     # 0x3C7896E1 - compressed image
     # 0x44494646 - diff image
     # other :原始镜像不处理
-DecompressFlag=0
+DecompressFlag=0x3C7896E1
 
 # ReRncFlag:升级镜像加密标记
     # 0x3C7896E1:加密
index bb9a674..4fcc44a 100755 (executable)
@@ -329,7 +329,7 @@ def get_image_bin_data(fota_image, image_confg_key, fota_obj):
         cmd = ' '.join([fota_obj.upg_tool, '4', '"%s"' % diff_cfg_file])
         ret = subprocess.run(cmd, shell=True)
         if ret.returncode != 0:
-            sys.exit("run diff tool failed: %d" % ret)
+            sys.exit("run diff tool failed: %s" % ret)
     with open(image_bin_file, 'rb') as fp: # 不压缩时新镜像和原镜像一致, file为原镜像
         image_bin= fp.read()
     file_stats = os.stat(image_bin_file)
index c67ea8f..b60dff1 100755 (executable)
@@ -275,7 +275,8 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = {
     /**G sensor G_INT1 S_AGPIO_L11 G_INT2 S_AGPIO_L19*/
     {   S_AGPIO_L11, HAL_GPIO_DIRECTION_INPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
     {   S_AGPIO_L19, HAL_GPIO_DIRECTION_INPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
-
+    /**S_AGPIO_R1 GPO alipay默认resetpin*/
+    {   S_AGPIO_R1, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
 };
 /**
  * @}
index 113d914..b0905ba 100755 (executable)
@@ -181,7 +181,11 @@ static uart_config_t g_uart_config[UART_BUS_MAX_NUMBER] = {
         NULL,
 #endif
         {
+            #ifdef ENABLE_SLIP
+            .baud_rate = 921600,
+            #else
             .baud_rate = 2000000,
+            #endif
             .data_bits = UART_DATA_BIT_8,
             .parity = UART_PARITY_NONE,
             .stop_bits = UART_STOP_BIT_1,
@@ -301,6 +305,10 @@ static void at_cmd_uart_rx_callback(const void *buf, uint16_t buf_len, bool rema
     #ifndef FT_SINGLE_UART
     at_cmd_msg_receive_handler((uint8_t *)buf, buf_len);
     #endif
+
+    #ifdef ENABLE_SLIP
+    slip_receive_handler((uint8_t *)buf, buf_len);
+    #endif
     hal_uart_clear_pending(SW_DEBUG_UART_BUS);
 }
 #endif
index 13c1597..4971908 100644 (file)
@@ -14,3 +14,4 @@ add_subdirectory_if_exist(slip)
 add_subdirectory_if_exist(utils)
 add_subdirectory_if_exist(rotary_encoder)
 add_subdirectory_if_exist(vibrator/service)
+# add_subdirectory_if_exist(cywee)
diff --git a/code/sdk/drivers/peripheral/cywee/CMakeLists.txt b/code/sdk/drivers/peripheral/cywee/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7ed64c0
--- /dev/null
@@ -0,0 +1,46 @@
+#===============================================================================
+# @brief    cmake file
+# Copyright (c) @CompanyNameMagicTag 2022-2023. All rights reserved.
+#===============================================================================
+set(COMPONENT_NAME "cywee")
+
+set(SOURCES ${SOURCES}
+    ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/src/main_dml.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/test_api.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/board_yh601s.c
+)
+set(PUBLIC_HEADER
+    ${CMAKE_CURRENT_SOURCE_DIR}/Inc
+)
+
+set(PRIVATE_HEADER
+)
+
+set(PRIVATE_DEFINES
+)
+
+set(PUBLIC_DEFINES
+)
+
+# use this when you want to add ccflags like -include xxx
+set(COMPONENT_PUBLIC_CCFLAGS
+)
+
+set(COMPONENT_CCFLAGS
+
+)
+
+set(WHOLE_LINK
+    true
+)
+
+set(MAIN_COMPONENT
+    false
+)
+
+find_library(LIB_PATH_CWM_LIB_DML Lib/CWM_LIB_DML_clang_riscv.a ${CMAKE_CURRENT_SOURCE_DIR})
+find_library(LIB_PATH_CWM_LIB Lib/CWM_LIB_clang_riscv.a ${CMAKE_CURRENT_SOURCE_DIR})
+target_link_libraries(${TARGET_NAME} PRIVATE -Wl,--whole-archive ${LIB_PATH_CWM_LIB_DML} ${LIB_PATH_CWM_LIB} PRIVATE -Wl,--whole-archive)
+
+build_component()
diff --git a/code/sdk/drivers/peripheral/cywee/Inc/CWM_CustomDataStruct.h b/code/sdk/drivers/peripheral/cywee/Inc/CWM_CustomDataStruct.h
new file mode 100644 (file)
index 0000000..0b91970
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef __CWM_CUSTOMDATASTRUCT_H__
+#define __CWM_CUSTOMDATASTRUCT_H__
+
+typedef struct CustomSensorData {
+    uint32_t sensorType;
+    float fData[16];
+    double dData[10];
+} CustomSensorData;
+
+#endif /* __CWM_CUSTOMDATASTRUCT_H__ */
diff --git a/code/sdk/drivers/peripheral/cywee/Inc/CWM_EventStructure.h b/code/sdk/drivers/peripheral/cywee/Inc/CWM_EventStructure.h
new file mode 100644 (file)
index 0000000..f670751
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef __CWM_EVENT_STRUCTURE_H__
+#define __CWM_EVENT_STRUCTURE_H__
+
+/**
+  * @brief  CyweeMotion task handle event structure. 
+  */
+typedef struct {
+    uint32_t tid;
+    uint32_t handleType;
+    int (*handleEvent)(void *pHandle, uint32_t evtType, void* evtData);
+    void *mem;
+} CWMHandle_t, *pCWMHandle_t;
+
+
+/**
+  * @brief  Sensor event structure. 
+  */
+typedef struct {
+    uint32_t sensorType;
+    uint32_t index;
+    float fData[16];
+    uint64_t timestamp_ns;
+    void *memData;
+} SensorEVT_t, *pSensorEVT_t;
+
+#endif /* __CWM_EVENT_STRUCTURE_H__ */
diff --git a/code/sdk/drivers/peripheral/cywee/Inc/OsApi.h b/code/sdk/drivers/peripheral/cywee/Inc/OsApi.h
new file mode 100644 (file)
index 0000000..49b35b1
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef __OS_API_H__
+#define __OS_API_H__
+
+/**
+  * @brief  System/OS/Peripheral API structure.
+  */
+
+typedef int (*PFN_IRQHANDLE)(void *);
+
+typedef struct{
+    int (*i2cRead)(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex);
+    int (*i2cWrite)(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex);
+    void *(*malloc)(int size);
+    void (*free)(void* ptr);
+    uint64_t (*GetTimeNs)(void);
+    void (*uSleep)(uint32_t);
+    void (*saveData)(uint8_t*, uint32_t);
+    void (*restoreData)(uint8_t*, uint32_t);
+    int (*dbgOutput)(const char*);
+    int (*enableGpioIRQ)(uint16_t, uint16_t, PFN_IRQHANDLE);
+    int (*disableGpioIRQ)(uint16_t, uint16_t);
+    int (*setGpio)(uint16_t, uint16_t, uint16_t);
+    int (*securityCodeWrite)(uint32_t, uint8_t*, uint32_t);
+    int (*i2cTransfer)(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int argument);
+    int (*spiRead)(uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex);
+    int (*spiWrite)(uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex);
+} OsAPI, *pOsAPI;
+
+typedef OsAPI os_api;
+
+#endif /* __OS_API_H__ */
diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib.h b/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib.h
new file mode 100644 (file)
index 0000000..173a477
--- /dev/null
@@ -0,0 +1,264 @@
+#ifndef __CWM_LIB_H__
+#define __CWM_LIB_H__
+
+#include "CWM_EventStructure.h"
+#include "OsApi.h"
+#include "CWM_CustomDataStruct.h"
+
+/**
+  * @brief Setting Control control ID
+  * @api CWM_SettingControl
+  * @param CtrId
+  */
+#define SCL_LOG                 0
+#define SCL_USER_INFO           1
+#define SCL_DATE_TIME           2
+#define SCL_SEDENTARY           3
+#define SCL_PEDO_RESET          4 // old
+#define SCL_RESET_DAILY_INFO    4 // new
+#define SCL_REQ_SLEEPING_DATA   5
+#define SCL_LOW_POWER_MODE      6
+#define SCL_SET_ACTIVITY_MODE   7
+#define SCL_GET_CHIP_INFO       8
+#define SCL_ACTIVITY_CONFIG     9
+#define SCL_LIB_DEBUG           10
+#define SCL_PEDO_CONFIG         11
+#define SCL_GET_LIB_INFO        12
+#define SCL_SWIM_CONFIG         13
+#define SCL_BIKING_CONFIG       14
+#define SCL_ACTIVITY_PAUSE      15
+#define SCL_HAND_UPDOWN_CONFIG  16
+#define SCL_CHIP_VENDOR_CONFIG  17
+#define SCL_SLEEP_CONFIG        18
+#define SCL_ABS_STATIC_CONFIG   19
+#define SCL_HEART_RATE_CONFIG   20
+#define SCL_REQ_SWIM_EXIT       21
+#define SCL_WATCH_FALL_CONFIG   22
+#define SCL_AR_ALERT_CONFIG     23
+#define SCL_WM_CONFIG           25
+#define SCL_INACTIVITY_CONFIG   26
+#define SCL_SET_INACTIVITY_MODE 27
+#define SCL_STAND_CONFIG        28
+#define SCL_SS_CONFIG           29
+#define SCL_ACT_INFO_CONFIG     30
+#define SCL_REQ_ACTIVITY_EXIT   31
+#define SCL_ACT_PAI_INFO        33
+#define SCL_ACT_INTSY_INFO      35
+#define SCL_DUMP_WI_INFO        36
+#define SCL_ACT_ZONE_TIME       37
+#define SCL_ACT_TRAINING_INFO   38
+#define SCL_WATCH_INTF_RESET    40
+#define SCL_PEDO_CONFIG2        42
+#define SCL_HG_INTF_CONFIG      43
+#define SCL_ACT_AUTO_PAUSE_CFG  44
+#define SCL_AR_ALERT2_CONFIG    45
+#define SCL_WI_SENS_REQ_CFG     46
+#define SCL_ACT_SA_METR_INFO    47
+#define SCL_SLEEP_ALARM_CFG     48
+#define SCL_FITNESS_INFO        49
+#define SCL_SZ_BREACH_CONFIG    50
+#define SCL_ACT_PAI_INFO2       51
+
+#define SCL_ALGO_PROC_CONFIG    100
+#define SCL_INPUT_SENSOR_CONFIG 101
+#define SCL_INPUT_DT_CONFIG     102
+#define SCL_SENS_RANGE_DETECT_CONFIG     103
+#define SCL_SENS_CALI_CONFIG    110
+#define SCL_SENS_CALI_CTRL_MAG  111
+#define SCL_SENS_CALI_CTRL_A    112
+#define SCL_SPV_CONFIG          113
+#define SCL_SPV_MODE            114
+#define SCL_SENS_CALI_SET_MAG   115
+#define SCL_SENS_CALI_SET_A     116
+
+#define SCL_SIN_HR_EXT          200
+
+/**
+  * @brief Custom Sensor Input sensorId
+  * @api CWM_CustomSensorInput
+  * @param CustomSensorData.sensorType extSensorId
+  * @
+  * @api CWM_CustomSensorInput_Fifo_Start CWM_CustomSensorInput_Fifo_End
+  * @param extSensorId
+  */
+#define CUSTOM_ACC              0
+#define CUSTOM_GYRO             1
+#define CUSTOM_MAG              2
+#define CUSTOM_BARO             3
+#define CUSTOM_TEMP             4
+#define CUSTOM_HEARTRATE        5
+#define CUSTOM_GNSS             6
+#define CUSTOM_OFFBODY_DETECT   7
+#define CUSTOM_ON_CHARGING      8
+#define CUSTOM_ACC_ANY_MOTION   9
+#define CUSTOM_SENS1            10
+
+
+/**
+  * @brief sensor enable/disable
+  * @api CWM_Sensor_Enable CWM_Sensor_Disable
+  * @param sensorId
+  */
+#define IDX_ACCEL                    0
+#define IDX_GYRO                     1
+#define IDX_MAG                      2
+#define IDX_BARO                     3
+#define IDX_TEMP                     4
+#define IDX_HEARTRATE                5
+#define IDX_GNSS                     6
+#define IDX_OFFBODY_DETECT           7
+#define IDX_ALGO_SEDENTARY           8
+#define IDX_ALGO_WATCH_HANDUP        9
+#define IDX_ALGO_SLEEP               10
+#define IDX_REQUEST_SENSOR           11
+#define IDX_ALGO_SHAKE               13
+#define IDX_ALGO_ACTIVITY_OUTPUT     14
+#define IDX_ALGO_ANY_MOTION          15
+#define IDX_ALGO_NO_MOTION           16
+#define IDX_ALGO_FALLING             17
+#define IDX_ONCHARGING_DETECT        18
+#define IDX_ALGO_ABSOLUTE_STATIC     19
+#define IDX_ALGO_SPV                 20
+#define IDX_ALGO_SENS_CALIBRATION    21
+#define IDX_ALGO_INACTIVITY_OUTPUT   22
+#define IDX_ALGO_STAND               23
+#define IDX_ALGO_SENS_RANGE_DETECT   24
+
+/**
+  * @brief activity mode setting
+  * @api CWM_SettingControl
+  * @param SCL_SET_ACTIVITY_MODE
+  */
+#define ACTIVITY_MODE_NORMAL                1001
+
+typedef struct {
+    int iData[16];
+} SettingControl_t;
+
+typedef void (*FN_SENSOR_LISTEN)(pSensorEVT_t);
+
+
+#define LOS_DATA_TYPE_INT               0
+#define LOS_DATA_TYPE_STR               1
+
+/**
+  * @brief 
+  * @param dataType: cmd data type indicater
+  *                  0 (LOS_DATA_TYPE_INT): int type data, dataInt accessible
+  *                  1 (LOS_DATA_TYPE_STR): string type data, *dataStr and dataStr_length accessible
+  */
+typedef struct {
+    const char  *optionString;
+    const char  *sectionName;
+    const char  *apiName;
+    int         cmdId;
+    int         dataType;
+    int         dataInt[16];
+    const char  *dataStr;
+    int         dataStr_length;
+} los_cmd_data_t;
+
+typedef void (*FN_LOS_CMD_EXECUTE)(los_cmd_data_t *);
+
+/**
+  * @brief  CyweeMotion internal process Initial
+  */
+void CWM_LibPreInit(OsAPI *api);
+
+/**
+  * @brief  Sensor Event register callback, when sensor event is triggered, 
+  *         this function will be called to notify
+  */
+void CWM_LibPostInit(FN_SENSOR_LISTEN pfn);
+
+/**
+  * @brief  lib deinit for special case. Not any situation can be used normally
+  */
+void CWM_LibDeinit(void);
+
+/**
+  * @brief  Sensor enable based on sensor index provided
+  * @param  sensorId: sensor register handle, if not setup this handle don't care
+  * @retval 0 is success, otherwise is failed
+  */
+int CWM_Sensor_Enable(uint32_t sensorId);
+
+/**
+  * @brief  Sensor disable based on sensor index provided
+  * @param  sensorId: sensor register handle, if not setup this handle don't care
+  * @retval 0 is success, otherwise is failed
+  */
+int CWM_Sensor_Disable(uint32_t sensorId);
+
+/**
+  * @brief  Read sensor data and output through sensor call-back function
+  * @retval 0 is no data to process, mcu can enter low power mode,
+            otherwise has some data needs process this function again.
+  */
+int CWM_process(void);
+
+/**
+  * @brief  Read sensor data and output through sensor call-back function
+  */
+int CWM_process2(int dt_us);
+
+/**
+  * @brief  Get how many event in CyweeMotion Library to be processed
+  * @retval 0 is no data to process, mcu can enter low power mode,
+            otherwise has some data
+  */
+int CWM_IsReadyForProcess(void);
+
+/**
+  * @brief  Put custom sensor data.
+  * @param  SensorDataInput: sensor data input handle, input format as below:
+  *                          sensorType= CustomSensorDataIndex
+  *                          fData     = sensor raw data
+  * @retval 0 is success, otherwise is failed
+  */
+int CWM_CustomSensorInput(CustomSensorData *SensorDataInput);
+
+/**
+  * @brief Get the duration time of the next event
+  * @retval the duration time (unit nanosecond)
+  */
+int64_t CWM_GetNextActionDuration_ns(void);
+
+/**
+  * @brief  set lib config
+  * @param  Control ID
+  * @param  Setting control array
+  * @retval 0 is success, otherwise is failed
+  */
+int CWM_SettingControl(int CtrId, SettingControl_t *pData);
+
+/**
+  * @brief Fifo initial
+  * @param max recored number of acc fifo
+  */
+void CWM_CustomSensorInput_Fifo_Init(int maxRecords_Acc);
+
+/**
+  * @brief  setting lib can start input fifo
+  * @param  sensor ID
+  * @param  timestamp that interrupt trigger to read hw fifo data
+  * @param  fifo delta_time
+  * @retval 0 is success, otherwise is failed
+  */
+int CWM_CustomSensorInput_Fifo_Start(uint32_t extSensorId, uint64_t triggerFifoRead_timeStamp_ns, uint64_t dt_ns);
+
+/**
+  * @brief  setting lib to stop input fifo
+  * @param  sensor ID
+  */
+void CWM_CustomSensorInput_Fifo_End(uint32_t extSensorId);
+
+/**
+  * @brief  Execute option string
+  * @param  optionString
+  * @param  sectionString section execute order 
+  * @param  custCallbackFunc custom option string execute function
+  * @param  skipExeDefault don't execute default command
+  */
+void CWM_LoadOptionString(const char *optionString, const char *sectionString, FN_LOS_CMD_EXECUTE custCallbackFunc, int skipExeDefault);
+#endif
diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib_dml.h b/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib_dml.h
new file mode 100644 (file)
index 0000000..ca7a5b8
--- /dev/null
@@ -0,0 +1,79 @@
+#ifndef __CWM_LIB_DML_H__
+#define __CWM_LIB_DML_H__
+
+#define SCL_DML_DRV_ENABLE              400
+#define SCL_DML_DRV_INIT                401
+#define SCL_DML_DRV_HW_CONFIG           402
+#define SCL_DML_DRV_AG_CONFIG           403
+#define SCL_DML_DRV_M_CONFIG            404
+#define SCL_DML_DEBUG                   405
+#define SCL_DML_GET_LIB_INFO            406
+#define SCL_DML_GET_INITED_LIST         407
+#define SCL_DML_DRV_AG_STATUS           408
+#define SCL_DML_DRV_ANYM_CONFIG         409
+#define SCL_DML_DRV_AG_PERF_CONFIG      410
+#define SCL_DML_DRV_M_PERF_CONFIG       411
+#define SCL_DML_DRV_AG_EXT_CONFIG       412
+#define SCL_DML_DRV_M_EXT_CONFIG        413
+#define SCL_DML_DRV_AG_REG_ACCESS       414
+#define SCL_DML_DRV_M_REG_ACCESS        415
+#define SCL_DML_DRV_AG_ODR_CALI         416
+
+#define SCL_DML_AUTO_RANGE_CONFIG       420
+
+int CWM_Dml_LibInit(void);
+int CWM_Dml_process(void);
+
+
+#define DML_SENSOR_DATA_VALID_DT         (1 << 0)
+#define DML_SENSOR_DATA_VALID_ACC        (1 << 1)
+#define DML_SENSOR_DATA_VALID_GYRO       (1 << 2)
+#define DML_SENSOR_DATA_VALID_MAG        (1 << 3)
+#define DML_SENSOR_DATA_VALID_ACC_TEMP   (1 << 4)
+
+typedef struct {
+    int     hwId;
+    int     auxId;
+    uint64_t ts_ns;
+
+    int     validData;
+
+    int dt_us;
+
+    float   acc_ratio;      //acc_data = acc_org * acc_ratio
+    int16_t acc_org[3];     //sensor hw original output data (axis adjusted)
+    float   acc_data[3];    //unit: m/s^2 (axis adjusted)
+
+    float   acc_temp;       //unit: celsius
+    
+    float   gyro_ratio;     //gyro_data = gyro_org * gyro_ratio
+    int16_t gyro_org[3];    //sensor hw original output data (axis adjusted)
+    float   gyro_data[3];   //unit: rad/s (axis adjusted)
+    
+    float   mag_data[3];    //unit: uT (axis adjusted)
+} dml_sensorData_t;
+
+typedef void (*FN_SENSOR_DATA_OUTPUT)(const dml_sensorData_t *);
+
+int CWM_Dml_sensorDataOutput_register(FN_SENSOR_DATA_OUTPUT sdo_callBack_func);
+void CWM_Dml_sensorDataOutput_logConfig(void);
+void CWM_Dml_sensorDataOutput_logOutput(const dml_sensorData_t *pSd);
+
+
+typedef struct {
+    int disable_unitConv;      // [input]  0: [acc_data] and [gyro_data] have output
+                               //          1: [acc_data] and [gyro_data] no output
+
+    int16_t acc_raw[3];        // [input]  sensor hw original output data (axis un-adjusted)
+    int16_t gyro_raw[3];       // [input]  sensor hw original output data (axis un-adjusted)
+
+    int16_t acc_org[3];        // [output] sensor hw original output data (axis    adjusted)
+    int16_t gyro_org[3];       // [output] sensor hw original output data (axis    adjusted)
+
+    float   acc_data[3];       // [output] unitConv to unit: m/s^2 (axis adjusted)
+    float   gyro_data[3];      // [output] unitConv to unit: rad/s (axis adjusted)
+} dml_cust_data_ag_t;
+
+void CWM_Dml_custData_converter_ag(dml_cust_data_ag_t *data);
+
+#endif
diff --git a/code/sdk/drivers/peripheral/cywee/Inc/simulate_signal.h b/code/sdk/drivers/peripheral/cywee/Inc/simulate_signal.h
new file mode 100644 (file)
index 0000000..bb9be91
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef __SIMULATE_SIGNAL_H__
+#define __SIMULATE_SIGNAL_H__
+
+#include <stdint.h>
+#include <stddef.h>
+
+typedef int (*fn_simulate_action)(int, int, int, float*);
+typedef struct {
+    fn_simulate_action  action;
+    int                 value;
+    int                 param1;
+    int                 param2;
+    float               *out_data;
+} simulate_action;
+
+typedef struct {
+    simulate_action     *actions;
+} time_axis_data;
+
+int simulate_pedo_moving_time(int duration_s, int freq_m, int reserve, float *out_data);
+int simulate_pedo_moving_step(int step, int freq_m, int reserve, float *out_data);
+int simulate_no_move_time(int duration_s, int reserve1, int reserve2, float *out_data);
+int simulate_static_time(int duration_s, int reserve1, int reserve2, float *out_data);
+int simulate_mix_no_move_handupdown(int duration_s, int reserve1, int reserve2, float *inout_data);
+int simulate_mix_moving_handupdown(int duration_s, int reserve1, int reserve2, float *inout_data);
+
+void init_simulate_time_axis();
+int simulate_time_axis(time_axis_data *data, float *out_data);
+uint64_t simulate_fake_get_time_ns();
+
+#endif
diff --git a/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_DML_clang_riscv.a b/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_DML_clang_riscv.a
new file mode 100644 (file)
index 0000000..96e0a69
Binary files /dev/null and b/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_DML_clang_riscv.a differ
diff --git a/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.a b/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.a
new file mode 100644 (file)
index 0000000..689b049
Binary files /dev/null and b/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.a differ
diff --git a/code/sdk/drivers/peripheral/cywee/doc/CWM lib Sensor Info_Gnt_Fd230_20240222.xlsx b/code/sdk/drivers/peripheral/cywee/doc/CWM lib Sensor Info_Gnt_Fd230_20240222.xlsx
new file mode 100644 (file)
index 0000000..2a05d10
Binary files /dev/null and b/code/sdk/drivers/peripheral/cywee/doc/CWM lib Sensor Info_Gnt_Fd230_20240222.xlsx differ
diff --git a/code/sdk/drivers/peripheral/cywee/doc/Cwm_Dml_Info__LIS2DOC__20230816.xlsx b/code/sdk/drivers/peripheral/cywee/doc/Cwm_Dml_Info__LIS2DOC__20230816.xlsx
new file mode 100644 (file)
index 0000000..deabcfe
Binary files /dev/null and b/code/sdk/drivers/peripheral/cywee/doc/Cwm_Dml_Info__LIS2DOC__20230816.xlsx differ
diff --git a/code/sdk/drivers/peripheral/cywee/doc/CyweeMotion Driver Manger Lib Porting Guide_v1.0 1.pdf b/code/sdk/drivers/peripheral/cywee/doc/CyweeMotion Driver Manger Lib Porting Guide_v1.0 1.pdf
new file mode 100644 (file)
index 0000000..1c96a75
Binary files /dev/null and b/code/sdk/drivers/peripheral/cywee/doc/CyweeMotion Driver Manger Lib Porting Guide_v1.0 1.pdf differ
diff --git a/code/sdk/drivers/peripheral/cywee/doc/CyweeMotion_Algo Lib_Tutorial_v1.3_20200903 1.pdf b/code/sdk/drivers/peripheral/cywee/doc/CyweeMotion_Algo Lib_Tutorial_v1.3_20200903 1.pdf
new file mode 100644 (file)
index 0000000..8dabff9
Binary files /dev/null and b/code/sdk/drivers/peripheral/cywee/doc/CyweeMotion_Algo Lib_Tutorial_v1.3_20200903 1.pdf differ
diff --git a/code/sdk/drivers/peripheral/cywee/doc/CyweeMotion_MotionSensor_Adjust_Guide_v1.6 1.pdf b/code/sdk/drivers/peripheral/cywee/doc/CyweeMotion_MotionSensor_Adjust_Guide_v1.6 1.pdf
new file mode 100644 (file)
index 0000000..1bab92d
Binary files /dev/null and b/code/sdk/drivers/peripheral/cywee/doc/CyweeMotion_MotionSensor_Adjust_Guide_v1.6 1.pdf differ
diff --git a/code/sdk/drivers/peripheral/cywee/src/board_apollo3.c b/code/sdk/drivers/peripheral/cywee/src/board_apollo3.c
new file mode 100644 (file)
index 0000000..2172273
--- /dev/null
@@ -0,0 +1,319 @@
+/*********************/
+/*** Include Files ***/
+/*********************/
+#include <stdlib.h>
+#include <string.h>
+#include "am_mcu_apollo.h"
+#include "am_bsp.h"
+#include "am_util.h"
+#include "am_devices_i2c.h"
+#include "cwm_lib.h"
+#include "config.h"
+
+/*********************/
+/*** Macro Defines ***/
+/*********************/
+#define CLOCK_FREQ 1000  //It is clock frequency setting.
+#define IOM_MODULE_NUMBER   0
+#define IOM_IRQn            ((IRQn_Type)(IOMSTR0_IRQn + IOM_MODULE_NUMBER))
+
+//
+// Take over the interrupt handler for whichever IOM we're using.
+//
+#define iom_isr                                                          \
+    am_iom_isr1(IOM_MODULE_NUMBER)
+#define am_iom_isr1(n)                                                   \
+    am_iom_isr(n)
+#define am_iom_isr(n)                                                    \
+    am_iomaster ## n ## _isr
+
+
+/*************************/
+/*** Variables Defines ***/
+/*************************/
+uint32_t  DMATCBBuffer[256];
+void      *g_pIOMHandle;
+
+am_hal_iom_config_t     g_sIomCfg =
+{
+    .eInterfaceMode       = AM_HAL_IOM_I2C_MODE,
+    .ui32ClockFreq        = AM_HAL_IOM_100KHZ,
+};
+
+static uint32_t m_tickLast = 0;
+static uint64_t m_elpsedTime_us = 0;
+
+
+/************************/
+/*** Function Defines ***/
+/************************/
+int CWM_OS_dbgPrintf(const char * format,...);
+
+
+/********************************/
+/*** Function Implementations ***/
+/********************************/
+void iom_isr(void)
+{
+    uint32_t ui32Status;
+
+    if (!am_hal_iom_interrupt_status_get(g_pIOMHandle, true, &ui32Status))
+    {
+        if ( ui32Status )
+        {
+            am_hal_iom_interrupt_clear(g_pIOMHandle, ui32Status);
+            am_hal_iom_interrupt_service(g_pIOMHandle, ui32Status);
+        }
+    }
+}
+
+static void I2C_init(void)
+{
+    g_sIomCfg.ui32NBTxnBufLength = sizeof(DMATCBBuffer) / 4;
+    g_sIomCfg.pNBTxnBuf = &DMATCBBuffer[0];
+
+    am_devices_i2c_init(IOM_MODULE_NUMBER, &g_sIomCfg, &g_pIOMHandle);
+
+    return;
+}
+
+static void am_i2c_setting(void)
+{
+    I2C_init();
+    NVIC_EnableIRQ(IOM_IRQn);
+}
+
+static void am_i2c_deinit(void)
+{
+    am_devices_i2c_term(0);
+    NVIC_DisableIRQ(IOM_IRQn);
+}
+
+static void APOLLO_I2C_Reset(void)
+{
+    am_i2c_deinit();
+    am_util_delay_ms(20);
+    am_i2c_setting();
+}
+
+static void stimer_init(void)
+{
+    am_hal_stimer_int_enable(AM_HAL_STIMER_INT_COMPAREA);
+    NVIC_EnableIRQ(STIMER_CMPR0_IRQn);
+    am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
+    am_hal_stimer_compare_delta_set(0, CLOCK_FREQ);//1 second timer
+    am_hal_stimer_config(AM_HAL_STIMER_LFRC_1KHZ |
+                         AM_HAL_STIMER_CFG_COMPARE_A_ENABLE);
+    m_tickLast = am_hal_stimer_counter_get();
+}
+
+static uint64_t platsystickTicksToUs(uint64_t tick) {
+    return (uint64_t)(tick * 1000000/CLOCK_FREQ);
+}
+
+static inline uint64_t calcElapsedTicks(uint64_t tickNow, uint64_t tickLast)
+{
+    if(tickNow >= tickLast)
+        return tickNow - tickLast;
+    else
+        return 0xFFFFFFFF - tickLast + tickNow;
+}
+
+static void systickUpdate(void)
+{
+    //To implement the CWM_OS_GetTimeNs(), this function needs to be triggered every second
+    uint64_t tickNow;
+    uint64_t delta_ticks;
+
+    tickNow = am_hal_stimer_counter_get();
+    delta_ticks = calcElapsedTicks(tickNow, m_tickLast);
+    m_elpsedTime_us += platsystickTicksToUs(delta_ticks);
+
+    m_tickLast = tickNow;
+}
+
+void am_stimer_cmpr0_isr(void)
+{
+    //To implement the CWM_OS_GetTimeNs(), this function needs to be triggered every second
+    systickUpdate();
+
+    am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREA);
+    am_hal_stimer_compare_delta_set(0, CLOCK_FREQ);//1 second timer
+}
+
+#define BUS_RETRY_TIMES     3
+#define BUS_RECOVER_TIMES   1
+
+int CWM_OS_i2cRead(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int argument)
+{
+    int res;
+    int rty = BUS_RETRY_TIMES;
+    int rcovery = BUS_RECOVER_TIMES;
+
+    do{
+        res = am_devices_i2c_blocking_read(slaveAddr, reg, readData, readDataSize);
+
+        if(res == 0)
+            break;
+
+        rty --;
+        if(rcovery > 0)
+        {
+            if(rty == 0)
+            {
+                rty = BUS_RETRY_TIMES;
+                rcovery --;
+                APOLLO_I2C_Reset();
+            }
+        }
+    }while(rty > 0);
+
+
+    return (res>0) ? res*-1: res;
+}
+
+int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int argument)
+{
+    int res;
+    int rty = BUS_RETRY_TIMES;
+    int rcovery = BUS_RECOVER_TIMES;
+
+    do{
+        res = am_devices_i2c_blocking_write(slaveAddr, reg, writeData, writeDataSize);
+
+        if(res == 0)
+            break;
+
+        rty --;
+        if(rcovery > 0)
+        {
+            if(rty == 0)
+            {
+                rty = BUS_RETRY_TIMES;
+                rcovery --;
+                APOLLO_I2C_Reset();
+            }
+        }
+    }while(rty > 0);
+
+    return (res>0) ? res*-1: res;
+}
+
+int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int argument)
+{
+    am_hal_iom_transfer_t desc;
+    memset(&desc, 0, sizeof(am_hal_iom_transfer_t));
+
+    desc.ui32InstrLen    = regLength;
+    desc.ui32Instr       = reg;
+    desc.uPeerInfo.ui32I2CDevAddr = slaveAddr >> 1;
+    desc.ui8RepeatCount  = 0;
+    desc.ui32PauseCondition = 0;
+    desc.ui32StatusSetClr = 0;
+    desc.bContinue = false;
+
+    if (readDataSize == 0) {
+        if (writeDataSize == 0 || writeData == NULL)
+            return -1;
+
+        // write mode
+        desc.eDirection      = AM_HAL_IOM_TX;
+        desc.ui32NumBytes    = writeDataSize;
+        desc.pui32TxBuffer   = (uint32_t *) writeData;
+    }
+    else {
+        if (readData == NULL)
+            return -1;
+
+        // read mode
+        desc.eDirection      = AM_HAL_IOM_RX;
+        desc.ui32NumBytes    = readDataSize;
+        desc.pui32RxBuffer   = (uint32_t *) readData;
+    }
+
+    return am_hal_iom_blocking_transfer(g_pIOMHandle, &desc);
+}
+
+void CWM_OS_uSleep(uint32_t time)
+{
+    uint32_t ms = time / 1000;
+
+    if (ms == 0)
+        ms = 1;
+    am_util_delay_ms(ms);
+}
+
+uint64_t CWM_OS_GetTimeNs(void)
+{
+    uint64_t tickNow;
+    uint64_t delta_ticks;
+    uint64_t timeNow_us;
+
+    tickNow = am_hal_stimer_counter_get();
+    delta_ticks = calcElapsedTicks(tickNow, m_tickLast);
+    timeNow_us = m_elpsedTime_us + platsystickTicksToUs(delta_ticks);
+
+    return timeNow_us * 1000;
+}
+
+void* CWM_OS_malloc(int size)
+{
+    if (size == 0)
+        size = 1;
+    return malloc(size);
+}
+
+void CWM_OS_free(void *ptr)
+{
+    if (ptr == NULL)
+        return;
+
+    free(ptr);
+}
+
+int CWM_OS_dbgOutput(const char * format)
+{
+    am_util_stdio_printf("%s", format);
+    return 0;
+}
+
+int CWM_OS_dbgOutput_checkLog(const char * format)
+{
+    static int s_sn = 0;
+
+    am_util_stdio_printf("#_#|%d|%s", s_sn, format);
+    s_sn ++;
+    return 0;
+}
+
+int CWM_OS_dbgPrintf(const char * format,...)
+{
+    char InputBuff[255];
+    va_list    args;
+
+    va_start(args, format);
+    am_util_stdio_vsprintf(InputBuff, format, args);
+    va_end(args);
+    CWM_OS_dbgOutput(InputBuff);
+    return 0;
+}
+
+void board_init(void)
+{
+    am_hal_clkgen_control(AM_HAL_CLKGEN_CONTROL_SYSCLK_MAX, 0);  //Set the clock frequency.
+    am_hal_cachectrl_config(&am_hal_cachectrl_defaults);  //default cache configuration
+    am_hal_cachectrl_enable();
+    am_bsp_low_power_init();  //Configure the board for low power operation.
+
+#ifdef PRINTF_FROM_UART
+    am_bsp_uart_printf_enable();  //Enable the UART print interface.
+#else
+    am_bsp_itm_printf_enable();  //Enable the ITM print interface. Using "SWO Viewer" to show log
+#endif
+    am_util_stdio_terminal_clear();  //Clear the terminal and print the banner.
+    am_i2c_setting();
+    am_hal_interrupt_master_enable();
+
+    stimer_init();  //Timer Init
+}
+
diff --git a/code/sdk/drivers/peripheral/cywee/src/board_nordic.c b/code/sdk/drivers/peripheral/cywee/src/board_nordic.c
new file mode 100644 (file)
index 0000000..1e1373e
--- /dev/null
@@ -0,0 +1,479 @@
+/*********************/
+/*** Include Files ***/
+/*********************/
+#include <stdarg.h>
+#include "boards.h"
+#include "app_util_platform.h"
+#include "nrf_delay.h"
+#include "nrf_drv_timer.h"
+#include "nrf_log.h"
+#include "nrf_log_ctrl.h"
+#include "nrf_log_default_backends.h"
+#include "nrf_drv_twi.h"
+#include "pca10040.h"
+#include "cwm_lib.h"
+#include "config.h"
+#include "nrf_drv_clock.h"
+#include "app_timer.h"
+#include "nrf_drv_gpiote.h"
+
+
+/*********************/
+/*** Macro Defines ***/
+/*********************/
+#define PCA10040_PIN_25        25
+#define PCA10040_PIN_28        28
+#define BUS_RETRY_TIMES     3
+#define BUS_RECOVER_TIMES   1
+#define TWI_INSTANCE_ID     0
+#define TIMER_PERIOD_1_SEC    APP_TIMER_TICKS(1000)
+
+/*************************/
+/*** Variables Defines ***/
+/*************************/
+nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);
+
+static uint64_t m_tickLast = 0;
+static uint64_t m_elpsedTime_us = 0;
+APP_TIMER_DEF(m_one_sec_timer);
+
+typedef struct
+{
+    uint16_t sensorType;
+    uint16_t sensorPin;
+    uint16_t mcuPin;
+    uint16_t mcu_int_method;
+    uint16_t mcu_int_connect;
+    PFN_IRQHANDLE callback;
+} irq_item;
+
+typedef struct
+{
+    uint16_t sensorType;
+    uint16_t sensorPin;
+} irq_argument;
+
+static irq_item m_irqHandler[] =
+{
+    {
+        .sensorType = CUSTOM_ACC,
+        .sensorPin = PIN_INT1,
+        .mcuPin = PCA10040_PIN_25,
+        .mcu_int_method = INT_TRIGGER_TYPE_FALLING,
+        .mcu_int_connect = INT_RESISTOR_NOPULL,
+        .callback = NULL,
+    },
+    {
+        .sensorType = CUSTOM_ACC,
+        .sensorPin = PIN_INT2,
+        .mcuPin = PCA10040_PIN_28,
+        .mcu_int_method = INT_TRIGGER_TYPE_RISING,
+        .mcu_int_connect = INT_RESISTOR_PULLDOWN,
+        .callback = NULL,
+    },
+};
+
+
+/************************/
+/*** Function Defines ***/
+/************************/
+int CWM_OS_dbgPrintf(const char * format,...);
+
+
+/********************************/
+/*** Function Implementations ***/
+/********************************/
+static void I2C_Init_Nordic(void)
+{
+    const nrf_drv_twi_config_t twi_config = {
+       .scl                = ARDUINO_SCL_PIN,
+       .sda                = ARDUINO_SDA_PIN,
+       .frequency          = NRF_DRV_TWI_FREQ_400K,
+       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
+       .clear_bus_init     = false
+    };
+
+    nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL);
+    nrf_drv_twi_enable(&m_twi);
+}
+
+static void I2C_Uninit_Nordic(void)
+{
+    nrf_drv_twi_uninit(&m_twi);
+    *(volatile uint32_t *)0x40003FFC = 0;
+    *(volatile uint32_t *)0x40003FFC;
+    *(volatile uint32_t *)0x40003FFC = 1;
+}
+
+static void I2C_Reset_Nordic(void)
+{
+    I2C_Uninit_Nordic();
+    I2C_Init_Nordic();
+}
+
+static inline uint64_t calcElapsedTicks(uint64_t tickNow, uint64_t tickLast)
+{
+    if(tickNow >= tickLast)
+        return tickNow - tickLast;
+    else
+        return APP_TIMER_MAX_CNT_VAL - tickLast + tickNow; //Nordic RTC resolution is 24 bit, APP_TIMER_MAX_CNT_VAL = 0x00FFFFFF
+}
+
+static uint64_t platsystickTicksToUs(uint64_t tick) {
+    return (uint64_t)(tick * 1000000 / APP_TIMER_CLOCK_FREQ);
+}
+
+static void systickUpdate()
+{
+    //To implement the CWM_OS_GetTimeNs(), this function needs to be triggered every second
+    uint64_t tickNow;
+    uint64_t delta_ticks;
+
+    tickNow = app_timer_cnt_get();
+    delta_ticks = calcElapsedTicks(tickNow, m_tickLast);
+    m_elpsedTime_us += platsystickTicksToUs(delta_ticks);
+    m_tickLast = tickNow;
+}
+
+static void one_sec_timer_handle(void * p_context)
+{
+    //To implement the CWM_OS_GetTimeNs(), this function needs to be triggered every second
+    systickUpdate();
+}
+
+static void timer_init(void)
+{
+    ret_code_t ret;
+
+    ret = nrf_drv_clock_init();
+    APP_ERROR_CHECK(ret);
+
+    nrf_drv_clock_lfclk_request(NULL);
+
+    ret = app_timer_init();
+    APP_ERROR_CHECK(ret);
+
+    ret = app_timer_create(&m_one_sec_timer, APP_TIMER_MODE_REPEATED, one_sec_timer_handle);
+    APP_ERROR_CHECK(ret);
+
+    ret = app_timer_start(m_one_sec_timer, TIMER_PERIOD_1_SEC, NULL);//1 second timer
+    APP_ERROR_CHECK(ret);
+}
+
+static void nordic_system_init(void)
+{
+    bsp_board_init(BSP_INIT_NONE);
+    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
+    NRF_LOG_DEFAULT_BACKENDS_INIT();
+    I2C_Init_Nordic();
+}
+
+void Irq_callback(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
+{
+    for (int i=0; i<ARRAY_SIZE(m_irqHandler); i++)
+    {
+        if (m_irqHandler[i].mcuPin == pin && m_irqHandler[i].callback != NULL)
+        {
+            irq_argument arg;
+            arg.sensorType = m_irqHandler[i].sensorType;
+            arg.sensorPin = m_irqHandler[i].sensorPin;
+
+            m_irqHandler[i].callback((void*) &arg);
+            return;
+        }
+    }
+}
+
+// To Implement CWM_enableGpioIRQ & CWM_disableGpioIRQ,
+// convert_int_pullMode_cwm_to_nRF() api should be implemented as well
+// It would convert gpio pull mode define from CWM to nRF52
+static nrf_gpio_pin_pull_t convert_int_pullMode_cwm_to_nRF(uint16_t int_connect)
+{
+    switch(int_connect)
+    {
+        case INT_RESISTOR_PULLUP:
+            return NRF_GPIO_PIN_PULLUP;
+
+        case INT_RESISTOR_PULLDOWN:
+            return NRF_GPIO_PIN_PULLDOWN;
+
+        default:
+            return NRF_GPIO_PIN_NOPULL;
+    }
+}
+
+// To Implement CWM_enableGpioIRQ & CWM_disableGpioIRQ,
+// convert_int_edgeMode_cwm_to_nRF() api should be implemented as well
+// It would convert edge mode define from CWM to nRF52
+static nrf_gpiote_polarity_t convert_int_edgeMode_cwm_to_nRF(uint16_t int_method)
+{
+    switch(int_method)
+    {
+        case INT_TRIGGER_TYPE_RISING:
+            return NRF_GPIOTE_POLARITY_LOTOHI;
+
+        case INT_TRIGGER_TYPE_FALLING:
+            return NRF_GPIOTE_POLARITY_HITOLO;
+
+        default:
+            return NRF_GPIOTE_POLARITY_TOGGLE;
+    }
+}
+
+//In order to make Nordic SDK GPIOTE functions work, defines in Nordic/vendor_sdk/other/sdk_config.h
+//must be enabled. Open the file and edit GPIOTE related defines.
+static void nRF_SetGpioIRQ(uint16_t mcuPin, uint16_t int_method, uint16_t int_connect)
+{
+    uint32_t err_code;
+
+    nrf_drv_gpiote_in_config_t io_cfg = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
+    if(!nrf_drv_gpiote_is_init())
+    {
+        err_code = nrf_drv_gpiote_init();
+        APP_ERROR_CHECK(err_code);
+    }
+    switch(mcuPin)
+    {
+        case PCA10040_PIN_28:
+            io_cfg.sense = convert_int_edgeMode_cwm_to_nRF(int_method);
+            io_cfg.pull = convert_int_pullMode_cwm_to_nRF(int_connect);
+            nrf_drv_gpiote_in_init(PCA10040_PIN_28, &io_cfg, Irq_callback);
+            nrf_drv_gpiote_in_event_enable(PCA10040_PIN_28, true);
+            break;
+        case PCA10040_PIN_25:
+            io_cfg.sense = convert_int_edgeMode_cwm_to_nRF(int_method);
+            io_cfg.pull = convert_int_pullMode_cwm_to_nRF(int_connect);
+            nrf_drv_gpiote_in_init(PCA10040_PIN_25, &io_cfg, Irq_callback);
+            nrf_drv_gpiote_in_event_enable(PCA10040_PIN_25, true);
+            break;
+        default:
+            break;
+    }
+}
+
+//In order to make Nordic SDK GPIOTE functions work, defines in Nordic/vendor_sdk/other/sdk_config.h
+//must be enabled. Open the file and edit GPIOTE related defines.
+static void nRF_UnsetGpioIRQ(uint16_t mcuPin)
+{
+    switch(mcuPin)
+    {
+        case PCA10040_PIN_28:
+            nrf_drv_gpiote_in_event_disable(PCA10040_PIN_28);
+            break;
+        case PCA10040_PIN_25:
+            nrf_drv_gpiote_in_event_disable(PCA10040_PIN_25);
+            break;
+        default:
+            break;
+    }
+}
+
+int CWM_enableGpioIRQ(uint16_t sensorType, uint16_t sensorPin, PFN_IRQHANDLE callback)
+{
+    for (int i=0; i<ARRAY_SIZE(m_irqHandler); i++)
+    {
+        if (sensorType == m_irqHandler[i].sensorType && sensorPin == m_irqHandler[i].sensorPin)
+        {
+            m_irqHandler[i].callback = callback;
+            nRF_SetGpioIRQ(m_irqHandler[i].mcuPin,
+                          m_irqHandler[i].mcu_int_method,
+                          m_irqHandler[i].mcu_int_connect);
+
+            return 0;
+        }
+    }
+    return 1;
+}
+
+int CWM_disableGpioIRQ(uint16_t sensorType, uint16_t sensorPin)
+{
+    for (int i=0; i<ARRAY_SIZE(m_irqHandler); i++)
+    {
+        if (sensorType == m_irqHandler[i].sensorType && sensorPin == m_irqHandler[i].sensorPin)
+        {
+            m_irqHandler[i].callback = NULL;
+            nRF_UnsetGpioIRQ(m_irqHandler[i].mcuPin);
+
+            return 0;
+        }
+    }
+    return 1;
+}
+
+int CWM_OS_i2cRead(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int argument)
+{
+    int res;
+    int rty = BUS_RETRY_TIMES;
+    int rcovery = BUS_RECOVER_TIMES;
+
+    do{
+        res = nrf_drv_twi_tx(&m_twi, slaveAddr >> 1, (uint8_t*) &reg, regLength, true);
+        if (res == NRF_SUCCESS) {
+            nrf_drv_twi_rx(&m_twi, slaveAddr >> 1, readData, readDataSize);
+        }
+
+        if(res != 0)
+            break;
+
+        rty --;
+        if(rcovery > 0)
+        {
+            if(rty == 0)
+            {
+                rty = BUS_RETRY_TIMES;
+                rcovery --;
+                I2C_Reset_Nordic();
+            }
+        }
+    }while(rty > 0);
+
+
+    return (res>0) ? res*-1: res;
+}
+
+int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int argument)
+{
+    int res;
+    int rty = BUS_RETRY_TIMES;
+    int rcovery = BUS_RECOVER_TIMES;
+
+    do{
+        uint8_t data[20];
+        memset(data, 0, sizeof(data));
+
+        if (writeDataSize + 1 > sizeof(data)) {
+            return -1;
+        }
+
+        memcpy(data, &reg, regLength);
+        memcpy(&data[regLength], writeData, writeDataSize);
+        res = nrf_drv_twi_tx(&m_twi, slaveAddr >> 1, data, writeDataSize + regLength, false);
+
+        if(res != 0)
+            break;
+
+        rty --;
+        if(rcovery > 0)
+        {
+            if(rty == 0)
+            {
+                rty = BUS_RETRY_TIMES;
+                rcovery --;
+                I2C_Reset_Nordic();
+            }
+        }
+    }while(rty > 0);
+
+    return (res>0) ? res*-1: res;
+}
+
+int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int argument)
+{
+    uint8_t writeBuf[20];
+    memset(writeBuf, 0, sizeof(writeBuf));
+
+    nrf_drv_twi_xfer_desc_t desc;
+    memset(&desc, 0, sizeof(nrf_drv_twi_xfer_desc_t));
+
+    desc.address = slaveAddr >> 1;
+    memcpy(writeBuf, &reg, regLength);
+    desc.primary_length = regLength;
+
+    if (readDataSize == 0) {
+        if (writeDataSize == 0 || writeData == NULL)
+            return -1;
+
+        // write mode
+        memcpy(writeBuf + regLength, writeData, writeDataSize);
+        desc.primary_length += writeDataSize;
+        desc.type = NRF_DRV_TWI_XFER_TX;
+    } else {
+        if (readData == NULL)
+            return -1;
+
+        // read mode
+        desc.type = NRF_DRV_TWI_XFER_TXRX;
+    }
+
+    desc.p_primary_buf = writeBuf;
+    desc.secondary_length =  readDataSize;
+    desc.p_secondary_buf = readData;
+
+    return nrf_drv_twi_xfer(&m_twi, &desc, 0);
+}
+
+void CWM_OS_uSleep(uint32_t time)
+{
+    uint32_t ms = time / 1000;
+
+    if (ms == 0)
+        ms = 1;
+    nrf_delay_ms(ms);
+}
+
+uint64_t CWM_OS_GetTimeNs(void)
+{
+    uint64_t tick;
+    uint64_t delta_ticks;
+    uint64_t timeNow_us;
+
+    tick = app_timer_cnt_get();
+    delta_ticks = calcElapsedTicks(tick, m_tickLast);
+    timeNow_us = m_elpsedTime_us + platsystickTicksToUs(delta_ticks);
+
+    return timeNow_us * 1000;
+}
+
+void* CWM_OS_malloc(int size)
+{
+    if (size == 0)
+        size = 1;
+    return malloc(size);
+}
+
+void CWM_OS_free(void *ptr)
+{
+    if (ptr == NULL)
+        return;
+
+    free(ptr);
+}
+
+int CWM_OS_dbgOutput(const char * format)
+{
+    NRF_LOG_INFO("%s", format);
+    NRF_LOG_FLUSH();
+
+    return 0;
+}
+
+int CWM_OS_dbgOutput_checkLog(const char * format)
+{
+    static int s_sn = 0;
+
+    NRF_LOG_INFO("#_#|%d|%s", s_sn, format);
+    s_sn ++;
+    NRF_LOG_FLUSH();
+
+    return 0;
+}
+
+int CWM_OS_dbgPrintf(const char * format,...)
+{
+    char InputBuff[255];
+    va_list    args;
+
+    va_start(args, format);
+
+    vsprintf(InputBuff, format, args);
+
+    va_end(args);
+    CWM_OS_dbgOutput(InputBuff);
+    return 0;
+}
+
+void board_init(void)
+{
+    nordic_system_init();
+    timer_init();
+}
diff --git a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c
new file mode 100644 (file)
index 0000000..1e1373e
--- /dev/null
@@ -0,0 +1,479 @@
+/*********************/
+/*** Include Files ***/
+/*********************/
+#include <stdarg.h>
+#include "boards.h"
+#include "app_util_platform.h"
+#include "nrf_delay.h"
+#include "nrf_drv_timer.h"
+#include "nrf_log.h"
+#include "nrf_log_ctrl.h"
+#include "nrf_log_default_backends.h"
+#include "nrf_drv_twi.h"
+#include "pca10040.h"
+#include "cwm_lib.h"
+#include "config.h"
+#include "nrf_drv_clock.h"
+#include "app_timer.h"
+#include "nrf_drv_gpiote.h"
+
+
+/*********************/
+/*** Macro Defines ***/
+/*********************/
+#define PCA10040_PIN_25        25
+#define PCA10040_PIN_28        28
+#define BUS_RETRY_TIMES     3
+#define BUS_RECOVER_TIMES   1
+#define TWI_INSTANCE_ID     0
+#define TIMER_PERIOD_1_SEC    APP_TIMER_TICKS(1000)
+
+/*************************/
+/*** Variables Defines ***/
+/*************************/
+nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);
+
+static uint64_t m_tickLast = 0;
+static uint64_t m_elpsedTime_us = 0;
+APP_TIMER_DEF(m_one_sec_timer);
+
+typedef struct
+{
+    uint16_t sensorType;
+    uint16_t sensorPin;
+    uint16_t mcuPin;
+    uint16_t mcu_int_method;
+    uint16_t mcu_int_connect;
+    PFN_IRQHANDLE callback;
+} irq_item;
+
+typedef struct
+{
+    uint16_t sensorType;
+    uint16_t sensorPin;
+} irq_argument;
+
+static irq_item m_irqHandler[] =
+{
+    {
+        .sensorType = CUSTOM_ACC,
+        .sensorPin = PIN_INT1,
+        .mcuPin = PCA10040_PIN_25,
+        .mcu_int_method = INT_TRIGGER_TYPE_FALLING,
+        .mcu_int_connect = INT_RESISTOR_NOPULL,
+        .callback = NULL,
+    },
+    {
+        .sensorType = CUSTOM_ACC,
+        .sensorPin = PIN_INT2,
+        .mcuPin = PCA10040_PIN_28,
+        .mcu_int_method = INT_TRIGGER_TYPE_RISING,
+        .mcu_int_connect = INT_RESISTOR_PULLDOWN,
+        .callback = NULL,
+    },
+};
+
+
+/************************/
+/*** Function Defines ***/
+/************************/
+int CWM_OS_dbgPrintf(const char * format,...);
+
+
+/********************************/
+/*** Function Implementations ***/
+/********************************/
+static void I2C_Init_Nordic(void)
+{
+    const nrf_drv_twi_config_t twi_config = {
+       .scl                = ARDUINO_SCL_PIN,
+       .sda                = ARDUINO_SDA_PIN,
+       .frequency          = NRF_DRV_TWI_FREQ_400K,
+       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
+       .clear_bus_init     = false
+    };
+
+    nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL);
+    nrf_drv_twi_enable(&m_twi);
+}
+
+static void I2C_Uninit_Nordic(void)
+{
+    nrf_drv_twi_uninit(&m_twi);
+    *(volatile uint32_t *)0x40003FFC = 0;
+    *(volatile uint32_t *)0x40003FFC;
+    *(volatile uint32_t *)0x40003FFC = 1;
+}
+
+static void I2C_Reset_Nordic(void)
+{
+    I2C_Uninit_Nordic();
+    I2C_Init_Nordic();
+}
+
+static inline uint64_t calcElapsedTicks(uint64_t tickNow, uint64_t tickLast)
+{
+    if(tickNow >= tickLast)
+        return tickNow - tickLast;
+    else
+        return APP_TIMER_MAX_CNT_VAL - tickLast + tickNow; //Nordic RTC resolution is 24 bit, APP_TIMER_MAX_CNT_VAL = 0x00FFFFFF
+}
+
+static uint64_t platsystickTicksToUs(uint64_t tick) {
+    return (uint64_t)(tick * 1000000 / APP_TIMER_CLOCK_FREQ);
+}
+
+static void systickUpdate()
+{
+    //To implement the CWM_OS_GetTimeNs(), this function needs to be triggered every second
+    uint64_t tickNow;
+    uint64_t delta_ticks;
+
+    tickNow = app_timer_cnt_get();
+    delta_ticks = calcElapsedTicks(tickNow, m_tickLast);
+    m_elpsedTime_us += platsystickTicksToUs(delta_ticks);
+    m_tickLast = tickNow;
+}
+
+static void one_sec_timer_handle(void * p_context)
+{
+    //To implement the CWM_OS_GetTimeNs(), this function needs to be triggered every second
+    systickUpdate();
+}
+
+static void timer_init(void)
+{
+    ret_code_t ret;
+
+    ret = nrf_drv_clock_init();
+    APP_ERROR_CHECK(ret);
+
+    nrf_drv_clock_lfclk_request(NULL);
+
+    ret = app_timer_init();
+    APP_ERROR_CHECK(ret);
+
+    ret = app_timer_create(&m_one_sec_timer, APP_TIMER_MODE_REPEATED, one_sec_timer_handle);
+    APP_ERROR_CHECK(ret);
+
+    ret = app_timer_start(m_one_sec_timer, TIMER_PERIOD_1_SEC, NULL);//1 second timer
+    APP_ERROR_CHECK(ret);
+}
+
+static void nordic_system_init(void)
+{
+    bsp_board_init(BSP_INIT_NONE);
+    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
+    NRF_LOG_DEFAULT_BACKENDS_INIT();
+    I2C_Init_Nordic();
+}
+
+void Irq_callback(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
+{
+    for (int i=0; i<ARRAY_SIZE(m_irqHandler); i++)
+    {
+        if (m_irqHandler[i].mcuPin == pin && m_irqHandler[i].callback != NULL)
+        {
+            irq_argument arg;
+            arg.sensorType = m_irqHandler[i].sensorType;
+            arg.sensorPin = m_irqHandler[i].sensorPin;
+
+            m_irqHandler[i].callback((void*) &arg);
+            return;
+        }
+    }
+}
+
+// To Implement CWM_enableGpioIRQ & CWM_disableGpioIRQ,
+// convert_int_pullMode_cwm_to_nRF() api should be implemented as well
+// It would convert gpio pull mode define from CWM to nRF52
+static nrf_gpio_pin_pull_t convert_int_pullMode_cwm_to_nRF(uint16_t int_connect)
+{
+    switch(int_connect)
+    {
+        case INT_RESISTOR_PULLUP:
+            return NRF_GPIO_PIN_PULLUP;
+
+        case INT_RESISTOR_PULLDOWN:
+            return NRF_GPIO_PIN_PULLDOWN;
+
+        default:
+            return NRF_GPIO_PIN_NOPULL;
+    }
+}
+
+// To Implement CWM_enableGpioIRQ & CWM_disableGpioIRQ,
+// convert_int_edgeMode_cwm_to_nRF() api should be implemented as well
+// It would convert edge mode define from CWM to nRF52
+static nrf_gpiote_polarity_t convert_int_edgeMode_cwm_to_nRF(uint16_t int_method)
+{
+    switch(int_method)
+    {
+        case INT_TRIGGER_TYPE_RISING:
+            return NRF_GPIOTE_POLARITY_LOTOHI;
+
+        case INT_TRIGGER_TYPE_FALLING:
+            return NRF_GPIOTE_POLARITY_HITOLO;
+
+        default:
+            return NRF_GPIOTE_POLARITY_TOGGLE;
+    }
+}
+
+//In order to make Nordic SDK GPIOTE functions work, defines in Nordic/vendor_sdk/other/sdk_config.h
+//must be enabled. Open the file and edit GPIOTE related defines.
+static void nRF_SetGpioIRQ(uint16_t mcuPin, uint16_t int_method, uint16_t int_connect)
+{
+    uint32_t err_code;
+
+    nrf_drv_gpiote_in_config_t io_cfg = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
+    if(!nrf_drv_gpiote_is_init())
+    {
+        err_code = nrf_drv_gpiote_init();
+        APP_ERROR_CHECK(err_code);
+    }
+    switch(mcuPin)
+    {
+        case PCA10040_PIN_28:
+            io_cfg.sense = convert_int_edgeMode_cwm_to_nRF(int_method);
+            io_cfg.pull = convert_int_pullMode_cwm_to_nRF(int_connect);
+            nrf_drv_gpiote_in_init(PCA10040_PIN_28, &io_cfg, Irq_callback);
+            nrf_drv_gpiote_in_event_enable(PCA10040_PIN_28, true);
+            break;
+        case PCA10040_PIN_25:
+            io_cfg.sense = convert_int_edgeMode_cwm_to_nRF(int_method);
+            io_cfg.pull = convert_int_pullMode_cwm_to_nRF(int_connect);
+            nrf_drv_gpiote_in_init(PCA10040_PIN_25, &io_cfg, Irq_callback);
+            nrf_drv_gpiote_in_event_enable(PCA10040_PIN_25, true);
+            break;
+        default:
+            break;
+    }
+}
+
+//In order to make Nordic SDK GPIOTE functions work, defines in Nordic/vendor_sdk/other/sdk_config.h
+//must be enabled. Open the file and edit GPIOTE related defines.
+static void nRF_UnsetGpioIRQ(uint16_t mcuPin)
+{
+    switch(mcuPin)
+    {
+        case PCA10040_PIN_28:
+            nrf_drv_gpiote_in_event_disable(PCA10040_PIN_28);
+            break;
+        case PCA10040_PIN_25:
+            nrf_drv_gpiote_in_event_disable(PCA10040_PIN_25);
+            break;
+        default:
+            break;
+    }
+}
+
+int CWM_enableGpioIRQ(uint16_t sensorType, uint16_t sensorPin, PFN_IRQHANDLE callback)
+{
+    for (int i=0; i<ARRAY_SIZE(m_irqHandler); i++)
+    {
+        if (sensorType == m_irqHandler[i].sensorType && sensorPin == m_irqHandler[i].sensorPin)
+        {
+            m_irqHandler[i].callback = callback;
+            nRF_SetGpioIRQ(m_irqHandler[i].mcuPin,
+                          m_irqHandler[i].mcu_int_method,
+                          m_irqHandler[i].mcu_int_connect);
+
+            return 0;
+        }
+    }
+    return 1;
+}
+
+int CWM_disableGpioIRQ(uint16_t sensorType, uint16_t sensorPin)
+{
+    for (int i=0; i<ARRAY_SIZE(m_irqHandler); i++)
+    {
+        if (sensorType == m_irqHandler[i].sensorType && sensorPin == m_irqHandler[i].sensorPin)
+        {
+            m_irqHandler[i].callback = NULL;
+            nRF_UnsetGpioIRQ(m_irqHandler[i].mcuPin);
+
+            return 0;
+        }
+    }
+    return 1;
+}
+
+int CWM_OS_i2cRead(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int argument)
+{
+    int res;
+    int rty = BUS_RETRY_TIMES;
+    int rcovery = BUS_RECOVER_TIMES;
+
+    do{
+        res = nrf_drv_twi_tx(&m_twi, slaveAddr >> 1, (uint8_t*) &reg, regLength, true);
+        if (res == NRF_SUCCESS) {
+            nrf_drv_twi_rx(&m_twi, slaveAddr >> 1, readData, readDataSize);
+        }
+
+        if(res != 0)
+            break;
+
+        rty --;
+        if(rcovery > 0)
+        {
+            if(rty == 0)
+            {
+                rty = BUS_RETRY_TIMES;
+                rcovery --;
+                I2C_Reset_Nordic();
+            }
+        }
+    }while(rty > 0);
+
+
+    return (res>0) ? res*-1: res;
+}
+
+int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int argument)
+{
+    int res;
+    int rty = BUS_RETRY_TIMES;
+    int rcovery = BUS_RECOVER_TIMES;
+
+    do{
+        uint8_t data[20];
+        memset(data, 0, sizeof(data));
+
+        if (writeDataSize + 1 > sizeof(data)) {
+            return -1;
+        }
+
+        memcpy(data, &reg, regLength);
+        memcpy(&data[regLength], writeData, writeDataSize);
+        res = nrf_drv_twi_tx(&m_twi, slaveAddr >> 1, data, writeDataSize + regLength, false);
+
+        if(res != 0)
+            break;
+
+        rty --;
+        if(rcovery > 0)
+        {
+            if(rty == 0)
+            {
+                rty = BUS_RETRY_TIMES;
+                rcovery --;
+                I2C_Reset_Nordic();
+            }
+        }
+    }while(rty > 0);
+
+    return (res>0) ? res*-1: res;
+}
+
+int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int argument)
+{
+    uint8_t writeBuf[20];
+    memset(writeBuf, 0, sizeof(writeBuf));
+
+    nrf_drv_twi_xfer_desc_t desc;
+    memset(&desc, 0, sizeof(nrf_drv_twi_xfer_desc_t));
+
+    desc.address = slaveAddr >> 1;
+    memcpy(writeBuf, &reg, regLength);
+    desc.primary_length = regLength;
+
+    if (readDataSize == 0) {
+        if (writeDataSize == 0 || writeData == NULL)
+            return -1;
+
+        // write mode
+        memcpy(writeBuf + regLength, writeData, writeDataSize);
+        desc.primary_length += writeDataSize;
+        desc.type = NRF_DRV_TWI_XFER_TX;
+    } else {
+        if (readData == NULL)
+            return -1;
+
+        // read mode
+        desc.type = NRF_DRV_TWI_XFER_TXRX;
+    }
+
+    desc.p_primary_buf = writeBuf;
+    desc.secondary_length =  readDataSize;
+    desc.p_secondary_buf = readData;
+
+    return nrf_drv_twi_xfer(&m_twi, &desc, 0);
+}
+
+void CWM_OS_uSleep(uint32_t time)
+{
+    uint32_t ms = time / 1000;
+
+    if (ms == 0)
+        ms = 1;
+    nrf_delay_ms(ms);
+}
+
+uint64_t CWM_OS_GetTimeNs(void)
+{
+    uint64_t tick;
+    uint64_t delta_ticks;
+    uint64_t timeNow_us;
+
+    tick = app_timer_cnt_get();
+    delta_ticks = calcElapsedTicks(tick, m_tickLast);
+    timeNow_us = m_elpsedTime_us + platsystickTicksToUs(delta_ticks);
+
+    return timeNow_us * 1000;
+}
+
+void* CWM_OS_malloc(int size)
+{
+    if (size == 0)
+        size = 1;
+    return malloc(size);
+}
+
+void CWM_OS_free(void *ptr)
+{
+    if (ptr == NULL)
+        return;
+
+    free(ptr);
+}
+
+int CWM_OS_dbgOutput(const char * format)
+{
+    NRF_LOG_INFO("%s", format);
+    NRF_LOG_FLUSH();
+
+    return 0;
+}
+
+int CWM_OS_dbgOutput_checkLog(const char * format)
+{
+    static int s_sn = 0;
+
+    NRF_LOG_INFO("#_#|%d|%s", s_sn, format);
+    s_sn ++;
+    NRF_LOG_FLUSH();
+
+    return 0;
+}
+
+int CWM_OS_dbgPrintf(const char * format,...)
+{
+    char InputBuff[255];
+    va_list    args;
+
+    va_start(args, format);
+
+    vsprintf(InputBuff, format, args);
+
+    va_end(args);
+    CWM_OS_dbgOutput(InputBuff);
+    return 0;
+}
+
+void board_init(void)
+{
+    nordic_system_init();
+    timer_init();
+}
diff --git a/code/sdk/drivers/peripheral/cywee/src/config.h b/code/sdk/drivers/peripheral/cywee/src/config.h
new file mode 100644 (file)
index 0000000..fd0a010
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef __CWM_SAMPLE_PROJ_CONFIG_H__
+#define __CWM_SAMPLE_PROJ_CONFIG_H__
+
+//#define RUN_TEST_API_PROCESS
+
+//#define PRINTF_FROM_UART
+
+//#define CHECK_LOG_TOOL
+
+//#define SIGNAL_SIMULATE_PROCESS
+//#define INPUT_DATA_WITH_FIFO_MODE
+
+#endif //__CWM_SAMPLE_PROJ_CONFIG_H__
diff --git a/code/sdk/drivers/peripheral/cywee/src/main.c b/code/sdk/drivers/peripheral/cywee/src/main.c
new file mode 100644 (file)
index 0000000..77f99ae
--- /dev/null
@@ -0,0 +1,312 @@
+/*********************/
+/*** Include Files ***/
+/*********************/
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include "cwm_lib.h"
+#include "config.h"
+#include "simulate_signal.h"
+
+/*********************/
+/*** Macro Defines ***/
+/*********************/
+
+
+/*************************/
+/*** Variables Defines ***/
+/*************************/
+static const char* REQ_SENS_NAME[] = {"acc", "gyro", "mag", "baro", "temp", "hr", "gnss", "ob", "oc", "accany"};
+static int m_req_sensor_state = 0;
+
+/************************/
+/*** Function Defines ***/
+/************************/
+
+extern void board_init(void);
+extern void CWM_OS_uSleep(uint32_t time);
+extern uint64_t CWM_OS_GetTimeNs(void);
+extern void* CWM_OS_malloc(int size);
+extern void CWM_OS_free(void *ptr);
+extern int CWM_OS_dbgOutput(const char * format);
+extern int CWM_OS_dbgOutput_checkLog(const char * format);
+extern int CWM_OS_dbgPrintf(const char * format,...);
+extern void test_api(void);
+
+/********************************/
+/*** Function Implementations ***/
+/********************************/
+int getReqSensor(int index) {
+    if (m_req_sensor_state & (1<<index))
+        return 1;
+    return 0;
+}
+/**
+  * @brief  Sensor listen callback, when you register sensor listen,
+  *            when sensor data is ready, sensor manager will call this function to send pSensorEVT_t.
+  * @param  handle  sensor register handle, if not setup this handle don't care.
+  * @sensorEVT  Sensor data event.
+  * @retval None
+  */
+void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
+    switch (sensorEVT->sensorType) {
+        case IDX_REQUEST_SENSOR:
+            if (sensorEVT->fData[2] != 0)
+                m_req_sensor_state |= (1<<(int)sensorEVT->fData[1]);
+            else
+                m_req_sensor_state &= ~(1<<(int)sensorEVT->fData[1]);
+
+            CWM_OS_dbgPrintf("req_sensor input_sensor: %s(%.1f), switch: %.1f\n",\
+                REQ_SENS_NAME[(int)sensorEVT->fData[1]], sensorEVT->fData[1], sensorEVT->fData[2]);
+            CWM_OS_dbgPrintf("input_sensor now: acc=%d gyro=%d mag=%d baro=%d temp=%d hr=%d gnss=%d ob=%d oc=%d accany=%d\n",\
+                getReqSensor(0), getReqSensor(1), getReqSensor(2), getReqSensor(3), getReqSensor(4),\
+                getReqSensor(5), getReqSensor(6), getReqSensor(7), getReqSensor(8), getReqSensor(9));
+        break;
+
+        case IDX_ACCEL:
+            CWM_OS_dbgPrintf("%s: %.4f, %.4f, %.4f\n", "accel",
+                                                       sensorEVT->fData[0],
+                                                       sensorEVT->fData[1],
+                                                       sensorEVT->fData[2]);
+        break;
+
+        case IDX_ALGO_ACTIVITY_OUTPUT:
+            CWM_OS_dbgPrintf("%s: %.4f, %.4f, %.4f, %.4f, "\
+                                  "%.4f, %.4f, %.4f, %.4f, "\
+                                  "%.4f, %.4f, %.4f, %.4f, "\
+                                  "%.4f, %.4f, %.4f, %.4f\n", "activity output",
+                                                       sensorEVT->fData[0],
+                                                       sensorEVT->fData[1],
+                                                       sensorEVT->fData[2],
+                                                       sensorEVT->fData[3],
+                                                       sensorEVT->fData[4],
+                                                       sensorEVT->fData[5],
+                                                       sensorEVT->fData[6],
+                                                       sensorEVT->fData[7],
+                                                       sensorEVT->fData[8],
+                                                       sensorEVT->fData[9],
+                                                       sensorEVT->fData[10],
+                                                       sensorEVT->fData[11],
+                                                       sensorEVT->fData[12],
+                                                       sensorEVT->fData[13],
+                                                       sensorEVT->fData[14],
+                                                       sensorEVT->fData[15]);
+        break;
+
+        default:
+            CWM_OS_dbgPrintf("%d: %.4f, %.4f, %.4f, %.4f, "\
+                                  "%.4f, %.4f, %.4f, %.4f, "\
+                                  "%.4f, %.4f, %.4f, %.4f, "\
+                                  "%.4f, %.4f, %.4f, %.4f", sensorEVT->sensorType,
+                                                       sensorEVT->fData[0],
+                                                       sensorEVT->fData[1],
+                                                       sensorEVT->fData[2],
+                                                       sensorEVT->fData[3],
+                                                       sensorEVT->fData[4],
+                                                       sensorEVT->fData[5],
+                                                       sensorEVT->fData[6],
+                                                       sensorEVT->fData[7],
+                                                       sensorEVT->fData[8],
+                                                       sensorEVT->fData[9],
+                                                       sensorEVT->fData[10],
+                                                       sensorEVT->fData[11],
+                                                       sensorEVT->fData[12],
+                                                       sensorEVT->fData[13],
+                                                       sensorEVT->fData[14],
+                                                       sensorEVT->fData[15]);
+        break;
+    }
+}
+
+#ifdef SIGNAL_SIMULATE_PROCESS
+#define SIGNAL_SIMULATE_FIFO_COUNT 10
+
+static void sample_fifo_input_data(time_axis_data *taxis) {
+    int i;
+    float acc[3];
+    CWM_CustomSensorInput_Fifo_Start(CUSTOM_ACC,
+                                     simulate_fake_get_time_ns(),
+                                     20 * 1000000);
+
+    for (i=0; i<SIGNAL_SIMULATE_FIFO_COUNT; i++) {
+        if (simulate_time_axis(taxis, acc) != 0) {
+            CWM_CustomSensorInput_Fifo_End(CUSTOM_ACC);
+            return;
+        }
+        CustomSensorData data;
+        memset(&data, 0, sizeof(data));
+        data.sensorType = CUSTOM_ACC;
+        memcpy(data.fData, acc, sizeof(float) *3);
+        CWM_CustomSensorInput(&data);
+    }
+    CWM_CustomSensorInput_Fifo_End(CUSTOM_ACC);
+}
+
+static void sample_polling_input_data(time_axis_data *taxis) {
+    float acc[3];
+    if (simulate_time_axis(taxis, acc) != 0) {
+        return;
+    }
+    CustomSensorData data;
+    memset(&data, 0, sizeof(data));
+    data.sensorType = CUSTOM_ACC;
+    memcpy(data.fData, acc, sizeof(float) *3);
+    CWM_CustomSensorInput(&data);
+}
+
+void sample_data_input() {
+    time_axis_data taxis;
+    memset(&taxis, 0, sizeof(time_axis_data));
+
+    simulate_action actions[] = {
+        { simulate_pedo_moving_step, 200, 66, 0, NULL },
+        { simulate_pedo_moving_step, 1000, 150, 0, NULL },
+        { simulate_pedo_moving_time, 300, 66, 0, NULL },
+        { simulate_no_move_time, 3600 * 2, 0, 0, NULL },
+        { simulate_pedo_moving_step, 100, 66, 0, NULL },
+        { NULL, 0, 0, 0, NULL },
+    };
+
+    taxis.actions = actions;
+
+
+#ifdef INPUT_DATA_WITH_FIFO_MODE
+    sample_fifo_input_data(&taxis);
+#else
+    sample_polling_input_data(&taxis);
+#endif
+}
+#endif
+
+int main(void)
+{
+    OsAPI device_func =
+    {
+        .malloc       = CWM_OS_malloc,
+        .free         = CWM_OS_free,
+        .GetTimeNs    = CWM_OS_GetTimeNs,
+        .dbgOutput    = CWM_OS_dbgOutput,
+    };
+
+#ifdef CHECK_LOG_TOOL
+    device_func.dbgOutput = CWM_OS_dbgOutput_checkLog;
+#endif
+
+    SettingControl_t scl;
+
+    board_init();
+
+#ifdef BUILD_IAR
+    CWM_OS_dbgPrintf("Use IAR\n");
+#elif defined(BUILD_KEIL)
+    CWM_OS_dbgPrintf("Use KEIL\n");
+#endif
+
+#ifdef SIGNAL_SIMULATE_PROCESS
+    device_func.GetTimeNs = simulate_fake_get_time_ns;
+#   ifdef INPUT_DATA_WITH_FIFO_MODE
+       CWM_CustomSensorInput_Fifo_Init(SIGNAL_SIMULATE_FIFO_COUNT);
+#   endif
+#endif
+
+#ifdef RUN_TEST_API_PROCESS
+    test_api();
+    return 0;
+#endif
+
+    //get lib version information
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    CWM_SettingControl(SCL_GET_LIB_INFO, &scl);
+    CWM_OS_dbgPrintf("version:%d.%d.%d.%d product:%d model:%d\n", scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5], scl.iData[6]);
+
+    CWM_LibPreInit(&device_func);
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 0;
+    scl.iData[2] = 0;
+    scl.iData[3] = 0;
+    CWM_SettingControl(SCL_CHIP_VENDOR_CONFIG, &scl);
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 0;
+    //CWM_SettingControl(SCL_LIB_DEBUG, &scl);
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 25;
+    CWM_SettingControl(SCL_ALGO_PROC_CONFIG, &scl);
+
+    CWM_LibPostInit(CWM_AP_SensorListen);
+
+    //get chip information
+    char chipInfo[64];
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 1;
+    scl.iData[2] = (int)chipInfo;
+    scl.iData[3] = sizeof(chipInfo);
+    scl.iData[4] = 0;
+    scl.iData[5] = 0;
+    scl.iData[6] = 0;
+    CWM_SettingControl(SCL_GET_CHIP_INFO, &scl);
+    CWM_OS_dbgPrintf("have_security = %d.%d ret_buff_size = %d  chipInfo = %s\n", scl.iData[5], scl.iData[6], scl.iData[4], chipInfo);
+    CWM_OS_dbgPrintf("chip_settings = %d, %d, %d\n", scl.iData[9], scl.iData[10], scl.iData[11]);
+    CWM_OS_dbgPrintf("secFileId = %08X\n", scl.iData[7]);
+
+#if 0
+    //turn on input log
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[3] = 1;
+    scl.iData[4] = 5;
+    CWM_SettingControl(SCL_LOG, &scl);
+#endif
+
+    //initial request_sensor to receive hardware_sensor on/off event
+    CWM_Sensor_Enable(IDX_REQUEST_SENSOR);
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    CWM_SettingControl(SCL_REQ_ACTIVITY_EXIT, &scl);
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 1001;
+    CWM_SettingControl(SCL_SET_ACTIVITY_MODE, &scl);
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 2021;
+    scl.iData[2] = 10;
+    scl.iData[3] = 8;
+    scl.iData[4] = 12;
+    scl.iData[5] = 0;
+    CWM_SettingControl(SCL_DATE_TIME, &scl);
+
+
+    //CWM_Sensor_Enable(IDX_ACCEL);
+    CWM_Sensor_Enable(IDX_ALGO_ACTIVITY_OUTPUT);
+
+    while (1)
+    {
+        int64_t next_duration = CWM_GetNextActionDuration_ns();
+
+#ifdef SIGNAL_SIMULATE_PROCESS
+        sample_data_input();
+        next_duration = 0;
+#endif
+
+        if (next_duration > 0) {
+            /* Do Low power process here
+            */
+
+            CWM_OS_uSleep(next_duration / 1000);
+        }
+
+        CWM_process();
+    }
+}
diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c
new file mode 100644 (file)
index 0000000..6f776d6
--- /dev/null
@@ -0,0 +1,224 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <cwm_lib.h>
+#include <cwm_lib_dml.h>
+
+// #define AP_ENABLE_DML_SDO_LISTEN
+
+uint64_t CWM_OS_GetTimeNs(void) {
+    return (uint64_t) HAL_GetTick() * 1000000;
+}
+
+int CWM_OS_dbgOutput(const char * format) {
+    printf("%s\r", format);
+    return 0;
+}
+
+void CWM_OS_uSleep(unsigned int udelay) {
+    __IO uint32_t Delay = udelay*100/8; //hclk /8
+
+    do {
+        __NOP();
+    } while (Delay--);
+}
+
+int CWM_OS_i2cRead(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex) {
+    return HAL_I2C_Mem_Read(&hi2c2, slaveAddr<<1, reg, I2C_MEMADD_SIZE_8BIT, readData, readDataSize, 100);
+}
+
+int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex) {
+    return HAL_I2C_Mem_Write(&hi2c2, slaveAddr<<1, reg, I2C_MEMADD_SIZE_8BIT, writeData, writeDataSize, 100);
+}
+
+int CWM_OS_spiRead(uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex) {
+    uint8_t ret;
+    uint8_t reg_addr;
+
+    if (busIndex == 0)
+        HAL_GPIO_WritePin(SPI2_nCS_GPIO_Port, SPI2_nCS_Pin, GPIO_PIN_RESET);
+
+    reg_addr = (uint8_t)reg;
+
+    ret = HAL_SPI_Transmit(&hspi2, &reg_addr, (uint16_t)(regLength), 20);
+    ret = HAL_SPI_Receive(&hspi2, readData, (uint16_t)(readDataSize), 20);
+
+    if (busIndex == 0)
+        HAL_GPIO_WritePin(SPI2_nCS_GPIO_Port, SPI2_nCS_Pin, GPIO_PIN_SET);
+
+    return ret;
+}
+
+int CWM_OS_spiWrite(uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex) {
+    uint8_t ret;
+    uint8_t reg_addr;
+    
+    if (busIndex == 0)
+        HAL_GPIO_WritePin(SPI2_nCS_GPIO_Port, SPI2_nCS_Pin, GPIO_PIN_RESET);
+
+    reg_addr = (uint8_t)reg;
+    
+    ret = HAL_SPI_Transmit(&hspi2, &reg_addr, (uint16_t)(regLength), 20);
+    ret = HAL_SPI_Transmit(&hspi2, writeData, (uint16_t)(writeDataSize), 20);
+
+    if (busIndex == 0)
+        HAL_GPIO_WritePin(SPI2_nCS_GPIO_Port, SPI2_nCS_Pin, GPIO_PIN_SET);
+
+    return ret;
+}
+
+void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
+    switch (sensorEVT->sensorType) {
+        case 0:
+            CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n",
+                                                       sensorEVT->fData[0],
+                                                       sensorEVT->fData[1],
+                                                       sensorEVT->fData[2]
+                                                        );
+            break;
+
+        case 1:
+            CWM_OS_dbgPrintf("gyro: x=%.3f, y=%.3f, z=%.3f\n",
+                                                       sensorEVT->fData[0],
+                                                       sensorEVT->fData[1],
+                                                       sensorEVT->fData[2]
+                                                        );
+            break;
+
+        default:
+            CWM_OS_dbgPrintf("IDX[%d]: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", sensorEVT->sensorType,
+                                                       sensorEVT->fData[0],
+                                                       sensorEVT->fData[1],
+                                                       sensorEVT->fData[2],
+                                                       sensorEVT->fData[3],
+                                                       sensorEVT->fData[4],
+                                                       sensorEVT->fData[5],
+                                                       sensorEVT->fData[6],
+                                                       sensorEVT->fData[7]
+                                                        );
+    }
+}
+
+#ifdef AP_ENABLE_DML_SDO_LISTEN
+void CWM_AP_dmlSensorDataOutput_listen(const dml_sensorData_t * pSdo) {
+
+    if (pSdo->validData & DML_SENSOR_DATA_VALID_DT)
+        CWM_OS_dbgPrintf("dt: %d us\n", pSdo->dt_us);
+
+    if (pSdo->validData & DML_SENSOR_DATA_VALID_ACC)
+        CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n", pSdo->acc_data[0], pSdo->acc_data[1], pSdo->acc_data[2]);
+}
+#endif
+
+int main(int argc, char* argv[]) {
+
+    int i;
+    SettingControl_t scl;
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    CWM_SettingControl(SCL_GET_LIB_INFO, &scl);
+    CWM_OS_dbgPrintf("version:%d.%d.%d.%d product:%d model:%d\n", scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5], scl.iData[6]);
+
+    os_api api = {
+        .GetTimeNs    = CWM_OS_GetTimeNs,
+        .dbgOutput    = CWM_OS_dbgOutput,
+        .i2cRead      = CWM_OS_i2cRead,
+        .i2cWrite     = CWM_OS_i2cWrite,
+        .spiRead      = CWM_OS_spiRead,
+        .spiWrite     = CWM_OS_spiWrite,
+        .uSleep       = CWM_OS_uSleep,
+    };
+    
+    CWM_LibPreInit(&api);
+
+    //set mcu_chip information, must call this before CWM_LibPostInit()
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 2; // 0: mcu_auto_detect 2: skip_mcu_auto_detect
+    CWM_SettingControl(SCL_CHIP_VENDOR_CONFIG, &scl);
+
+    CWM_LibPostInit(CWM_AP_SensorListen);
+
+    //get chip information
+    char chipInfo[64];
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 1;
+    scl.iData[2] = (int)chipInfo;
+    scl.iData[3] = sizeof(chipInfo);
+    scl.iData[4] = 0;
+    scl.iData[5] = 0;
+    scl.iData[6] = 0;
+    CWM_SettingControl(SCL_GET_CHIP_INFO, &scl);
+    CWM_OS_dbgPrintf("have_security = %d.%d ret_buff_size = %d  chipInfo = %s\n", scl.iData[5], scl.iData[6], scl.iData[4], chipInfo);
+    CWM_OS_dbgPrintf("chip_settings = %d, %d, %d\n", scl.iData[9], scl.iData[10], scl.iData[11]);
+
+
+
+    CWM_Dml_LibInit();
+
+    #ifdef AP_ENABLE_DML_SDO_LISTEN
+    // This API allows customers to develop custom features.
+    // Specific settingControl commands needs to be called for this API to work.
+    // No need to enable or implement this function for general usage.
+    CWM_Dml_sensorDataOutput_register(CWM_AP_dmlSensorDataOutput_listen);
+    #endif
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    CWM_SettingControl(SCL_DML_GET_LIB_INFO, &scl);
+    CWM_OS_dbgPrintf("dml version:%d.%d.%d.%d product:%d model:%d\n", scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5], scl.iData[6]);
+
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 1;
+    //CWM_SettingControl(SCL_DML_DEBUG, &scl);
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[3] = 2;
+    scl.iData[4] = 2;
+    scl.iData[8] = 52; // for st sensor(52Hz)
+    CWM_SettingControl(SCL_DML_DRV_AG_CONFIG, &scl);
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 1;
+    CWM_SettingControl(SCL_DML_DRV_INIT, &scl); 
+
+    CWM_OS_dbgPrintf("DML device=%d\n", scl.iData[2]);
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    CWM_SettingControl(SCL_DML_GET_INITED_LIST, &scl);
+
+    for (i = 0; i < scl.iData[2]; i ++) {
+
+        CWM_OS_dbgPrintf("DML device[%d]: hw_id=%d hw_attr=%d\n", i, scl.iData[6 + i * 2], scl.iData[7 + i * 2]);
+    }
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 1;
+    scl.iData[2] = 3;
+    CWM_SettingControl(SCL_DML_DRV_ENABLE, &scl);
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[3] = 3;
+    scl.iData[4] = 5;
+    CWM_SettingControl(SCL_LOG, &scl);
+
+    CWM_Sensor_Enable(CUSTOM_ACC);
+    CWM_Sensor_Enable(CUSTOM_GYRO);
+
+    while (1) {
+        CWM_Dml_process();
+    }
+
+    return 0;
+}
diff --git a/code/sdk/drivers/peripheral/cywee/src/test_api.c b/code/sdk/drivers/peripheral/cywee/src/test_api.c
new file mode 100644 (file)
index 0000000..3c51ee8
--- /dev/null
@@ -0,0 +1,244 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+extern void CWM_OS_uSleep(uint32_t time);
+extern uint64_t CWM_OS_GetTimeNs(void);
+extern void* CWM_OS_malloc(int size);
+extern void CWM_OS_free(void *ptr);
+extern int CWM_OS_dbgOutput(const char * format);
+extern int CWM_OS_dbgPrintf(const char * format,...);
+
+int test_malloc_1() {
+    char *pBuf1;
+    int alloc_size;
+    char buf1[0x100];
+
+    CWM_OS_dbgPrintf("[test_malloc_1] start.\r\n");
+
+    alloc_size = 15 * 1024;
+    pBuf1 = (char*)CWM_OS_malloc(alloc_size);
+    if (pBuf1 == NULL)
+        goto __FAIL;
+
+    memset(pBuf1, 0x7a, alloc_size);
+    if (pBuf1[0] != 0x7a)
+        goto __FAIL;
+
+    if (pBuf1[alloc_size - 1] != 0x7a)
+        goto __FAIL;
+
+    strcpy(pBuf1, "success!!!!");
+
+    sprintf(buf1, "[test_malloc_1] end. %s\r\n", pBuf1);
+    CWM_OS_dbgPrintf(buf1);
+
+    return 1;
+
+__FAIL:
+    CWM_OS_dbgPrintf("[test_malloc_1] end. failure!!!!\r\n");
+
+    return 0;
+}
+
+int test_free_1() {
+    char *pBuf1;
+    char *pBuf2;
+    int alloc_size;
+
+    CWM_OS_dbgPrintf("[test_free_1] start.\r\n");
+
+    alloc_size = 16;
+    pBuf1 = (char*)CWM_OS_malloc(alloc_size);
+    if(pBuf1 == NULL)
+        goto __FAIL;
+
+    //In none-OS or single thread system, if we use malloc() to acquire a memory block and free it immediately,
+    //the next malloc() would get same memory block address
+    //THIS IS A VERY ROUGHLY TEST
+    CWM_OS_free(pBuf1);
+
+    pBuf2 = (char*)CWM_OS_malloc(alloc_size);
+    if(pBuf2 == NULL)
+        goto __FAIL;
+
+    if(pBuf1 == pBuf2)
+        CWM_OS_dbgPrintf("[test_free_1] end. success!!!\r\n");
+    else
+        goto __FAIL;
+
+    return 1;
+__FAIL:
+    CWM_OS_dbgPrintf("[test_free_1] end. failure!!!!\r\n");
+
+    return 0;
+}
+
+void test_GetTimeNs_0() {
+    uint64_t timeNow;
+
+    CWM_OS_dbgPrintf("[test_GetTimeNs_0] test up_time start\r\n");
+
+    timeNow = CWM_OS_GetTimeNs();
+
+    if (timeNow < (uint64_t)60 * 1000000000) {
+        CWM_OS_dbgPrintf("[test_GetTimeNs_0] end. success!!!!\r\n");
+    } else {
+        CWM_OS_dbgPrintf("[test_GetTimeNs_0] end. failure!!!!\r\n");
+    }
+}
+
+void test_GetTimeNs_1() {
+    uint64_t timeNow, timeLast, timeDiff;
+
+    CWM_OS_dbgPrintf("[test_GetTimeNs_1] test 10 seconds start\r\n");
+
+    timeLast = CWM_OS_GetTimeNs();
+    while (1) {
+        timeNow = CWM_OS_GetTimeNs();
+        timeDiff = timeNow - timeLast;
+        //CWM_OS_dbgPrintf("timeNow=%lld\ttimeLast=%lld\ttimeDiff=%lld\n", timeNow, timeLast, timeDiff);
+        if (timeDiff >= (uint64_t)10 * 1000000000) {
+            CWM_OS_dbgPrintf("[test_GetTimeNs_1] test 10 seconds end\r\n");
+            break;
+        }
+    }
+}
+
+void test_GetTimeNs_2() {
+    uint64_t timeNow, timeLast, timeDiff;
+    uint64_t count;
+
+    CWM_OS_dbgPrintf("[test_GetTimeNs_2] test 10 seconds start\r\n");
+
+    timeLast = CWM_OS_GetTimeNs();
+    count = 0;
+    while (1) {
+        timeNow = CWM_OS_GetTimeNs();
+        timeDiff = timeNow - timeLast;
+        //CWM_OS_dbgPrintf("timeNow=%lld\ttimeLast=%lld\ttimeDiff=%lld\n", timeNow, timeLast, timeDiff);
+        if (timeDiff >= (uint64_t)1 * 1000000) {
+            count ++;
+            //CWM_OS_dbgPrintf("count=%lld\n", count);
+            timeLast = timeNow;
+            if (count >= (uint64_t)10 * 1000) {
+                CWM_OS_dbgPrintf("[test_GetTimeNs_2] test 10 seconds end\r\n");
+                break;
+            }
+        }
+    }
+}
+
+void test_GetTimeNs_3() {
+    uint64_t timeNow, timeLast, timeDiff;
+
+    CWM_OS_dbgPrintf("[test_GetTimeNs_3] test 20 minutes start\r\n");
+
+    timeLast = CWM_OS_GetTimeNs();
+    while (1) {
+        timeNow = CWM_OS_GetTimeNs();
+        timeDiff = timeNow - timeLast;
+        //CWM_OS_dbgPrintf("timeNow=%lld\ttimeLast=%lld\ttimeDiff=%lld\n", timeNow, timeLast, timeDiff);
+        if (timeDiff >= (uint64_t)20 * 60 * 1000000000) {
+            CWM_OS_dbgPrintf("[test_GetTimeNs_3] test 20 minutes end\r\n");
+            break;
+        }
+    }
+}
+
+void test_uSleep_1() {
+
+    CWM_OS_dbgPrintf("[test_uSleep_1] test 10 seconds start\r\n");
+
+    CWM_OS_uSleep(10 * 1000000);
+
+    CWM_OS_dbgPrintf("[test_uSleep_1] test 10 seconds end\r\n");
+}
+
+void test_uSleep_2() {
+    int i, j;
+
+    CWM_OS_dbgPrintf("[test_uSleep_2] test 10 seconds start\r\n");
+
+    for (j = 0; j < 10; j ++) {
+        for (i = 0; i < 1000; i++) {
+            CWM_OS_uSleep(1000);
+        }
+    }
+
+    CWM_OS_dbgPrintf("[test_uSleep_2] test 10 seconds end\r\n");
+}
+
+void test_uSleep_3() {
+    int i, j, k;
+
+    CWM_OS_dbgPrintf("[test_uSleep_3] test 10 seconds start\r\n");
+
+    for (j = 0; j < 10; j ++) {
+        for (i = 0; i < 1000; i ++) {
+            for (k = 0; k < 1000; k ++) {
+                CWM_OS_uSleep(1);
+            }
+        }
+    }
+
+    CWM_OS_dbgPrintf("[test_uSleep_3] test 10 seconds end\r\n");
+}
+
+#ifndef CHECK_STACK_TIME_MS
+#define CHECK_STACK_TIME_MS (uint64_t)(5 * 60 * 1000)
+#endif
+
+void test_stack() {
+    // in FreeRTOS
+    // set the config in FreeRTOSConfig.h file
+    // #define configUSE_MALLOC_FAILED_HOOK 1
+    // #define configCHECK_FOR_STACK_OVERFLOW 2
+    // and implemnt vApplicationStackOverflowHook and vApplicationMallocFailedHook
+    // the 2 api will be run while stack or memory allocate has problem
+
+    volatile char buff[4096]; // stack size = 4096
+    memset ((char*) buff, 0x96, sizeof(buff));
+    uint64_t current_time = CWM_OS_GetTimeNs() / 1000000;
+    uint64_t begin_time = CWM_OS_GetTimeNs() / 1000000;
+
+    CWM_OS_dbgPrintf("[test_stack] test for %lld ms start\r\n", CHECK_STACK_TIME_MS);
+
+    while (1) {
+        for (int i=0; i< sizeof(buff); i++) {
+            if (buff[i] != 0x96) {
+                CWM_OS_dbgPrintf("[test_stack] somebody touch my stack!!!\r\n");
+                CWM_OS_dbgPrintf("[test_stack] test for %lld ms end\r\n", CHECK_STACK_TIME_MS);
+                return;
+            }
+        }
+
+        CWM_OS_uSleep(200000);
+        current_time = CWM_OS_GetTimeNs() / 1000000;
+
+        if (current_time > begin_time && (current_time - begin_time > CHECK_STACK_TIME_MS)) {
+            break;
+        }
+        else if (begin_time > current_time && (0xffffffffffffffff - begin_time + current_time) > CHECK_STACK_TIME_MS) {
+            break;
+        }
+    }
+
+    CWM_OS_dbgPrintf("[test_stack] test for %lld ms end\r\n", CHECK_STACK_TIME_MS);
+}
+
+void test_api() {
+
+    test_GetTimeNs_0(); // up_time, accumulate ts_ns from zero
+    test_GetTimeNs_1(); // 10 seconds
+    test_GetTimeNs_2(); // 10 seconds, accurate to 1ms
+    test_GetTimeNs_3(); // 20 minutes
+
+    test_malloc_1();
+    test_free_1();
+
+    test_uSleep_1(); // 10 seconds
+    test_uSleep_2(); // 10 seconds, accurate to 1ms
+    test_uSleep_3(); // 10 seconds, accurate to 1us
+}
diff --git a/code/sdk/drivers/peripheral/cywee/tools/cwm_log_check.py b/code/sdk/drivers/peripheral/cywee/tools/cwm_log_check.py
new file mode 100644 (file)
index 0000000..7e80e7c
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+# # -*- coding: utf-8 -*-
+
+import re
+import sys
+
+def main():
+    if len(sys.argv) != 2:
+        print("usage: %s log_file_name" % (sys.argv[0]))
+        exit(1)
+
+    inputFile = sys.argv[1]
+
+    line_last = ""
+    sn_last = 0
+    line_no = 0
+    fail_times = 0;
+
+    with open(inputFile) as origin_file:
+        for line in origin_file:
+
+            line_no += 1
+
+            m = re.match(r'.*#_#\|(\d+)\|.*', line)
+            if m:
+                sn = int(m.group(1))
+
+                sn_diff = sn - sn_last
+
+                if sn_diff != 1 and sn != 0:
+                    fail_times += 1
+                    print("\nline_no=%d: %s" % (line_no - 1, line_last.strip()))
+                    print("line_no=%d: %s" % (line_no, line.strip()))
+                    print("SN_ERROR: sn_lost=%d" % (sn_diff -1))
+
+                sn_last = sn
+                line_last = line
+
+    if fail_times == 0:
+        print("\n=======log ok")
+    else:
+        print("\n=======log fail times=%d" % (fail_times))
+
+if __name__ == "__main__":
+    main()
diff --git a/code/sdk/drivers/peripheral/cywee/tools/cwm_log_check__readme.txt b/code/sdk/drivers/peripheral/cywee/tools/cwm_log_check__readme.txt
new file mode 100644 (file)
index 0000000..a0d6f10
--- /dev/null
@@ -0,0 +1,11 @@
+Any version of the Python program is available. (2.x or 3.x)
+
+command line, please input log_file name:
+python cwm_log_check.py test1.log
+
+
+The output of success:
+=======log ok
+
+The output of failure:
+=======log fail times=
index 6d67b87..115aa97 100644 (file)
@@ -1,60 +1,2 @@
-#===============================================================================
-# @brief    cmake file
-# Copyright (c) @CompanyNameMagicTag 2022-2023. All rights reserved.
-#===============================================================================
-set(COMPONENT_NAME "ppg_sensor")
-
-if("PPG_HX3695" IN_LIST DEFINES)
-set(SOURCES ${SOURCES}
-    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695/hx3695.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695/hx3695_check_touch.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695/hx3695_factory_test.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695/hx3695_hrs_agc.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695/hx3695_hrv_agc.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695/hx3695_spo2_agc.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695/hx3695_hrs_custom.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695/hx3695_at_cmd.c
-)
-set(PUBLIC_HEADER
-    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695
-)
-
-else()
-set(SOURCES ${SOURCES}
-    # ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_ctrl.c
-)
-set(PUBLIC_HEADER
-    ${CMAKE_CURRENT_SOURCE_DIR}
-)
-endif()
-
-
-set(PRIVATE_HEADER
-)
-
-set(PRIVATE_DEFINES
-)
-
-set(PUBLIC_DEFINES
-SUPPORT_AT_HX3695
-)
-
-# use this when you want to add ccflags like -include xxx
-set(COMPONENT_PUBLIC_CCFLAGS
-)
-
-set(COMPONENT_CCFLAGS
-)
-
-set(WHOLE_LINK
-    true
-)
-
-set(MAIN_COMPONENT
-    false
-)
-
-build_component()
-
-find_library(LIB_PATH_HX3695 hx3695/libhx3695.a ${CMAKE_CURRENT_SOURCE_DIR})
-target_link_libraries(${TARGET_NAME} PRIVATE -Wl,--whole-archive ${LIB_PATH_HX3695} PRIVATE -Wl,--whole-archive)
\ No newline at end of file
+add_subdirectory_if_exist(service)
+add_subdirectory_if_exist(hx3695)
\ No newline at end of file
diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/CMakeLists.txt b/code/sdk/drivers/peripheral/ppg/hx3695/CMakeLists.txt
new file mode 100644 (file)
index 0000000..ae485d7
--- /dev/null
@@ -0,0 +1,60 @@
+#===============================================================================
+# @brief    cmake file
+# Copyright (c) @CompanyNameMagicTag 2022-2023. All rights reserved.
+#===============================================================================
+set(COMPONENT_NAME "ppg_sensor")
+
+if("PPG_HX3695" IN_LIST DEFINES)
+set(SOURCES ${SOURCES}
+    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695_check_touch.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695_factory_test.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695_hrs_agc.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695_hrv_agc.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695_spo2_agc.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695_hal.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/hx3695_hrs_custom.c
+)
+set(PUBLIC_HEADER
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+else()
+set(SOURCES ${SOURCES}
+    # ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_ctrl.c
+)
+set(PUBLIC_HEADER
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
+endif()
+
+
+set(PRIVATE_HEADER
+)
+
+set(PRIVATE_DEFINES
+)
+
+set(PUBLIC_DEFINES
+# SUPPORT_AT_HX3695
+)
+
+# use this when you want to add ccflags like -include xxx
+set(COMPONENT_PUBLIC_CCFLAGS
+)
+
+set(COMPONENT_CCFLAGS
+)
+
+set(WHOLE_LINK
+    true
+)
+
+set(MAIN_COMPONENT
+    false
+)
+
+build_component()
+
+find_library(LIB_PATH_HX3695 libhx3695.a ${CMAKE_CURRENT_SOURCE_DIR})
+target_link_libraries(${TARGET_NAME} PRIVATE -Wl,--whole-archive ${LIB_PATH_HX3695} PRIVATE -Wl,--whole-archive)
\ No newline at end of file
index a88f9d2..fff8e98 100644 (file)
@@ -2654,7 +2654,7 @@ void hx3695_hrs_ppg_Int_handle(void)
     bp_results_t    bp_alg_results;\r
     bp_alg_results = tyhx_alg_get_bp_results();\r
 #endif\r
-\r
+ \r
 ////////////////////////////////////////BLE+DISPLAY/////////////////////////////////\r
 \r
 \r
@@ -2679,7 +2679,12 @@ void hx3695_hrs_ppg_Int_handle(void)
     }\r
     ble_rawdata_send_handler();\r
 #endif\r
-\r
+    hx3695_msg_callback_t func =  hx3695_get_send_msg_callback_func();\r
+    if(func != NULL)\r
+    {\r
+      func(HX3695_MSG_TYPE_WEARSTAT_UPDATE,&hrsresult.wearstatus,sizeof(int32_t));\r
+      func(HX3695_MSG_TYPE_HRS_UPDATE,&hrsresult,sizeof(FT_CUSTOM_RESULTS_t));\r
+    }\r
 ////////////////////////////////////////////////////////////////////////////////////\r
 }\r
 #endif\r
@@ -2963,7 +2968,7 @@ void hx3695_spo2_ppg_Int_handle(void)
 \r
     spo2_alg_results = tyhx_spo2_alg_get_results();\r
 //------------------------adjust-------------------\r
-    //DEBUG_PRINTF("block_cnt: %d, data_cnt:%d, hr_result:%d,ir_quality:%d,motion:%d,poor_signal:%d,reliable_score_result:%d,screen_up:%d,spo2_result:%d\r\n",spo2_alg_results.block_cnt,spo2_alg_results.data_cnt,spo2_alg_results.hr_result,spo2_alg_results.ir_quality,spo2_alg_results.motion,spo2_alg_results.poor_signal,spo2_alg_results.reliable_score_result,spo2_alg_results.screen_up,spo2_alg_results.spo2_result);\r
+    DEBUG_PRINTF("block_cnt: %d, data_cnt:%d, hr_result:%d,ir_quality:%d,motion:%d,poor_signal:%d,reliable_score_result:%d,screen_up:%d,spo2_result:%d\r\n",spo2_alg_results.block_cnt,spo2_alg_results.data_cnt,spo2_alg_results.hr_result,spo2_alg_results.ir_quality,spo2_alg_results.motion,spo2_alg_results.poor_signal,spo2_alg_results.reliable_score_result,spo2_alg_results.screen_up,spo2_alg_results.spo2_result);\r
 \r
     hrsresult.lastestspo2 = spo2_alg_results.spo2_result;\r
 //     if(hrsresult.lastestspo2)\r
@@ -2973,7 +2978,13 @@ void hx3695_spo2_ppg_Int_handle(void)
 //             gui_send_message_by_data(MSG_SPO2_DATA, &hrsresult.lastestspo2, 1);\r
 //             hr_sensor_notify_factory_test();\r
        }\r
-       \r
+           \r
+    hx3695_msg_callback_t func =  hx3695_get_send_msg_callback_func();\r
+    if(func != NULL)\r
+    {\r
+      func(HX3695_MSG_TYPE_WEARSTAT_UPDATE,&hrsresult.wearstatus,sizeof(spo2_wear_status));\r
+      func(HX3695_MSG_TYPE_SPO2_UPDATE,&hrsresult,sizeof(FT_CUSTOM_RESULTS_t));\r
+    }\r
 \r
 \r
 /////////////////////////////////////////BLE+DISPLAY//////////////////////////////////////////\r
index ba6c31b..7e91109 100644 (file)
@@ -25,7 +25,7 @@ NEW_GSEN_SCHME     DEMO调试使用, 客户关闭
 #define HRS_ALG_LIB   \r
 #define SPO2_ALG_LIB\r
 // #define HRV_ALG_LIB\r
-//#define CHECK_TOUCH_LIB\r
+// #define CHECK_TOUCH_LIB\r
 //#define CHECK_LIVING_LIB\r
 #define BP_CUSTDOWN_ALG_LIB\r
 \r
@@ -296,4 +296,6 @@ hx3695_living_results_t hx3695_living_get_results(void);
 void agc_timeout_handler(void * p_context);\r
 void heart_rate_meas_timeout_handler(void * p_context);\r
 \r
+#include "hx3695_hal.h"\r
+\r
 #endif\r
diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_at_cmd.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_at_cmd.c
deleted file mode 100644 (file)
index 630f414..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-
-#include "hx3695.h"
-#include "tyhx_hrs_custom.h"
-#include "at_cmd_api.h"
-#include "pm_control.h"
-
-
-#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
-#define HX3695_MAX_ARGC            8
-#define HX3695_MAX_ARGV_LEN        64
-
-#define HX3695_SUCCESS             0
-#define HX3695_FAILED              (-1)
-
-static int ConvertCmdToParam(uint8_t *para, uint32_t paraLen,
-        uint8_t argv[HX3695_MAX_ARGC][HX3695_MAX_ARGV_LEN], uint32_t* argc)
-{
-    uint32_t pos = 0;
-    *argc = 0;
-
-    for (uint32_t i = 0; i < paraLen; i++) {
-        if ((para[i] == ' ' || para[i] == '\n') && pos != 0) {
-            argv[*argc][pos] = '\0';
-            *argc += 1;
-            pos = 0;
-            if (*argc >= HX3695_MAX_ARGC) {
-                return HX3695_FAILED;
-            }
-        } else {
-            argv[*argc][pos] = para[i];
-            pos++;
-            if (pos >= HX3695_MAX_ARGV_LEN) {
-                return HX3695_FAILED;
-            }
-        }
-    }
-    if (pos != 0) {
-        *argc += 1;
-    }
-
-    return HX3695_SUCCESS;
-}
-
-
-static uint32_t hx3695_do_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
-{
-    UNUSED(strCommonCmd);
-    uint8_t argv[HX3695_MAX_ARGC][HX3695_MAX_ARGV_LEN] = { 0 };
-    uint32_t argc = 0;
-
-    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
-    if (ret != HX3695_SUCCESS) {
-        TYHX_ERROR("HX3695TEST ATCMD Convert Command Failed\n");
-        return ERRCODE_FAIL;
-    }
-
-    if (argc != 2) {
-        TYHX_ERROR("HX3695TEST ATCMD Set Parameter Failed\n");
-        return ERRCODE_FAIL;
-    }
-    char *mode = (char*)argv[0];
-    WORK_MODE_T md = NULL_MODE;
-    if (strcmp(mode, "hrs") == 0) {
-        md = HRS_MODE;
-    } else if (strcmp(mode, "hrv") == 0) {
-        md = HRV_MODE;
-    } else if (strcmp(mode, "spo2") == 0) {
-        md = SPO2_MODE;
-    } else if (strcmp(mode, "leaklight") == 0) {
-        md = FT_LEAK_LIGHT_MODE;
-    } else if (strcmp(mode, "graycard") == 0) {
-        md = FT_GRAY_CARD_MODE;
-    }
-    char *enable = (char *)argv[1];
-    if (strcmp(enable, "enable") == 0) {
-
-        uapi_pm_control(PM_APP_WAKE_NEEDED);
-        tyhx_poweron();
-        hx3695_init(md);
-    } else {
-       if(md == HRS_MODE|| md == FT_LEAK_LIGHT_MODE || md == FT_GRAY_CARD_MODE)
-        {
-#ifdef HRS_ALG_LIB   
-            hx3695_hrs_disable();
-#endif
-        }else  if(md == HRV_MODE)
-        {
-#ifdef HRV_ALG_LIB
-            hx3695_hrv_disable();
-#endif
-        }else  if(md == SPO2_MODE)
-        {
-#ifdef SPO2_ALG_LIB
-            hx3695_spo2_disable();
-#endif
-        }
-
-        uapi_pm_control(PM_APP_WAKE_NONEED);
-        tyhx_poweroff();
-    } 
-
-    return ERRCODE_SUCC;
-}
-
-static const at_cmd_table_t g_hx3695_cmd[] = {
-    { (char *)"AT^HX3695TEST",      hx3695_do_test, (char *)"hrs enable" },
-};
-
-at_cmd_table_t *get_hx3695_cmd_table(uint32_t *cmd_count)
-{
-    *cmd_count = ARRAY_COUNT(g_hx3695_cmd);
-    return (at_cmd_table_t *)g_hx3695_cmd;
-}
index 9b2b56f..c7e559a 100644 (file)
@@ -8,10 +8,9 @@
 #include "hx3695.h"\r
 #include "hx3695_factory_test.h"\r
 \r
-\r
 void hx3695_factory_wear_mode_config(void)\r
 {\r
-  uint16_t sample_rate = 10;                  /*config the data rate of chip alps2_fm ,uint is Hz*/\r
+    uint16_t sample_rate = 10;                  /*config the data rate of chip alps2_fm ,uint is Hz*/\r
     uint32_t prf_clk_num = 32000/sample_rate;   /*period in clk num, num = Fclk/fs */\r
          \r
     uint8_t adc_rst_post_num=0;       /* 00=16,01=32,10=64,11=128*/      \r
diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c
new file mode 100644 (file)
index 0000000..4d4d723
--- /dev/null
@@ -0,0 +1,82 @@
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "pm_control.h"
+#include "tyhx_hrs_custom.h"
+#include "hx3695.h"
+#include "hx3695_hal.h"
+#include "hx3695.h"
+
+
+hx3695_msg_callback_t g_send_msg_toUI = NULL;
+
+// typedef void (*hx3695_msg_callback_t)(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen);
+uint32_t hx3695_register_msg_callback(hx3695_msg_callback_t func)
+{
+    g_send_msg_toUI = func;
+    return 0;
+}
+
+hx3695_msg_callback_t hx3695_get_send_msg_callback_func(void)
+{
+    return g_send_msg_toUI;
+}
+
+
+#include "hx3695.h"
+#include "tyhx_hrs_custom.h"
+
+void ppg_send_cmd_to_driver(char* mode, uint8_t enable)
+{
+
+    WORK_MODE_T md = NULL_MODE;
+    if (strcmp(mode, "hrs") == 0) {
+        md = HRS_MODE;
+    } else if (strcmp(mode, "hrv") == 0) {
+        md = HRV_MODE;
+    } else if (strcmp(mode, "spo2") == 0) {
+        md = SPO2_MODE;
+    } else if (strcmp(mode, "leaklight") == 0) {
+        md = FT_LEAK_LIGHT_MODE;
+    } else if (strcmp(mode, "graycard") == 0) {
+        md = FT_GRAY_CARD_MODE;
+    }
+
+   
+    if (enable == 1) {
+
+        // ppg_service_running_stat = true;
+        uapi_pm_control(PM_APP_WAKE_NEEDED);
+        tyhx_poweron();
+        hx3695_init(md);
+    } else {
+
+    //    ppg_service_running_stat = false;
+       if(md == HRS_MODE|| md == FT_LEAK_LIGHT_MODE || md == FT_GRAY_CARD_MODE)
+        {
+#ifdef HRS_ALG_LIB   
+            hx3695_hrs_disable();
+#endif
+        }else  if(md == HRV_MODE)
+        {
+#ifdef HRV_ALG_LIB
+            hx3695_hrv_disable();
+#endif
+        }else  if(md == SPO2_MODE)
+        {
+#ifdef SPO2_ALG_LIB
+            hx3695_spo2_disable();
+#endif
+        }else{
+#ifdef HRS_ALG_LIB   
+            hx3695_hrs_disable();
+#endif
+        }
+        uapi_pm_control(PM_APP_WAKE_NONEED);
+        tyhx_poweroff();
+    } 
+}
\ No newline at end of file
diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.h b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.h
new file mode 100644 (file)
index 0000000..fffa641
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef HX_3695_H__
+#define HX_3695_H__
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#include "stdint.h"
+#include "tyhx_hrs_custom.h"
+
+typedef uint32_t PPG_CMD_TYPE_T ;
+
+typedef enum{
+    HX3695_MSG_TYPE_HRS_UPDATE,
+    HX3695_MSG_TYPE_HRV_UPDATE,
+    HX3695_MSG_TYPE_SPO2_UPDATE,
+    HX3695_MSG_TYPE_LEAKLIGHT_UPDATE,
+    HX3695_MSG_TYPE_GRAYCARD_UPDATE,
+    HX3695_MSG_TYPE_WEARSTAT_UPDATE,
+} hx3695_msg_type_t;
+
+
+typedef void (*hx3695_msg_callback_t)(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen);
+uint32_t hx3695_register_msg_callback(hx3695_msg_callback_t func);
+hx3695_msg_callback_t hx3695_get_send_msg_callback_func(void);
+
+void ppg_send_cmd_to_driver(char* mode, uint8_t enable);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif
\ No newline at end of file
index 7ea0bc3..5fa347d 100644 (file)
@@ -11,7 +11,6 @@
 #include "hx3695_hrs_agc.h"\r
 #include "tyhx_hrs_alg.h"\r
 \r
-\r
 #ifdef HRS_ALG_LIB\r
 extern const uint8_t  hx3695_hrs_agc_idac;\r
 extern uint8_t  hx3695_hrs_g1_agc_idac;\r
index 0a70049..46bff12 100644 (file)
@@ -50,7 +50,7 @@ typedef struct {
 \r
 typedef enum {    \r
     hrsCalStart, \r
-               hrsCalStart1,\r
+       hrsCalStart1,\r
     hrsCalLed,\r
     hrsCalLed2,\r
     hrsCalLed3,\r
@@ -65,18 +65,18 @@ typedef struct {
        uint8_t int_cnt;\r
        uint8_t cur255_cnt;\r
        uint8_t Group1_Ledidac;   //led_idac\r
-  uint8_t Group2_Ledidac; \r
-  uint8_t Group3_Ledidac;      \r
+       uint8_t Group2_Ledidac; \r
+       uint8_t Group3_Ledidac;         \r
        uint16_t Group1_Cur;   //LED; \r
        uint16_t Group2_Cur;   //LED;\r
        uint16_t Group3_Cur;   //LED;\r
 //     uint8_t LEDDAC; \r
        uint8_t Group1_AMBDAC; \r
-  uint8_t Group2_AMBDAC;\r
-  uint8_t Group3_AMBDAC;       \r
+       uint8_t Group2_AMBDAC;\r
+       uint8_t Group3_AMBDAC;  \r
        uint8_t Group1_RF;\r
-  uint8_t Group2_RF;\r
-  uint8_t Group3_RF;   \r
+       uint8_t Group2_RF;\r
+       uint8_t Group3_RF;      \r
        uint32_t Group1_step;\r
        uint32_t Group2_step;\r
        uint32_t Group3_step;\r
index 6a6224b..37e867d 100644 (file)
@@ -191,12 +191,12 @@ bool tyhx_timer_stop(uint32_t ms)
 
 uint32_t tyhx_suspend(void)
 {
-
+    i2c_save_reg(HX3695_I2C_BUS);
     return 0;
 }
 uint32_t tyhx_resume(void)
 {
-
+    i2c_recovery_reg(HX3695_I2C_BUS);
     return 0;
 }
 
index db07398..59d4ae5 100644 (file)
@@ -29,7 +29,7 @@
 typedef enum {    \r
    \r
     sCalStart,\r
-               sCalStart1,     \r
+       sCalStart1,     \r
     sCalLed,\r
     sCalLed2,\r
     sCalLed3,\r
@@ -117,6 +117,6 @@ bool hx3695_spo2_check_wear(int32_t infrared_data);
 SPO2_CAL_SET_T get_spo2_agc_status(void);\r
 SPO2_CAL_SET_T PPG_spo2_agc(void);\r
 void hx3695_spo2_data_reset(void);\r
-void hx3695_spo2_read_data(int32_t *s_buf);\r
+// void hx3695_spo2_read_data(int32_t *s_buf);\r
 \r
 #endif\r
index de67fcb..00dfde0 100644 (file)
@@ -33,12 +33,12 @@ extern FT_CUSTOM_RESULTS_t hrsresult;
 
 #define TYHX_ERROR(x, ...) \
     do { \
-        PRINT("[ERROR]%s(%d): "x"\r\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
+        PRINT("[ERROR]%s(%d): " x"\r\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
     } while (0)
 
 #define TYHX_WARNING(x, ...) \
     do { \
-        PRINT("[WARNING]%s(%d): "x"\r\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
+        PRINT("[WARNING]%s(%d): " x"\r\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
     } while (0)
 
 
@@ -77,6 +77,7 @@ extern void hx3695_hrs_disable(void);
 extern void hx3695_hrv_disable(void);
 extern void hx3695_spo2_disable(void);
 
-
+//读取acc数据函数
 void readFifoByHrsModule(void);
+
 #endif //__TYHX_HRS_CUSTOM_H__
\ No newline at end of file
diff --git a/code/sdk/drivers/peripheral/ppg/service/CMakeLists.txt b/code/sdk/drivers/peripheral/ppg/service/CMakeLists.txt
new file mode 100644 (file)
index 0000000..bed307c
--- /dev/null
@@ -0,0 +1,58 @@
+#===============================================================================
+# @brief    cmake file
+# Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved.
+#===============================================================================
+
+set(COMPONENT_NAME "ppg_service")
+
+set(PUBLIC_HEADER
+${CMAKE_CURRENT_SOURCE_DIR}
+)
+set(PRIVATE_HEADER
+    ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits
+    ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits
+    ${ROOT_DIR}/application/wearable/nativeapp/nativeui/heartrate/include
+)
+
+set(SOURCES
+${CMAKE_CURRENT_SOURCE_DIR}/ppg_at_cmd.cpp
+${CMAKE_CURRENT_SOURCE_DIR}/ppg_service.cpp
+)
+
+set(COMPONENT_PUBLIC_CCFLAGS
+)
+
+set(COMPONENT_CCFLAGS
+    -std=c++11
+    -Wno-error
+    -Wno-unused-parameter
+    -fno-exceptions
+    -fno-unwind-tables
+    -fno-asynchronous-unwind-tables
+    -Wno-undef
+    -Wno-bitwise-op-parentheses
+    -Wno-shift-op-parentheses
+    -nostdlibinc
+    -nostdinc
+    -nostdlib
+    -Wno-c++11-narrowing
+    -Wno-error=unused-function
+)
+
+set(WHOLE_LINK
+    true
+)
+
+set(MAIN_COMPONENT
+    false
+)
+
+set(PUBLIC_DEFINES
+SUPPORT_PPG_SERVICE
+SUPPORT_AT_PPG
+)
+
+set(PRIVATE_DEFINES
+)
+
+build_component()
diff --git a/code/sdk/drivers/peripheral/ppg/service/ppg_at_cmd.cpp b/code/sdk/drivers/peripheral/ppg/service/ppg_at_cmd.cpp
new file mode 100644 (file)
index 0000000..e58c738
--- /dev/null
@@ -0,0 +1,106 @@
+
+#include "at_cmd_api.h"
+#include "pm_control.h"
+#include "ppg_service.h"
+#include "ppg_at_cmd.h"
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
+#define PPG_MAX_ARGC            8
+#define PPG_MAX_ARGV_LEN        64
+
+#define PPG_SUCCESS             0
+#define PPG_FAILED              (-1)
+
+static int ConvertCmdToParam(uint8_t *para, uint32_t paraLen,
+        uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN], uint32_t* argc)
+{
+    uint32_t pos = 0;
+    *argc = 0;
+
+    for (uint32_t i = 0; i < paraLen; i++) {
+        if ((para[i] == ' ' || para[i] == '\n') && pos != 0) {
+            argv[*argc][pos] = '\0';
+            *argc += 1;
+            pos = 0;
+            if (*argc >= PPG_MAX_ARGC) {
+                return PPG_FAILED;
+            }
+        } else {
+            argv[*argc][pos] = para[i];
+            pos++;
+            if (pos >= PPG_MAX_ARGV_LEN) {
+                return PPG_FAILED;
+            }
+        }
+    }
+    if (pos != 0) {
+        *argc += 1;
+    }
+
+    return PPG_SUCCESS;
+}
+
+
+static uint32_t ppg_do_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN] = { 0 };
+    uint32_t argc = 0;
+
+    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+    if (ret != PPG_SUCCESS) {
+        printf("PPGTEST ATCMD Convert Command Failed\n");
+        return ERRCODE_FAIL;
+    }
+
+    if (argc != 2) {
+        printf("PPGTEST ATCMD Set Parameter Failed\n");
+        return ERRCODE_FAIL;
+    }
+    char *mode = (char*)argv[0];
+    int enabled = atoi((char*)argv[1]);
+
+    uint32_t md = PPG_SERVICE_CMD_TYPE_DO_PPG_TEST;
+    if (strcmp(mode, "hrs") == 0) {
+        md = PPG_SERVICE_CMD_TYPE_DO_PPG_TEST;
+    } else if (strcmp(mode, "hrv") == 0) {
+        md = PPG_SERVICE_CMD_TYPE_DO_HRV_TEST;
+    } else if (strcmp(mode, "spo2") == 0) {
+        md = PPG_SERVICE_CMD_TYPE_DO_SPO2_TEST;
+    } else if (strcmp(mode, "leaklight") == 0) {
+        md = PPG_SERVICE_CMD_TYPE_DO_LEAKLIGHT_TEST;
+    } else if (strcmp(mode, "graycard") == 0) {
+        md = PPG_SERVICE_CMD_TYPE_DO_GRAYCARD_TEST;
+    }
+    if(enabled == 0 )
+    {   
+        if (md == PPG_SERVICE_CMD_TYPE_DO_SPO2_TEST)
+        {
+            md = PPG_SERVICE_CMD_TYPE_STOP_SPO2_TEST;
+        }else{
+            md = PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST;
+        }
+    }
+    
+    printf("PPGTEST ATCMD  cmd %s, enable %d, mode 0x%02X \n",mode,enabled,md);
+
+    send_ppg_cmd_msg(md);
+
+    return ERRCODE_SUCC;
+}
+
+static const at_cmd_table_t g_ppg_cmd[] = {
+    { (char *)"AT^PPGTEST",      ppg_do_test, (char *)"hrs enable" },
+};
+
+at_cmd_table_t *get_ppg_cmd_table(uint32_t *cmd_count)
+{
+    *cmd_count = ARRAY_COUNT(g_ppg_cmd);
+    return (at_cmd_table_t *)g_ppg_cmd;
+}
@@ -21,7 +21,7 @@ extern "C" {
 #endif /* __cplusplus */
 #endif /* __cplusplus */
 
-at_cmd_table_t *get_hx3695_cmd_table(uint32_t *cmd_count);
+at_cmd_table_t *get_ppg_cmd_table(uint32_t *cmd_count);
 
 #ifdef __cplusplus
 #if __cplusplus
diff --git a/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp b/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp
new file mode 100644 (file)
index 0000000..7176797
--- /dev/null
@@ -0,0 +1,277 @@
+/**
+ * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n
+ *
+ * Description: Test  source \n
+ * Author: @CompanyNameTag \n
+ * History: \n
+ * 2022-08-16, Create file. \n
+ */
+
+#include "wearable_log.h"
+#include "securec.h"
+#include "broadcast_service.h"
+#include "broadcast_feature.h"
+#include "service_id_define.h"
+#include "samgr_lite.h"
+#include "thread_adapter.h"
+#include "graphic_service.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#include "pinctrl.h"
+#include "debug_print.h"
+#include "soc_osal.h"
+#include "tcxo.h"
+#include "irmalloc.h"
+#include "errcode.h"
+#include "common_def.h"
+
+#include "chip_core_irq.h"
+#include "chip_io.h"
+#include "gpio.h"
+#include "pm_veto.h"
+
+#include "rtc.h"
+#include "timer.h"
+#include "systick.h"
+#include "cmsis_os2.h"
+#include "ppg_service.h"
+#include "los_printf.h"
+
+
+#include "hx3695_hal.h"
+
+static bool g_ppg_service_initialled = false;
+
+/***
+ * 其他cmd在Header里定义,对外开放
+*/
+
+
+#define PPG_SERVICE_MSG_COUNT       16
+#define PPG_SERVICE_TASK_SIZE       0x800
+#define PPG_SERVICE_TASK_PRIO       5
+
+#define MAG_CHECK_MS 20
+static unsigned long g_app_queue;
+
+static bool ppg_service_running_stat = false;
+
+
+
+void CustomEventPublish(uint16_t topic, uint8_t *data , uint32_t size)
+{
+    int32 ret;
+    
+    Request *request = NULL;
+    BroadcastApi *broadcastApi = NULL;
+    IUnknown *api = NULL;
+
+    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish topic=%u!!", topic);
+
+    /* alloc request */
+    request = SAMGR_AllocRequestMsg(0, PLATFORM_CORE, BROADCAST_SVR_ID, size);
+    if (request == NULL) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SAMGR_AllocRequestMsg failed");
+        return;
+    }
+    request->msgId = topic;
+    ret = memcpy_s(request->data, size, (const void *)data, size);
+    if (ret != EOK) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish memcpy_s rateDataTmp fail! ret = %d", ret);
+        return;
+    }
+    request->len = size;
+    request->msgValue = 0;
+
+    /* public request */
+    api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, BROADCAST_FEATURE_NAME);
+    if (api == NULL) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetFeatureApi failed");
+        SAMGR_FreeRequestMsg(request);
+        return;
+    }
+    ret = api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi);
+    if (ret != 0 || broadcastApi == NULL) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "QueryInterface failed");
+        SAMGR_FreeRequestMsg(request);
+        return;
+    }
+    broadcastApi->PublishTopic((IUnknown *)broadcastApi, request);
+    broadcastApi->Release((IUnknown *)broadcastApi);
+    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish end!!");
+
+    return;
+}
+
+
+
+errcode_t update_spo2_event_notify(uint8_t spo2)
+{
+   
+    CustomEventPublish(TOPIC_EVENT_STEPDATA_UPDATE,(uint8_t*)&spo2,sizeof(spo2));
+    return 0;
+}
+errcode_t update_spo2_event_sendmsg_toUI(uint8_t spo2)
+{
+
+    /**通过UI事件发送Notify*/
+    GraphicService::GetInstance()->PostGraphicEvent(std::bind(update_spo2_event_notify, spo2));
+    return ERRCODE_SUCC;
+}
+
+#include "hx3695_hal.h"
+void hx3695_msg_callback(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen)
+{
+    switch(msg_type)
+    {
+        case HX3695_MSG_TYPE_HRS_UPDATE:
+            break;
+        case HX3695_MSG_TYPE_HRV_UPDATE:
+            break;
+        case HX3695_MSG_TYPE_SPO2_UPDATE:
+            break;
+        case HX3695_MSG_TYPE_LEAKLIGHT_UPDATE:
+            break;
+        case HX3695_MSG_TYPE_GRAYCARD_UPDATE:
+            break;
+        case HX3695_MSG_TYPE_WEARSTAT_UPDATE:
+            break;
+        default:
+            break;
+    }
+}
+
+void uapi_ppg_service_deinit(void)
+{
+
+
+    ppg_service_running_stat = false;
+}
+
+#include "tyhx_hrs_custom.h"
+
+uint32_t ppg_suspend(void)
+{
+    return tyhx_suspend();
+}
+uint32_t ppg_resume(void)
+{
+    return tyhx_resume();
+}
+
+
+void send_ppg_cmd_msg(int cmd)
+{
+    int ret;
+
+    PPG_CMD_TYPE_T mail = 0;
+    mail = cmd;
+    ret = osal_msg_queue_write_copy(g_app_queue, (void *)&mail,
+                                    sizeof(PPG_CMD_TYPE_T), 0);
+    if (ret != OSAL_SUCCESS) {
+        PRINT_ERR("Error mag Check MSG 0x%02X send failed! err=0x%x! \r\n",cmd, ret);
+    }
+    
+}
+
+static void ppg_service_check_task(void const *arg)
+{
+    unused(arg);
+    int32_t ret;
+    uint32_t mail;
+    uint32_t msgsize = (uint32_t)sizeof(PPG_CMD_TYPE_T);
+
+    while (1) {
+        ret = osal_msg_queue_read_copy(g_app_queue, (void *)&mail, &msgsize,
+                                       OSAL_MSGQ_WAIT_FOREVER);
+        if (ret != OSAL_SUCCESS) {
+            continue;
+        }
+
+        char* cmd = "hrs";
+        int enable = 1;
+        if (mail == PPG_SERVICE_CMD_TYPE_DO_PPG_TEST){
+            cmd = "hrs";
+            enable = 1;
+        }else if (mail == PPG_SERVICE_CMD_TYPE_DO_HRV_TEST){
+            cmd = "hrv";
+            enable = 1;
+        }else if (mail == PPG_SERVICE_CMD_TYPE_DO_SPO2_TEST){
+            cmd = "spo2";
+            enable = 1;
+        }else if (mail == PPG_SERVICE_CMD_TYPE_DO_LEAKLIGHT_TEST){
+            cmd = "leaklight";
+            enable = 1;
+        }else if (mail == PPG_SERVICE_CMD_TYPE_DO_GRAYCARD_TEST){
+            cmd = "graycard";
+            enable = 1;
+        }else if (mail == PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST){
+           
+            cmd = "hrs";
+            enable = 0;
+        }else if (mail == PPG_SERVICE_CMD_TYPE_STOP_SPO2_TEST){
+   
+            cmd = "spo2";
+            enable = 0;
+        }
+        if (ppg_service_running_stat == true && enable ==1 )
+        {
+            PRINT_ERR("ppg service already started! \r\n");
+            continue ;
+        }else if ( ppg_service_running_stat == false && enable == 0 )
+        {
+            PRINT_ERR("ppg service already stopped! \r\n");
+            continue ;
+        }
+        ppg_send_cmd_to_driver(cmd,enable);
+        if(enable == 1)
+            ppg_service_running_stat = true;
+        else
+            ppg_service_running_stat = false;
+        
+    }
+}
+
+errcode_t uapi_ppg_service_init(void)
+{
+    if (osal_msg_queue_create("ppg_service_queue", PPG_SERVICE_MSG_COUNT, &g_app_queue,
+                              0, sizeof(PPG_CMD_TYPE_T)) != ERRCODE_SUCC) {
+        PRINT_ERR("[mag][service] app create mail fail\n");
+        return ERRCODE_FAIL;
+    }
+
+
+    osal_task *task_handle = osal_kthread_create((osal_kthread_handler)ppg_service_check_task, NULL,
+                                                 "ppg_service_service", PPG_SERVICE_TASK_SIZE);
+    if (task_handle == NULL) {
+        osal_msg_queue_is_full(g_app_queue);
+        PRINT_ERR("create mag service thread fail!\r\n");
+        return ERRCODE_FAIL;
+    }
+
+    osal_kthread_set_priority(task_handle, PPG_SERVICE_TASK_PRIO);
+
+    return ERRCODE_SUCC;
+}
+
+// void ppg_service_service_resume(void)
+// {
+//     DEBUG_PRINTF("ppg_service_service resume!\r\n");
+//     ppg_service_check_timer_callback(0);
+// }
+// void ppg_service_service_suspend(void)
+// {
+//     DEBUG_PRINTF("ppg_service_service suspend!\r\n");
+// }
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
diff --git a/code/sdk/drivers/peripheral/ppg/service/ppg_service.h b/code/sdk/drivers/peripheral/ppg/service/ppg_service.h
new file mode 100644 (file)
index 0000000..545e813
--- /dev/null
@@ -0,0 +1,75 @@
+/**
+ * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n
+ *
+ * Description: Test adc header \n
+ * Author: @CompanyNameTag \n
+ * History: \n
+ * 2022-08-16, Create file. \n
+ */
+
+#ifndef PPG_SERVICE_H__
+#define PPG_SERVICE_H__
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#include "stdint.h"
+#include "errcode.h"
+
+
+#define PPG_SERVICE_CMD_TYPE_DO_PPG_TEST 0x11
+#define PPG_SERVICE_CMD_TYPE_DO_HRV_TEST 0x12
+#define PPG_SERVICE_CMD_TYPE_DO_SPO2_TEST 0x13
+#define PPG_SERVICE_CMD_TYPE_DO_LEAKLIGHT_TEST 0x14
+#define PPG_SERVICE_CMD_TYPE_DO_GRAYCARD_TEST 0x15
+#define PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST 0x1E
+#define PPG_SERVICE_CMD_TYPE_STOP_SPO2_TEST 0x1F
+
+errcode_t uapi_ppg_service_init(void);
+void uapi_ppg_service_deinit(void);
+/**
+ * 测试指令 参数cmd 选项: PPG_SERVICE_CMD_START_CHECK,PPG_SERVICE_CMD_STOP_CHECK
+*/
+void send_ppg_cmd_msg(int cmd);
+
+float ppg_service_get_fAzimuth(void);
+int ppg_service_get_iAccuracy(void);
+
+uint32_t ppg_suspend(void);
+uint32_t ppg_resume(void);
+
+typedef enum {
+    PPG_TEST_MODE_HRS,
+    PPG_TEST_MODE_SPO2,
+    PPG_TEST_MODE_LEAKLIGHT,
+    PPG_TEST_MODE_GRAYCARD,
+    PPG_TEST_MODE_NOTSUPPORT,
+} ppg_data_mode_t;
+
+typedef enum {
+    PPG_DATA_WORKING_STAT_STOP,
+    PPG_DATA_WORKING_STAT_TESTING,
+    PPG_DATA_WORKING_STAT_RESULT,
+    PPG_DATA_WORKING_STAT_UNKNOWN,
+} ppg_data_working_status_t;
+
+typedef struct {
+    uint8_t mode; // 0 hrs, 1 spo2,
+    uint8_t status; // 0 stop, 1 testing data , 2 result
+    uint16_t hrs; // 心率 
+    uint16_t spo2; //血氧
+    uint64_t timestamp; //上报数据时间戳, 单位ms
+}ppg_data_t;
+
+void CustomEventPublish(uint16_t topic, uint8_t *data , uint32_t size);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif
\ No newline at end of file
index bd7ece6..e325f46 100644 (file)
@@ -69,10 +69,8 @@ static uint32_t rotary_encoder_get_state(struct re_driver_data *redd)
 
 static void convert_encoder_info(input_dev_data_t* data, re_input_event_info* encoder_info)
 {
-    data->x = (int16_t)encoder_info->re_event_info.x_axis[0];
-    data->y = (int16_t)encoder_info->re_event_info.y_axis[0];
     data->type = INDEV_TYPE_ENCODER;
-    data->encoderDiff = data->x;
+    data->rotate = (int16_t)encoder_info->re_event_info.x_axis[0];
     data->timestamp = (uint32_t)encoder_info->tv_usec;
     if ((encoder_info->re_event == MC_RE_PRESS) || (encoder_info->re_event == MC_RE_MOVE)) {
         data->state = INDEV_STATE_PRESS;
@@ -91,7 +89,7 @@ static void report_or_enqueue_event(re_input_event_info* encoder_info, struct re
         // if (data.state == INDEV_STATE_UNKNOWN) {
             // return;
         // }
-        re_print("report encoder diff %d ,state %d \n",data.encoderDiff,data.state);
+        // re_print("report encoder diff %d ,state %d \n",data.encoderDiff,data.state);
         g_re_report_event_cb(&data);
     } else {
         // re_print("re_en_queue encoder diff %d \n",encoder_info->re_event_info.x_axis[0]);
@@ -136,18 +134,22 @@ ext_errno encoder_info_process(void)
         if (ret != EXT_ERR_SUCCESS) {
             re_err("get encoder info fail! ret=0x%x", ret);
         }
-        // re_print("encoder_info_process\n");
+        re_print("encoder_info_process1\n");
         report_or_enqueue_event(&encoder_info, redd);
 #if defined(SUPPORT_POWER_MANAGER)
         report_event_to_power_manager(&encoder_info);
 #endif
     }
+    
+    
+    re_print("encoder_info_process2\n");
 
     return EXT_ERR_SUCCESS;
 }
 
 static void re_callback_func(void)
 {
+    return ;
     ext_errno ret;
     if (g_attr_re != NULL) {
         common_notify_mail_t mail = {0};
index f7d7878..4cd1aca 100644 (file)
@@ -2,22 +2,22 @@
 # @brief    cmake file
 # Copyright (c) @CompanyNameMagicTag 2023-2023. All rights reserved.
 #===============================================================================
-set(COMPONENT_NAME "SLIP")
+set(COMPONENT_NAME "slip")
 set(LWIP_PORT_SOURCES 
-    ${CMAKE_CURRENT_SOURCE_DIR}/port/vfs_lwip.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/port/debug/lwip_debug.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/port/netif/ethernetif.c
+    ${ROOT_DIR}/open_source/openharmony/third_party/lwip/port/vfs_lwip.c
+    ${ROOT_DIR}/open_source/openharmony/third_party/lwip/port/debug/lwip_debug.c
+    ${ROOT_DIR}/open_source/openharmony/third_party/lwip/port/netif/ethernetif.c
 )
 set(SOURCES ${SOURCES}
     ${CMAKE_CURRENT_SOURCE_DIR}/asio.c
     ${CMAKE_CURRENT_SOURCE_DIR}/slipif.c
     ${CMAKE_CURRENT_SOURCE_DIR}/uart_slip.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/uart_slip.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/udp_server.c
     # ${LWIP_PORT_SOURCES}
 )
 set(PUBLIC_HEADER
     ${CMAKE_CURRENT_SOURCE_DIR}
-    # ${CMAKE_CURRENT_SOURCE_DIR}/port
+    ${ROOT_DIR}/open_source/openharmony/third_party/lwip/port
 )
 set(PUBLIC_DEFINES
     SUPPORT_AT_SLIP
index 34de6ab..4912c80 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
+// #include "freertos/FreeRTOS.h"
+// #include "freertos/task.h"
 
 #include "driver/uart.h"
 #include "lwip/sio.h"
 
-#ifdef QUECTEL_CONFIG_HIGH_SPEED_SUPPORT
-#define SEND_BUFFER_MAX (6)
-#else
-#define SEND_BUFFER_MAX (1)
-#endif
+#include "uart.h"
+#include "osal_debug.h"
+#include "osal_addr.h"
+#include "osal_interrupt.h"
+#include "securec.h"
+#include "common_def.h"
+
+#include "tcxo.h"
+#include "osal_debug.h"
+
+
+#define SLIP_UART_SEND_BUFFER_MAX (64)
+#define SLIP_UART_RX_BUFF_SIZE (64)
+
 
 struct slip_send_buffer_t {
-       uint8_t buffer[SEND_BUFFER_MAX+1];
+       uint8_t buffer[SLIP_UART_SEND_BUFFER_MAX+1];
        int len;
 };
 
@@ -56,6 +65,101 @@ struct slip_send_buffer_t slip_send_buffer;
 /* The following functions can be defined to something else in your cc.h file
    or be implemented in your custom sio.c file. */
 
+
+
+#if defined(CONFIG_UART_SUPPORT_DMA)
+#include "hal_dma.h"
+#endif  /* CONFIG_UART_SUPPORT_DMA */
+
+
+
+
+
+typedef enum {
+    UART_TRANSFER_MODE_POLL,
+    UART_TRANSFER_MODE_INT,
+    UART_TRANSFER_MODE_DMA
+} uart_transfer_mode_t;
+
+uint8_t g_uart_rx_buff[SLIP_UART_RX_BUFF_SIZE] = { 0 };
+static uint32_t g_uart_read_count = 0;
+static uint32_t g_test_uart_read_int_num = 0;
+uart_buffer_config_t g_uart_buffer_config = {
+    .rx_buffer = g_uart_rx_buff,
+    .rx_buffer_size = SLIP_UART_RX_BUFF_SIZE
+};
+uart_bus_t g_uart_bus = UART_BUS_0;
+static void uart_slip_read_int_handler(const void *buffer, uint16_t length, bool error)
+{
+    unused(error);
+    osal_printk("uart_slip_read_int_handler length=%x\r\n", length);
+
+    // do_uart_slip_cmd(0x01,buffer,length);
+    
+}
+static int32_t slip_uart_config(void)
+{
+
+    bool tx_dma_enable = false;
+    bool rx_dma_enable = false;
+    uart_attr_t attr = { 0 };
+
+    uint32_t param_index = 0;
+    uart_bus_t bus = UART_BUS_0;
+    
+    uapi_uart_deinit(bus);
+
+    attr.baud_rate = 921600;
+    attr.data_bits = UART_DATA_BIT_8;
+    attr.stop_bits = UART_STOP_BIT_1;
+    attr.parity = UART_PARITY_NONE;
+
+    osal_printk("uapi_uart_init bus=%d baud_rate=%d, data_bits=%d, stop_bits=%d, parity=%d\r\n", bus, attr.baud_rate, \
+                attr.data_bits, attr.stop_bits, attr.parity);   
+
+    uart_pin_config_t pin_config = {
+        .tx_pin = S_MGPIO19,
+        .rx_pin = S_MGPIO20,
+        .cts_pin = PIN_NONE,
+        .rts_pin = PIN_NONE
+    };
+    
+    uart_extra_attr_t extra_attr = {
+        .tx_dma_enable = tx_dma_enable,
+        .tx_int_threshold = 0,
+        .rx_dma_enable = rx_dma_enable,
+        .rx_int_threshold = 0
+    };
+
+    errcode_t errcode = uapi_uart_init(bus, &pin_config, &attr, &extra_attr, &g_uart_buffer_config);
+    osal_printk("uapi_uart_init ret=%x\r\n", errcode);
+    if (errcode != ERRCODE_SUCC) {
+        return ERRCODE_UART_INIT_TRX_STATE_FAIL;
+    }
+    g_uart_bus = bus;
+
+
+   errcode = uapi_uart_register_rx_callback(g_uart_bus, UART_RX_CONDITION_FULL_OR_SUFFICIENT_DATA_OR_IDLE,
+                                   SLIP_UART_RX_BUFF_SIZE, uart_slip_read_int_handler);
+                                   
+    osal_printk("uapi_uart_register_rx_callback ret=%x\r\n", errcode);
+
+       if (errcode != ERRCODE_SUCC) {
+        return ERRCODE_UART_INIT_TRX_STATE_FAIL;
+    }
+    return ERRCODE_SUCC;
+}
+
+static int slip_uart_write(uint8_t *tx_buff,uint32_t size)
+{
+ 
+       return uapi_uart_write(g_uart_bus, tx_buff, size,0);
+
+}
+uint32_t slip_uart_read( uint8_t *data, uint32_t len)
+{
+    return uapi_uart_read(g_uart_bus,data,len,0);
+}
 /**
  * Opens a serial device for communication.
  *
@@ -65,6 +169,8 @@ struct slip_send_buffer_t slip_send_buffer;
 sio_fd_t sio_open(u8_t devnum)
 {
        memset(&slip_send_buffer, 0x00, sizeof(struct slip_send_buffer_t));
+
+       // slip_uart_config();
        return 1;
 }
 
@@ -78,22 +184,26 @@ sio_fd_t sio_open(u8_t devnum)
  */
 void sio_send(u8_t c, sio_fd_t fd)
 {
+       // slip_uart_write( (const char *)&c, 1);
        //uart_write_bytes(UART_NUM_0, (const char *)&c, 1);
        slip_send_buffer.buffer[slip_send_buffer.len] = c;
        slip_send_buffer.len += 1;
-       if( slip_send_buffer.len >= (SEND_BUFFER_MAX) ) {
+       if( slip_send_buffer.len >= (SLIP_UART_SEND_BUFFER_MAX) ) {
                //printf("send2 data len = %d\n", slip_send_buffer.len);
-               uart_write_bytes(UART_NUM_0, (const char *)slip_send_buffer.buffer, slip_send_buffer.len);
+               // uart_write_bytes(UART_NUM_0, (const char *)slip_send_buffer.buffer, slip_send_buffer.len);
+               slip_uart_write((const char *)slip_send_buffer.buffer, slip_send_buffer.len);
                slip_send_buffer.len = 0;
        }
 }
 
 void sio_send_all(u8_t c, sio_fd_t fd)
 {
+       // slip_uart_write( (const char *)&c, 1);
        //uart_write_bytes(UART_NUM_0, (const char *)&c, 1);
        if( slip_send_buffer.len > 0 ) {
                //printf("send data len = %d\n", slip_send_buffer.len);
-               uart_write_bytes(UART_NUM_0, (const char *)slip_send_buffer.buffer, slip_send_buffer.len);
+               slip_uart_write((const char *)slip_send_buffer.buffer, slip_send_buffer.len);
+               // uart_write_bytes(UART_NUM_0, (const char *)slip_send_buffer.buffer, slip_send_buffer.len);
                slip_send_buffer.len = 0;
        }
 }
@@ -107,5 +217,12 @@ void sio_send_all(u8_t c, sio_fd_t fd)
  */
 u8_t sio_recv(sio_fd_t fd)
 {
-       return 0;
+    u8_t tmp = 0;
+    slip_uart_read(&tmp,1);
+       return tmp;
 }
+
+u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len)
+{
+       return slip_uart_read(data,len);
+}
\ No newline at end of file
diff --git a/code/sdk/drivers/peripheral/slip/cat1slip.c b/code/sdk/drivers/peripheral/slip/cat1slip.c
deleted file mode 100644 (file)
index 0b33566..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#define SLIP_UART_BUS UART_BUS_1
-#define CHIP_FIXED_TX_PIN S_MGPIO33
-#define CHIP_FIXED_RX_PIN S_MGPIO34
-
-void slipinit(void)
-{
-       uart_set_baudrate(UART_NUM_1,921600);
-
-    uint8_t ret = slip_uart_init((int)setting);
-    if( ret != 0 ) {
-        printf("custom_uart_init fail ret = %d\n", ret);
-        return;
-    }
-   
-    user_netif_set_default();
-}
\ No newline at end of file
index 0e4fc53..8b5cd2e 100644 (file)
@@ -265,7 +265,7 @@ slipif_rxbyte(struct netif *netif, u8_t c)
   if (priv->p == NULL) {
     /* allocate a new pbuf */
     LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n"));
-    priv->p = pbuf_alloc(PBUF_LINK, (PBUF_POOL_BUFSIZE - PBUF_LINK_HLEN - PBUF_LINK_ENCAPSULATION_HLEN), PBUF_POOL);
+    priv->p = pbuf_alloc(PBUF_LINK, (PBUF_POOL_BUFSIZE - PBUF_LINK_HLEN - PBUF_LINK_ENCAPSULATION_HLEN), PBUF_RAM);
 
     if (priv->p == NULL) {
       LINK_STATS_INC(link.drop);
@@ -329,12 +329,13 @@ slipif_rxbyte_input(struct netif *netif, u8_t c)
  *
  * @param nf the lwip network interface structure for this slipif
  */
-static void
+void
 slipif_loop_thread(void *nf)
 {
   u8_t c;
   struct netif *netif = (struct netif *)nf;
   struct slipif_priv *priv = (struct slipif_priv *)netif->state;
+  LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread  !\n"));
 
   while (1) {
     if (sio_read(priv->sd, &c, 1) > 0) {
@@ -359,6 +360,13 @@ slipif_loop_thread(void *nf)
  * @note If netif->state is interpreted as an u8_t serial port number.
  *
  */
+
+#if SLIP_USE_RX_THREAD
+#define SLIP_CMD_TASK_MSG_COUNT 16
+#define SLIP_CMD_TASK_SIZE 0x100
+#define SLIP_CMD_TASK_PRIO 5
+#include "soc_osal.h"
+#endif
 err_t
 slipif_init(struct netif *netif)
 {
@@ -375,6 +383,7 @@ slipif_init(struct netif *netif)
   if( priv == NULL ) {
     priv = (struct slipif_priv *)mem_malloc(sizeof(struct slipif_priv));
     if (!priv) {
+      LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: priv no mem\n"));
       return ERR_MEM;
     }
   }
@@ -394,6 +403,8 @@ slipif_init(struct netif *netif)
   priv->sd = sio_open(sio_num);
   if (!priv->sd) {
     /* Opening the serial port failed. */
+      LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: sio_open failed!\n"));
+
     mem_free(priv);
     return ERR_IF;
   }
@@ -410,14 +421,34 @@ slipif_init(struct netif *netif)
 
   netif->state = priv;
 
+  // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: MIB2_INIT_NETIF !\n"));
+
   /* initialize the snmp variables and counters inside the struct netif */
   MIB2_INIT_NETIF(netif, snmp_ifType_slip, SLIP_SIO_SPEED(priv->sd));
 
+// #if SLIP_USE_RX_THREAD
+//   /* Create a thread to poll the serial line. */
+//   sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop_thread, netif,
+//                  SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO);
+// #endif /* SLIP_USE_RX_THREAD */
+  LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: 1 !\n"));
+  
 #if SLIP_USE_RX_THREAD
-  /* Create a thread to poll the serial line. */
-  sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop_thread, netif,
-                 SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO);
-#endif /* SLIP_USE_RX_THREAD */
+
+    //  osal_task *task_handle = osal_kthread_create((osal_kthread_handler)slipif_loop_thread, netif,
+    //                                              "uart_slip_service", SLIP_CMD_TASK_SIZE);
+    // if (task_handle == NULL) {
+    //     LWIP_DEBUGF(SLIP_DEBUG, ("create uart_slip service thread fail!\r\n"));
+    //     return ERR_ABRT;
+    // }
+
+    // osal_kthread_set_priority(task_handle, SLIP_CMD_TASK_PRIO);
+
+
+#endif
+
+  LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: success !\n"));
+
   return ERR_OK;
 }
 
index ac23514..6129c24 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "freertos/queue.h"
+// #include "freertos/FreeRTOS.h"
+// #include "freertos/task.h"
+// #include "freertos/queue.h"
 #include "driver/uart.h"
-#include "esp_log.h"
+// #include "esp_log.h"
 
 #include "lwip/ip.h"
 #include "lwip/netif.h"
 #include "netif/slipif.h"
 #include "lwip/init.h"
-#include "lwip/lwip_napt.h"
-
+// #include "lwip/lwip_napt.h"
 #include "lwip/inet_chksum.h"
 
+#include "pinctrl.h"
+#include "debug_print.h"
+#include "soc_osal.h"
+#include "tcxo.h"
+#include "irmalloc.h"
+#include "errcode.h"
+#include "common_def.h"
+#include "wearable_log.h"
+
 struct netif sl_netif;
 
-/**
- * This example shows how to use the UART driver to handle special UART events.
- *
- * It also reads data from UART0 directly, and echoes it to console.
- *
- * - Port: UART0
- * - Receive (Rx) buffer: on
- * - Transmit (Tx) buffer: on
- * - Flow control: off
- * - Event queue: on
- * - Pin assignment: TxD (default), RxD (default)
- */
-
-#define EX_UART_NUM UART_NUM_0
-
-#define BUF_SIZE (1024)
-#define RD_BUF_SIZE (BUF_SIZE)
-
-static QueueHandle_t uart0_queue;
-static void uart_event_task(void *pvParameters)
+#define UART_SLIP_CMD_MSG_READ_DATA 0x01
+#define UART_SLIP_CMD_MSG_FLUSH_DATA 0x02
+static unsigned long g_slip_cmd_queue;
+#define MAX_BUFFER_SIZE (64)
+typedef struct {
+    uint8_t cmd;
+    uint32_t size;
+    uint8_t *buffer;
+} slip_uart_cmd_t;
+void do_uart_slip_cmd(int cmd,uint8_t *buffer,uint32_t size)
+{
+    int ret;
+
+    slip_uart_cmd_t mail = {0};
+
+    mail.buffer = osal_kmalloc(size+1, OSAL_GFP_KERNEL);
+    if (mail.buffer == NULL) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"uart message buffer memory alloc fail, length is %d "NEWLINE, size);
+        return;
+    }
+    memset_s(mail.buffer,size+1,0,size+1);
+    memcpy_s(mail.buffer,MAX_BUFFER_SIZE,buffer,size);
+    mail.cmd = cmd;
+    mail.size = size;
+    ret = osal_msg_queue_write_copy(g_slip_cmd_queue, (void *)&mail,
+                                    sizeof(slip_uart_cmd_t), 0);
+    if (ret != OSAL_SUCCESS) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"Error uart_slip cmd msg %d send failed! err=0x%02X!"NEWLINE,cmd, ret);
+    }
+    
+}
+
+static void uart_event_task(void const *arg)
 {
-    uart_event_t event;
-    uint8_t *dtmp = (uint8_t *) malloc(RD_BUF_SIZE);
-       int len = 0;
-    size_t remain_len = 0;
-    for (;;) {
-        // Waiting for UART event.
-        if (xQueueReceive(uart0_queue, (void *)&event, (portTickType)portMAX_DELAY)) {
-           // ESP_LOGI(TAG, "uart[%d] event:", EX_UART_NUM);
-
-            switch (event.type) {
-                // Event of UART receving data
-                // We'd better handler data event fast, there would be much more data events than
-                // other types of events. If we take too much time on data event, the queue might be full.
-                case UART_DATA:
-                    len = uart_read_bytes(EX_UART_NUM, dtmp, event.size, 0);
+    unused(arg);
+    int32_t ret;
+    slip_uart_cmd_t mail;
+    uint32_t msgsize = (uint32_t)sizeof(slip_uart_cmd_t);
+    
+    ret = user_netif_init();
+    // if( ret != 0 ) return -1;
+     WEARABLE_LOGD(WEARABLE_LOG_MODULE_MAIN_SERVICE,"user_netif_init ret=0x%02X! \r\n",ret);
+
+    while (1) {
+
+        (void)memset_s(&mail, sizeof(slip_uart_cmd_t), 0, sizeof(slip_uart_cmd_t));
+
+        ret = osal_msg_queue_read_copy(g_slip_cmd_queue, (void *)&mail, &msgsize,
+                                       OSAL_MSGQ_WAIT_FOREVER);
+        if (ret != OSAL_SUCCESS) {
+            continue;
+        }
+
+        if (mail.cmd == UART_SLIP_CMD_MSG_READ_DATA) {
+       
+                // case UART_DATA:
+                    // len = uart_read_bytes(EX_UART_NUM, dtmp, event.size, 0);
                     //xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
                    // ESP_LOGI(TAG, "[DATA EVT]:");
-                           slipif_received_bytes(&sl_netif, dtmp, len);
-                          // slipif_process_rxqueue(&sl_netif);
-                    break;
-                // Event of HW FIFO overflow detected
-                case UART_FIFO_OVF:
-                    //uart_get_buffered_data_len(EX_UART_NUM, &remain_len);
-                    //printf("event.size = %d, remain_len=%d\n", event.size, remain_len);
-                    //printf("hw fifo overflow\n");
-                    // If fifo overflow happened, you should consider adding flow control for your application.
-                    // The ISR has already reset the rx FIFO,
-                    // As an example, we directly flush the rx buffer here in order to read more data.
-                    uart_flush_input(EX_UART_NUM);
-                    xQueueReset(uart0_queue);
-                    break;
-
-                // Event of UART ring buffer full
-                case UART_BUFFER_FULL:
-                    printf("ring buffer full\n");
-                    // If buffer full happened, you should consider encreasing your buffer size
-                    // As an example, we directly flush the rx buffer here in order to read more data.
-                    uart_flush_input(EX_UART_NUM);
-                    xQueueReset(uart0_queue);
-                    break;
-
-                case UART_PARITY_ERR:
-                    printf("uart parity errori\n");
-                    break;
-
-                // Event of UART frame error
-                case UART_FRAME_ERR:
-                    printf("uart frame errori\n");
-                    break;
-                // Others
-                default:
-                    printf("uart event type: %d\n", event.type);
-                    break;
-            }
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_MAIN_SERVICE,"recv size=%d! %s \r\n",mail.size,mail.buffer);
+
+                       slipif_received_bytes(&sl_netif, mail.buffer, mail.size);
+                       //    // slipif_process_rxqueue(&sl_netif);
+                //     break;
+                // // Event of HW FIFO overflow detected
+                // case UART_FIFO_OVF:
+                //     //uart_get_buffered_data_len(EX_UART_NUM, &remain_len);
+                //     //printf("event.size = %d, remain_len=%d\n", event.size, remain_len);
+                //     //printf("hw fifo overflow\n");
+                //     // If fifo overflow happened, you should consider adding flow control for your application.
+                //     // The ISR has already reset the rx FIFO,
+                //     // As an example, we directly flush the rx buffer here in order to read more data.
+                //     uart_flush_input(EX_UART_NUM);
+                //     xQueueReset(uart0_queue);
+                //     break;
+
+                // // Event of UART ring buffer full
+                // case UART_BUFFER_FULL:
+                //     printf("ring buffer full\n");
+                //     // If buffer full happened, you should consider encreasing your buffer size
+                //     // As an example, we directly flush the rx buffer here in order to read more data.
+                //     uart_flush_input(EX_UART_NUM);
+                //     xQueueReset(uart0_queue);
+                //     break;
+
         }
+        osal_kfree(mail.buffer);
     }
-
-    free(dtmp);
-    dtmp = NULL;
-    vTaskDelete(NULL);
 }
-
-void user_netif_deinit()
+void user_netif_deinit(void)
 {
     ip_addr_t ipaddr;
-    IP4_ADDR(&ipaddr, 172, 16, 1, 5);
-    if(sl_netif.napt == 1 ) {
-        ip_napt_enable(ipaddr.addr, 0);
-    }
+    IP_ADDR4(&ipaddr, 172, 16, 1, 5);
+    // if(sl_netif.napt == 1 ) {
+    //     ip_napt_enable(ipaddr.addr, 0);
+    // }
        netif_set_link_down(&sl_netif);
     netif_set_down(&sl_netif);
     netif_remove(&sl_netif);
 }
 
-void user_netif_set_default()
+void user_netif_set_default(void)
 {
     netif_set_default(&sl_netif);
 }
-
-int user_netif_init(int mode)
+static bool slipif_initialled = false;
+int user_netif_init(void)
 {
        ip_addr_t ipaddr;
        ip_addr_t netmask;
@@ -140,61 +154,64 @@ int user_netif_init(int mode)
 
        struct netif *temp;
 
-       IP4_ADDR(&ipaddr, 172, 16, 1, 5);
-    IP4_ADDR(&netmask, 255, 255, 255, 0);
-    IP4_ADDR(&gw, 172, 16, 1, 1);
+       IP_ADDR4(&ipaddr, 172, 16, 1, 5);
+    IP_ADDR4(&netmask, 255, 255, 255, 0);
+    IP_ADDR4(&gw, 172, 16, 1, 1);
     temp = netif_add(&sl_netif, &ipaddr, &netmask, &gw, &int_no, slipif_init, ip_input);
        if( temp == NULL ) {
-               printf("fail to netif init\n");
+               WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"fail to netif init\n");
         return -1;
        }
     netif_set_up(&sl_netif);
        sl_netif.mtu = 1500;
        netif_set_link_up(&sl_netif);
 
-    if( mode == 1 ) {
-        ip_napt_enable(ipaddr.addr, 1);
-    } else if(mode == 2) {
+    // if( mode == 1 ) {
+        // ip_napt_enable(ipaddr.addr, 1);
+    // } else if(mode == 2) {
         netif_set_default(&sl_netif);
-    }
-
+    // }
+    slipif_initialled = true;
     return 0;
 }
 
-int slip_uart_init(int mode)
+
+void slip_receive_handler(uint8_t *buffer, int32_t size)
 {
-#ifdef QUECTEL_CONFIG_UART0_SWAP_SUPPORT
-    uart_enable_swap();
-#endif
-    // Configure parameters of an UART driver, 921600
-    // communication pins and install the driver
-    uart_config_t uart_config = {
-        .baud_rate = 921600,
-        .data_bits = UART_DATA_8_BITS,
-        .parity = UART_PARITY_DISABLE,
-        .stop_bits = UART_STOP_BITS_1,
-        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
-    };
-    uart_param_config(EX_UART_NUM, &uart_config);
-       esp_err_t err;
-    int ret = 0;
-
-    // Install UART driver, and get the queue.
-#ifdef QUECTEL_CONFIG_HIGH_SPEED_SUPPORT
-    err = uart_driver_install(EX_UART_NUM, BUF_SIZE * 16, BUF_SIZE * 12, 512, &uart0_queue, 0);
-#else
-    err = uart_driver_install(EX_UART_NUM, BUF_SIZE * 8, BUF_SIZE * 4, 512, &uart0_queue, 0);
-#endif
-       if( err != ERR_OK ) {
-        printf("uart_driver_install fail err = %d\n", err);
-        return -1;
+
+       // WEARABLE_LOGD(WEARABLE_LOG_MODULE_MAIN_SERVICE,"slip_receive_handler %d \n",size);
+    if (slipif_initialled == true)
+        do_uart_slip_cmd(UART_SLIP_CMD_MSG_READ_DATA,buffer,size);
+}
+
+#define SLIP_CMD_TASK_MSG_COUNT 16
+#define SLIP_CMD_TASK_SIZE 0x100
+#define SLIP_CMD_TASK_PRIO 5
+
+int slip_uart_init(void)
+{
+
+    #if 1
+    if (osal_msg_queue_create("uart_slip_cmd_queue", SLIP_CMD_TASK_MSG_COUNT, &g_slip_cmd_queue,
+                              0, sizeof(slip_uart_cmd_t)) != ERRCODE_SUCC) {
+        LWIP_DEBUGF(SLIP_DEBUG, ("[slip][service] app create mail fail\n"));
+        return ERRCODE_FAIL;
     }
-    //uart_set_rx_timeout(EX_UART_NUM, 1);
-    ret = user_netif_init(mode);
-    if( ret != 0 ) return -1;
- 
-    // Create a task to handler UART event from ISR
-    xTaskCreate(uart_event_task, "uart_event_task", 2048, NULL, 10, NULL);
 
-    return 0;
+    osal_task *task_handle = osal_kthread_create((osal_kthread_handler)uart_event_task, NULL,
+                                                 "uart_slip_service", SLIP_CMD_TASK_SIZE);
+    if (task_handle == NULL) {
+        osal_msg_queue_is_full(g_slip_cmd_queue);
+        LWIP_DEBUGF(SLIP_DEBUG, ("create uart_slip service thread fail!\r\n"));
+        return ERRCODE_FAIL;
+    }
+
+    osal_kthread_set_priority(task_handle, SLIP_CMD_TASK_PRIO);
+    #else
+
+    user_netif_init();
+
+    #endif
+    return ERRCODE_SUCC;
 }
+
index 510159b..029c6b4 100644 (file)
 #ifndef __CUSTOM_UART_H
 #define __CUSTOM_UART_H
 
+#define MODE_DEFAULT_IP    2
+#define MODE_ENABLE_NEW_IP 1
+#include "stdint.h"
 /**
  * @brief init uart config and config uart as slip netif bridge
  */
-int slip_uart_init(int mode);
+int slip_uart_init(void);
 
 /**
  * @brief remove slip netif
  */
 void user_netif_deinit(void);
 
-void user_netif_set_default();
+void user_netif_set_default(void);
 
 /**
  * @brief add slip netif
  */
-int user_netif_init(int mode);
+int user_netif_init(void);
 
+void do_uart_slip_cmd(int cmd,uint8_t *buffer,uint32_t size);
 #endif
index b8d4844..df0f981 100644 (file)
 #include <sys/param.h>
 #include <string.h>
 
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "esp_system.h"
-#include "esp_log.h"
-#include "esp_netif.h"
-#include "esp_event.h"
-#include "nvs.h"
-#include "nvs_flash.h"
-
+// #include "freertos/FreeRTOS.h"
+// #include "freertos/task.h"
+// #include "esp_system.h"
+// #include "esp_log.h"
+// #include "esp_netif.h"
+// #include "esp_event.h"
+// #include "nvs.h"
+// #include "nvs_flash.h"
+#include <netinet/in.h>
 #include "lwip/err.h"
 #include "lwip/sockets.h"
 #include "lwip/sys.h"
 #include <lwip/netdb.h>
-#include "esp_wifi.h"
-
+// #include "esp_wifi.h"
+#include "errno.h"
 #include "uart_slip.h"
-#include "wifi_ap.h"
-#include "wifi_station.h"
-#include "web_server.h"
+// #include "wifi_ap.h"
+// #include "wifi_station.h"
+// #include "web_server.h"
 #include "udp_server.h"
-#include "app_version.h"
+// #include "app_version.h"
 
 #ifdef QUECTEL_CONFIG_SMARTCONFIG_SUPPORT
 #include "smartconfig.h"
@@ -388,6 +388,10 @@ static int resolve_msg_ota(struct tcp_msg_t *msg)
 #endif
     return index;
 }
+const char* build_sdk = "602";
+const char* build_model = "debug";
+const char* build_version = "v1.0";
+const char* build_time = "240222";
 
 static int resolve_msg_app_version(struct tcp_msg_t *msg)
 {
@@ -495,7 +499,7 @@ void udp_server_task(void *pvParameters)
         g_listen_sock = udp_socket_init();
         if( g_listen_sock < 0 ) {
             printf("socket init fail and retry\n");
-            vTaskDelay(1000/portTICK_RATE_MS);
+            // vTaskDelay(1000/portTICK_RATE_MS);
             continue;
         }
 
@@ -524,15 +528,14 @@ void udp_server_task(void *pvParameters)
                 tcp_device_restart();
             } else if( quec_wifi_status.s_status == SSS_WORKING_REINIT ) {
                 user_netif_deinit();
-                   vTaskDelay(1000/portTICK_RATE_MS);
-                   user_netif_init(quec_wifi_status.mode);
+                   // vTaskDelay(1000/portTICK_RATE_MS);
+                   user_netif_init();
                 quec_wifi_status.s_status = SSS_WORKING_NONE;
                 break;
             }
         }
        }
        
-       vTaskDelete(NULL);
 }
 #if 0
 void wifi_status()
index c1c28fb..3614ec5 100644 (file)
@@ -89,6 +89,37 @@ void uapi_reboot_device(void)
     mcu_os_sys_reset(NULL,NULL);
 }
 
+#include "upg.h"
+errcode_t uaip_cmd_update_request(void)
+{
+    errcode_t ret;
+
+    ret = uapi_upg_request_upgrade(false);
+    if (ret != ERRCODE_SUCC) {
+        printf("uapi_upg_request_upgrade error = 0x%x\r\n", ret);
+    } else {
+        printf("uapi_upg_request_upgrade OK!!\r\n");
+    }
+    return ret;
+}
+
+
+#include "systick.h"
+#include "sys/time.h"
+#include "time.h"
+errcode_t uapi_get_timestampe_ms(uint64_t *tm)
+{
+    struct timeval tv = { 0 };
+
+    if (gettimeofday(&tv, NULL)) {
+        return ERRCODE_FAIL;
+    }
+    *tm = (uint64_t)(tv.tv_sec*1000 + tv.tv_usec/1000 );
+        
+    return ERRCODE_SUCC;
+}
+
+
 #if 0
 
 #define PM_SLEEP_SOFT_RESET_FORCE_WKUP_REG 0x57000014
index a40b377..254e310 100644 (file)
@@ -23,6 +23,10 @@ uint32_t zh_get_sn(uint8_t *buf_sn, uint32_t *len_sn);
 uint32_t zh_set_sn(uint8_t *buf_sn, uint32_t len_sn);
 void uapi_poweroff_device(void);
 void uapi_reboot_device(void);
+errcode_t uaip_cmd_update_request(void);
+
+/**获取单位ms的时间戳*/
+errcode_t uapi_get_timestampe_ms(uint64_t *tm);
 
 /**
  * @}
index 5174b36..cf7a552 100644 (file)
@@ -67,7 +67,14 @@ static uint32_t custom_utils_setsn(uint8_t *para, uint32_t paraLen, char *strCom
     uint16_t len = strlen((const char*)sn_buf);
     PRINT("set sn = %s \r\n",sn_buf);
     uint32_t rret = zh_set_sn(sn_buf,len);
-    return rret;
+    return 0;
+}
+
+static uint32_t custom_start_ota(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    PRINT("custom_start_ota  \r\n");
+    return uaip_cmd_update_request();
 }
 static uint32_t custom_utils_getsn(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 {
@@ -76,11 +83,12 @@ static uint32_t custom_utils_getsn(uint8_t *para, uint32_t paraLen, char *strCom
     uint32_t len = 0;
     uint32_t ret = zh_get_sn(sn_buf,&len);
     PRINT("get sn len %d , %s \r\n",len,sn_buf);
-    return ret;
+    return 0;
 }
 static const at_cmd_table_t g_custom_utils_cmd[] = {
     { (char *)"AT^CUSTOM_SN",      custom_utils_setsn, (char *)"123456789ABCDEF2345678" },
-    { (char *)"AT^CUSTOM_SN?",      custom_utils_getsn, (char *)" " },
+    { (char *)"AT^CUSTOM_SN_REQ",  custom_utils_getsn, (char *)" " },
+    { (char *)"AT^STARTOTA",      custom_start_ota, (char *)" " },
 };
 
 at_cmd_table_t *get_custom_utils_cmd_table(uint32_t *cmd_count)
index 2948a64..6f15153 100755 (executable)
@@ -127,6 +127,8 @@ void pm_core_suspend(void)
         if (g_frs_sleep_flag) { touch_suspend_for_i2c(); }
         g_frs_sleep_flag = 0;
     }
+    //ADD alipay I2C3 suspend, 
+    alipay_suspend();
     display_suspend_power_off();
 #endif
     storage_device_suspend();
@@ -259,6 +261,7 @@ void pm_core_resume(void)
     if (lcd_get_status() != 0) {
         display_resume_tmp();
     }
+    alipay_resume();
 #endif
     dsp_resume_tmp();
     reg16_setbit(0x520003e4, 0x0); // set mcpu_clken_slp in MSUB_SLP_CFG
index 757583c..a972a9e 100644 (file)
 
 #ifndef GRAPHIC_LITE_LITE_ENCODER_DEVICE_H
 #define GRAPHIC_LITE_LITE_ENCODER_DEVICE_H
-#include "dock/pointer_input_device.h"
+#include "dock/rotate_input_device.h"
 
 namespace OHOS {
-class LiteEncoderDevice : public PointerInputDevice {
+class LiteEncoderDevice : public RotateInputDevice {
 public:
     LiteEncoderDevice() {}
     ~LiteEncoderDevice() override {}
index 70947da..c191d89 100755 (executable)
@@ -26,9 +26,8 @@
 #endif
 namespace OHOS {
 static DeviceData g_lastData = {0};
-static DeviceData g_lastEncoderData = {0};
 LiteInputDistributer::LiteInputDistributer()
-    : deviceData_({}),encoderData_({}) {}
+    : deviceData_({}) {}
 
 LiteInputDistributer::~LiteInputDistributer() {}
 
@@ -36,9 +35,7 @@ void LiteInputDistributer::SendRawEvent(const RawEvent& rawEvent)
 {
     RawEvent event = rawEvent;
     DisplayDev* displayDev = DisplayDev::GetInstance();
-    if ((event.type == InputDevType::INDEV_TYPE_TOUCH 
-    // || event.type == InputDevType::INDEV_TYPE_ENCODER
-    ) &&
+    if ((event.type == InputDevType::INDEV_TYPE_TOUCH) &&
         (displayDev->GetLayerRotateType(LAYER_0) == LayerRotateType::LAYER_ROTATE_90)) {
         LayerBuffer* buffer = displayDev->GetCurrentBuffer(LAYER_0);
         if (buffer == nullptr) {
@@ -60,16 +57,18 @@ void LiteInputDistributer::GetEventData(DeviceData& data, InputDevType type)
     eventLock_.Lock();
     
     if (type == InputDevType::INDEV_TYPE_ENCODER) {
-        g_lastEncoderData = encoderData_;
-        if (IsShowPoint() && (encoderData_.timestamp != g_lastEncoderData.timestamp)) {
-            DfxTPGetEvent();
+         if (encoderDataList_.IsEmpty()) {
+            data.rotate = 0;
+            eventLock_.Unlock();
+            return;
         }
-        data.point.x = encoderData_.point.x;
-        data.point.y = encoderData_.point.y;
-        data.encoderDiff = encoderData_.encoderDiff;
-        data.state = encoderData_.state;
-        data.timestamp = encoderData_.timestamp;
-        eventLock_.Unlock();
+        DeviceData* tmp = encoderDataList_.Front();
+        encoderDataList_.PopFront();
+        data.rotate = tmp->rotate;
+        data.state = tmp->state;
+        data.timestamp = tmp->timestamp;
+        delete tmp;
+        tmp = nullptr;
         return;
     }
     if (type == InputDevType::INDEV_TYPE_TOUCH) {
@@ -106,18 +105,7 @@ void LiteInputDistributer::SetEventData(const RawEvent& event)
 {
     LowPowerManager::GetInstance()->ExitLowPower();
     eventLock_.Lock();
-    if (event.type == InputDevType::INDEV_TYPE_ENCODER) {
-        if (IsShowPoint()) {
-            DfxTPSetEvent(event.timestamp - encoderData_.timestamp);
-        }
-        encoderData_.encoderDiff = event.x;
-        encoderData_.point.x = event.x;
-        encoderData_.point.y = event.y;
-        encoderData_.state = event.state;
-        encoderData_.timestamp = event.timestamp;
-        eventLock_.Unlock();
-        return;
-    }
+    
     if (event.type == InputDevType::INDEV_TYPE_TOUCH) {
         if (IsShowPoint()) {
             DfxTPSetEvent(event.timestamp - deviceData_.timestamp);
@@ -129,6 +117,23 @@ void LiteInputDistributer::SetEventData(const RawEvent& event)
         eventLock_.Unlock();
         return;
     }
+    if (event.type == InputDevType::INDEV_TYPE_ENCODER) {
+        // if (IsShowPoint()) {
+        //     DfxTPSetEvent(event.timestamp - encoderDataList_.timestamp);
+        // }
+        DeviceData* data = new DeviceData();
+        data->rotate = event.rotate;
+        data->state = event.state;
+        data->timestamp = event.timestamp;
+        if (encoderDataList_.Size() >= MAX_ENCODER_DATA_LIST_SIZE) {
+            DeviceData* tmp = encoderDataList_.Front();
+            encoderDataList_.PopFront();
+            delete tmp;
+            tmp = nullptr;
+        }
+        encoderDataList_.PushBack(data);
+        return;
+    }
     if (event.type == InputDevType::INDEV_TYPE_KEY) {
         DeviceData* data = new DeviceData();
         data->keyId = event.keyId;
@@ -152,7 +157,7 @@ bool LiteInputDistributer::IsEventEmpty(InputDevType type)
     } else if (type == InputDevType::INDEV_TYPE_KEY) {
         return keyList_.IsEmpty();
     } else if (type == InputDevType::INDEV_TYPE_ENCODER){
-      //  return ((g_lastEncoderData.state == 0) && (encoderData_.state == 0));
+        return encoderDataList_.IsEmpty();
     }
     return true;
 }
index 99bcd70..e939b45 100755 (executable)
@@ -54,12 +54,10 @@ static void EventCallback(InputDevData* data)
         event.timestamp = data->timestamp;\r
         event.type = InputDevType::INDEV_TYPE_TOUCH;\r
     } else if (data->type == INDEV_TYPE_ENCODER) {\r
-         if (IsShowTPRaw()) {\r
-            GRAPHIC_LOGP("Encoder s: %u, x: %d, y: %d, diff: %d, t: %u", data->state, data->x, data->y,data->encoderDiff,\r
-                data->timestamp);\r
-        }\r
-        event.x = data->encoderDiff;\r
-        event.y = data->encoderDiff;\r
+        //  if (IsShowTPRaw()) {\r
+            GRAPHIC_LOGP("Encoder s: %u, rotate: %d, t: %u", data->state,data->rotate, data->timestamp);\r
+        // }\r
+        event.rotate = data->rotate;\r
         event.state = data->state;\r
         event.timestamp = data->timestamp;\r
         event.type = InputDevType::INDEV_TYPE_ENCODER;\r
index 85b4882..5a013d6 100755 (executable)
@@ -25,6 +25,7 @@
 namespace OHOS {
 const uint16_t INVALID_KEY_ID = 0xffff;
 const uint8_t MAX_KEY_LIST_SIZE = 60;
+const uint8_t MAX_ENCODER_DATA_LIST_SIZE = 2;
 class LiteInputDistributer : public HeapBase {
 public:
     static LiteInputDistributer* GetInstance()
@@ -46,7 +47,7 @@ private:
 
     GraphicMutex eventLock_;
     DeviceData deviceData_;
-    DeviceData encoderData_;
+    List<DeviceData*> encoderDataList_;
     List<DeviceData*> keyList_;
 };
 }
index 46f9fd3..19b1f64 100755 (executable)
@@ -49,6 +49,9 @@ struct RawEvent {
             uint16_t state;
 #endif
         };
+#if ENABLE_ROTATE_INPUT
+        int16_t rotate; /* rotate type device used this param for rotate */
+#endif
         uint16_t keyId; /* key type device use this param for touched key id */
     };
 #ifdef VERSION_IOT
index bb5a3e3..79744de 100644 (file)
@@ -45,10 +45,10 @@ set(SOURCES
     ${lwipcore4_SRCS}
     ${lwipapi_SRCS}
     ${lwipnetif_SRCS}
-    ${lwiphttp_SRCS}
+    ${lwipcore6_SRCS}
     ${lwipsntp_SRCS}
     ${lwipmbedtls_SRCS}
-    ${lwiphttp_SRCS}
+    # ${lwiphttp_SRCS}
     ${lwiphttp_SRCS}
     ${PORT_SOURCES}
 )
diff --git a/code/sdk/open_source/openharmony/third_party/lwip/doc/doxygen/output/index.html b/code/sdk/open_source/openharmony/third_party/lwip/doc/doxygen/output/index.html
deleted file mode 100644 (file)
index a52e09f..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-  <title>Redirection</title>
-  <meta http-equiv="refresh" content="0; url=html/index.html" />
-</head>
-<body>
-  <a href="html/index.html">index.html</a>
-</body>
-</html>
index c4936fb..064ac93 100644 (file)
@@ -44,6 +44,7 @@
 #define LWIP_SOCKET                     0
 #define SYS_LIGHTWEIGHT_PROT            0
 #define LWIP_COMPAT_MUTEX               2
+#define LWIP_IPV4                       1
 #define LWIP_IPV6                       1
 #define IPV6_FRAG_COPYHEADER            1
 #define LWIP_IPV6_DUP_DETECT_ATTEMPTS   0
 #define CHECKSUM_CHECK_ICMP             0
 #define CHECKSUM_CHECK_ICMP6            0
 
+#define MEM_USE_POOLS 0
+#define MEM_LIBC_MALLOC 1
+#define SLIP_USE_RX_THREAD 1
+
 /* Minimal changes to opt.h required for tcp unit tests: */
-#define MEM_SIZE                        16000
-#define TCP_SND_QUEUELEN                40
+#define MEM_SIZE                        (1*1024)
 #define MEMP_NUM_TCP_SEG                TCP_SND_QUEUELEN
 #define TCP_OVERSIZE                    1
-#define TCP_SND_BUF                     (12 * TCP_MSS)
-#define TCP_WND                         (10 * TCP_MSS)
+#define TCP_SND_BUF                     (4 * TCP_MSS)  /*TCP_MSS 536 as default**/
+#define TCP_WND                         (2 * TCP_MSS)
+#define TCP_SND_QUEUELEN                 ((8 * (TCP_SND_BUF)) / (TCP_MSS))
 #define LWIP_WND_SCALE                  1
 #define TCP_RCV_SCALE                   2
-#define PBUF_POOL_SIZE                  400 /* pbuf tests need ~200KByte */
+#define PBUF_POOL_SIZE                  4 /* pbuf tests need ~200KByte */
 
 /* Minimal changes to opt.h required for etharp unit tests: */
 #define ETHARP_SUPPORT_STATIC_ENTRIES   1
@@ -82,5 +87,6 @@
 #define LWIP_SNMP                       1
 #define MIB2_STATS                      1
 #define LWIP_MDNS_RESPONDER             1
-
+#define SLIP_DEBUG                      0x80U //LWIP_DBG_ON
+#define LWIP_DEBUG
 #endif /* LWIP_HDR_LWIPOPTS_H__ */
index ef4cc0f..07cf932 100644 (file)
@@ -93,7 +93,7 @@ set(lwipnetif_SRCS
     ${LWIP_DIR}/src/netif/ethernet.c
     ${LWIP_DIR}/src/netif/bridgeif.c
     ${LWIP_DIR}/src/netif/bridgeif_fdb.c
-    ${LWIP_DIR}/src/netif/slipif.c
+    # ${LWIP_DIR}/src/netif/slipif.c
 )
 
 # 6LoWPAN
index 579fd24..326bde8 100644 (file)
 /** Enable debug message printing, but only if debug message type is enabled
  *  AND is of correct type AND is at least LWIP_DBG_LEVEL.
  */
-#ifdef __DOXYGEN__
-#define LWIP_DEBUG
-#undef LWIP_DEBUG
-#endif
+// #ifdef __DOXYGEN__
+// #define LWIP_DEBUG
+// #undef LWIP_DEBUG
+// #endif
 
 #ifdef LWIP_DEBUG
 #define LWIP_DEBUGF(debug, message) do { \
index 65ba31f..2593a5a 100644 (file)
@@ -56,7 +56,7 @@
  * If disabled, slipif_poll() polls the serial line (using sio_tryread()).
  */
 #ifndef SLIP_RX_FROM_ISR
-#define SLIP_RX_FROM_ISR 0
+#define SLIP_RX_FROM_ISR 1
 #endif
 
 /** Set this to 1 (default for SLIP_RX_FROM_ISR) to queue incoming packets