zhyinch
2018-09-15 4979f7565cbd5f093e280f9f277ae29bb450acb8
增加低功耗标签

增加低功耗标签
已添加3个文件
已修改7个文件
146 ■■■■■ 文件已修改
.gitignore 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
源码/核心板/Src/OnChipDevices/RTC.c 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
源码/核心板/Src/OnChipDevices/RTC.h 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
源码/核心板/Src/OnChipDevices/Rcc_Nvic_Systick.c 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
源码/核心板/Src/OnChipDevices/Rcc_Nvic_Systick.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
源码/核心板/Src/OnChipDevices/Spi.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
源码/核心板/Src/application/dw_app.c 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
源码/核心板/Src/application/serial_at_cmd_app.c 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
源码/核心板/Src/main.c 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
源码/核心板/Src/stm32f10x_it.c 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,15 @@
*.txt
*.crf
*.d
*.o
*.ini
*.dbgconf
*.lst
*.map
*.iex
*.dep
*.axf
*.htm
*.lnp
*.sct
Ô´Âë/ºËÐİå/Src/OnChipDevices/RTC.c
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,54 @@
#include "RTC.h"
void RTC_SET_ALARM(u32 sec)
{
//DEBUG_COM_STREAM("-??-",NULL);
RTC_SetAlarm(RTC_GetCounter()+sec);
//DEBUG_COM_STREAM("-??1-",NULL);
RTC_WaitForLastTask();
//DEBUG_COM_STREAM("-??2-",NULL);
RTC_ITConfig(RTC_FLAG_ALR,ENABLE);
}
void RTC_Configuration(void)
{
    /* Enable PWR and BKP clocks */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
    /* Allow access to BKP Domain */
    PWR_BackupAccessCmd(ENABLE);
    /* Reset Backup Domain */
    //BKP_DeInit();
    RCC_LSICmd(ENABLE);
    /* Enable LSE */
    //RCC_LSEConfig(RCC_LSE_ON);
    /* Wait till LSE is ready */
    while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET){}
    /* Select LSE as RTC Clock Source */
    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
    /* Enable RTC Clock */
    RCC_RTCCLKCmd(ENABLE);
    /* Wait for RTC registers synchronization */
    RTC_WaitForSynchro();
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
    /* Enable the RTC Second */
    //RTC_ITConfig(RTC_IT_SEC, ENABLE);
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
    RTC_ITConfig(RTC_IT_ALR,ENABLE); //?? RTC ???
        RTC_WaitForLastTask();
    /* Set RTC prescaler: set RTC period to 1sec */
    RTC_SetPrescaler(40000); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
    RTC_SET_ALARM(1);
}
Ô´Âë/ºËÐİå/Src/OnChipDevices/RTC.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,4 @@
#include "stm32f10x.h"
void RTC_Configuration(void);
Ô´Âë/ºËÐİå/Src/OnChipDevices/Rcc_Nvic_Systick.c
@@ -44,7 +44,7 @@
void Nvic_Init(void)
{
    NVIC_InitTypeDef NVIC_InitStructure;
        EXTI_InitTypeDef EXTI_InitStructure;
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
    
    /* Enable and set EXTI Interrupt to the lowest priority */
@@ -53,6 +53,17 @@
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        EXTI_InitStructure.EXTI_Line = EXTI_Line17;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);
        NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE;
    NVIC_Init(&NVIC_InitStructure);
}
@@ -89,4 +100,4 @@
{  
    uint32_t i=1000*nTimer;  
    delay_us(i);  
}
}
Ô´Âë/ºËÐİå/Src/OnChipDevices/Rcc_Nvic_Systick.h
@@ -11,5 +11,5 @@
int Systick_Init(void);
void delay_us(uint32_t nTimer);
void delay_ms(uint32_t nTimer);
void RTC_Configuration(void);
#endif
Ô´Âë/ºËÐİå/Src/OnChipDevices/Spi.h
@@ -5,7 +5,7 @@
#include "stm32f10x.h"
#define SPIx_PRESCALER_SLOW            SPI_BaudRatePrescaler_32
#define SPIx_PRESCALER_FAST            SPI_BaudRatePrescaler_8
#define SPIx_PRESCALER_FAST            SPI_BaudRatePrescaler_16
#define SPIx                        SPI1
#define SPIx_GPIO                    GPIOA
Ô´Âë/ºËÐİå/Src/application/dw_app.c
@@ -47,13 +47,13 @@
#define POLL_TX_TO_RESP_RX_DLY_UUS 150
/* This is the delay from Frame RX timestamp to TX reply timestamp used for calculating/setting the DW1000's delayed TX function. This includes the
 * frame length of approximately 2.66 ms with above configuration. */
#define RESP_RX_TO_FINAL_TX_DLY_UUS 4100
#define RESP_RX_TO_FINAL_TX_DLY_UUS 5100
/* Receive response timeout. See NOTE 5 below. */
#define RESP_RX_TIMEOUT_UUS 14700
#define POLL_RX_TO_RESP_TX_DLY_UUS 3600
/* This is the delay from the end of the frame transmission to the enable of the receiver, as programmed for the DW1000's wait for response feature. */
#define RESP_TX_TO_FINAL_RX_DLY_UUS 500
#define RESP_TX_TO_FINAL_RX_DLY_UUS 1500
/* Receive final timeout. See NOTE 5 below. */
#define FINAL_RX_TIMEOUT_UUS 4300
@@ -223,7 +223,9 @@
    /* Configure DW1000. See NOTE 6 below. */
    dwt_configure(&config);//配置DW1000
    /* Apply default antenna delay value. See NOTE 1 below. */
    dwt_setrxantennadelay(RX_ANT_DLY);        //设置接收天线延迟
    dwt_settxantennadelay(TX_ANT_DLY);        //设置发射天线延迟
@@ -233,11 +235,24 @@
    dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS);            //设置发送后开启接收,并设定延迟时间
    dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);                        //设置接收超时时间
}
void Delayus(uint16_t time)
{
  uint16_t i = 0;
  while (time--) {
    i = 10;
    while (i--)
      ;
  }
}
void Tag_App(void)//发送模式(TAG标签)
{
    uint32_t frame_len;
    uint32_t final_tx_time;
    GPIO_ResetBits(SPIx_GPIO, SPIx_CS);
    Delayus(2000);
    GPIO_SetBits(SPIx_GPIO, SPIx_CS);
    
    /* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */
    tx_poll_msg[ALL_MSG_SN_IDX] = frame_seq_nb;
@@ -319,7 +334,8 @@
    }
    LED0_BLINK;
    /* Execute a delay between ranging exchanges. */
    deca_sleep(RNG_DELAY_MS + random_delay_tim); //休眠固定时间
    dwt_entersleep();
}
void Anchor_App(void)
Ô´Âë/ºËÐİå/Src/application/serial_at_cmd_app.c
@@ -4,7 +4,7 @@
uint8_t g_frame_data[MAX_FRAME_LEN] = {0};
uint8_t g_frame_data_len = 0;
uint32_t g_alarm_dist = 200;
uint32_t g_alarm_dist = 50;
uint8_t g_alarm_dev = 0;
void ParseFrame(void)
Ô´Âë/ºËÐİå/Src/main.c
@@ -9,6 +9,7 @@
#include "filters.h"
#include "stm32f10x_it.h"
#include "serial_at_cmd_app.h"
#include "deca_device_api.h"
//#define WORK_MODE_TAG
#define WORK_MODE_ANCHOR
@@ -23,6 +24,9 @@
    SystemInit();
    Nvic_Init();
    Systick_Init();
#ifdef WORK_MODE_TAG
    RTC_Configuration();
#endif
    Led_Init();
    Beep_Init();
    DW_GPIO_Init();
@@ -47,6 +51,7 @@
 *
 * @return none
 */
extern uint8_t send_start;
int main(void)
{
    LPFilter_Frac* p_Dis_Filter;
@@ -56,11 +61,23 @@
    Dw1000_Init();
    p_Dis_Filter = New_LP_Frac(0.7);
    #ifdef WORK_MODE_TAG
   dwt_configuresleep(0x940, 0x7);
     _dwt_aonarrayupload();
    //dwt_entersleep();
    #endif
    /* Loop forever initiating ranging exchanges. */
    while(1)
    {
#ifdef WORK_MODE_TAG
    if(send_start)
    {send_start=0;
        Tag_App();
    }
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);
#else 
        Anchor_App();
Ô´Âë/ºËÐİå/Src/stm32f10x_it.c
@@ -62,5 +62,18 @@
  }   
}
uint8_t tt=0;
uint8_t send_start=0;
void RTCAlarm_IRQHandler(void)
{
   EXTI_ClearITPendingBit(EXTI_Line17);
    RTC_ClearITPendingBit(RTC_FLAG_ALR);
    send_start=1;
    RTC_SET_ALARM(1);
    tt++;
    //GPIO_Toggle(GPIOA,LED_PIN);
  //SYS.wake_id|=1<<17;
}
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/