zhyinch
2018-10-18 2d82c2dfc1a64b05cf92a1bf1bd6fc840cb84e79
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
 
#include "Rcc_Nvic_Systick.h"
#include "Usart.h"
#include "Spi.h"
#include "led.h"
#include "beep.h"
#include "dw_driver.h"
#include "dw_app.h"
#include "stm32f10x_it.h"
#include "serial_at_cmd_app.h"
#include "global_param.h"
 
#define WORK_MODE_TAG
//#define WORK_MODE_ANCHOR
 
void Device_Init(void)
{
    RCC_Configuration();
    //SystemInit();
    Nvic_Init();
    Systick_Init();
    Led_Init();
    Beep_Init();
    DW_GPIO_Init();
    Uart1_Init();
    Spi_Init();
    
    
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
}
 
void Program_Init(void)
{uint16_t i;
    Usart1ParseDataCallback = UsartParseDataHandler;
    parameter_init();
    #ifdef WORK_MODE_TAG    
    printf("DEVICE MODE: TAG .\r\n");
    printf("DEVICE ID: %d .\r\n",g_com_map[DEV_ID]);
    printf("DEVICE INTERVAL: %d .\r\n",g_com_map[COM_INTERVAL]);
    #else
    printf("DEVICE MODE: ANCHOR .\r\n");
    printf("DEVICE ID: %d .\r\n",g_com_map[DEV_ID]);
    printf("DEVICE PAIRID: %d .\r\n",g_com_map[PAIR_ID]);
    printf("DEVICE ALARM DISTANCE: 1.%d 2.%d 3.%d .\r\n",g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],g_com_map[ALARM_DISTANCE3]);
    #endif
    for(i=0;i<255;i++)
    {
        g_Tagdist[i]=0xffff;
    }
}
 
/*! ------------------------------------------------------------------------------------------------------------------
 * @fn main()
 *
 * @brief Application entry point.
 *
 * @param  none
 *
 * @return none
 */
 
int main(void)
{
 
    Device_Init();
    Program_Init();
    Dw1000_Init();
  delay_ms(1000);    
#ifdef WORK_MODE_TAG
    RTC_Configuration(g_com_map[COM_INTERVAL]*20);
    tag_sleep_configuraion();
#endif
    Dw1000_App_Init();
    /* Loop forever initiating ranging exchanges. */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
    while(1)
    {
#ifdef WORK_MODE_TAG
    if(g_start_send_flag)
    {
        g_start_send_flag = 0;
        Tag_App();
    }
//    UART_CheckReceive();
    PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);    
#else 
        Anchor_App();
#endif
 
    }
}