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
#include "lis2doc_at_cmd.h"\r
#endif\r
\r
+#ifdef SUPPORT_AT_CYWEE\r
+#include "cywee_at_cmd.h"\r
+#endif\r
+\r
#ifdef SUPPORT_AT_MMC5603\r
#include "mmc5603_at_cmd.h"\r
#endif\r
at_cmd_add_moudle(lis2doc_table, lis2doc_cmd_count);\r
#endif\r
\r
+#ifdef SUPPORT_AT_CYWEE\r
+ uint32_t cywee_cmd_count;\r
+ at_cmd_table_t *cywee_table = get_cywee_cmd_table(&cywee_cmd_count);\r
+ at_cmd_add_moudle(cywee_table, cywee_cmd_count);\r
+#endif\r
+\r
#ifdef SUPPORT_AT_MMC5603\r
uint32_t mmc5603_cmd_count;\r
at_cmd_table_t *mmc5603_table = get_mmc5603_cmd_table(&mmc5603_cmd_count);\r
#include "acc_service.h"\r
#endif\r
\r
+#ifdef ENABLE_CYWEE\r
+#include "cywee_service.h"\r
+#endif\r
+\r
#ifdef SUPPORT_ALIPAY_SEC\r
#include "alipay_feature.h"\r
#endif\r
#ifdef SUPPORT_CAT1_SERVICE\r
cat1_server_init();\r
#endif\r
+\r
+#ifdef ENABLE_CYWEE\r
+ uapi_cywee_service_init();\r
+#endif \r
+\r
set_startup_finish_flag();\r
}\r
\r
'ENABLE_ECC',
'FT_SINGLE_UART',
'PPG_HX3695',
- 'ACC_LIS2DOC',
+ # 'ACC_LIS2DOC',
+ 'ENABLE_CYWEE',
+ 'SUPPORT_AT_CYWEE',
'MAG_MMC5603',
'ENABLE_VIBRATOR',
'ENABLE_SLIP',
'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",
#"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'],
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)
static int lis2doc_install_success = -1;\r
\r
/*初始化GPIO*/\r
-int gpio_int_pin_init(void)\r
+static int gpio_int_pin_init(void)\r
{\r
if ((uapi_pin_set_mode(G_INT1_PIN, (pin_mode_t)HAL_PIO_FUNC_GPIO) != ERRCODE_SUCC) ||\r
(uapi_pin_set_pull(G_INT1_PIN, (pin_pull_t)HAL_PIO_PULL_UP) != ERRCODE_SUCC) ||\r
/* 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) {
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");
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
#ifndef __CWM_EVENT_STRUCTURE_H__
#define __CWM_EVENT_STRUCTURE_H__
-
+#include <stdint.h>
/**
* @brief CyweeMotion task handle event structure.
*/
#ifndef __OS_API_H__
#define __OS_API_H__
-
+#include <stdint.h>
/**
* @brief System/OS/Peripheral API structure.
*/
--- /dev/null
+/**
+ * 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 <stdint.h>
+#include <stdio.h>
+#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
--- /dev/null
+/**
+ * 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
--- /dev/null
+/**
+ * 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
--- /dev/null
+
+#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;
+}
--- /dev/null
+/**
+ * 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
/*** 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"
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <math.h>
+
+#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;
/************************/
/********************************/
/*** 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; 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;
- }
+ errcode_t ret;
+ uint32_t retry;
+ i2c_data_t data;
+ uint8_t *write_data = NULL;
+ cywee_i2c_init();
+
+ write_data = (uint8_t *)osal_kmalloc(regLength, OSAL_GFP_KERNEL);
+ if (write_data == NULL) {
+ PRINT_ERR("cywee send buff malloc fail!");
+ goto error;
}
-}
-// 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)
+ if( regLength == 2)
{
- case INT_RESISTOR_PULLUP:
- return NRF_GPIO_PIN_PULLUP;
-
- case INT_RESISTOR_PULLDOWN:
- return NRF_GPIO_PIN_PULLDOWN;
-
- default:
- return NRF_GPIO_PIN_NOPULL;
+ write_data[0] = ((uint8_t*)®)[0];
+ write_data[1] = ((uint8_t*)®)[1];
+ }else{
+ write_data[0] = (uint8_t)reg;
}
-}
-// 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;
+ data.send_buf = write_data;
+ data.send_len = regLength;
+ data.receive_buf = readData;
+ data.receive_len = readDataSize;
- 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:
+ 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;
+ }
}
-}
-
-//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;
+ if (ret != ERRCODE_SUCC) {
+ PRINT_ERR("cywee data read fail! ret=0x%x", ret);
}
+ osal_kfree(write_data);
+error:
+ return (ret>0) ? 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<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;
- }
+ errcode_t ret;
+ uint32_t retry;
+ i2c_data_t data;
+ uint8_t *write_data = NULL;
+ uint16_t send_len;
+ uint8_t *data_buf=writeData;
+ uint16_t data_len=writeDataSize;
+
+ cywee_i2c_init();
+ send_len = data_len + regLength;
+ write_data = (uint8_t *)osal_kmalloc(send_len, OSAL_GFP_KERNEL);
+ if (write_data == NULL) {
+ PRINT_ERR("cywee send buff malloc fail!");
+ goto error;
}
- return 1;
-}
-int CWM_disableGpioIRQ(uint16_t sensorType, uint16_t sensorPin)
-{
- for (int i=0; i<ARRAY_SIZE(m_irqHandler); i++)
+ if( regLength == 2)
{
- if (sensorType == m_irqHandler[i].sensorType && sensorPin == m_irqHandler[i].sensorPin)
- {
- m_irqHandler[i].callback = NULL;
- nRF_UnsetGpioIRQ(m_irqHandler[i].mcuPin);
-
- return 0;
- }
+ write_data[0] = ((uint8_t*)®)[0];
+ write_data[1] = ((uint8_t*)®)[1];
+ }else{
+ write_data[0] = (uint8_t)reg;
+ }
+ ret = (uint32_t)memcpy_s(write_data + regLength, send_len - regLength, data_buf, data_len);
+ if (ret != EOK) {
+ PRINT_ERR("cywee send_buf content copy fail! ret=0x%x", ret);
+ goto free_mem;
}
- 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*) ®, 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)
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;
}
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;
}
#include <string.h>
#include "cwm_lib.h"
#include "config.h"
+#ifdef SIGNAL_SIMULATE_PROCESS
#include "simulate_signal.h"
+#endif
/*********************/
/*** Macro Defines ***/
}
#endif
-int main(void)
+int cywee_main(void)
{
OsAPI device_func =
{
SettingControl_t scl;
- board_init();
-
#ifdef BUILD_IAR
CWM_OS_dbgPrintf("Use IAR\n");
#elif defined(BUILD_KEIL)
#include <cwm_lib.h>
#include <cwm_lib_dml.h>
-// #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) {
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);
.spiWrite = CWM_OS_spiWrite,
.uSleep = CWM_OS_uSleep,
};
-
+
CWM_LibPreInit(&api);
//set mcu_chip information, must call this before CWM_LibPostInit()
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();
+}
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
+#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);
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];
return 0;
}
-int test_free_1() {
+int test_free_1(void)
+{
char *pBuf1;
char *pBuf2;
int alloc_size;
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");
}
}
-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");
}
}
-void test_GetTimeNs_2() {
+void test_GetTimeNs_2(void)
+{
uint64_t timeNow, timeLast, timeDiff;
uint64_t count;
}
}
-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");
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");
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");
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);
}
}
}
#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
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;
}
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