chen
2024-09-20 292ed46c6066d47289f1330b1c2bcc6d74761f95
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*******************************************************************************
 * File Name         : BSP.c
 * Description       :
 * Created on        : 2018Äê7ÔÂ23ÈÕ
 * Author            : ¶Å¼ü
 *******************************************************************************/
 
/*******************************************************************************
 *                              Include Files                                  *
 *******************************************************************************/
#include "BSP.h"
#include "stm32f4xx_hal.h"
#include "HIDO_Debug.h"
#include "Uart.h"
#include "Shell.h"
#include "DBG.h"
//#include "RTC.h"
//#include "SPI.h"
#ifdef __EC600S__
#include "EC600SDriver.h"
#endif
//#include "LED.h"
#include "Delay.h"
#include "SPIFlash.h"
//#include "Power.h"
#include "GPS.h"
#include "RTC.h"
#include "ADC_hal.h"
#include "global_param.h"
#include "dw_app.h"
#include "AppConfig.h"
/*******************************************************************************
 *                                  Macro                                      *
 *******************************************************************************/
 
/*******************************************************************************
 *                             Type Definition                                 *
 *******************************************************************************/
 
/*******************************************************************************
 *                             Global Variable                                 *
 *******************************************************************************/
 
extern SPI_HandleTypeDef hspi1;
extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart2;
extern UART_HandleTypeDef huart6;
extern ADC_HandleTypeDef hadc1;
extern DMA_HandleTypeDef hdma_usart1_rx;
extern DMA_HandleTypeDef hdma_usart1_tx;
extern DMA_HandleTypeDef hdma_usart2_rx;
extern DMA_HandleTypeDef hdma_usart2_tx;
 
/*******************************************************************************
 *                             Local Variable                                  *
 *******************************************************************************/
 
/*******************************************************************************
 *                        Local Function Declaration                           *
 *******************************************************************************/
 
/*******************************************************************************
 *                             Local Function                                  *
 *******************************************************************************/
/*******************************************************************************
 * Function Name     : BSP_ResourceInit
 * Description       :
 * Input             :
 * Output            :
 * Return            :
 * Author            : ¶Å¼ü
 * Modified Date:    : 2018Äê7ÔÂ23ÈÕ
 *******************************************************************************/
static HIDO_INT32 BSP_ResourceInit(void)
{
    /* UART */
 #ifdef __APP_CODE__  
    ADC_Register(&hadc1);
 #endif
    /* SpiFlash */
    SPI_Register(SPI_ID_FLASH, &hspi1);
    SPIFlash_SPIRegister(SPI_FLASH_ID_0, SPI_ID_FLASH);
    SPIFlash_PinRegister(SPI_FLASH_ID_0, SPI_FLASH_PIN_CS, GPIOB, GPIO_PIN_5);
    SPIFlash_PinRegister(SPI_FLASH_ID_0, SPI_FLASH_PIN_SCK, GPIOA, GPIO_PIN_5);
    SPIFlash_PinRegister(SPI_FLASH_ID_0, SPI_FLASH_PIN_MISO, GPIOA, GPIO_PIN_6);
    SPIFlash_PinRegister(SPI_FLASH_ID_0, SPI_FLASH_PIN_MOSI, GPIOA, GPIO_PIN_7);
 
    /* UART */
    Uart_Register(UART_ID_DBG, &huart1);
    Uart_Register(UART_ID_4G, &huart6);
    Uart_Register(UART_ID_GPS, &huart2);
 
    //TODO ADC_Register(&hadc1);
    //Delay_TimerRegister(&htim16);
#ifdef _RTK_MODE_
    /* EC600S */
    
    
    EC600SDriver_PinRegister(EC600S_PIN_3V8_EN, GPIOB, GPIO_PIN_10); 
    //EC600SDriver_PinRegister(EC600S_PIN_3V8_EN, GPIOA, GPIO_PIN_8);
    EC600SDriver_PinRegister(EC600S_PIN_PWRKEY, GPIOB, GPIO_PIN_0);
    EC600SDriver_PinRegister(EC600S_PIN_RI, GPIOB, GPIO_PIN_12);
#ifdef __APP_CODE__
    /* F9P */
    GPS_PinRegister(GPS_PIN_REST, GPIOC, GPIO_PIN_6);
    GPS_PinRegister(GPS_PIN_EN, GPIOA, GPIO_PIN_12);
#endif
#endif
    return HIDO_OK;
}
 
/*******************************************************************************
 *                             Global Function                                 *
 *******************************************************************************/
/*******************************************************************************
 * Function Name     : HAL_UART_ErrorCallback
 * Description       :
 * Input             :
 * Output            :
 * Return            :
 * Author            : ¶Å¼ü
 * Modified Date:    : 2018Äê7ÔÂ23ÈÕ
 *******************************************************************************/
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
    Uart_RxErrorFromISR(huart);
}
 
/*******************************************************************************
 * Function Name     : HAL_UART_TxCpltCallback
 * Description       :
 * Input             :
 * Output            :
 * Return            :
 * Author            : ¶Å¼ü
 * Modified Date:    : 2018Äê7ÔÂ23ÈÕ
 *******************************************************************************/
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
    Uart_TxOverFromISR(huart);
}
 
/*******************************************************************************
 * Function Name     : HAL_UART_RxCpltCallback
 * Description       :
 * Input             :
 * Output            :
 * Return            :
 * Author            : ¶Å¼ü
 * Modified Date:    : 2018Äê7ÔÂ23ÈÕ
 *******************************************************************************/
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
    Uart_RxOverFromISR(huart);
}
 
/*******************************************************************************
 * Function Name     : HAL_RTC_AlarmAEventCallback
 * Description       :
 * Input             :
 * Output            :
 * Return            :
 * Author            : ¶Å¼ü
 * Modified Date:    : 2018Äê7ÔÂ23ÈÕ
 *******************************************************************************/
//void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
//{
//#ifdef __APP_CODE__
//    HIDO_Debug("HAL_RTC_AlarmAEventCallback\r\n");
//#endif
//}
 
/*******************************************************************************
 * Function Name     : HAL_GPIO_EXTI_Callback
 * Description       :
 * Input             :
 * Output            :
 * Return            :
 * Author            : ¶Å¼ü
 * Modified Date:    : 2018Äê7ÔÂ23ÈÕ
 *******************************************************************************/
extern float nomove_count;
extern u8 flag_ancupd_start;
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
#ifdef __APP_CODE__
    if(GPIO_Pin == GPIO_PIN_12)
    {
        PowerDownDetect();
    }
    if(GPIO_Pin == GPIO_PIN_0)
    {
        nomove_count = 0;
    }
    if(GPIO_Pin == GPIO_PIN_9&&flag_ancupd_start==0)
    {
     Anchor_App();
    }
         if(GPIO_Pin == GPIO_PIN_9&&flag_ancupd_start==1)
    {
      UWBYmodemT_App();
    }
    //HIDO_Debug("HAL_GPIO_EXTI_Callback %x\r\n", GPIO_Pin);
#endif
}
 
/*******************************************************************************
 * Function Name     : HAL_TIM_PeriodElapsedCallback
 * Description       :
 * Input             :
 * Output            :
 * Return            :
 * Author            : ¶Å¼ü
 * Modified Date:    : 2018Äê7ÔÂ23ÈÕ
 *******************************************************************************/
extern u8 bat_percent2;
extern u16 basesystimer,g_Resttimer;
extern u8 g_start_sync_flag;
extern u32 sync_timer,target_time;
float nomove_count=0;
u8 uwb_timeout;
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
#ifdef __APP_CODE__
    basesystimer++;    
 
    uwb_timeout++;
     if(basesystimer>=1000)
     {
        basesystimer = 0;
     //   BepperTask();
        g_Resttimer++;
         nomove_count++;
         g_start_sync_flag = 1;
         if(g_Resttimer>10&&DBG_GetMode() != DBG_MODE_CHARGE)
         {
            NVIC_SystemReset();
         }
        if(g_com_map[UWBENABLE_INDEX]==0)
        {
         if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)&&DBG_GetMode() != DBG_MODE_CHARGE)
        {
            Set4LEDColor(uwbled,rtkled,led4g,powerled);
        }
        }   
     }
         if(basesystimer==target_time)
    { 
        g_start_send_flag = 1;
    }
#endif
//    if(synctimer%100==0)
//    {g_start_send_flag = 1;}
}
 
 
/*******************************************************************************
 * Function Name     : BSP_Init
 * Description       :
 * Input             :
 * Output            :
 * Return            :
 * Author            : ¶Å¼ü
 * Modified Date:    : 2018Äê7ÔÂ23ÈÕ
 *******************************************************************************/
HIDO_INT32 BSP_Init(void)
{
    BSP_ResourceInit();
    
    return HIDO_OK;
}