DA14531 Timer1捕获

⚠️
大家好. .感谢来到论坛。令人兴奋的消息!我们现在正在转移到新的论坛平台的过程中,它将提供更好的功能,并包含在主对话网站。所有的帖子和账号已经迁移。我们现在只接受新论坛的流量-请发布任何新的帖子在//www.wsdof.com/support.我们会在接下来的几天修复bug /优化搜索和标记。
6个员额/ 0个新员额
最后发表
离线
最后一次露面:2个月前1年
加入:2019-11-25 00:42
DA14531 Timer1捕获

你好!

我是一个试图熟悉smarsnippets开发环境的新用户。我使用:

Dev-kit:DA14531-00FXDEVKT-P
SDK:6.0.12.1020

现在我需要测量一定时间内脉冲的数量,10毫秒内大约1200个脉冲。根据官网的示例“da14531_timer1_software_example”,我使用Timer1的捕获功能成功测量了正确的脉冲数。

“user_timer1.c”相关代码片段如下所示:

#include“user_timer1.h”#include  #include“arch_system.h”#include“user_periph_setup.h”#include“timer1.h”#include“timer0_2.h”#包括“timer0.h”extern volatile uint32_t计数;BOOL C_FLAG = 0;// timer1捕获/周期计数配置结构静态Timer1_Event_Options_t Timer1_Event_1 = {/ *时间戳类型要存储在每个事件* / .stamp_type = tim1_event_stamp_cnt,/ *要计算的句点数* / .period_count = 100,/ * timer1事件IRQ掩码* / .irq_mask = tim1_event_irq_mask_off,/ * timer1事件类型* / .event_type = tim1_event_type_cap,/ * timer1边缘类型* / .ederge_type = tim1_event_edge_risising,/ * gpio引脚被监视* / .gpio_pin = tim1_event_gpio_pin_3,};静态void timer1_event1_user_callback_function(void){c_flag = 1;count ++;setbits32(timer1_clr_event_reg,timer1_clr_in1_event,1);} / ** ****************************************************** * @brief Timer1 setup capturing finction * @param[in] void * @return void **************************************************************************************** */ void timer1_capturing_setup() { //Start Timer1 timer1_start(); // enable SWTIM_IRQn irq timer1_enable_irq(); // Timer1 configurations and register callback function for SWTIM_IRQn irq timer1_event1_config(&timer1_event_1,timer1_event1_user_callback_function); }

在GPIO_PIN_3引脚上捕获传感器脉冲,并且每个上升沿到达时计数数量增加1。每个时段测量的脉冲数为约1126。

但是我需要通过蓝牙“信标”广播脉冲的数量,所以我尝试将代码合并到网站上的“da14531-da14585-586_Simple信标Example”中。但是当我完成移植并运行程序时,我发现“Timer1”无法捕获正确的脉冲数。捕获的脉冲数量在几十到100或200之间跳跃。这两个程序之间的“user_timer1.c”是相同的。我把脉冲数据处理代码放在while(1)循环的开始部分。具体相关规范如下:

/ ** **************************************************************************************** * * @file arch_main.c * * @brief Main loop of the application. * * Copyright (c) 2012-2019 Dialog Semiconductor. All rights reserved. * * This software ("Software") is owned by Dialog Semiconductor. * * By using this Software you agree that Dialog Semiconductor retains all * intellectual property and proprietary rights in and to this Software and any * use, reproduction, disclosure or distribution of the Software without express * written permission or a license agreement from Dialog Semiconductor is * strictly prohibited. This Software is solely for use on or in conjunction * with Dialog Semiconductor products. * * EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE * SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. EXCEPT AS OTHERWISE * PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL * DIALOG SEMICONDUCTOR BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THE SOFTWARE. * **************************************************************************************** */ /* * INCLUDES **************************************************************************************** */ #include  #include  #include  // standard definitions #include  // boolean definition #include "arch.h" #include "arch_api.h" #include "boot.h" // boot definition #include "rwip.h" // BLE initialization #include "syscntl.h" // System control initialization #include "em_map_ble.h" #include "ke_mem.h" #include "ke_event.h" #include "user_periph_setup.h" #include "uart.h" // UART initialization #include "nvds.h" // NVDS initialization #include "rf.h" // RF initialization #include "app.h" // application functions #include "dbg.h" // For dbg_warning function #include "datasheet.h" #include "timer1.h" #include "user_timer1.h" #include "em_map_ble.h" #include "lld_sleep.h" #include "rwble.h" #include "rf_585.h" #include "gpio.h" #include "hw_otpc.h" #include "lld_evt.h" #include "arch_console.h" #include "arch_system.h" #include "system_library.h" #include "arch_wdg.h" #include "user_callback_config.h" #include "ea.h" #include "arch_ram.h" #if defined (__DA14531__) #include "otp_cs.h" #include "adc.h" #endif #if (USE_RANGE_EXT) #include "range_ext_api.h" #endif /** * @addtogroup DRIVERS * @{ */ /* * DEFINES **************************************************************************************** */ /* * STRUCTURE DEFINITIONS **************************************************************************************** */ /* * GLOBAL VARIABLE DEFINITIONS **************************************************************************************** */ extern struct arch_sleep_env_tag sleep_env; extern last_ble_evt arch_rwble_last_event; volatile int count=0;//²¶×½µÄÂö³åÊý volatile int data3=0; volatile int data2=0; volatile int data1=0;//×îÖÕζȶÔÓ¦µÄÂö³åÊý extern bool c_flag;//²¶»ñ±êÖ¾ bool Temp_enable=0; static uint32_t code_size __SECTION_ZERO("retention_mem_area0"); static uint8_t ret_mode_for_non_ret_heap __SECTION_ZERO("retention_mem_area0"); static uint8_t ret_mode __SECTION_ZERO("retention_mem_area0"); static uint8_t ret_mode_for_ret_data __SECTION_ZERO("retention_mem_area0"); static uint8_t reinit_non_ret_heap __SECTION_ZERO("retention_mem_area0"); /* * LOCAL FUNCTION DECLARATIONS **************************************************************************************** */ static inline void otp_prepare(uint32_t code_size); static inline bool ble_is_powered(void); static inline void ble_turn_radio_off(void); static inline void schedule_while_ble_on(void); static inline void arch_turn_peripherals_off(sleep_mode_t current_sleep_mode); static inline void arch_goto_sleep(sleep_mode_t current_sleep_mode); static inline void arch_switch_clock_goto_sleep(sleep_mode_t current_sleep_mode); static inline void arch_resume_from_sleep(void); static inline sleep_mode_t rwip_power_down(void); static inline arch_main_loop_callback_ret_t app_asynch_trm(void); static inline arch_main_loop_callback_ret_t app_asynch_proc(void); static inline void app_asynch_sleep_proc(void); static inline void app_sleep_prepare_proc(sleep_mode_t *sleep_mode); static inline void app_sleep_exit_proc(void); static inline void app_sleep_entry_proc(sleep_mode_t sleep_mode); void delay10ms(void); static inline void init_retention_mode(void); #if !defined (__DA14531__) static inline void set_ldo_ret_trim(uint8_t retained_ram_blocks); #endif #if !defined (CFG_CUSTOM_SCATTER_FILE) static inline uint8_t get_retention_mode(void); static inline uint8_t get_retention_mode_data(void); #endif static inline uint8_t get_retention_mode_non_ret_heap(void); /* * MAIN FUNCTION **************************************************************************************** */ /** **************************************************************************************** * @brief BLE main function. * This function is called right after the booting process has completed. * It contains the main function loop. **************************************************************************************** */ int main(void); int main(void) { sleep_mode_t sleep_mode; // initialize retention mode init_retention_mode(); //global initialise system_init(); periph_init(); /*Enable PD_TIM power domain*/ SetBits16(PMU_CTRL_REG, TIM_SLEEP, 0); timer1_capturing_setup(); Temp_enable=1;//Temperature measuring function enables /* ************************************************************************************ * Platform initialization ************************************************************************************ */ while(1) { if(Temp_enable==1) { timer1_start(); GPIO_SetActive(LED_PORT, LED_PIN);//Enable sensor power port if(c_flag==1) { c_flag=0; delay10ms(); //If the rising edge is not recaptured within 10ms, //the number of pulses within a period (50ms) has been captured, // and the number of pulses currently captured is output if(c_flag==0) { data3=count; count=0; data2++; if(data2==2)//Filter the first cycle after power { data1=data3; GPIO_SetInactive(LED_PORT, LED_PIN);//Disable sensor power port timer1_stop(); data2=0; } } } } else if (Temp_enable==0) { } do { // schedule all pending events schedule_while_ble_on(); } while (app_asynch_proc() != GOTO_SLEEP); //grant control to the application, try to go to power down //if the application returns GOTO_SLEEP //wait for interrupt and go to sleep if this is allowed if (((!BLE_APP_PRESENT) && (check_gtl_state())) || (BLE_APP_PRESENT)) { //Disable the interrupts GLOBAL_INT_STOP(); app_asynch_sleep_proc(); // get the allowed sleep mode // time from rwip_power_down() to __WFI() must be kept as short as possible!! sleep_mode = rwip_power_down(); if ((sleep_mode == mode_ext_sleep) || (sleep_mode == mode_ext_sleep_otp_copy)) { //power down the radio and whatever is allowed arch_goto_sleep(sleep_mode); // In extended sleep mode the watchdog timer is disabled // (power domain PD_SYS is automatically OFF). However, if the debugger // is attached the watchdog timer remains enabled and must be explicitly // disabled. if ((GetWord16(SYS_STAT_REG) & DBG_IS_UP) == DBG_IS_UP) { wdg_freeze(); // Stop watchdog timer } //wait for an interrupt to resume operation __WFI(); if ((GetWord16(SYS_STAT_REG) & DBG_IS_UP) == DBG_IS_UP) { wdg_resume(); // Resume watchdog timer } //resume operation arch_resume_from_sleep(); } else if (sleep_mode == mode_idle) { if (((!BLE_APP_PRESENT) && check_gtl_state()) || (BLE_APP_PRESENT)) { //wait for an interrupt to resume operation __WFI(); } } // restore interrupts GLOBAL_INT_START(); } wdg_reload(WATCHDOG_DEFAULT_PERIOD); } } /** **************************************************************************************** * @brief Power down the BLE Radio and whatever is allowed according to the sleep mode and * the state of the system and application * @param[in] current_sleep_mode The current sleep mode proposed by the application. * @return void **************************************************************************************** */ static inline void arch_goto_sleep(sleep_mode_t current_sleep_mode) { sleep_mode_t sleep_mode = current_sleep_mode; #if (USE_RANGE_EXT) // Disable range extender range_ext.disable(NULL); #endif // Turn the radio off ble_turn_radio_off(); // Grant access to the application to check if we can go to sleep app_sleep_prepare_proc(&sleep_mode); // SDK Improvements for uniformity this one should be changed? #if ((EXTERNAL_WAKEUP) && (!BLE_APP_PRESENT)) // External wake up, only in external processor designs ext_wakeup_enable(EXTERNAL_WAKEUP_GPIO_PORT, EXTERNAL_WAKEUP_GPIO_PIN, EXTERNAL_WAKEUP_GPIO_POLARITY); #endif // Turn the peripherals off according to the current sleep mode arch_turn_peripherals_off(sleep_mode); // Hook for app specific tasks just before sleeping app_sleep_entry_proc(sleep_mode); #if defined (__DA14531__) // Buck mode: switch on LDO_LOW (DC/DC will be automatically disabled in sleep) if (!GetBits16(ANA_STATUS_REG, BOOST_SELECTED)) { /* In buck mode make sure that LDO_LOW is on before going to sleep. Set the LDO_LOW in low current mode. */ SetBits16(POWER_CTRL_REG, LDO_LOW_CTRL_REG, 2); } // Set for proper RCX operation SetBits16(GP_DATA_REG, 0x60, 2); #endif // Do the last house keeping of the clocks and go to sleep arch_switch_clock_goto_sleep(sleep_mode); } /** **************************************************************************************** * @brief Manage the clocks and go to sleep. * @param[in] current_sleep_mode The current sleep mode proposed by the system so far * @return void **************************************************************************************** */ static inline void arch_switch_clock_goto_sleep(sleep_mode_t current_sleep_mode) { if ( (current_sleep_mode == mode_ext_sleep) || (current_sleep_mode == mode_ext_sleep_otp_copy) ) { #if !defined (__DA14531__) SetBits16(CLK_16M_REG, XTAL16_BIAS_SH_ENABLE, 0); // Set BIAS to '0' if sleep has been decided #endif #if (USE_POWER_OPTIMIZATIONS) #if defined (__DA14531__) SetBits16(CLK_RC32M_REG, RC32M_DISABLE, 0); // Enable RC32M #else SetBits16(CLK_16M_REG, RC16M_ENABLE, 1); // Enable RC16M #endif for (volatile int i = 0; i < 20; i++); SetBits16(CLK_CTRL_REG, SYS_CLK_SEL, 1); // Switch to RC16M (DA14585/586) or RC32M (DA14531) #if defined (__DA14531__) while( (GetWord16(CLK_CTRL_REG) & RUNNING_AT_RC32M) == 0 ); #else while( (GetWord16(CLK_CTRL_REG) & RUNNING_AT_RC16M) == 0 ); #endif SetWord16(CLK_FREQ_TRIM_REG, 0); // Set zero value to CLK_FREQ_TRIM_REG // Do not disable the XTAL16M (DA14585/586) or XTAL32M (DA14531). // It will be disabled when we sleep... #endif // (USE_POWER_OPTIMIZATIONS) } } /** **************************************************************************************** * @brief An interrupt came, resume from sleep. * @return void **************************************************************************************** */ static inline void arch_resume_from_sleep(void) { #if defined (__DA14531__) if (!GetBits16(ANA_STATUS_REG, BOOST_SELECTED) && GetBits16(DCDC_CTRL_REG, DCDC_ENABLE)) { /* In buck mode turn off LDO_LOW if DC/DC converter is enabled to allow the DC/DC converter to power VBAT_LOW rail. */ SetBits16(POWER_CTRL_REG, LDO_LOW_CTRL_REG, 1); } // Set for proper RCX operation SetBits16(GP_DATA_REG, 0x60, 1); #endif // Check if non retained heap should be re-initialized if (reinit_non_ret_heap) { ke_mem_init(KE_MEM_NON_RETENTION, (uint8_t*)(rom_cfg_table[rwip_heap_non_ret_pos]), rom_cfg_table[rwip_heap_non_ret_size]); } #if defined (__DA14531__) // Re-initialize peripherals and pads periph_init(); #endif // Hook for app specific tasks just after waking up app_sleep_exit_proc( ); #if ((EXTERNAL_WAKEUP) && (!BLE_APP_PRESENT)) // external wake up, only in external processor designs ext_wakeup_resume_from_sleep(); #endif // restore ARM Sleep mode // reset SCR[2]=SLEEPDEEP bit else the mode=idle __WFI() will cause a deep sleep // instead of a processor halt SCB->SCR &= ~(1<<2); } /** **************************************************************************************** * @brief Check if the BLE module is powered on. * @return void **************************************************************************************** */ static inline bool ble_is_powered() { return ((GetBits16(CLK_RADIO_REG, BLE_ENABLE) == 1) && (GetBits32(BLE_DEEPSLCNTL_REG, DEEP_SLEEP_STAT) == 0) && !(rwip_prevent_sleep_get() & RW_WAKE_UP_ONGOING)); } /** **************************************************************************************** * @brief Call the scheduler if the BLE module is powered on. * @return void **************************************************************************************** */ static inline void schedule_while_ble_on(void) { // BLE clock is enabled while (ble_is_powered()) { //execute messages and events rwip_schedule(); #if defined (__DA14531__) rcx20_read_freq(false); #endif #if !defined(__FPGA__) if (arch_rwble_last_event == BLE_EVT_END) { #if defined (__DA14531__) rcx20_read_freq(true); #else rcx20_read_freq(); #endif uint32_t sleep_duration = 0; //if you have enough time run a temperature calibration of the radio if (ea_sleep_check(&sleep_duration, 4)) //6 slots -> 3.750 ms { // check time and temperature to run radio calibrations. conditionally_run_radio_cals(); } } #endif //grant control to the application, try to go to sleep //if the application returns GOTO_SLEEP if (app_asynch_trm() != GOTO_SLEEP) { continue; // so that rwip_schedule() is called again } else { arch_printf_process(); break; } } } /** **************************************************************************************** * @brief Power down the ble ip if possible. * @return sleep_mode_t return the current sleep mode **************************************************************************************** */ static inline sleep_mode_t rwip_power_down(void) { sleep_mode_t sleep_mode; // if app has turned sleep off, rwip_sleep() will act accordingly // time from rwip_sleep() to __WFI() must be kept as short as possible! sleep_mode = rwip_sleep(); // BLE is sleeping ==> app defines the mode if (sleep_mode == mode_sleeping) { if (sleep_env.slp_state == ARCH_EXT_SLEEP_ON) { sleep_mode = mode_ext_sleep; } else { sleep_mode = mode_ext_sleep_otp_copy; } } return (sleep_mode); } /** **************************************************************************************** * @brief Turn the radio off. * @return void **************************************************************************************** */ static inline void ble_turn_radio_off(void) { SetBits16(PMU_CTRL_REG, RADIO_SLEEP, 1); // turn off radio } /** **************************************************************************************** * @brief Initialize retention mode. * @return void **************************************************************************************** */ static inline void init_retention_mode(void) { #if defined (CFG_CUSTOM_SCATTER_FILE) // User selects which RAM blocks to retain (code and retention data or only retention data) ret_mode = ret_mode_for_ret_data = ALL_RAM_BLOCKS; #else // RAM retention mode for retention data only ret_mode_for_ret_data = get_retention_mode_data(); // RAM retention mode for code and data #if defined (__DA14531__) ret_mode = get_retention_mode() & ret_mode_for_ret_data; #else ret_mode = get_retention_mode() | ret_mode_for_ret_data; #endif #endif // RAM retention mode for the non retainable heap data only ret_mode_for_non_ret_heap = get_retention_mode_non_ret_heap(); } /** **************************************************************************************** * @brief Define which RAM blocks will be retained based on the base address of the * retention data which touch the aforementioned RAM blocks. * The last RAM block is always retained. * @return the retention mode (the RAM blocks to be retained) * @note This function is strongly related to the default SDK scatter file structure. **************************************************************************************** */ #if !defined (CFG_CUSTOM_SCATTER_FILE) static inline uint8_t get_retention_mode_data(void) { uint32_t ret_mem_base_addr = RET_MEM_BASE; #if defined (__DA14531__) // Check the base address of the retention data if (ret_mem_base_addr >= RAM_3_BASE_ADDR) { // Retain RAM_3 block return (RAM_3_BLOCK); } else if (ret_mem_base_addr >= RAM_2_BASE_ADDR) { // Retain RAM_2 and RAM_3 block return (RAM_2_BLOCK & RAM_3_BLOCK); } #else // Check the base address of the retention data if (ret_mem_base_addr >= RAM_4_BASE_ADDR) { // Retain RAM_4 block return (RAM_4_BLOCK); } else if (ret_mem_base_addr >= RAM_3_BASE_ADDR) { // Retain RAM_3 and RAM_4 block return (RAM_3_BLOCK | RAM_4_BLOCK); } else if (ret_mem_base_addr >= RAM_2_BASE_ADDR) { // Retain RAM_2, RAM_3 and RAM_4 block return (RAM_2_BLOCK | RAM_3_BLOCK | RAM_4_BLOCK); } #endif // Retain all RAM blocks return ALL_RAM_BLOCKS; } /** **************************************************************************************** * @brief Define which RAM blocks will be retained based on the code and the retention * data size. * The last RAM block is always retained. * @return the retention mode (the RAM blocks to be retained) * @note This function is strongly related to the default SDK scatter file. **************************************************************************************** */ static inline uint8_t get_retention_mode(void) { // The following equation calculates the code size and is strongly related to the // default SDK scatter file structure. Count vector table and rom patches as well. code_size = (CODE_AREA_BASE - RAM_1_BASE_ADDR) + CODE_AREA_LENGTH; #if defined (__DA14531__) // Check the code size if (code_size <= (RAM_2_BASE_ADDR - RAM_1_BASE_ADDR)) { // Code fits in RAM_1 block return (RAM_1_BLOCK); } #else // Check the code size if (code_size <= (RAM_2_BASE_ADDR - RAM_1_BASE_ADDR)) { // Code fits in RAM_1 block return (RAM_1_BLOCK); } else if (code_size <= (RAM_3_BASE_ADDR - RAM_1_BASE_ADDR)) { // Code fits in RAM_1 block and RAM_2 block return (RAM_1_BLOCK | RAM_2_BLOCK); } #endif // Retain all RAM blocks return ALL_RAM_BLOCKS; } #endif // CFG_CUSTOM_SCATTER_FILE /** **************************************************************************************** * @brief Calculate the RAM blocks which will be retained depending on the non retained * heap base address and size. * @return the retention mode (the RAM blocks to be retained) **************************************************************************************** */ static inline uint8_t get_retention_mode_non_ret_heap() { uint32_t non_ret_heap_base = NON_RET_HEAP_BASE; uint32_t non_ret_heap_length = NON_RET_HEAP_LENGTH; #if defined (__DA14531__) if (non_ret_heap_base >= RAM_3_BASE_ADDR) { return (RAM_3_BLOCK); } else if (non_ret_heap_base >= RAM_2_BASE_ADDR) { if (non_ret_heap_base + non_ret_heap_length < RAM_3_BASE_ADDR) { return (RAM_2_BLOCK); } else { return (RAM_2_BLOCK & RAM_3_BLOCK); } } else { if (non_ret_heap_base + non_ret_heap_length < RAM_2_BASE_ADDR) { return (RAM_1_BLOCK); } else if (non_ret_heap_base + non_ret_heap_length < RAM_3_BASE_ADDR) { return (RAM_1_BLOCK & RAM_2_BLOCK); } else { return ALL_RAM_BLOCKS; } } #else if (non_ret_heap_base >= RAM_4_BASE_ADDR) { return (RAM_4_BLOCK); } else if (non_ret_heap_base >= RAM_3_BASE_ADDR) { if (non_ret_heap_base + non_ret_heap_length < RAM_4_BASE_ADDR) { return (RAM_3_BLOCK); } else { return (RAM_3_BLOCK | RAM_4_BLOCK); } } else if (non_ret_heap_base >= RAM_2_BASE_ADDR) { if (non_ret_heap_base + non_ret_heap_length < RAM_3_BASE_ADDR) { return (RAM_2_BLOCK); } else if (non_ret_heap_base + non_ret_heap_length < RAM_4_BASE_ADDR) { return (RAM_2_BLOCK | RAM_3_BLOCK); } else { return (RAM_2_BLOCK | RAM_3_BLOCK | RAM_4_BLOCK); } } else { if (non_ret_heap_base + non_ret_heap_length < RAM_2_BASE_ADDR) { return (RAM_1_BLOCK); } else if (non_ret_heap_base + non_ret_heap_length < RAM_3_BASE_ADDR) { return (RAM_1_BLOCK | RAM_2_BLOCK); } else if (non_ret_heap_base + non_ret_heap_length < RAM_4_BASE_ADDR) { return (RAM_1_BLOCK | RAM_2_BLOCK | RAM_3_BLOCK); } else { return ALL_RAM_BLOCKS; } } #endif } #if !defined (__DA14531__) /** **************************************************************************************** * @brief Set required LDO_RET_TRIM value in BANDGAP_REG. This value depends on the * size of retained RAM and the temperature range device operation. * @param[in] retained_ram_blocks RAM blocks to be retained. * @return void * @note By default the [BANDGAP_REG.LDO_RET_TRIM] is loaded with the respective OTP * header value (done by ROM booter). **************************************************************************************** */ static inline void set_ldo_ret_trim(uint8_t retained_ram_blocks) { #if (USE_MID_TEMPERATURE) SetBits16(BANDGAP_REG, LDO_RET_TRIM, DEFAULT_LDO_SET); #elif (USE_HIGH_TEMPERATURE || USE_EXT_TEMPERATURE) if ((retained_ram_blocks == RAM_SIZE_80KB_OPT1) || (retained_ram_blocks == RAM_SIZE_80KB_OPT2) || (retained_ram_blocks == RAM_SIZE_96KB_OPT1)) { SetBits16(BANDGAP_REG, LDO_RET_TRIM, DEFAULT_LDO_SET_96K); // LDO trim value up to 96KB retained RAM } else { SetBits16(BANDGAP_REG, LDO_RET_TRIM, DEFAULT_LDO_SET_64K); // LDO trim value up to 64KB retained RAM } #endif } #endif /** **************************************************************************************** * @brief Turn the peripherals off according to the current sleep mode. * @param[in] current_sleep_mode The current sleep mode proposed by the system so far * @return void **************************************************************************************** */ static inline void arch_turn_peripherals_off(sleep_mode_t current_sleep_mode) { if (current_sleep_mode == mode_ext_sleep || current_sleep_mode == mode_ext_sleep_otp_copy) { uint8_t retained_ram_blocks = 0; SCB->SCR |= 1<<2; // enable deep sleep mode bit in System Control Register (SCR[2]=SLEEPDEEP) #if defined (__DA14531__) SetBits16(PAD_LATCH_REG, PAD_LATCH_EN, 0); #else SetBits16(SYS_CTRL_REG, PAD_LATCH_EN, 0); // activate PAD latches SetBits16(PMU_CTRL_REG, PERIPH_SLEEP, 1); // turn off peripheral power domain #endif if (current_sleep_mode == mode_ext_sleep) { /* * Sleep mode: EXTENDED - image kept at external resource * * The RAM blocks that hold the code and the retention data * must be retained. */ // OTP copy and OTP copy emulation will be disabled SetBits16(SYS_CTRL_REG, OTP_COPY, 0); retained_ram_blocks = ret_mode; } else { /* * Sleep mode: EXTENDED - image kept at OTP (OTP mirroring takes place on wake-up) * * The RAM blocks that hold the retention data must be retained. */ #if (DEVELOPMENT_DEBUG) // enable OTP copy emulation SetBits16(SYS_CTRL_REG, OTP_COPY, 1); SetBits16(SYS_CTRL_REG, DEV_PHASE, 1); retained_ram_blocks = ret_mode; #else // enable OTP copy SetBits16(SYS_CTRL_REG, DEV_PHASE, 0); retained_ram_blocks = ret_mode_for_ret_data; #endif otp_prepare((code_size + 3) >> 2); // convert function argument from bytes to 32-bit words } // manage the non-retained heap // Note: non-retained heap is either empty or not. If it is non empty it must be retained. if (!ke_mem_is_empty(KE_MEM_NON_RETENTION)) { reinit_non_ret_heap = 0; #if defined (__DA14531__) retained_ram_blocks &= ret_mode_for_non_ret_heap; #else retained_ram_blocks |= ret_mode_for_non_ret_heap; #endif } else { reinit_non_ret_heap = 1; } // dynamically select the retained RAM blocks arch_ram_set_retention_mode(retained_ram_blocks); #if !defined (__DA14531__) set_ldo_ret_trim(retained_ram_blocks); #endif } } /** **************************************************************************************** * @brief Prepare OTP Controller in order to be able to reload SysRAM at the next power-up. **************************************************************************************** */ static inline void otp_prepare(uint32_t code_size) { // Initialize OTP controller hw_otpc_init(); SetBits16(SYS_CTRL_REG, OTP_COPY, 1); // Copy the size of software from the first word of the retention mem. SetWord32 (OTPC_NWORDS_REG, code_size - 1); // Close OTP controller hw_otpc_close(); #if defined (__DA14531__) && (!USE_POWER_MODE_BYPASS) // In Boost mode enable the DCDC converter to supply VBAT_HIGH for OTP when the system will // wake up. if (GetBits16(ANA_STATUS_REG, BOOST_SELECTED)) { // Clear reservation status of DCDC converter hw_otpc_clear_dcdc_reserved(); // Set DCDC converter voltage level for OTP read (required for OTP copy to RAM at wake up) syscntl_dcdc_set_level(SYSCNTL_DCDC_LEVEL_1V8); // Enable the DCDC converter (required for OTP copy to RAM at wake up) SetBits16(DCDC_CTRL_REG, DCDC_ENABLE, 1); } #endif } /** **************************************************************************************** * @brief Used for sending messages to kernel tasks generated from * asynchronous events that have been processed in app_asynch_proc. * @return KEEP_POWERED to force calling of schedule_while_ble_on(), else GOTO_SLEEP **************************************************************************************** */ static inline arch_main_loop_callback_ret_t app_asynch_trm(void) { if (user_app_main_loop_callbacks.app_on_ble_powered != NULL) { return user_app_main_loop_callbacks.app_on_ble_powered(); } else { return GOTO_SLEEP; } } /** **************************************************************************************** * @brief Used for processing of asynchronous events at ?user? level. The * corresponding ISRs should be kept as short as possible and the * remaining processing should be done at this point. * @return KEEP_POWERED to force calling of schedule_while_ble_on(), else GOTO_SLEEP **************************************************************************************** */ static inline arch_main_loop_callback_ret_t app_asynch_proc(void) { if (user_app_main_loop_callbacks.app_on_system_powered != NULL) { return user_app_main_loop_callbacks.app_on_system_powered(); } else { return GOTO_SLEEP; } } /** **************************************************************************************** * @brief Used for updating the state of the application just before sleep checking starts. * @return void **************************************************************************************** */ static inline void app_asynch_sleep_proc(void) { if (user_app_main_loop_callbacks.app_before_sleep != NULL) user_app_main_loop_callbacks.app_before_sleep(); } /** **************************************************************************************** * @brief Used to override the slected extended sleep mode , based on the current * application state. * BLE and Radio are still powered off. * @param[in] sleep_mode Sleep Mode * @return void **************************************************************************************** */ static inline void app_sleep_prepare_proc(sleep_mode_t *sleep_mode) { if (user_app_main_loop_callbacks.app_validate_sleep != NULL) (*sleep_mode) = user_app_main_loop_callbacks.app_validate_sleep(*sleep_mode); } /** **************************************************************************************** * @brief Used for application specific tasks just before entering the low power mode. * @param[in] sleep_mode Sleep Mode * @return void **************************************************************************************** */ static inline void app_sleep_entry_proc(sleep_mode_t sleep_mode) { if (user_app_main_loop_callbacks.app_going_to_sleep != NULL) user_app_main_loop_callbacks.app_going_to_sleep(sleep_mode); } /** **************************************************************************************** * @brief Used for application specific tasks immediately after exiting the low power mode. * @param[in] sleep_mode Sleep Mode * @return void **************************************************************************************** */ static inline void app_sleep_exit_proc(void) { if (user_app_main_loop_callbacks.app_resume_from_sleep != NULL) user_app_main_loop_callbacks.app_resume_from_sleep(); } #if defined (__GNUC__) // Defining these functions forces the linker to ignore unwind functions void __aeabi_unwind_cpp_pr0(void) {}; void __aeabi_unwind_cpp_pr1(void) {}; void __aeabi_unwind_cpp_pr2(void) {}; #endif /// @} DRIVERS void delay10ms(void) //Îó²î -0.25us { unsigned char a,b; for(b=91;b>0;b--) for(a=145;a>0;a--); }

对于“DA14531-DA14585-586_SIMPLE_BEACON_EXAMPLE”,我没有更改代码的其余部分。我只是在“da1458x_config_basic.h”文件中注明了“#define cfg_wdog”。删除“ARCH_MAIN.c”文件并添加一个具有相同内容的新“main.c”文件。

我很困惑,相同的代码片段将在“da14531_timer1_software_example”中工作正常,但不在“da14531-da14585-586_simple_beacon_example”中。当我第一次刻录“da14531_timer1_software_example”时,然后刻录“da14531_timer1_software_example”,脉冲数将也变得不正确,只有30多个。程序中捕获的脉冲数将恢复正常并在充电后变为1000多个。

我附上了两个计划的结果。

非常感谢你的帮助。

设备:
PM_DIALOG.
离线
最后一次露面:2天21小时前
工作人员
加入:2018-02-08 11:03
嗨,朱,

嗨,朱,

感谢你的在线问题,很高兴你从DA14531 SoC开始。因为你是一个新用户,你没有以前的经验,让我分享我的建议/建议。

  1. 您应该阅读的前两个文档是UM-B-117: DA14531 Getting Started with the Pro Development Kit (HTML)UM-B-119: DA14585-DA14531 SW平台参考.UM-B-117将帮助您设置硬件开发环境,安装所需的软件,下载和运行DA14531 Pro开发工具平台的示例应用程序。UM-B-119将帮助您了解SDK架构。如果您尚未阅读该文档,则这是如此。
  2. arch_main.c文件是SDK文件,强烈建议不要修改SDK文件。以SDK_*开头的文件/文件夹是SDK文件,其中包含一对驱动程序和文件。更多信息请参阅UM-B-119。所有用户配置和源代码都应该放在以user_*开头的文件中,例如user_peripher_setup .h。
  3. 因为您希望在Simple Beacon代码中添加捕获功能,所以应该使用timer1_capturing_setup()和user_simple_beacon.c中适当的函数。
  4. 另外,我建议不要删除任何宏定义,比如CFG_WDOG

谢谢,PM_DIALOG.

离线
最后一次露面:2个月前1年
加入:2019-11-25 00:42
你好!

你好!

非常感谢您的快速回复!

我现在的问题是,我添加到简单的信标代码的捕获功能不能正确地捕获脉冲的数量。但是我可以通过在其他代码中单独运行capture来捕获正确的脉冲数量。我现在想知道Timer1的捕获特性是否与官方的简单信标代码冲突。

非常感谢你的帮助。

PM_DIALOG.
离线
最后一次露面:2天21小时前
工作人员
加入:2018-02-08 11:03
嗨,朱,

嗨,朱,

我们从未测试过,但我相信它们没有任何限制或冲突。您应该将Timer 1应用程序代码添加到Simple Beacon应用程序代码中。因此,您应该从arch_main.c文件中删除。请尽量使用与示例相同的函数。唯一的限制可能是如果您正在使用任何一种睡眠模式,那么您应该将Timer 1时钟更改为低功率时钟(LPC)。

谢谢,PM_DIALOG.

离线
最后一次露面:2个月前1年
加入:2019-11-25 00:42
你好!

你好!

非常感谢您的快速回复!

现在我的程序运行正常,在我评论出在“Arch_Main.c”中的一些陈述之后.I不明白这些陈述所做的事情,而且我不知道评论它们是否会对该程序有任何其他影响。我评论的程序代码如下:

否则if(sleep_mode == mode_idle){/// if((!ble_app_present)&& check_gtl_state())||(ble_app_present)))/// {//等待中断以恢复操作/// __wfi();///}}

非常感谢你的帮助。

PM_DIALOG.
离线
最后一次露面:2天21小时前
工作人员
加入:2018-02-08 11:03
嗨,朱,

嗨,朱,

我强烈建议你不要修改arch_main.c和SDK文件。请从所附代码段中删除注释,并尝试将其合并到应用程序级别。我已经给你们提供了指导方针。这种工作方式是不正确的。这将防止系统进入睡眠,芯片将永远不会进入WFI(等待中断)。请参考我之前的评论。

谢谢,PM_DIALOG.