From: SnickerSun Date: Thu, 14 Mar 2024 06:28:37 +0000 (+0800) Subject: 完善cywee的库集成,目前库文件不可被调用,系统函数移植已经完成 X-Git-Tag: release_V1.2.70_20241020_135402~1274^2~8^2~7^2 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=e9e52713143f41815d06f111186a400398bd5cd2;p=mirrors%2FFD230.git 完善cywee的库集成,目前库文件不可被调用,系统函数移植已经完成 --- diff --git a/.gitignore b/.gitignore index 8c6ad7543..0313d221c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/file.bin code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/file_tmp.bin code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/file.bin code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/file_tmp.bin +code/sdk/drivers/peripheral/cywee/doc/~$CWM lib Sensor Info_Gnt_Fd230_20240222.xlsx +code/sdk/drivers/peripheral/cywee/doc/~$Cwm_Dml_Info__LIS2DOC__20230816.xlsx diff --git a/code/sdk/application/brandy/brandy_standard/service_init.c b/code/sdk/application/brandy/brandy_standard/service_init.c index 062767c93..953c74f7d 100755 --- a/code/sdk/application/brandy/brandy_standard/service_init.c +++ b/code/sdk/application/brandy/brandy_standard/service_init.c @@ -58,6 +58,10 @@ #include "lis2doc_at_cmd.h" #endif +#ifdef SUPPORT_AT_CYWEE +#include "cywee_at_cmd.h" +#endif + #ifdef SUPPORT_AT_MMC5603 #include "mmc5603_at_cmd.h" #endif @@ -149,6 +153,12 @@ static void register_at_service(void) at_cmd_add_moudle(lis2doc_table, lis2doc_cmd_count); #endif +#ifdef SUPPORT_AT_CYWEE + uint32_t cywee_cmd_count; + at_cmd_table_t *cywee_table = get_cywee_cmd_table(&cywee_cmd_count); + at_cmd_add_moudle(cywee_table, cywee_cmd_count); +#endif + #ifdef SUPPORT_AT_MMC5603 uint32_t mmc5603_cmd_count; at_cmd_table_t *mmc5603_table = get_mmc5603_cmd_table(&mmc5603_cmd_count); diff --git a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c index 636b507ed..a004aba23 100755 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -69,6 +69,10 @@ #include "acc_service.h" #endif +#ifdef ENABLE_CYWEE +#include "cywee_service.h" +#endif + #ifdef SUPPORT_ALIPAY_SEC #include "alipay_feature.h" #endif @@ -348,6 +352,11 @@ static void thread_main(const void *unused) #ifdef SUPPORT_CAT1_SERVICE cat1_server_init(); #endif + +#ifdef ENABLE_CYWEE + uapi_cywee_service_init(); +#endif + set_startup_finish_flag(); } diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 4db6cfb34..69d491789 100755 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -118,7 +118,9 @@ target = { 'ENABLE_ECC', 'FT_SINGLE_UART', 'PPG_HX3695', - 'ACC_LIS2DOC', + # 'ACC_LIS2DOC', + 'ENABLE_CYWEE', + 'SUPPORT_AT_CYWEE', 'MAG_MMC5603', 'ENABLE_VIBRATOR', 'ENABLE_SLIP', @@ -149,7 +151,7 @@ target = { 'bt_manager_at_service', "audio_proc", "audio_dump", "audio_probe", "power_manager", "gpu_proc", 'bts_header', "ppg_sensor", - "acc_sensor", + # "acc_sensor", "mag_sensor", "vibrator", "vibrator_service", @@ -162,6 +164,7 @@ target = { #"nativelauncher", "fd230launcher", "ppg_service", + "cywee", "batterry_service" ], 'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_uikit', 'bgh_audio', 'dfx_set', 'ohos_set', 'wearable_set', 'alipay_set'], diff --git a/code/sdk/drivers/peripheral/CMakeLists.txt b/code/sdk/drivers/peripheral/CMakeLists.txt index 8e944fc99..af2060e59 100644 --- a/code/sdk/drivers/peripheral/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/CMakeLists.txt @@ -15,4 +15,4 @@ add_subdirectory_if_exist(slip/cat1Service) add_subdirectory_if_exist(utils) add_subdirectory_if_exist(rotary_encoder) add_subdirectory_if_exist(vibrator/service) -# add_subdirectory_if_exist(cywee) +add_subdirectory_if_exist(cywee) diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_data_single.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_data_single.c index 42a01a816..f2fad4b1a 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_data_single.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_data_single.c @@ -91,7 +91,7 @@ static stmdev_ctx_t dev_ctx; static int lis2doc_install_success = -1; /*初始化GPIO*/ -int gpio_int_pin_init(void) +static int gpio_int_pin_init(void) { if ((uapi_pin_set_mode(G_INT1_PIN, (pin_mode_t)HAL_PIO_FUNC_GPIO) != ERRCODE_SUCC) || (uapi_pin_set_pull(G_INT1_PIN, (pin_pull_t)HAL_PIO_PULL_UP) != ERRCODE_SUCC) || diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.c index 91bf6cbba..0fc4a8bbf 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.c @@ -80,14 +80,6 @@ void platform_init(void) /* init i2c */ if ( g_acc_installed == 1 ) return ; - result = uapi_i2c_master_init(LIS2DOC_I2C_BUS, 400000, I2C_SPEED_MODE_FS); - if ( result == ERRCODE_I2C_ALREADY_INIT) - { - g_acc_installed = 1; - LIS_WARNING("lis2doc:i2c_id = %d i2c_speed = %d slave_addr = 0x%x ,already initiallized\r\n", - LIS2DOC_I2C_BUS, 400000, LIS2DOC_I2C_DEV_7ADDR); - return ; - } result = uapi_i2c_master_init(LIS2DOC_I2C_BUS, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ if (result != ERRCODE_SUCC) { diff --git a/code/sdk/drivers/peripheral/acc/service/acc_service.c b/code/sdk/drivers/peripheral/acc/service/acc_service.c index 849a5add4..a9449c2a7 100644 --- a/code/sdk/drivers/peripheral/acc/service/acc_service.c +++ b/code/sdk/drivers/peripheral/acc/service/acc_service.c @@ -143,7 +143,7 @@ errcode_t uapi_acc_service_init(void) osal_task *task_handle = osal_kthread_create((osal_kthread_handler)acc_service_check_task, NULL, - "acc_service_service", APP_BOARD_TASK_SIZE); + "acc_service", APP_BOARD_TASK_SIZE); if (task_handle == NULL) { osal_msg_queue_is_full(g_app_queue); PRINT("create mag service thread fail!\r\n"); diff --git a/code/sdk/drivers/peripheral/cywee/CMakeLists.txt b/code/sdk/drivers/peripheral/cywee/CMakeLists.txt index 7ed64c0b7..ab52b0ffe 100644 --- a/code/sdk/drivers/peripheral/cywee/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/cywee/CMakeLists.txt @@ -5,22 +5,29 @@ set(COMPONENT_NAME "cywee") set(SOURCES ${SOURCES} - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + # ${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 + ${CMAKE_CURRENT_SOURCE_DIR}/src/test_api.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/board_yh601s.c + ${CMAKE_CURRENT_SOURCE_DIR}/service/cywee_service.c + ${CMAKE_CURRENT_SOURCE_DIR}/service/cywee_at_cmd.c + ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC/examples/lis2doc_read_data_single.c + ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC/lis2doc_porting.c ) set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/Inc ) set(PRIVATE_HEADER + ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC/driver + ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC ) set(PRIVATE_DEFINES ) set(PUBLIC_DEFINES +SUPPORT_AT_CYWEE ) # use this when you want to add ccflags like -include xxx diff --git a/code/sdk/drivers/peripheral/cywee/Inc/CWM_EventStructure.h b/code/sdk/drivers/peripheral/cywee/Inc/CWM_EventStructure.h index f67075104..611cbb1ed 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/CWM_EventStructure.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/CWM_EventStructure.h @@ -1,6 +1,6 @@ #ifndef __CWM_EVENT_STRUCTURE_H__ #define __CWM_EVENT_STRUCTURE_H__ - +#include /** * @brief CyweeMotion task handle event structure. */ diff --git a/code/sdk/drivers/peripheral/cywee/Inc/OsApi.h b/code/sdk/drivers/peripheral/cywee/Inc/OsApi.h index 49b35b160..28edf6d0b 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/OsApi.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/OsApi.h @@ -1,6 +1,6 @@ #ifndef __OS_API_H__ #define __OS_API_H__ - +#include /** * @brief System/OS/Peripheral API structure. */ diff --git a/code/sdk/drivers/peripheral/cywee/src/config.h b/code/sdk/drivers/peripheral/cywee/Inc/config.h similarity index 100% rename from code/sdk/drivers/peripheral/cywee/src/config.h rename to code/sdk/drivers/peripheral/cywee/Inc/config.h diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_at_cmd.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_at_cmd.h new file mode 100644 index 000000000..954789335 --- /dev/null +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_at_cmd.h @@ -0,0 +1,32 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Provides at cmd register func \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-07-20, Create file. \n + */ +#ifndef CYWEE_AT_PROCESS_H +#define CYWEE_AT_PROCESS_H + +#include +#include +#include "errcode.h" +#include "soc_osal.h" +#include "at_cmd_api.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +at_cmd_table_t *get_cywee_cmd_table(uint32_t *cmd_count); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h new file mode 100644 index 000000000..0905eed2f --- /dev/null +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h @@ -0,0 +1,31 @@ +/** + * 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 CYWEE_HAL_H__ +#define CYWEE_HAL_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#include "stdint.h" +#include "errcode.h" + +int cywee_main_dml(void); +void cywee_int_handler(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h new file mode 100644 index 000000000..dd90c18e4 --- /dev/null +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h @@ -0,0 +1,43 @@ +/** + * 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 CYWEE_SERVICE_H__ +#define CYWEE_SERVICE_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#include "stdint.h" +#include "errcode.h" + + +#define CYWEE_SERVICE_CMD_TIMER_CHECK 0x11 +#define CYWEE_SERVICE_CMD_START_CHECK 0x12 +#define CYWEE_SERVICE_CMD_STOP_CHECK 0x13 +#define CYWEE_SERVICE_CMD_TEST 0x14 + +errcode_t uapi_acc_service_init(void); +void uapi_acc_service_deinit(void); +/** + * 测试指令 参数cmd 选项: ACC_SERVICE_CMD_START_CHECK,ACC_SERVICE_CMD_STOP_CHECK +*/ +void do_cywee_service_check_msg(int cmd); + +void do_cywee_service_check_msg(int cmd); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/cywee/service/cywee_at_cmd.c b/code/sdk/drivers/peripheral/cywee/service/cywee_at_cmd.c new file mode 100644 index 000000000..bbfb9ac26 --- /dev/null +++ b/code/sdk/drivers/peripheral/cywee/service/cywee_at_cmd.c @@ -0,0 +1,77 @@ + +#include "at_cmd_api.h" +#include "los_printf.h" +#include "cywee_service.h" +#include "cywee_at_cmd.h" +#include "common_def.h" + +#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) +#define CYWEE_MAX_ARGC 8 +#define CYWEE_MAX_ARGV_LEN 64 + + +static int ConvertCmdToParam(uint8_t *para, uint32_t paraLen, + uint8_t argv[CYWEE_MAX_ARGC][CYWEE_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 >= CYWEE_MAX_ARGC) { + return ERRCODE_FAIL; + } + } else { + argv[*argc][pos] = para[i]; + pos++; + if (pos >= CYWEE_MAX_ARGV_LEN) { + return ERRCODE_FAIL; + } + } + } + if (pos != 0) { + *argc += 1; + } + + return ERRCODE_SUCC; +} + + +static uint32_t cywee_do_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + unused(strCommonCmd); + uint8_t argv[CYWEE_MAX_ARGC][CYWEE_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != ERRCODE_SUCC) { + PRINT_ERR("CYWEETEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + if (argc < 1) { + PRINT_ERR("CYWEETEST ATCMD Set Parameter Failed\n"); + return ERRCODE_FAIL; + } + char *mode = (char*)argv[0]; + if (strcmp(mode, "start") == 0) { + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_START_CHECK); + } else if (strcmp(mode, "stop") == 0) { + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_STOP_CHECK); + } else if (strcmp(mode, "test") == 0) { + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_TEST); + } + return ERRCODE_SUCC; +} + +static const at_cmd_table_t g_cywee_cmd[] = { + { (char *)"AT^CYWEETEST", cywee_do_test, (char *)"test" }, +}; + +at_cmd_table_t *get_cywee_cmd_table(uint32_t *cmd_count) +{ + *cmd_count = ARRAY_COUNT(g_cywee_cmd); + return (at_cmd_table_t *)g_cywee_cmd; +} diff --git a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c new file mode 100644 index 000000000..61e97ffd9 --- /dev/null +++ b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c @@ -0,0 +1,182 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Test adc source \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-08-16, Create file. \n + */ + +#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 "tcxo.h" + +#include "cmsis_os2.h" +#include "cywee_service.h" +#include "los_printf.h" + +typedef struct +{ + uint8_t cmd; +} cywee_cmd_t; +/*** + * 其他cmd在Header里定义,对外开放 +*/ + +#define CYWEE_CHECK_MS 200 + +osTimerId_t g_cywee_service_timer = NULL; +static bool g_batter_service_initialled = false; + +static bool g_bat_timer_is_running = false; +static unsigned long g_cywee_queue; + +static bool cywee_service_running_stat = false; +static void cywee_service_check_timer_callback(void* data); + +static void cywee_service_timer_start_check(uint32_t rtc_ms) +{ + + if (g_cywee_service_timer == NULL) return ; + if (g_bat_timer_is_running ) osTimerStop(g_cywee_service_timer); + if (cywee_service_running_stat == true) osTimerStart(g_cywee_service_timer, rtc_ms); + g_bat_timer_is_running = true; + +} + +static void cywee_service_check_timer_callback(void * data) +{ + unused(data); + g_bat_timer_is_running = false; + if(cywee_service_running_stat == true){ + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_TIMER_CHECK); + // cywee_service_timer_start_check(CYWEE_CHECK_MS); + } +} +void uapi_cywee_service_deinit(void) +{ + /* Stop the time and clear the pin map */ + + if (g_cywee_service_timer == NULL) return ; + + osTimerStop(g_cywee_service_timer); + osTimerDelete(g_cywee_service_timer); + g_cywee_service_timer = NULL; + g_bat_timer_is_running = false; + +} + + + +void do_cywee_service_check_msg(int cmd) +{ + int ret; + + cywee_cmd_t mail = {0}; + mail.cmd = cmd; + ret = osal_msg_queue_write_copy(g_cywee_queue, (void *)&mail, sizeof(cywee_cmd_t), 0); + if (ret != OSAL_SUCCESS) { + PRINT("Error mag Check MSG 0x%02X send failed! err=0x%x! \r\n",cmd, ret); + } + +} +// #define TEST_CYWEE_LIB +#ifdef TEST_CYWEE_LIB +typedef struct { + int iData[16]; +} SettingControl_t; +#define SCL_GET_LIB_INFO 12 +#endif + +static void cywee_service_check_task(void const *arg) +{ + unused(arg); + int32_t ret; + cywee_cmd_t mail; + uint32_t msgsize = (uint32_t)sizeof(cywee_cmd_t); + + while (1) { + ret = osal_msg_queue_read_copy(g_cywee_queue, (void *)&mail, &msgsize, + OSAL_MSGQ_WAIT_FOREVER); + if (ret != OSAL_SUCCESS) { + continue; + } + + if (mail.cmd == CYWEE_SERVICE_CMD_TIMER_CHECK) { + // cywee_int_handler(); + lis2doc_read_data(); + PRINT("CYWEE_SERVICE_CMD_TIMER_CHECK\r\n"); + }else if (mail.cmd == CYWEE_SERVICE_CMD_TEST){ + test_api(); + }else if (mail.cmd == CYWEE_SERVICE_CMD_START_CHECK){ + cywee_service_running_stat = true; + #ifdef TEST_CYWEE_LIB + SettingControl_t scl; + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + CWM_SettingControl(SCL_GET_LIB_INFO, &scl); + + #endif + // cywee_main_dml(); + cywee_service_timer_start_check(CYWEE_CHECK_MS); + }else if (mail.cmd == CYWEE_SERVICE_CMD_STOP_CHECK){ + cywee_service_running_stat = false; + if (g_cywee_service_timer != NULL) osTimerStop(g_cywee_service_timer); + + } + } +} +#define CYWEE_APP_BOARD_MSG_COUNT 50 +#define CYWEE_APP_BOARD_TASK_SIZE 0x1C00 +#define CYWEE_BOARD_TASK_PRIO 7 +errcode_t uapi_cywee_service_init(void) +{ + + if (osal_msg_queue_create("cywee_service_queue", CYWEE_APP_BOARD_MSG_COUNT, &g_cywee_queue, + 0, sizeof(cywee_cmd_t)) != ERRCODE_SUCC) { + PRINT("[cywee][service] app create mail fail\n"); + return ERRCODE_FAIL; + } + + + + osal_task *task_handle = osal_kthread_create((osal_kthread_handler)cywee_service_check_task, NULL, + "cywee_service", CYWEE_APP_BOARD_TASK_SIZE); + if (task_handle == NULL) { + osal_msg_queue_is_full(g_cywee_queue); + PRINT("create cywee service thread fail!\r\n"); + return ERRCODE_FAIL; + } + + osal_kthread_set_priority(task_handle, CYWEE_BOARD_TASK_PRIO); + + g_cywee_service_timer = osTimerNew((osTimerFunc_t)cywee_service_check_timer_callback, osTimerPeriodic, NULL, NULL); + + + return ERRCODE_SUCC; +} + +// void cywee_service_service_resume(void) +// { +// PRINT("cywee_service_service resume!\r\n"); +// cywee_service_check_timer_callback(0); +// } +// void cywee_service_service_suspend(void) +// { +// PRINT("cywee_service_service suspend!\r\n"); +// } \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c index 1e1373eff..c47c115cf 100644 --- a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c +++ b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c @@ -2,76 +2,47 @@ /*** Include Files ***/ /*********************/ #include -#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" +#include +#include +#include +#include +#include + +#include "osal_timer.h" +#include "osal_mutex.h" +#include "pinctrl.h" +#include "chip_io.h" +#include "time.h" +#include "i2c.h" +#include "gpio.h" +#include "hal_gpio.h" +#include "hal_i2c.h" +#include "soc_osal.h" +#include "tcxo.h" +#include "debug_print.h" +#include "platform_core.h" +#include "los_tick.h" +#include "cwm_lib.h" +#include "los_typedef.h" +#include "config.h" +#include "OsApi.h" +#include "los_printf.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) + +#define CYWEE_I2C_BUS I2C_BUS_2 +#define CYWEE_I2C_RETRY_TIME_MAX 3 +#define G_INT1_PIN S_AGPIO_L11 +#define G_INT2_PIN S_AGPIO_L19 /*************************/ /*** 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, - }, -}; +static uint8_t g_cywee_installed = 0; /************************/ @@ -83,345 +54,218 @@ 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) +/*初始化GPIO*/ +int gpio_int_pin_init(void) { - 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 + if ((uapi_pin_set_mode(G_INT1_PIN, (pin_mode_t)HAL_PIO_FUNC_GPIO) != ERRCODE_SUCC) || + (uapi_pin_set_pull(G_INT1_PIN, (pin_pull_t)HAL_PIO_PULL_UP) != ERRCODE_SUCC) || + (uapi_gpio_set_dir(G_INT1_PIN, GPIO_DIRECTION_INPUT) != ERRCODE_SUCC)) { + PRINT_ERR("gpio G_INT1_PIN config failed\r\n"); + return ERRCODE_FAIL; + } + if ((uapi_pin_set_mode(G_INT2_PIN, (pin_mode_t)HAL_PIO_FUNC_GPIO) != ERRCODE_SUCC) || + (uapi_pin_set_pull(G_INT2_PIN, (pin_pull_t)HAL_PIO_PULL_UP) != ERRCODE_SUCC) || + (uapi_gpio_set_dir(G_INT2_PIN, GPIO_DIRECTION_INPUT) != ERRCODE_SUCC)) { + PRINT_ERR("gpio G_INT2_PIN config failed\r\n"); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; } -static uint64_t platsystickTicksToUs(uint64_t tick) { - return (uint64_t)(tick * 1000000 / APP_TIMER_CLOCK_FREQ); -} -static void systickUpdate() +int CWM_enableGpioIRQ(uint16_t sensorType, uint16_t sensorPin, PFN_IRQHANDLE callback) { - //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; + + return 1; } -static void one_sec_timer_handle(void * p_context) +int CWM_disableGpioIRQ(uint16_t sensorType, uint16_t sensorPin) { - //To implement the CWM_OS_GetTimeNs(), this function needs to be triggered every second - systickUpdate(); -} -static void timer_init(void) -{ - ret_code_t ret; + return 1; +} - ret = nrf_drv_clock_init(); - APP_ERROR_CHECK(ret); - nrf_drv_clock_lfclk_request(NULL); - ret = app_timer_init(); - APP_ERROR_CHECK(ret); +static errcode_t cywee_i2c_init(void) +{ + errcode_t result; + /* init i2c */ + if ( g_cywee_installed == 1 ) + return ERRCODE_SUCC; + + result = uapi_i2c_master_init(CYWEE_I2C_BUS, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ + if (result != ERRCODE_SUCC) { + PRINT_ERR("cywee i2c init fail! ret=0x%x", result); + return ERRCODE_FAIL; + } - ret = app_timer_create(&m_one_sec_timer, APP_TIMER_MODE_REPEATED, one_sec_timer_handle); - APP_ERROR_CHECK(ret); + PRINT_DEBUG("cywee:i2c_id = %d i2c_speed = %d \r\n", CYWEE_I2C_BUS, 400000); - ret = app_timer_start(m_one_sec_timer, TIMER_PERIOD_1_SEC, NULL);//1 second timer - APP_ERROR_CHECK(ret); -} + g_cywee_installed = 1; -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(); + return ERRCODE_SUCC; } -void Irq_callback(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) +int CWM_OS_i2cRead(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex) { - for (int i=0; i0) ? ret*-1: ret; } -int CWM_enableGpioIRQ(uint16_t sensorType, uint16_t sensorPin, PFN_IRQHANDLE callback) +int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex) { - for (int i=0; i> 1, (uint8_t*) ®, regLength, true); - if (res == NRF_SUCCESS) { - nrf_drv_twi_rx(&m_twi, slaveAddr >> 1, readData, readDataSize); - } + data.send_buf = write_data; + data.send_len = send_len; + data.receive_buf = NULL; + data.receive_len = 0; - if(res != 0) + for (retry = 0; retry < CYWEE_I2C_RETRY_TIME_MAX; retry++) { + ret = uapi_i2c_master_write(CYWEE_I2C_BUS, slaveAddr, &data); + if (ret == ERRCODE_SUCC) { 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; + } + if (ret != ERRCODE_SUCC) { + PRINT_ERR("cywee data write fail! ret=0x%x", ret); + } +free_mem: + osal_kfree(write_data); +error: + return (ret>0) ? ret*-1: ret; } -int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int argument) +int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int busIndex) { - 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; - } + errcode_t ret; + uint32_t retry; + i2c_data_t data; + uint8_t *write_data = NULL; + int16_t write_len = 0; + + cywee_i2c_init(); + write_len = regLength + writeDataSize; + write_data = (uint8_t *)osal_kmalloc(write_len, OSAL_GFP_KERNEL); + if (write_data == NULL) { + PRINT_ERR("cywee send buff malloc fail!"); + goto error; + } - memcpy(data, ®, regLength); - memcpy(&data[regLength], writeData, writeDataSize); - res = nrf_drv_twi_tx(&m_twi, slaveAddr >> 1, data, writeDataSize + regLength, false); + if( regLength == 2) + { + write_data[0] = ((uint8_t*)®)[0]; + write_data[1] = ((uint8_t*)®)[1]; + }else{ + write_data[0] = (uint8_t)reg; + } - if(res != 0) + ret = (uint32_t)memcpy_s(write_data + regLength, writeDataSize, writeData, writeDataSize); + if (ret != EOK) { + PRINT_ERR("cywee send_buf content copy fail! ret=0x%x", ret); + goto free_mem; + } + data.send_buf = write_data; + data.send_len = write_len; + data.receive_buf = readData; + data.receive_len = readDataSize; + + for (retry = 0; retry < CYWEE_I2C_RETRY_TIME_MAX; retry++) { + ret = uapi_i2c_master_writeread(CYWEE_I2C_BUS, CYWEE_I2C_RETRY_TIME_MAX, &data); + if (ret == ERRCODE_SUCC) { 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, ®, 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; + } + if (ret != ERRCODE_SUCC) { + PRINT_ERR("cywee data read fail! ret=0x%x", ret); } - desc.p_primary_buf = writeBuf; - desc.secondary_length = readDataSize; - desc.p_secondary_buf = readData; - - return nrf_drv_twi_xfer(&m_twi, &desc, 0); +free_mem: + osal_kfree(write_data); +error: + return (ret>0) ? ret*-1: ret; } +//实际精度只能到1ms void CWM_OS_uSleep(uint32_t time) { uint32_t ms = time / 1000; - - if (ms == 0) - ms = 1; - nrf_delay_ms(ms); + if (ms == 0) ms = 1; + osDelay(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; + uint64_t timeNowNs; + timeNowNs = LOS_CurrNanosec(); + return timeNowNs; } void* CWM_OS_malloc(int size) @@ -441,20 +285,15 @@ void CWM_OS_free(void *ptr) int CWM_OS_dbgOutput(const char * format) { - NRF_LOG_INFO("%s", format); - NRF_LOG_FLUSH(); - + PRINT("%s", format); return 0; } int CWM_OS_dbgOutput_checkLog(const char * format) { static int s_sn = 0; - - NRF_LOG_INFO("#_#|%d|%s", s_sn, format); + PRINT("#_#|%d|%s", s_sn, format); s_sn ++; - NRF_LOG_FLUSH(); - return 0; } @@ -472,8 +311,13 @@ int CWM_OS_dbgPrintf(const char * format,...) return 0; } -void board_init(void) -{ - nordic_system_init(); - timer_init(); +int CWM_OS_spiRead(uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex) { + uint8_t ret; + return ret; +} + +int CWM_OS_spiWrite(uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex) { + uint8_t ret; + + return ret; } diff --git a/code/sdk/drivers/peripheral/cywee/src/main.c b/code/sdk/drivers/peripheral/cywee/src/main.c index 77f99ae4b..8705498e3 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main.c +++ b/code/sdk/drivers/peripheral/cywee/src/main.c @@ -6,7 +6,9 @@ #include #include "cwm_lib.h" #include "config.h" +#ifdef SIGNAL_SIMULATE_PROCESS #include "simulate_signal.h" +#endif /*********************/ /*** Macro Defines ***/ @@ -178,7 +180,7 @@ void sample_data_input() { } #endif -int main(void) +int cywee_main(void) { OsAPI device_func = { @@ -194,8 +196,6 @@ int main(void) SettingControl_t scl; - board_init(); - #ifdef BUILD_IAR CWM_OS_dbgPrintf("Use IAR\n"); #elif defined(BUILD_KEIL) diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 6f776d60c..462b35a66 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -5,68 +5,17 @@ #include #include -// #define AP_ENABLE_DML_SDO_LISTEN +#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; +extern uint64_t CWM_OS_GetTimeNs(void); +extern int CWM_OS_dbgOutput(const char * format); +extern int CWM_OS_dbgPrintf(const char * format,...); +extern void CWM_OS_uSleep(unsigned int udelay); - ret = HAL_SPI_Transmit(&hspi2, ®_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, ®_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; -} +extern int CWM_OS_i2cRead(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex); +extern int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex); +extern int CWM_OS_spiRead(uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex); +extern int CWM_OS_spiWrite(uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex); void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { switch (sensorEVT->sensorType) { @@ -110,12 +59,15 @@ void CWM_AP_dmlSensorDataOutput_listen(const dml_sensorData_t * pSdo) { CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n", pSdo->acc_data[0], pSdo->acc_data[1], pSdo->acc_data[2]); } #endif +static int cywee_installized = 0 ; -int main(int argc, char* argv[]) { +int cywee_main_dml(void) { + if (cywee_installized==1) + return 0; + cywee_installized = 1; int i; SettingControl_t scl; - memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; CWM_SettingControl(SCL_GET_LIB_INFO, &scl); @@ -130,7 +82,7 @@ int main(int argc, char* argv[]) { .spiWrite = CWM_OS_spiWrite, .uSleep = CWM_OS_uSleep, }; - + CWM_LibPreInit(&api); //set mcu_chip information, must call this before CWM_LibPostInit() @@ -214,11 +166,12 @@ int main(int argc, char* argv[]) { CWM_SettingControl(SCL_LOG, &scl); CWM_Sensor_Enable(CUSTOM_ACC); - CWM_Sensor_Enable(CUSTOM_GYRO); - - while (1) { - CWM_Dml_process(); - } + // CWM_Sensor_Enable(CUSTOM_GYRO); return 0; } + +void cywee_int_handler(void) +{ + CWM_Dml_process(); +} diff --git a/code/sdk/drivers/peripheral/cywee/src/test_api.c b/code/sdk/drivers/peripheral/cywee/src/test_api.c index 3c51ee857..cb18e1b56 100644 --- a/code/sdk/drivers/peripheral/cywee/src/test_api.c +++ b/code/sdk/drivers/peripheral/cywee/src/test_api.c @@ -2,6 +2,9 @@ #include #include #include +#include "cmsis_os2.h" +#include "errcode.h" +#include "los_task_base.h" extern void CWM_OS_uSleep(uint32_t time); extern uint64_t CWM_OS_GetTimeNs(void); @@ -10,7 +13,7 @@ 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() { +int test_malloc_1(void) { char *pBuf1; int alloc_size; char buf1[0x100]; @@ -42,7 +45,8 @@ __FAIL: return 0; } -int test_free_1() { +int test_free_1(void) +{ char *pBuf1; char *pBuf2; int alloc_size; @@ -75,7 +79,8 @@ __FAIL: return 0; } -void test_GetTimeNs_0() { +void test_GetTimeNs_0(void) +{ uint64_t timeNow; CWM_OS_dbgPrintf("[test_GetTimeNs_0] test up_time start\r\n"); @@ -89,7 +94,8 @@ void test_GetTimeNs_0() { } } -void test_GetTimeNs_1() { +void test_GetTimeNs_1(void) +{ uint64_t timeNow, timeLast, timeDiff; CWM_OS_dbgPrintf("[test_GetTimeNs_1] test 10 seconds start\r\n"); @@ -106,7 +112,8 @@ void test_GetTimeNs_1() { } } -void test_GetTimeNs_2() { +void test_GetTimeNs_2(void) +{ uint64_t timeNow, timeLast, timeDiff; uint64_t count; @@ -130,7 +137,8 @@ void test_GetTimeNs_2() { } } -void test_GetTimeNs_3() { +void test_GetTimeNs_3(void) +{ uint64_t timeNow, timeLast, timeDiff; CWM_OS_dbgPrintf("[test_GetTimeNs_3] test 20 minutes start\r\n"); @@ -140,14 +148,15 @@ void test_GetTimeNs_3() { 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) { + if (timeDiff >= (uint64_t)1 * 60 * 1000000000) { CWM_OS_dbgPrintf("[test_GetTimeNs_3] test 20 minutes end\r\n"); break; } } } -void test_uSleep_1() { +void test_uSleep_1(void) +{ CWM_OS_dbgPrintf("[test_uSleep_1] test 10 seconds start\r\n"); @@ -156,7 +165,7 @@ void test_uSleep_1() { CWM_OS_dbgPrintf("[test_uSleep_1] test 10 seconds end\r\n"); } -void test_uSleep_2() { +void test_uSleep_2(void) { int i, j; CWM_OS_dbgPrintf("[test_uSleep_2] test 10 seconds start\r\n"); @@ -170,14 +179,17 @@ void test_uSleep_2() { CWM_OS_dbgPrintf("[test_uSleep_2] test 10 seconds end\r\n"); } -void test_uSleep_3() { +void test_uSleep_3(void) { int i, j, k; - + //CWM_OS_uSleep 只能到ms,所以实际上等于10000秒 CWM_OS_dbgPrintf("[test_uSleep_3] test 10 seconds start\r\n"); for (j = 0; j < 10; j ++) { + // CWM_OS_dbgPrintf("j=%d",j); for (i = 0; i < 1000; i ++) { + // if (i%10 == 0) CWM_OS_dbgPrintf("i=%d",i); for (k = 0; k < 1000; k ++) { + // if (k%100 == 0) CWM_OS_dbgPrintf("k=%d",k); CWM_OS_uSleep(1); } } @@ -187,10 +199,10 @@ void test_uSleep_3() { } #ifndef CHECK_STACK_TIME_MS -#define CHECK_STACK_TIME_MS (uint64_t)(5 * 60 * 1000) +#define CHECK_STACK_TIME_MS (uint64_t)(1 * 60 * 1000) #endif -void test_stack() { +void test_stack(void) { // in FreeRTOS // set the config in FreeRTOSConfig.h file // #define configUSE_MALLOC_FAILED_HOOK 1 @@ -207,8 +219,8 @@ void test_stack() { 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"); + if ( (buff[i]&0xFF) != 0x96) { + CWM_OS_dbgPrintf("[test_stack] somebody touch my stack!!! buf[%d]=0x%X\r\n",i, buff[i]); CWM_OS_dbgPrintf("[test_stack] test for %lld ms end\r\n", CHECK_STACK_TIME_MS); return; } @@ -228,17 +240,55 @@ void test_stack() { CWM_OS_dbgPrintf("[test_stack] test for %lld ms end\r\n", CHECK_STACK_TIME_MS); } -void test_api() { + +static errcode_t pcm_stream_task_body(void *data) +{ + + + test_malloc_1(); + test_free_1(); 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 + + test_stack(); + test_GetTimeNs_3(); // 20 minutes + // test_uSleep_3(); // 10 seconds, accurate to 1us + + return ERRCODE_SUCC; } + +#define TASK_PRIORITY_PCM_STREAM (osPriority_t)(osPriorityLow3) +#define PCM_STREAM_MSG_STACK_SIZE 0x1C00 +static osThreadId_t g_test_thread = NULL; +void test_api(void) { + + if (g_test_thread == NULL) + { + osThreadAttr_t attr = {"cywee_test", 0, NULL, 0, NULL, PCM_STREAM_MSG_STACK_SIZE, TASK_PRIORITY_PCM_STREAM, 0, 0 }; + g_test_thread = osThreadNew((osThreadFunc_t)pcm_stream_task_body, NULL, &attr); + if (g_test_thread == NULL) { + CWM_OS_dbgPrintf( "create cywee_test task fail!\r\n"); + }else{ + + } + }else{ + + + osThreadTerminate(g_test_thread); + g_test_thread = NULL; + CWM_OS_dbgPrintf( "create cywee_test task already running stop it !\r\n"); + + } + + +} + + + + + \ No newline at end of file