From: SnickerSun Date: Sat, 20 Jan 2024 02:27:16 +0000 (+0800) Subject: 1. 电池电量获取日志取消 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=04fffb0b244f1d1443b711b011e1898fc2cafc10;p=mirrors%2FFD230.git 1. 电池电量获取日志取消 2. 添加MG_MMC5603 驱动,增加算法库,优化 ACC_LIS2DOC驱动 3. heapinfo at指令添加总和数据打印 4. export i2c_master_init_check 函数 i2c.c 5. LITEOS TASK LIMIT 增加到48 --- diff --git a/code/sdk/application/battery/service/battery_service.c b/code/sdk/application/battery/service/battery_service.c index 7c9065a9e..fe8602114 100644 --- a/code/sdk/application/battery/service/battery_service.c +++ b/code/sdk/application/battery/service/battery_service.c @@ -177,7 +177,7 @@ static bool adc_get_sample_result(float *voltage, uint8_t channel) *voltage = adc_trans_systick_to_battery_ntc(stick); else if (channel == 5) *voltage = adc_trans_systick_to_pcb_ntc(stick); - ///osal_printk("channel = %d , tick = %d , voltage = %.04f.\r\n", channel,stick,*voltage); + // osal_printk("channel = %d , tick = %d , voltage = %.04f.\r\n", channel,stick,*voltage); UNUSED(discard_number); return true; @@ -299,7 +299,7 @@ void disable_02c(void) uint8_t get_charge_stat(void) { uint16_t vbus_status = reg32_getbit(ULP_WKUP_INT_STS, 0x4); - uint16_t g_ulp_wkup_flag = readw(ULP_WKUP_INT_STS); + uint16_t g_ulp_wkup_flag = reg32_getbit(ULP_WKUP_INT_STS, 0x5); PRINT("get_charge_stat %02X %02X\r\n",vbus_status,g_ulp_wkup_flag); if (vbus_status == 1) { return 1; @@ -312,14 +312,6 @@ errcode_t uapi_battery_init(void); #include "tcxo.h" uint8_t batteryservice_get_voltage(float *voltage) { - - // if (g_batter_service_initialled == false) - // { - // uapi_battery_init(); - // g_batter_service_initialled = true; - // *voltage = 0; - // return 0; - // } uint8_t percent = 0; *voltage = current_battery_info.battery_voltage; if (*voltage <= batteryservice_VOLTAGE_MIN) @@ -332,28 +324,12 @@ uint8_t batteryservice_get_voltage(float *voltage) uint8_t batteryservice_get_battery_temp(float *temp) { - // if (g_batter_service_initialled == false) - // { - // uapi_battery_init(); - // g_batter_service_initialled = true; - // *temp = 0; - // return 0; - // } - *temp = current_battery_info.battery_ntc_temp; return 0; } uint8_t batteryservice_get_pcb_temp(float *temp) { - - // if (g_batter_service_initialled == false) - // { - // uapi_battery_init(); - // g_batter_service_initialled = true; - // *temp = 0; - // return 0; - // } *temp = current_battery_info.pcb_ntc_temp; return 0; } @@ -362,68 +338,49 @@ uint8_t batteryservice_get_pcb_temp(float *temp) * 电池电压读取逻辑: * 充电10秒,停止充电1秒,并读取电压。之后再开始充电10秒,再停止充电一秒,读取电压,然后再开始充电。。。。依此类推。 * **/ -#define USE_APP_TIMER 1 #include "cmsis_os2.h" #include "input_app.h" -#if USE_APP_TIMER + osTimerId_t g_battery_timer = NULL; -#else -timer_handle_t g_battery_timer = {0}; -#endif + static bool g_bat_timer_is_running = false; #define DISABLE_CHARGE_CHECK_MS 1000 #define ENABLE_CHARGE_TIMEOUT_MS 10000 -bool last_battery_charge_enable_status=false; // true上次刚设置在充电状态,false 上次设置不在充电状态。注意这个是充电IC的充电开关设置,并非真正处于充电状态的标识。 +bool last_battery_charge_enable_status=true; // true上次刚设置在充电状态,false 上次设置不在充电状态。注意这个是充电IC的充电开关设置,并非真正处于充电状态的标识。 static unsigned long g_app_queue; #define BATTERY_CMD_CHECK_VOLTAGE 0x11 #define BATTERY_CMD_DISABLE_CHARGE 0x12 -#if USE_APP_TIMER + static void battery_check_timer_callback(void* data); -#else -static void battery_check_timer_callback(uint32_t data); -#endif + static void battery_timer_start_check_released(uint32_t rtc_ms) { - // bool start = false; - // if (!g_bat_timer_is_running) { - // g_bat_timer_is_running = true; - // start = true; - // } - - -#if USE_APP_TIMER - if (g_bat_timer_is_running) osTimerStop(g_battery_timer); - osTimerStart(g_battery_timer, rtc_ms); -#else - if (g_bat_timer_is_running) uapi_rtc_stop(g_battery_timer); - uapi_rtc_start(g_battery_timer, rtc_ms, battery_check_timer_callback, 1); -#endif + if (g_bat_timer_is_running) osTimerStop(g_battery_timer); + osTimerStart(g_battery_timer, rtc_ms); g_bat_timer_is_running = true; } void do_battery_check_msg(int cmd); static void battery_check_and_enable_charge(void); -#if USE_APP_TIMER + + static void battery_check_timer_callback(void * data) -#else -static void battery_check_timer_callback(uint32_t data) -#endif { unused(data); g_bat_timer_is_running = false; if(last_battery_charge_enable_status == true){ - // do_battery_check_msg(BATTERY_CMD_DISABLE_CHARGE); - disable_charge(); - uapi_tcxo_delay_ms(20); + do_battery_check_msg(BATTERY_CMD_DISABLE_CHARGE); + // disable_charge(); + // uapi_tcxo_delay_ms(20); battery_timer_start_check_released(DISABLE_CHARGE_CHECK_MS); last_battery_charge_enable_status = false; }else{ - // do_battery_check_msg(BATTERY_CMD_CHECK_VOLTAGE); - battery_check_and_enable_charge(); - uapi_tcxo_delay_ms(20); + do_battery_check_msg(BATTERY_CMD_CHECK_VOLTAGE); + // battery_check_and_enable_charge(); + // uapi_tcxo_delay_ms(20); battery_timer_start_check_released(ENABLE_CHARGE_TIMEOUT_MS); last_battery_charge_enable_status = true; } @@ -432,13 +389,8 @@ static void battery_check_timer_callback(uint32_t data) void uapi_battery_deinit(void) { /* Stop the time and clear the pin map */ -#if USE_APP_TIMER osTimerStop(g_battery_timer); osTimerDelete(g_battery_timer); -#else - uapi_rtc_stop(g_battery_timer); - uapi_rtc_delete(g_battery_timer); -#endif g_bat_timer_is_running = false; g_battery_timer = NULL; } @@ -476,34 +428,13 @@ static void battery_check_task(void const *arg) common_notify_mail_t mail; uint32_t msgsize = (uint32_t)sizeof(common_notify_mail_t); -#if USE_APP_TIMER - g_battery_timer = osTimerNew((osTimerFunc_t)battery_check_timer_callback, osTimerPeriodic, NULL, NULL); -#else - // ret = uapi_rtc_init(); - - // ret |= uapi_rtc_adapter(0, RTC_0_IRQN, irq_prio(RTC_0_IRQN)); /* 1: using timer1 */ - // if (ret != ERRCODE_SUCC) { - // PRINT("uapi_rtc_init FAILED 0x%x", ret); - // return ; - // } - ret = uapi_rtc_create(RTC_1, &g_battery_timer); /* 1: using timer1 */ - if (ret != ERRCODE_SUCC) { - PRINT("uapi_rtc_create FAILED 0x%x", ret); - return ; - } - -#endif - - //开始timer - battery_timer_start_check_released(ENABLE_CHARGE_TIMEOUT_MS); - while (1) { ret = osal_msg_queue_read_copy(g_app_queue, (void *)&mail, &msgsize, OSAL_MSGQ_WAIT_FOREVER); if (ret != OSAL_SUCCESS) { continue; } - + get_charge_stat(); if (mail.comm.app == BATTERY_CMD_CHECK_VOLTAGE) { battery_check_and_enable_charge(); uapi_tcxo_delay_ms(20); @@ -531,7 +462,11 @@ errcode_t uapi_battery_init(void) return ERRCODE_FAIL; } - osal_kthread_set_priority(task_handle, APP_BOARD_TASK_PRIO); + // osal_kthread_set_priority(task_handle, APP_BOARD_TASK_PRIO); + osal_kthread_set_priority(task_handle, 10); + g_battery_timer = osTimerNew((osTimerFunc_t)battery_check_timer_callback, osTimerPeriodic, NULL, NULL); + //开始timer + battery_timer_start_check_released(DISABLE_CHARGE_CHECK_MS); return ERRCODE_SUCC; } diff --git a/code/sdk/application/battery/service/battery_service.h b/code/sdk/application/battery/service/battery_service.h index 5e64cc8da..3aa4a8027 100644 --- a/code/sdk/application/battery/service/battery_service.h +++ b/code/sdk/application/battery/service/battery_service.h @@ -7,8 +7,8 @@ * 2022-08-16, Create file. \n */ -#ifndef BATTERY_H__ -#define BATTERY_H__ +#ifndef BATTERY_SERVICE_H__ +#define BATTERY_SERVICE_H__ #ifdef __cplusplus #if __cplusplus 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 df411ad5d..e215a2ee8 100755 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -55,7 +55,12 @@ #ifdef SUPPORT_BATTERY_SERVICE #include "battery_service.h" #endif - +#ifdef MAG_MMC5603 +#include "mag_service.h" +#endif +#ifdef ACC_LIS2DOC +#include "acc_service.h" +#endif #define EMMC_BASE_ADDR 0x52062000 #define TASK_PRIORITY_APP (osPriority_t)(17) #define TICK_TEN_MS (10U) @@ -271,6 +276,12 @@ static void thread_main(const void *unused) #ifdef SUPPORT_BATTERY_SERVICE uapi_battery_init(); +#endif +#ifdef MAG_MMC5603 + uapi_mag_service_init(); +#endif +#ifdef ACC_LIS2DOC + uapi_acc_service_init(); #endif set_startup_finish_flag(); } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassModel.cpp index c973cec4f..f0bc64454 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassModel.cpp @@ -12,6 +12,8 @@ #ifdef __cplusplus extern "C" { #endif +#include "mag_service.h" + using namespace OHOS; @@ -38,10 +40,7 @@ uint8_t CompassModel::GetCalibrationStatus(void) void CompassModel::SetDisplayAngle(uint16_t angle) { - displayAngle += angle; - if (displayAngle > 359) { - displayAngle = 0; - } + displayAngle = (int16_t)mag_service_get_fAzimuth(); } uint16_t CompassModel::GetDisplayAngle(void) @@ -68,11 +67,14 @@ time_t CompassModel::GetCurrentTime(void) bool CompassModel::OpenCompassSensor(void) { + + do_mag_service_check_msg(MAG_SERVICE_CMD_START_CHECK); return true; } bool CompassModel::CloseCompassSensor(void) { + do_mag_service_check_msg(MAG_SERVICE_CMD_STOP_CHECK); return true; } } diff --git a/code/sdk/application/wstp/at_service/app/app_at_process.c b/code/sdk/application/wstp/at_service/app/app_at_process.c index 5cc8878f1..b76e33e43 100755 --- a/code/sdk/application/wstp/at_service/app/app_at_process.c +++ b/code/sdk/application/wstp/at_service/app/app_at_process.c @@ -437,7 +437,8 @@ uint32_t mcu_os_heap_info(uint8_t *para, uint32_t para_len) heapMan->stat.taskMemstats[taskId].memUsed, heapMan->stat.taskMemstats[taskId].memPeak); } wstp_print("\r\n"); - + wstp_print("mem total used 0x%-8x peak 0x%-8x\r\n", + heapMan->stat.memTotalUsed, heapMan->stat.memTotalPeak); #endif #if defined __FREERTOS__ && defined FREERTOS_DEBUG freertos_heap_print(); diff --git a/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h b/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h index ab289434d..c67ea8f43 100755 --- a/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h +++ b/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h @@ -150,7 +150,7 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L9 dsp uart TP35 { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L10 dsp uart TP36 #endif - { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L11 a+g int1 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L11 G_INT1 { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L12 i2c data HX3507_SDIO { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L13 i2c CLK HX3507_SCLK @@ -161,7 +161,7 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L17 HX3507_INT { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L18 VDDEN //暂时无用,采用VDDIO 默认开启 EXt V3.0 EXt V1.8 - { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L19 a+g int1 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L19 G_INT2 { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L20 0.2C_CHRG { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L21 NTC_VDD_ON 给低打开 NTC上拉电源 @@ -271,6 +271,11 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { //默认开启 EXT LDO V3.0 V1.8 { S_AGPIO_L18, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL }, + + /**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 }, + }; /** * @} diff --git a/code/sdk/drivers/drivers/driver/i2c/i2c.c b/code/sdk/drivers/drivers/driver/i2c/i2c.c index 002dc1778..30701aff6 100755 --- a/code/sdk/drivers/drivers/driver/i2c/i2c.c +++ b/code/sdk/drivers/drivers/driver/i2c/i2c.c @@ -904,7 +904,7 @@ static void i2c_writeread_mutex_unlock(i2c_bus_t bus) } #if defined(CONFIG_I2C_SUPPORT_MASTER) && (CONFIG_I2C_SUPPORT_MASTER == 1) -static errcode_t i2c_master_init_check(i2c_bus_t bus, uint32_t baudrate, uint8_t hscode) +errcode_t i2c_master_init_check(i2c_bus_t bus, uint32_t baudrate, uint8_t hscode) { if (unlikely(bus >= I2C_BUS_MAX_NUM)) { return ERRCODE_I2C_INVALID_PARAMETER; diff --git a/code/sdk/drivers/peripheral/acc/CMakeLists.txt b/code/sdk/drivers/peripheral/acc/CMakeLists.txt index 583644d08..4bff8c819 100644 --- a/code/sdk/drivers/peripheral/acc/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/acc/CMakeLists.txt @@ -9,16 +9,18 @@ set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/lis2doc_porting.c ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/lis2doc_at_cmd.c ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/driver/lis2doc_reg.c - ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_activity.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_activity.c # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_free_fall.c # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_orientation.c # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_read_data_polling.c ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_read_data_single.c # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_read_fifo.c - ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_self_test.c - ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_wake_up.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_self_test.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_wake_up.c + ${CMAKE_CURRENT_SOURCE_DIR}/service/acc_service.c ) set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR}/service ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC ) set(PUBLIC_DEFINES @@ -34,16 +36,18 @@ set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/lis2doc_porting.c ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/lis2doc_at_cmd.c ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/driver/lis2doc_reg.c - ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_activity.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_activity.c # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_free_fall.c # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_orientation.c # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_read_data_polling.c ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_read_data_single.c # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_read_fifo.c - ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_self_test.c - ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_wake_up.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_self_test.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_wake_up.c + ${CMAKE_CURRENT_SOURCE_DIR}/service/acc_service.c ) set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR}/service ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC ) set(PUBLIC_DEFINES diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_common.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_common.c new file mode 100644 index 000000000..de5b372f8 --- /dev/null +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_common.c @@ -0,0 +1,163 @@ +/* + ****************************************************************************** + * @file activity.c + * @author Sensors Software Solution Team + * @brief This file show the simplest way to detect activity/inactivity + * from sensor. + * + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* + * This example was developed using the following STMicroelectronics + * evaluation boards: + * + * - STEVAL_MKI109V3 + STEVAL-MKI179V1 + * - NUCLEO_F411RE + X_NUCLEO_IKS01A3 + * - DISCOVERY_SPC584B + X_NUCLEO_IKS01A3 + * + * and STM32CubeMX tool with STM32CubeF4 MCU Package + * + * Used interfaces: + * + * STEVAL_MKI109V3 - Host side: USB (Virtual COM) + * - Sensor side: SPI(Default) / I2C(supported) + * + * NUCLEO_STM32F411RE - Host side: UART(COM) to USB bridge + * - I2C(Default) / SPI(supported) + * + * DISCOVERY_SPC584B - Host side: UART(COM) to USB bridge + * - Sensor side: I2C(Default) / SPI(supported) + * + * If you need to run this example on a different hardware platform a + * modification of the functions: `platform_write`, `platform_read`, + * `tx_com` and 'platform_init' is required. + * + */ + +/* STMicroelectronics evaluation boards definition + * + * Please uncomment ONLY the evaluation boards in use. + * If a different hardware is used please comment all + * following target board and redefine yours. + */ + +//#define STEVAL_MKI109V3 /* little endian */ +//#define NUCLEO_F411RE /* little endian */ +//#define SPC584B_DIS /* big endian */ + +/* ATTENTION: By default the driver is little endian. If you need switch + * to big endian please see "Endianness definitions" in the + * header file of the driver (_reg.h). + */ + + +#if defined(STEVAL_MKI109V3) +/* MKI109V3: Define communication interface */ +#define SENSOR_BUS hspi2 +/* MKI109V3: Vdd and Vddio power supply values */ +#define PWM_3V3 915 + +#elif defined(NUCLEO_F411RE) +/* NUCLEO_F411RE: Define communication interface */ +#define SENSOR_BUS hi2c1 + +#elif defined(SPC584B_DIS) +/* DISCOVERY_SPC584B: Define communication interface */ +#define SENSOR_BUS I2CD1 + +#endif + +/* Includes ------------------------------------------------------------------*/ +#include +#include +#include "lis2doc_reg.h" +#include "lis2doc_porting.h" + +/* Private macro -------------------------------------------------------------*/ +#define BOOT_TIME 20 //ms + +/* Private variables ---------------------------------------------------------*/ +static lis2doc_mode_t pm; +static uint8_t whoamI, rst; +static uint8_t tx_buffer[1000]; + + +/* Main Example --------------------------------------------------------------*/ +void lis2doc_init(void) +{ + /* Initialize mems driver interface */ + stmdev_ctx_t dev_ctx; + lis2doc_reg_t int_route; + dev_ctx.write_reg = platform_write; + dev_ctx.read_reg = platform_read; + dev_ctx.handle = &SENSOR_BUS; + /* Initialize platform specific hardware */ + platform_init(); + /* Wait sensor boot time */ + platform_delay(BOOT_TIME); + /* Check device ID */ + lis2doc_device_id_get(&dev_ctx, &whoamI); + + if (whoamI != LIS2DOC_ID) + { + /* manage here device not found */ + LIS_ERROR("read lis2doc id 0x%02X != 0x%02X\r\n",whoamI,LIS2DOC_ID); + return ; + } + + /* Restore default configuration */ + lis2doc_reset_set(&dev_ctx, PROPERTY_ENABLE); + + do { + lis2doc_reset_get(&dev_ctx, &rst); + } while (rst); + + /* Set full scale */ + lis2doc_full_scale_set(&dev_ctx, LIS2DOC_2g); + /* Configure filtering chain + * Accelerometer - filter path / bandwidth + */ + lis2doc_filter_path_set(&dev_ctx, LIS2DOC_LPF_ON_OUT); + lis2doc_filter_bandwidth_set(&dev_ctx, LIS2DOC_ODR_DIV_4); + + /* Configure power mode */ + pm.lpm = 1; + pm.low_noise = 1; + lis2doc_power_mode_set(&dev_ctx, pm); + + /* Set wake-up duration + * Wake up duration event 1LSb = 1 / ODR + */ + lis2doc_wkup_dur_set(&dev_ctx, 2); + /* Set sleep duration + * Duration to go in sleep mode (1 LSb = 512 / ODR) + */ + lis2doc_act_sleep_dur_set(&dev_ctx, 2); + /* Set Activity wake-up threshold + * Threshold for wake-up 1 LSB = FS_XL / 64 + */ + lis2doc_wkup_threshold_set(&dev_ctx, 2); + /* Data sent to wake-up interrupt function */ + lis2doc_wkup_feed_data_set(&dev_ctx, LIS2DOC_HP_FEED); + /* Config activity / inactivity or stationary / motion detection */ + lis2doc_act_mode_set(&dev_ctx, LIS2DOC_DETECT_ACT_INACT); + /* Enable activity detection interrupt */ + lis2doc_pin_int1_route_get(&dev_ctx, &int_route.ctrl4_int1_pad_ctrl); + int_route.ctrl4_int1_pad_ctrl.int1_wu = PROPERTY_ENABLE; + lis2doc_pin_int1_route_set(&dev_ctx, &int_route.ctrl4_int1_pad_ctrl); + /* Set Output Data Rate */ + lis2doc_data_rate_set(&dev_ctx, LIS2DOC_XL_ODR_200Hz); + +} 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 9a1126973..e21c0500e 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 @@ -69,29 +69,59 @@ #include "lis2doc_reg.h" #include "lis2doc_porting.h" - +#include "pinctrl.h" +#include "platform_core.h" +#include "gpio.h" +#include "gpio_porting.h" +#include "errcode.h" /* Private macro -------------------------------------------------------------*/ #define BOOT_TIME 20 //ms /* Private variables ---------------------------------------------------------*/ static lis2doc_mode_t pm; static int16_t data_raw_acceleration[3]; -static float acceleration_mg[3]; +// static float acceleration_mg[3]; static uint8_t whoamI, rst; static uint8_t tx_buffer[1000]; static lis2doc_ctrl4_int1_pad_ctrl_t ctrl4_int1_pad; +static stmdev_ctx_t dev_ctx; +#define G_INT1_PIN S_AGPIO_L11 +#define G_INT2_PIN S_AGPIO_L19 +static int lis2doc_install_success = -1; -/* Main Example --------------------------------------------------------------*/ -void lis2doc_read_data_single(void) +/*初始化GPIO*/ +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) || + (uapi_gpio_set_dir(G_INT1_PIN, GPIO_DIRECTION_INPUT) != ERRCODE_SUCC)) { + PRINT("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("gpio G_INT2_PIN config failed\r\n"); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + + +int lis2doc_read_data_single_init(void) { - /* Initialize mems driver interface */ - stmdev_ctx_t dev_ctx; + /* Initialize mems driver interface */ + if(lis2doc_install_success == 1) return ERRCODE_SUCC; + dev_ctx.write_reg = platform_write; dev_ctx.read_reg = platform_read; dev_ctx.handle = &SENSOR_BUS; /* Initialize platform specific hardware */ platform_init(); + + gpio_int_pin_init(); + /* Wait sensor boot time */ platform_delay(BOOT_TIME); /* Check device ID */ @@ -101,13 +131,15 @@ void lis2doc_read_data_single(void) { /* manage here device not found */ LIS_ERROR("read lis2doc id 0x%02X != 0x%02X\r\n",whoamI,LIS2DOC_ID); - return ; + lis2doc_install_success = 0; + return ERRCODE_FAIL; } + lis2doc_install_success = 1; /* Restore default configuration */ lis2doc_reset_set(&dev_ctx, PROPERTY_ENABLE); - + // uint8_t count=0; do { lis2doc_reset_get(&dev_ctx, &rst); } while (rst); @@ -134,28 +166,59 @@ void lis2doc_read_data_single(void) lis2doc_power_mode_set(&dev_ctx, pm); lis2doc_data_rate_set(&dev_ctx, LIS2DOC_XL_SET_SW_TRIG); + return ERRCODE_SUCC; +} +int lis2doc_read_data_single(float *x,float *y ,float *z) +{ + + + if(lis2doc_install_success == -1) + { + lis2doc_read_data_single_init(); + } + if(lis2doc_install_success == 0) + { + return ERRCODE_FAIL; + } + /* Read samples in polling mode (no int) */ - /* Read samples in polling mode (no int) */ - while (1) { /* polling on DRDY signal */ // if (GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_0)) { - if (1 == 0) { + uint8_t val = uapi_gpio_get_val(G_INT1_PIN); + uint8_t val2 = uapi_gpio_get_val(G_INT2_PIN); + // PRINT("G_INT1_PIN %u,G_INT2_PIN %u \r\n",val,val2); + if( val == 0 || val2 == 0) + { /* Read acceleration data */ memset(data_raw_acceleration, 0x00, 3 * sizeof(int16_t)); lis2doc_acceleration_raw_get(&dev_ctx, data_raw_acceleration); - acceleration_mg[0] = lis2doc_from_fs2_lp1_to_mg( + *x = lis2doc_from_fs2_lp1_to_mg( data_raw_acceleration[0]); - acceleration_mg[1] = lis2doc_from_fs2_lp1_to_mg( + *y = lis2doc_from_fs2_lp1_to_mg( data_raw_acceleration[1]); - acceleration_mg[2] = lis2doc_from_fs2_lp1_to_mg( + *z = lis2doc_from_fs2_lp1_to_mg( data_raw_acceleration[2]); - + *x = (*x)/1000.0f; + *y = (*y)/1000.0f; + *z = (*z)/1000.0f; lis2doc_data_rate_set(&dev_ctx, LIS2DOC_XL_SET_SW_TRIG); + + } + return ERRCODE_SUCC; + +} +/* Main Example --------------------------------------------------------------*/ +void lis2doc_read_data(void) +{ + float x,y,z; + if(lis2doc_read_data_single(&x,&y,&z)==ERRCODE_SUCC) + { + sprintf((char *)tx_buffer, "Acceleration [mg]:%4.2f\t%4.2f\t%4.2f\r\n", - acceleration_mg[0], acceleration_mg[1], acceleration_mg[2]); + x, y, z); tx_com(tx_buffer, strlen((char const *)tx_buffer)); } - } + } diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_at_cmd.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_at_cmd.c index 2f4aa564c..ea0b9838e 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_at_cmd.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_at_cmd.c @@ -4,6 +4,7 @@ #include "at_cmd_api.h" #include "pm_control.h" #include "lis2doc_porting.h" +#include "acc_service.h" #define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) #define LIS2DOC_MAX_ARGC 8 @@ -58,14 +59,10 @@ static uint32_t lis2doc_do_test(uint8_t *para, uint32_t paraLen, char *strCommon return ERRCODE_FAIL; } char *mode = (char*)argv[0]; - if (strcmp(mode, "activity") == 0) { - lis2doc_activity(); - } else if (strcmp(mode, "wakeup") == 0) { - lis2doc_wake_up(); - } else if (strcmp(mode, "selftest") == 0) { - lis2doc_self_test(); - } else if (strcmp(mode, "readsingle") == 0) { - lis2doc_read_data_single(); + if (strcmp(mode, "start") == 0) { + do_acc_service_check_msg(ACC_SERVICE_CMD_START_CHECK); + } else if (strcmp(mode, "stop") == 0) { + do_acc_service_check_msg(ACC_SERVICE_CMD_STOP_CHECK); } return 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 0fc4a8bbf..91bf6cbba 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.c @@ -80,6 +80,14 @@ 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/lis2doc_STdC/lis2doc_porting.h b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.h index 4cb4a721d..a7470dcd4 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.h +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.h @@ -38,10 +38,10 @@ extern uint8_t SENSOR_BUS ; /******test functions********/ -void lis2doc_activity(void); -void lis2doc_wake_up(void); -void lis2doc_self_test(void); -void lis2doc_read_data_single(void); +// void lis2doc_activity(void); +// void lis2doc_wake_up(void); +// void lis2doc_self_test(void); +// void lis2doc_read_data_single(void); #endif \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/acc/service/acc_service.c b/code/sdk/drivers/peripheral/acc/service/acc_service.c new file mode 100644 index 000000000..849a5add4 --- /dev/null +++ b/code/sdk/drivers/peripheral/acc/service/acc_service.c @@ -0,0 +1,170 @@ +/** + * 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 "lis2doc_porting.h" + +static bool g_batter_service_initialled = false; + +#include "tcxo.h" + +#include "cmsis_os2.h" +#include "input_app.h" +#include "mmc5603_hal.h" +#include "acc_service.h" + + +/*** + * 其他cmd在Header里定义,对外开放 +*/ +#define ACC_SERVICE_CMD_TIMER_CHECK 0x11 + +osTimerId_t g_acc_service_timer = NULL; + +static bool g_bat_timer_is_running = false; +#define ACC_CHECK_MS 100 +static unsigned long g_app_queue; + +static bool acc_service_running_stat = false; +static void acc_service_check_timer_callback(void* data); + +static void acc_service_timer_start_check(uint32_t rtc_ms) +{ + + if (g_bat_timer_is_running ) osTimerStop(g_acc_service_timer); + if (acc_service_running_stat == true) osTimerStart(g_acc_service_timer, rtc_ms); + g_bat_timer_is_running = true; + +} +void do_acc_service_check_msg(int cmd); + +static void acc_service_check_timer_callback(void * data) +{ + unused(data); + + g_bat_timer_is_running = false; + + if(acc_service_running_stat == true){ + // mmc5603_check(); + lis2doc_read_data(); + acc_service_timer_start_check(ACC_CHECK_MS); + } + // do_acc_service_check_msg(ACC_SERVICE_CMD_TIMER_CHECK); + // uapi_tcxo_delay_ms(20); + + + +} +void uapi_acc_service_deinit(void) +{ + /* Stop the time and clear the pin map */ + osTimerStop(g_acc_service_timer); + osTimerDelete(g_acc_service_timer); + + g_bat_timer_is_running = false; + g_acc_service_timer = NULL; +} + + + +void do_acc_service_check_msg(int cmd) +{ + int ret; + + common_notify_mail_t mail = {0}; + mail.comm.app = cmd; + ret = osal_msg_queue_write_copy(g_app_queue, (void *)&mail, + sizeof(common_notify_mail_t), 0); + if (ret != OSAL_SUCCESS) { + PRINT("Error mag Check MSG 0x%02X send failed! err=0x%x! \r\n",cmd, ret); + } + +} + +static void acc_service_check_task(void const *arg) +{ + unused(arg); + int32_t ret; + common_notify_mail_t mail; + uint32_t msgsize = (uint32_t)sizeof(common_notify_mail_t); + + while (1) { + ret = osal_msg_queue_read_copy(g_app_queue, (void *)&mail, &msgsize, + OSAL_MSGQ_WAIT_FOREVER); + if (ret != OSAL_SUCCESS) { + continue; + } + + if (mail.comm.app == ACC_SERVICE_CMD_TIMER_CHECK) { + // acc_service_check_and_enable_charge(); + // mmc5603_check(); + PRINT("ACC_SERVICE_CMD_TIMER_CHECK\r\n"); + }else if (mail.comm.app == ACC_SERVICE_CMD_START_CHECK){ + acc_service_running_stat = true; + // lis2doc_read_data_single_init(); + acc_service_timer_start_check(ACC_CHECK_MS); + }else if (mail.comm.app == ACC_SERVICE_CMD_STOP_CHECK){ + acc_service_running_stat = false; + osTimerStop(g_acc_service_timer); + + } + } +} + +errcode_t uapi_acc_service_init(void) +{ + if (osal_msg_queue_create("acc_service_queue", APP_BOARD_MSG_COUNT, &g_app_queue, + 0, sizeof(common_notify_mail_t)) != ERRCODE_SUCC) { + PRINT("[mag][service] app create mail fail\n"); + return ERRCODE_FAIL; + } + + + osal_task *task_handle = osal_kthread_create((osal_kthread_handler)acc_service_check_task, NULL, + "acc_service_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"); + return ERRCODE_FAIL; + } + + // osal_kthread_set_priority(task_handle, APP_BOARD_TASK_PRIO); + osal_kthread_set_priority(task_handle, 10); + + g_acc_service_timer = osTimerNew((osTimerFunc_t)acc_service_check_timer_callback, osTimerPeriodic, NULL, NULL); + + + return ERRCODE_SUCC; +} + +// void acc_service_service_resume(void) +// { +// PRINT("acc_service_service resume!\r\n"); +// acc_service_check_timer_callback(0); +// } +// void acc_service_service_suspend(void) +// { +// PRINT("acc_service_service suspend!\r\n"); +// } \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/acc/service/acc_service.h b/code/sdk/drivers/peripheral/acc/service/acc_service.h new file mode 100644 index 000000000..2aaa5186d --- /dev/null +++ b/code/sdk/drivers/peripheral/acc/service/acc_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 ACC_SERVICE_H__ +#define ACC_SERVICE_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#include "stdint.h" +#include "errcode.h" + + +#define ACC_SERVICE_CMD_START_CHECK 0x12 +#define ACC_SERVICE_CMD_STOP_CHECK 0x13 + +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_acc_service_check_msg(int cmd); + +int lis2doc_read_data_single(float *x,float *y,float *z); + +void lis2doc_read_data(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/mag/CMakeLists.txt b/code/sdk/drivers/peripheral/mag/CMakeLists.txt index 468187744..3e81599d9 100644 --- a/code/sdk/drivers/peripheral/mag/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/mag/CMakeLists.txt @@ -8,27 +8,33 @@ set(COMPONENT_NAME "mag_sensor") if("MAG_MMC5603" IN_LIST DEFINES) set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/Customer.c - ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/main_sample.c + ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/mmc5603_main.c ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/MMC5603.c ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/mmc5603_at_cmd.c + ${CMAKE_CURRENT_SOURCE_DIR}/service/mag_service.c ) set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603 + ${CMAKE_CURRENT_SOURCE_DIR}/service ) set(PUBLIC_DEFINES + MAG_MMC5603 SUPPORT_AT_MMC5603 ) else() set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/Customer.c - ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/main_sample.c + ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/mmc5603_main.c ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/MMC5603.c ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/mmc5603_at_cmd.c + ${CMAKE_CURRENT_SOURCE_DIR}/service/mag_service.c ) set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603 + ${CMAKE_CURRENT_SOURCE_DIR}/service ) set(PUBLIC_DEFINES + MAG_MMC5603 SUPPORT_AT_MMC5603 ) endif() @@ -39,8 +45,6 @@ set(PRIVATE_HEADER set(PRIVATE_DEFINES ) - - # use this when you want to add ccflags like -include xxx set(COMPONENT_PUBLIC_CCFLAGS ) @@ -61,3 +65,6 @@ set(MAIN_COMPONENT build_component() install_sdk(${CMAKE_CURRENT_SOURCE_DIR} "*") + +find_library(LIB_PATH_MMC5603 ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/MemsicAlgo.a ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(${TARGET_NAME} PRIVATE -Wl,--whole-archive ${LIB_PATH_MMC5603} PRIVATE -Wl,--whole-archive) \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/mag/mmc5603/Customer.h b/code/sdk/drivers/peripheral/mag/mmc5603/Customer.h index 535e41eb0..585668424 100644 --- a/code/sdk/drivers/peripheral/mag/mmc5603/Customer.h +++ b/code/sdk/drivers/peripheral/mag/mmc5603/Customer.h @@ -28,7 +28,7 @@ /** * @brief Delay function. */ -void mmc5603_mmc5603_Delay_Ms(int cnt); +void mmc5603_Delay_Ms(int cnt); /** * @brief Delay function. diff --git a/code/sdk/drivers/peripheral/mag/mmc5603/MemsicAlgo.a b/code/sdk/drivers/peripheral/mag/mmc5603/MemsicAlgo.a new file mode 100644 index 000000000..9af3d8c04 Binary files /dev/null and b/code/sdk/drivers/peripheral/mag/mmc5603/MemsicAlgo.a differ diff --git a/code/sdk/drivers/peripheral/mag/mmc5603/MemsicAlgo.h b/code/sdk/drivers/peripheral/mag/mmc5603/MemsicAlgo.h new file mode 100644 index 000000000..ce1166575 --- /dev/null +++ b/code/sdk/drivers/peripheral/mag/mmc5603/MemsicAlgo.h @@ -0,0 +1,119 @@ +/***************************************************************************** +* Copyright (C), 2018, MEMSIC Inc. +* File Name : MemsicAlgo.h +* Author : MEMSIC AE Algoritm Team +* Description : This file is the head file of MemsicAlgo.lib. It provides the +* interface function declarations of the lib. +* History : 1. Data : 20180801 +* 2. Author : YGP +* 3. Modification : +*****************************************************************************/ +#ifndef _MEMSICALGORITHM_H_ +#define _MEMSICALGORITHM_H_ + +#define ANDROID_PLATFORM 1 +#define EVB_PLATFORM 2 +#define WINDOWS_PLATFORM 3 +#define PLATFORM EVB_PLATFORM + +#if((PLATFORM == ANDROID_PLATFORM)||(PLATFORM == EVB_PLATFORM)) +#define DLL_API +#define _stdcall +#elif(PLATFORM == WINDOWS_PLATFORM) +#define DLL_API extern "C" __declspec(dllexport) +#endif + +#if(PLATFORM == ANDROID_PLATFORM) +#include "MemsicConfig.h" +#include //ALOGE +#endif + +#ifndef MEMSIC_ALGORITHM_DATA_TYPES +#define MEMSIC_ALGORITHM_DATA_TYPES +typedef signed char int8; // signed 8-bit number (-128 to +127) +typedef unsigned char uint8; // unsigned 8-bit number (+0 to +255) +typedef signed short int16; // signed 16-bt number (-32,768 to +32,767) +typedef unsigned short uint16; // unsigned 16-bit number (+0 to +65,535) +typedef signed int int32; // signed 32-bit number (-2,147,483,648 to +2,147,483,647) +typedef unsigned int uint32; // unsigned 32-bit number (+0 to +4,294,967,295) +#endif + +#if(PLATFORM == ANDROID_PLATFORM) +/******************************************************************************************* +* Function Name : AlgoInitial +* Description : Initialize the algorithm. +* Input : None +* Output : None. +* Return : 1 --- succeed. +* -1 --- fail. +********************************************************************************************/ +int AlgoInitial(void); +#elif((PLATFORM == EVB_PLATFORM)||(PLATFORM == WINDOWS_PLATFORM)) +/******************************************************************************************* +* Function Name : InitialAlgorithm +* Description : Initial the corrected parameters for magnetic sensor. +* Input : sim[0-8] ---soft iron corrected parameters; +* mag_para[0-2]---mag offset; +* mag_para[3] ---mag radius or magnetic field strength; +* Output : None. +* Return : 1 --- succeed. +* -1 --- fail. +********************************************************************************************/ +DLL_API int _stdcall InitialAlgorithm(float *sim, float *mag_para); +#endif +/******************************************************************************************* +* Function Name : MainAlgorithmProcess +* Description : Pass the Acc and Mag raw data to the algorithm library. +* Input : acc[0-2] --- Acceleration raw data of three axis, unit is g; +* mag[0-2] --- Magnetic raw data of three axis, unit is gauss; +* enable_cali --- 1 means automatic mag calibration is enabled, 0 not; +* Output : None. +* Return : 1 --- succeed. +* -1 --- fail. +********************************************************************************************/ +DLL_API int _stdcall MainAlgorithmProcess(float *acc, float *mag, int enable_cali); + +/******************************************************************************************* +* Function Name : GetMagAccuracy +* Description : Get the accuracy of the calibration algorithm. +* Input : None +* Output : None +* Return : 0 --- Unreliable. +* : 1 --- Low. +* : 2 --- Medium. +* : 3 --- High. +********************************************************************************************/ +DLL_API int _stdcall GetMagAccuracy(void); + +/******************************************************************************************* +* Function Name : GetMagSaturation +* Description : Get the magnetic sensor saturation status. +* Input : None +* Output : None +* Return : 0 --- Indicate that magnetic sensor works normally. +* : 1 --- Indicate that magnetic sensor is saturated, need to do SET action. +********************************************************************************************/ +DLL_API int _stdcall GetMagSaturation(void); + +/******************************************************************************************* +* Function Name : GetCalPara +* Description : Get the calibrated parameters of magnetic sensor. +* Input : None +* Output : cp[0-2] --- magnetic field offset, unit is gauss. +* cp[3] --- strength of the magnetic field, unit is gauss. +* Return : 0 --- no need to save the calibrated magnetometer parameter. +* 1 --- need to save the new reliable calibrated magnetometer parameter. +********************************************************************************************/ +DLL_API int _stdcall GetCalPara(float *cp); + +/******************************************************************************************* +* Function Name : GetCalMag +* Description : Get the MEMSIC calibrated magnetic output. +* Input : None +* Output : cm[0-2] --- calibrated magnetic sensor data, unit is gauss. +* Return : debug use +********************************************************************************************/ +DLL_API int _stdcall GetCalMag(float *cm); + +#endif + diff --git a/code/sdk/drivers/peripheral/mag/mmc5603/MemsicCompass.h b/code/sdk/drivers/peripheral/mag/mmc5603/MemsicCompass.h new file mode 100644 index 000000000..4b48c9252 --- /dev/null +++ b/code/sdk/drivers/peripheral/mag/mmc5603/MemsicCompass.h @@ -0,0 +1,64 @@ +/***************************************************************************** +* Copyright (C), 2018, MEMSIC Inc. +* File Name : MemsicAlgo.h +* Author : MEMSIC AE Algoritm Team +* Description : This file is the head file of MemsicAlgo.lib. It provides the +* interface function declarations of the lib. +* History : 1. Data : 20180424 +* 2. Author : Yan Guopu +* 3. Modification : +*****************************************************************************/ +#ifndef _MEMSIC_COMPASS_H_ +#define _MEMSIC_COMPASS_H_ + +#define ANDROID_PLATFORM 1 +#define EVB_PLATFORM 2 +#define WINDOWS_PLATFORM 3 +#define PLATFORM EVB_PLATFORM + +#if((PLATFORM == ANDROID_PLATFORM)||(PLATFORM == EVB_PLATFORM)) +#define DLL_API +#define _stdcall +#elif(PLATFORM == WINDOWS_PLATFORM) +#define DLL_API extern "C" __declspec(dllexport) +#endif + +#if(PLATFORM == ANDROID_PLATFORM) +#include //ALOGE +#endif + +#ifndef MEMSIC_COMPASS_DATA_TYPES +#define MEMSIC_COMPASS_DATA_TYPES +// typedef signed char int8_t; // signed 8-bit number (-128 to +127) +// typedef unsigned char uint8_t; // unsigned 8-bit number (+0 to +255) +// typedef signed short int16_t; // signed 16-bt number (-32,768 to +32,767) +// typedef unsigned short uint16_t; // unsigned 16-bit number (+0 to +65,535) +// typedef signed int int32_t; // signed 32-bit number (-2,147,483,648 to +2,147,483,647) +// typedef unsigned int uint32_t; // unsigned 32-bit number (+0 to +4,294,967,295) +#endif + +/******************************************************************************************* +* Function Name : InitialCompassAlgo +* Description : Initial the filter coeficient for the compass filter. +* Input : sim[0-8] ---soft iron corrected parameters; +* mag_para[0-2]---mag offset; +* mag_para[3] ---mag radius or magnetic field strength; +* Output : None. +* Return : 1 --- succeed. +* -1 --- fail. +********************************************************************************************/ +DLL_API int _stdcall InitialCompassAlgo(float fc); + +/******************************************************************************************* +* Function Name : GetCalOri +* Description : Get the MEMSIC calibrated orientation vector. +* Input : acc[0-2] --- Accelerometer data of three axis, unit is gauss. +* : mag[0-2] --- Magnetic raw data of three axis, unit is gauss. +* Output : co[0-2] --- orientation data, azimuth, pitch, roll, unit is degree. +* Return : 1 --- succeed. +* -1 --- fail. +********************************************************************************************/ +DLL_API int _stdcall GetCalOri(float *acc, float *mag, float *co); + +#endif + diff --git a/code/sdk/drivers/peripheral/mag/mmc5603/main_sample.c b/code/sdk/drivers/peripheral/mag/mmc5603/main_sample.c deleted file mode 100644 index 9560c345b..000000000 --- a/code/sdk/drivers/peripheral/mag/mmc5603/main_sample.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "Customer.h" -#include "MMC5603.h" - -float magnetic_field_x; -float magnetic_field_y; -float magnetic_field_z; - -int test_mmc5603(void) -{ - /* Magnetic field vector, unit is gauss */ - float mag_raw_data[3] = {0.0}; - - /* Enable the sensor. */ - MMC5603_Enable(); - int count = 10; - while(count) - { - /* Get the MMC5603 data, unit is gauss */ - MMC5603_GetData(mag_raw_data); - - magnetic_field_x = mag_raw_data[0]; //unit is gauss - magnetic_field_y = mag_raw_data[1]; //unit is gauss - magnetic_field_z = mag_raw_data[2]; //unit is gauss - count-- ; - /* Sampling interval is 20ms, and the sampling rate is 50Hz. */ - - MMC_LOG("mag 5603 x %.03f, y %.03f , z %.03f \r\n",magnetic_field_x,magnetic_field_y,magnetic_field_z); - mmc5603_Delay_Ms(20); - } - MMC5603_Disable(); - return 0; -} diff --git a/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_at_cmd.c b/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_at_cmd.c index 5ad847534..869c7c2ca 100644 --- a/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_at_cmd.c +++ b/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_at_cmd.c @@ -6,6 +6,7 @@ #include "pm_control.h" #include "MMC5603.h" #include "Customer.h" +#include "mag_service.h" #define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) #define MMC5603_MAX_ARGC 8 @@ -43,16 +44,25 @@ static int ConvertCmdToParam(uint8_t *para, uint32_t paraLen, return MMC5603_SUCCESS; } -extern int test_mmc5603(void); -static uint32_t mmc5603_do_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +static uint32_t mmc5603_start_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { UNUSED(strCommonCmd); - test_mmc5603(); + UNUSED(paraLen); + UNUSED(para); + do_mag_service_check_msg(MAG_SERVICE_CMD_START_CHECK); + return ERRCODE_SUCC; +} +static uint32_t mmc5603_stop_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + UNUSED(paraLen); + UNUSED(para); + do_mag_service_check_msg(MAG_SERVICE_CMD_STOP_CHECK); return ERRCODE_SUCC; } - static const at_cmd_table_t g_mmc5603_cmd[] = { - { (char *)"AT^MMC5603TEST", mmc5603_do_test, (char *)"aac enable" }, + { (char *)"AT^MMC5603TESTSTART", mmc5603_start_test, (char *)"1" }, + { (char *)"AT^MMC5603TESTSTOP", mmc5603_stop_test, (char *)"1" }, }; at_cmd_table_t *get_mmc5603_cmd_table(uint32_t *cmd_count) diff --git a/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_hal.h b/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_hal.h new file mode 100644 index 000000000..8f769a5f9 --- /dev/null +++ b/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_hal.h @@ -0,0 +1,34 @@ +/** + * 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 MMC5603_HAL_H +#define MMC5603_HAL_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 */ + +int mmc5603_stop(void); +int mmc5603_check(void); +int mmc5603_start(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_main.c b/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_main.c new file mode 100644 index 000000000..c9ba9b361 --- /dev/null +++ b/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_main.c @@ -0,0 +1,369 @@ +/* This sample code teaches developer how to operate the MEMSIC alogrithm library + * to get Yaw, Pitch and Roll respectively. if developer want to use it as a part + * of his codes, he need to declare and define 3 functions by himself: + * ReadPara; + * Savepara; + * please NOTE it is ONLY a sample code and can be changed freely by developers. + */ + +#include "MemsicAlgo.h" +#include "MemsicCompass.h" +#include "Customer.h" +#include "MMC5603.h" + +#ifdef ACC_LIS2DOC +#include "acc_service.h" +#endif +float magnetic_field_x; +float magnetic_field_y; +float magnetic_field_z; + +#define A_LAYOUT 0 +#define M_LAYOUT 5 + + + +/* These variables are used to save the magnetic sensor calibrated data. */ +float calMagX, calMagY, calMagZ; + +/* These variables are used to save the calibrated orientation output. */ +float fAzimuth, fPitch, fRoll; + +/* This variable is used to save the calibration accuracy. */ +int iAccuracy; + +/* Read saved calibration parameters. These para is saved in somewhere that can not disappear when power-off + * ReadPara function should be create by customer.If customer can not implement this function, should comment it out + * If there is no parameter saved, ReadPara() should return -1, else return 1; + * If there is no para saved, pass the default value to the algorithm library + */ +int ReadPara(float *p); + +/* Save calibration parameters in somewhere that can not lose after power-off. + * When the system power on next time, need to read this parameters by the function ReadPara() for algorithm initial. + * If save parameter successfully, return 1, else return -1; + */ +int SavePara(float *p); + + +/** + * @brief Convert the sensor coordinate to right-front-up coordinate system; + */ +void acc_coordinate_raw_to_real(int layout, float *in, float *out); + +/** + * @brief Convert the sensor coordinate to right-front-up coordinate system; + */ +void mag_coordinate_raw_to_real(int layout, float *in, float *out); + +/** + * 校准数据 + */ +static float g_MagPara[4] = {0.0f}; + +/******************************************************************************* +* Function Name : main +* Description : the main function +*******************************************************************************/ + + + /* This variable is used to save calibrated mag para that need to be saved in system file */ +static float saveData[4] = {0.0f}; + +int mmc5603_start(void) +{ + int i; + /* magnetic sensor soft iron calibration matrix, default is unit matrix */ + float mag_smm[9] = { 1.0f, 0.0f, 0.0f, \ + 0.0f, 1.0f, 0.0f, \ + 0.0f, 0.0f, 1.0f}; + + /* default hard iron offset and magnetic field strength*/ + float mag_hmm[4] = {0.0f,0.0f,0.0f,0.5f}; + /* Read saved calibration parameters. These para is saved in somewhere that can not disappear when power-off + * ReadPara function should be create by customer.If customer can not implement this function, should comment it out + * If there is no parameter saved, ReadPara() should return -1, else return 1; + * If there is no para saved, pass the default value to the algorithm library + */ + if(ReadPara(saveData)==1){ + for(i=0;i<4;i++){ + mag_hmm[i] = saveData[i]; + } + } + + /* Initial the acc, mag, and calibrated parameters + * if already saved the calibrated offset and radius last time, read it out and init the magOffset and magRadius + */ + InitialAlgorithm(mag_smm, mag_hmm); + + /* Enable the sensor. */ + MMC5603_Enable(); + return 0; +} +int mmc5603_check(void) +{ + int i; + + /* This variable is used to store the accelerometer and magnetometer raw data. + * please NOTE that the data is going to store here MUST has been transmitted + * to match the Right-Handed coordinate sytem already. + */ + + float acc_raw_data[3] = {0.0f}; //accelerometer field vector, unit is g + float acc_real_data[3] = {0.0f}; + + float mag_raw_data[3] = {0.0f}; //magnetic field vector, unit is gauss + float mag_real_data[3] = {0.0f}; + + /* This variable is used to judge whether or not the developer + * should save the parameters in one place where will be read + * by the algorithm every time when the device restart. + * save_flag is a flag to if we need to save algorithm parameter into the system file. + */ + int save_flag=0; + /* Get the acc raw data, unit is g*/ + #ifdef ACC_LIS2DOC + lis2doc_read_data_single(&acc_raw_data[0],&acc_raw_data[1],&acc_raw_data[2]); + #endif + //acc_raw_data[0] = ; + //acc_raw_data[1] = ; + //acc_raw_data[2] = ; + + /* This variable is used to save the calibrated mag sensor XYZ output. */ + float caliMag[3] = {0.0f}; + + /* This variable is used to save the calibrated orientation data. */ + float caliOri[3] = {0.0f}; + + /* This variable is used to save calibrated mag sensor parameters */ + float caliMagPara[4] = {0.0f}; + /* convert the coordinate system */ + acc_coordinate_raw_to_real(A_LAYOUT, acc_raw_data, acc_real_data); + + /* Get the MMC5603 mag raw data, unit is gauss */ + MMC5603_GetData(mag_raw_data); + + /* Convert the coordinate system */ + mag_coordinate_raw_to_real(M_LAYOUT, mag_raw_data, mag_real_data); + + /* Below functions are algorithm interface. + * input acc, mag data into algorithm + * make sure that acc and mag XYZ data meet the right-hand(right-front-up) coordinate system + */ + MainAlgorithmProcess(acc_real_data, mag_real_data, 1); + + /* Get calibrated mag data */ + GetCalMag(caliMag); + + /* Calibrated magnetic sensor output, unit is gauss */ + calMagX = caliMag[0]; + calMagY = caliMag[1]; + calMagZ = caliMag[2]; + PRINT("== Mag x %.02F,y %.02F , z %.02F\r\n", + calMagX,//高斯X + calMagY,//高斯Y + calMagZ//高斯Z + ); + /* Get orientation vector */ + if (GetCalOri(acc_real_data, caliMag, caliOri) == 1 ) + { + + /* Get the accuracy of the algorithm */ + iAccuracy = GetMagAccuracy(); + + /* Get the fAzimuth Pitch Roll for the eCompass */ + fAzimuth = caliOri[0]; + fPitch = caliOri[1]; + fRoll = caliOri[2]; + PRINT("iAccuracy %d== Acc Azimuth %.02F,Pitch %.02F , Roll %.02F\r\n", + iAccuracy,//可信度 + fAzimuth, //水平方向角,左转右转 + fPitch,//上下俯仰角 + fRoll//左右翻滚角 + ); + + } + + + /* Get the SET Flag from algorithm */ + if(GetMagSaturation()) + { + //MEMSIC_Magnetic_Sensor_SET(); //Do SET action + MMC5603_SET(); + } + + /* Get corrected mag data */ + save_flag = GetCalPara(caliMagPara); + + if(save_flag == 1) + { + /* Get the offset and radius that need to be saved in system file */ + for(i=0;i<4;i++) + { + saveData[i] = caliMagPara[i]; + } + /* Save the calpara buffer into the system file */ + /* This function should be create by customer.If customer can not implement this function, should comment it out */ + SavePara(saveData); + PRINT("save para \r\n"); + } + + /* Sampling interval is 20ms. */ + // mmc5603_Delay_Ms(20); + + return 0; +} + +/* Read saved calibration parameters. These para is saved in somewhere that can not disappear when power-off + * ReadPara function should be create by customer.If customer can not implement this function, should comment it out + * If there is no parameter saved, ReadPara() should return -1, else return 1; + * If there is no para saved, pass the default value to the algorithm library + */ +int ReadPara(float *p) +{ + int i; + /* + . + . Need to be implemented by user. + . + */ + + for(i=0;i<4;i++){ + p[i] = g_MagPara[i]; + } + return 1; +} + +/* Save calibration parameters in somewhere that can not lose after power-off. + * When the system power on next time, need to read this parameters by the function ReadPara() for algorithm initial. + * If save parameter successfully, return 1, else return -1; + */ +int SavePara(float *p) +{ + /* + . + . Need to be implemented by user. + . + */ + int i=0; + for(i=0;i<4;i++){ + g_MagPara[i] = p[i]; + } + + return 1; +} + +/* Convert the sensor coordinate to right-front-up coordinate system; + */ +void acc_coordinate_raw_to_real(int layout, float *in, float *out) +{ + switch (layout) { + case 0: + out[0] = in[0]; + out[1] = in[1]; + out[2] = in[2]; + break; + case 1: + out[0] = -in[1]; + out[1] = in[0]; + out[2] = in[2]; + break; + case 2: + out[0] = -in[0]; + out[1] = -in[1]; + out[2] = in[2]; + break; + case 3: + out[0] = in[1]; + out[1] = -in[0]; + out[2] = in[2]; + break; + case 4: + out[0] = in[1]; + out[1] = in[0]; + out[2] = -in[2]; + break; + case 5: + out[0] = -in[0]; + out[1] = in[1]; + out[2] = -in[2]; + break; + case 6: + out[0] = -in[1]; + out[1] = -in[0]; + out[2] = -in[2]; + break; + case 7: + out[0] = in[0]; + out[1] = -in[1]; + out[2] = -in[2]; + break; + default: + out[0] = in[0]; + out[1] = in[1]; + out[2] = in[2]; + break; + } +} +/* Convert the sensor(MMC3630KJ) coordinate to right-front-up coordinate system; + */ +void mag_coordinate_raw_to_real(int layout, float *in, float *out) +{ + switch (layout) { + case 0: + out[0] = in[0]; + out[1] = in[1]; + out[2] = in[2]; + break; + case 1: + out[0] = -in[1]; + out[1] = in[0]; + out[2] = in[2]; + break; + case 2: + out[0] = -in[0]; + out[1] = -in[1]; + out[2] = in[2]; + break; + case 3: + out[0] = in[1]; + out[1] = -in[0]; + out[2] = in[2]; + break; + case 4: + out[0] = in[1]; + out[1] = in[0]; + out[2] = -in[2]; + break; + case 5: + out[0] = -in[0]; + out[1] = in[1]; + out[2] = -in[2]; + break; + case 6: + out[0] = -in[1]; + out[1] = -in[0]; + out[2] = -in[2]; + break; + case 7: + out[0] = in[0]; + out[1] = -in[1]; + out[2] = -in[2]; + break; + default: + out[0] = in[0]; + out[1] = in[1]; + out[2] = -in[2]; + break; + } +} +float mag_service_get_fAzimuth(void) +{ + return fAzimuth ; +} + +int mmc5603_stop(void) +{ + MMC5603_Disable(); + return 0; +} diff --git a/code/sdk/drivers/peripheral/mag/service/mag_service.c b/code/sdk/drivers/peripheral/mag/service/mag_service.c new file mode 100644 index 000000000..c67639d21 --- /dev/null +++ b/code/sdk/drivers/peripheral/mag/service/mag_service.c @@ -0,0 +1,203 @@ +/** + * 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 "adc.h" +#define TEST_PARAM_ARGC_1 1 +#define TEST_PARAM_ARGC_2 2 +#define TEST_PARAM_ARGC_3 3 +#define TEST_PARAM_ARGC_4 4 +#define TEST_PARAM_ARGC_5 5 +#define TEST_PARAM_ARGC_6 6 +#define TEST_PARAM_ARGC_7 7 +#define TEST_PARAM_4_BYTES 4 +#define TEST_PARAM_8_BYTES 8 +typedef enum { + SUITE_OK = 0, + SUITE_UNKNOWN_FUNCTION = -1, + SUITE_ERROR_TIMED_OUT = -2, + SUITE_ERROR_BAD_PARAMS = -3, + SUITE_ERROR_PIN_ALLOCATION = -4, + SUITE_ERROR_PIN_DEALLOCATION = -5, + SUITE_ERROR_UNEXPECTED_INTERRUPT = -6, + SUITE_ALLOC_FAILED = -7, + SUITE_CONFIG_FAILED = -8, + SUITE_TEST_FAILED = -254, +} magservice_error_e; + +#if defined(CONFIG_ADC_SUPPORT_AFE) + +#error CONFIG_ADC_SUPPORT_AFE + +#include "hal_adc_v152.h" +#include "hal_adc_v152_regs_op.h" +#else +#include "hal_adc_v151.h" +#include "hal_adc_v151_regs_op.h" +#endif + +#include "adc_porting.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 "chip_core_irq.h" +#include "chip_io.h" +#include "gpio.h" +#include "pm_veto.h" + +#include "rtc.h" +#include "timer.h" +#include "systick.h" + + +static bool g_batter_service_initialled = false; + +#include "tcxo.h" + +#include "cmsis_os2.h" +#include "input_app.h" +#include "mmc5603_hal.h" +#include "mag_service.h" + + +/*** + * 其他cmd在Header里定义,对外开放 +*/ +#define MAG_SERVICE_CMD_TIMER_CHECK 0x11 + +osTimerId_t g_mag_service_timer = NULL; + +static bool g_bat_timer_is_running = false; +#define MAG_CHECK_MS 200 +static unsigned long g_app_queue; + +static bool mag_service_running_stat = false; +static void mag_service_check_timer_callback(void* data); + +static void mag_service_timer_start_check(uint32_t rtc_ms) +{ + + if (g_bat_timer_is_running ) osTimerStop(g_mag_service_timer); + if (mag_service_running_stat == true) osTimerStart(g_mag_service_timer, rtc_ms); + g_bat_timer_is_running = true; + +} +void do_mag_service_check_msg(int cmd); + +static void mag_service_check_timer_callback(void * data) +{ + unused(data); + + g_bat_timer_is_running = false; + + if(mag_service_running_stat == true){ + mmc5603_check(); //此处只能直接加到timer callback中,采用queue的话,新能跟不上,系统资源会挂掉。 + mag_service_timer_start_check(MAG_CHECK_MS); + } + // do_mag_service_check_msg(MAG_SERVICE_CMD_TIMER_CHECK); + // uapi_tcxo_delay_ms(20); + + + +} +void uapi_mag_service_deinit(void) +{ + /* Stop the time and clear the pin map */ + osTimerStop(g_mag_service_timer); + osTimerDelete(g_mag_service_timer); + + g_bat_timer_is_running = false; + g_mag_service_timer = NULL; +} + + + +void do_mag_service_check_msg(int cmd) +{ + int ret; + + common_notify_mail_t mail = {0}; + mail.comm.app = cmd; + ret = osal_msg_queue_write_copy(g_app_queue, (void *)&mail, + sizeof(common_notify_mail_t), 0); + if (ret != OSAL_SUCCESS) { + PRINT("Error mag Check MSG 0x%02X send failed! err=0x%x! \r\n",cmd, ret); + } + +} + +static void mag_service_check_task(void const *arg) +{ + unused(arg); + int32_t ret; + common_notify_mail_t mail; + uint32_t msgsize = (uint32_t)sizeof(common_notify_mail_t); + + while (1) { + ret = osal_msg_queue_read_copy(g_app_queue, (void *)&mail, &msgsize, + OSAL_MSGQ_WAIT_FOREVER); + if (ret != OSAL_SUCCESS) { + continue; + } + + if (mail.comm.app == MAG_SERVICE_CMD_TIMER_CHECK) { + // mag_service_check_and_enable_charge(); + // mmc5603_check(); + PRINT("MAG_SERVICE_CMD_TIMER_CHECK\r\n"); + }else if (mail.comm.app == MAG_SERVICE_CMD_START_CHECK){ + mag_service_running_stat = true; + mmc5603_start(); + mag_service_timer_start_check(MAG_CHECK_MS); + }else if (mail.comm.app == MAG_SERVICE_CMD_STOP_CHECK){ + mag_service_running_stat = false; + osTimerStop(g_mag_service_timer); + mmc5603_stop(); + } + } +} + +errcode_t uapi_mag_service_init(void) +{ + if (osal_msg_queue_create("mag_service_queue", APP_BOARD_MSG_COUNT, &g_app_queue, + 0, sizeof(common_notify_mail_t)) != ERRCODE_SUCC) { + PRINT("[mag][service] app create mail fail\n"); + return ERRCODE_FAIL; + } + + + osal_task *task_handle = osal_kthread_create((osal_kthread_handler)mag_service_check_task, NULL, + "mag_service_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"); + return ERRCODE_FAIL; + } + + // osal_kthread_set_priority(task_handle, APP_BOARD_TASK_PRIO); + osal_kthread_set_priority(task_handle, 10); + + g_mag_service_timer = osTimerNew((osTimerFunc_t)mag_service_check_timer_callback, osTimerPeriodic, NULL, NULL); + + + return ERRCODE_SUCC; +} + +// void mag_service_service_resume(void) +// { +// PRINT("mag_service_service resume!\r\n"); +// mag_service_check_timer_callback(0); +// } +// void mag_service_service_suspend(void) +// { +// PRINT("mag_service_service suspend!\r\n"); +// } \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/mag/service/mag_service.h b/code/sdk/drivers/peripheral/mag/service/mag_service.h new file mode 100644 index 000000000..dfa628b32 --- /dev/null +++ b/code/sdk/drivers/peripheral/mag/service/mag_service.h @@ -0,0 +1,41 @@ +/** + * 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 MAG_SERVICE_H__ +#define MAG_SERVICE_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#include "stdint.h" +#include "errcode.h" + + +#define MAG_SERVICE_CMD_START_CHECK 0x12 +#define MAG_SERVICE_CMD_STOP_CHECK 0x13 + +errcode_t uapi_mag_service_init(void); +void uapi_mag_service_deinit(void); +/** + * 测试指令 参数cmd 选项: MAG_SERVICE_CMD_START_CHECK,MAG_SERVICE_CMD_STOP_CHECK +*/ +void do_mag_service_check_msg(int cmd); + +float mag_service_get_fAzimuth(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/code/sdk/include/driver/i2c.h b/code/sdk/include/driver/i2c.h index b8c8e178d..93ef6354c 100755 --- a/code/sdk/include/driver/i2c.h +++ b/code/sdk/include/driver/i2c.h @@ -86,6 +86,7 @@ typedef struct i2c_wait_condition { */ errcode_t uapi_i2c_master_init(i2c_bus_t bus, uint32_t baudrate, uint8_t hscode); +errcode_t i2c_master_init_check(i2c_bus_t bus, uint32_t baudrate, uint8_t hscode); /** * @if Eng * @brief I2C Master writes a buffer to target slave. There are three transfer modes: diff --git a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/tools/build/config/brandy.config b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/tools/build/config/brandy.config index 3115c2ae0..ba126b3e4 100755 --- a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/tools/build/config/brandy.config +++ b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/tools/build/config/brandy.config @@ -76,7 +76,7 @@ LOSCFG_TASK_JOINABLE=y LOSCFG_BASE_CORE_TSK_MONITOR=y LOSCFG_TASK_STACK_STATIC_ALLOCATION=y LOSCFG_TASK_STACK_DYNAMIC_ALLOCATION=y -LOSCFG_BASE_CORE_TSK_LIMIT=32 +LOSCFG_BASE_CORE_TSK_LIMIT=48 LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE=1024 LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE=2048 LOSCFG_BASE_CORE_TSK_SWTMR_STACK_SIZE=2048