From 25e75da8fdf33da1e2776ff992181e648aca06bb Mon Sep 17 00:00:00 2001 From: pvvx Date: Mon, 29 May 2017 01:43:16 +0300 Subject: [PATCH] update --- project/inc/FreeRTOSConfig.h | 2 +- project/inc/ina219/ina219drv.h | 55 ++++++++++++++++++++++++++++++ project/inc/wifi_user_set.h | 2 +- project/src/console/atcmd_user.c | 7 ++-- project/src/console/wifi_console.c | 3 +- project/src/ina219/ina219drv.c | 6 ++-- project/src/user/user_start.c | 2 +- project/src/web/web_int_vars.c | 4 +-- userset.mk | 1 + 9 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 project/inc/ina219/ina219drv.h diff --git a/project/inc/FreeRTOSConfig.h b/project/inc/FreeRTOSConfig.h index d4a9b1c..a5f1eaa 100644 --- a/project/inc/FreeRTOSConfig.h +++ b/project/inc/FreeRTOSConfig.h @@ -85,7 +85,7 @@ extern uint32_t SystemCoreClock; * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ -#define configUSE_STACK_TCM_HEAP 1 // RTL871xAx/RTL8195Ax Stack priority used TCM HEAP +#define configUSE_STACK_TCM_HEAP 5 // RTL871xAx/RTL8195Ax Stack priority used TCM HEAP #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 1 #define configUSE_TICK_HOOK 0 diff --git a/project/inc/ina219/ina219drv.h b/project/inc/ina219/ina219drv.h new file mode 100644 index 0000000..017b1cc --- /dev/null +++ b/project/inc/ina219/ina219drv.h @@ -0,0 +1,55 @@ +/************************************************************************** + * Драйвер для INA219 + **************************************************************************/ +#ifndef _INA219DRV_H_ +#define _INA219DRV_H_ +#include "ina219/ina219.h" +#include "device.h" +#include "timer_api.h" +#include "driver/i2c_drv.h" + +typedef struct _ina219_data { + union { + signed short voltage; // Voltage, 1mV + unsigned char vuc[2]; + } v; + union { + signed short current; // Current, 50uA? + unsigned char iuc[2]; + } i; +} INA219DATA, *PINA219DATA; + +typedef struct _ina219drv { + unsigned char status; + unsigned char addr; // адрес INA219 на шине I2C (формат 7 bit) + signed char init; + unsigned char tmp; + + unsigned short config; // регистр конфигурации INA219 + unsigned short calibration; // коэф. шунта для INA219 + + unsigned short count; // счетчик считанных значений + unsigned short overrun; // счет переполнений буфера + + unsigned short errs; // счет ошибок на I2C + unsigned short buf_idx; // объем буфера pbuf[buf_idx+1], максимальный индекс-номер замера + unsigned short buf_rx; // индекс-номер ещё не считанного замера + unsigned short buf_tx; // индекс-номер для записи следующего замера + PINA219DATA pbuf; + gtimer_t timer; + union { // буфер + unsigned char uc[4]; + unsigned short us[2]; + signed short ss[2]; + unsigned int ui; + } buf_i2c; + volatile i2c_drv_t i2c; +} INA219DRV, *PINA219DRV; + + +#define INA219_I2C_PIN_SDA PC_4 +#define INA219_I2C_PIN_SCL PC_5 +#define INA219_I2C_BUS_CLK 300000 //hz +#define INA219_TIMER TIMER3 // используемый таймер + +#endif // _INA219DRV_H_ diff --git a/project/inc/wifi_user_set.h b/project/inc/wifi_user_set.h index f0ad1cf..b7f0d0a 100644 --- a/project/inc/wifi_user_set.h +++ b/project/inc/wifi_user_set.h @@ -15,7 +15,7 @@ #define DEF_WIFI_COUNTRY RTW_COUNTRY_RU // Регион использования WiFi... #define DEF_WIFI_TX_PWR RTW_TX_PWR_PERCENTAGE_25 // RTW_TX_PWR_PERCENTAGE_75 // RTW_TX_PWR_PERCENTAGE_100 #define DEF_WIFI_BGN RTW_NETWORK_BGN // rtw_network_mode_t -#define DEF_WIFI_ADAPTIVITY RTW_ADAPTIVITY_NORMAL // RTW_ADAPTIVITY_DISABLE/RTW_ADAPTIVITY_NORMAL/RTW_ADAPTIVITY_CARRIER_SENSE +#define DEF_WIFI_ADAPTIVITY RTW_ADAPTIVITY_DISABLE // RTW_ADAPTIVITY_NORMAL // RTW_ADAPTIVITY_DISABLE/RTW_ADAPTIVITY_NORMAL/RTW_ADAPTIVITY_CARRIER_SENSE /* Опции загрузки конфигов по старту */ //#define DEF_LOAD_CFG 0 // старт в назначенном режиме по умолчанию diff --git a/project/src/console/atcmd_user.c b/project/src/console/atcmd_user.c index 15b3ff2..25ed09a 100644 --- a/project/src/console/atcmd_user.c +++ b/project/src/console/atcmd_user.c @@ -5,6 +5,7 @@ #include "FreeRTOS.h" #include "task.h" #include "semphr.h" +#include "freertos_pmu.h" #include "at_cmd/log_service.h" #include "at_cmd/atcmd_wifi.h" #include @@ -332,17 +333,17 @@ LOCAL void fATSP(int argc, char *argv[]) switch (argv[1][0]) { case 'a': // acquire { - acquire_wakelock(atoi(argv[2])); + pmu_acquire_wakelock(atoi(argv[2])); break; } case 'r': // release { - release_wakelock(atoi(argv[2])); + pmu_release_wakelock(atoi(argv[2])); break; } }; }; - printf("WakeLock Status %d\n", get_wakelock_status()); + printf("WakeLock Status %d\n", pmu_get_wakelock_status()); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ diff --git a/project/src/console/wifi_console.c b/project/src/console/wifi_console.c index b8af14d..71dd3ec 100644 --- a/project/src/console/wifi_console.c +++ b/project/src/console/wifi_console.c @@ -12,6 +12,7 @@ #include "wifi_conf.h" #include "rtl8195a/rtl_libc.h" #include "hal_platform.h" +#include "freertos_pmu.h" #include "section_config.h" #include "hal_diag.h" @@ -226,7 +227,7 @@ LOCAL void fATSF(int argc, char *argv[]) LOCAL void fATWP(int argc, char *argv[]) { if(argc > 1) { - release_wakelock(0xffff); + pmu_release_wakelock(0xffff); wifi_set_power_mode(1, 1); wifi_set_lps_dtim(atoi(argv[1])); } diff --git a/project/src/ina219/ina219drv.c b/project/src/ina219/ina219drv.c index 5daff4a..0a86eb7 100644 --- a/project/src/ina219/ina219drv.c +++ b/project/src/ina219/ina219drv.c @@ -33,7 +33,7 @@ INA219DRV ina219drv = { INA219_CONFIG_BVOLTAGERANGE_16V | // INA219_CONFIG_BVOLTAGERANGE_32V INA219_CONFIG_GAIN_8_320MV | // INA219_CONFIG_GAIN_1_40MV | INA219_CONFIG_BADCRES_12BIT | - INA219_CONFIG_SADCRES_12BIT_2S_1060US | // INA219_CONFIG_SADCRES_12BIT_128S_69MS | + INA219_CONFIG_SADCRES_12BIT_1S_532US | //INA219_CONFIG_SADCRES_12BIT_2S_1060US | // INA219_CONFIG_SADCRES_12BIT_1S_532US | // INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS, .calibration = 8192, // при шунте 0.1 Ом .buf_idx = 709, // циклический буфер на 710 замеров (по 4 байт -> sizeof(INA219DATA)) @@ -227,7 +227,7 @@ int ina219_ws(TCP_SERV_CONN *ts_conn, char cmd) }; _i2c_init(&p->i2c); gtimer_init(&p->timer, INA219_TIMER); - gtimer_start_periodical(&p->timer, 1000, (void*)ina_tick_handler, (uint32_t)&ina219drv); + gtimer_start_periodical(&p->timer, 532*2, (void*)ina_tick_handler, (uint32_t)&ina219drv); p->init = 1; // return 0; } @@ -276,7 +276,7 @@ void ina219_init(void) // Tick every 0.000532 sec (N*532 μs) // uint32 tus = (1 << ((p->config >> 3) & 7)); // tus *= 532; - gtimer_start_periodical(&p->timer, 1000, (void*)ina_tick_handler, (uint32_t)&ina219drv); + gtimer_start_periodical(&p->timer, 532*2, (void*)ina_tick_handler, (uint32_t)&ina219drv); rtl_printf("INA219 Timer Period = %u us\n", p->timer.hal_gtimer_adp.TimerLoadValueUs); p->init = 1; } diff --git a/project/src/user/user_start.c b/project/src/user/user_start.c index 8b1450d..314c317 100644 --- a/project/src/user/user_start.c +++ b/project/src/user/user_start.c @@ -89,7 +89,7 @@ void user_init_thrd(void) { webserver_init(syscfg.web_port); if(syscfg.cfg.b.powersave_enable) { - release_wakelock(~WAKELOCK_WLAN); + pmu_release_wakelock(~WAKELOCK_WLAN); } // xTaskCreate(x_init_thrd, "wifi_init", 1024, NULL, tskIDLE_PRIORITY + 1 + PRIORITIE_OFFSET, NULL); diff --git a/project/src/web/web_int_vars.c b/project/src/web/web_int_vars.c index 9d51342..4c38cf7 100644 --- a/project/src/web/web_int_vars.c +++ b/project/src/web/web_int_vars.c @@ -148,8 +148,8 @@ void ICACHE_FLASH_ATTR web_int_vars(TCP_SERV_CONN *ts_conn, uint8 *pcmd, uint8 * else ifcmp("pinclr") syscfg.cfg.b.pin_clear_cfg_enable = (val)? 1 : 0; else ifcmp("sleep") { syscfg.cfg.b.powersave_enable = (val)? 1 : 0; - if(val) release_wakelock(~WAKELOCK_WLAN); - else acquire_wakelock(~WAKELOCK_WLAN); + if(val) pmu_release_wakelock(~WAKELOCK_WLAN); + else pmu_acquire_wakelock(~WAKELOCK_WLAN); } else ifcmp("debug") { syscfg.cfg.b.debug_print_enable = val; diff --git a/userset.mk b/userset.mk index fe4d3d2..081445c 100644 --- a/userset.mk +++ b/userset.mk @@ -2,6 +2,7 @@ # User defined #============================================= SDK_PATH ?= ../RTL00MP3/RTL00_SDKV35a/ +#SDK_PATH ?= ../SDKRTLA/USD40a/ #GCC_PATH = d:/MCU/GNU_Tools_ARM_Embedded/5.2_2015q4/bin/# + or set in PATH #OPENOCD_PATH = d:/MCU/OpenOCD/bin/# + or set in PATH TOOLS_PATH ?= $(SDK_PATH)component/soc/realtek/8195a/misc/iar_utility/common/tools/