| BlueNRG-1 DK: BLE examples

- Main Page
- Modules
- Files

- File List

DTM_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : DTM_main.c
4 * Author : VMA DIVISION
5 * Version : 1.1.0
6 * Date : 27-June-2016
7 * Description : DTM application which configures a BlueNRG-1 device as a network coprocessor (UART or SPI conficuration) in order to be used with the BlueNRG GUI or other instruments as CBT
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
208 /* Includes ------------------------------------------------------------------*/
209 #include <stdint.h>
210 #include "BlueNRG1_conf.h"
211 #include "bluenrg1_stack.h"
212 #include "DTM_boot.h"
213 #include "sleep.h"
214 #include "transport_layer.h"
215 #include "hw_config.h"
216
217
218 typedef PACKED(struct) packed_crash_info_s {
219 uint8_t dummy[2];
220 crash_info_t crash_info;
221 uint8_t Debug_Data_Length;
222 } packed_crash_info_t;
223
224 #define RESET_REASON_WDG ((uint8_t)0x05)
225 #define RESET_REASON_LOCKUP ((uint8_t)0x06)
226 #define RESET_REASON_BOR ((uint8_t)0x07)
227 #define RESET_REASON_CRASH ((uint8_t)0x08)
228
229
230 /*
231 ******************************************************************************
232 ******************************************************************************
233 * The DTM project memory layout is as follows:
234 *
235 * ------------- 0x10067FFF
236 *
237 * DTM
238 *
239 * ------------- 0x10040800
240 * DTM Updater
241 * ------------- 0x10040000
242 *
243 * The DTM Updater allows to access the memory flash through ACI_HAL commands.
244 * The DTM Updater can be activated in the following way:
245 * 1) Activation by using ACI_HAL_UPDATER_START
246 * 2) Activation by using IO3 pin (high level at start up).
247 * Note: if the IO3 pin is used and is high at start up, this will cause the
248 * DTM Updater starts. So, to avoid this, the support of the DTM Updater
249 * can be removed.
250 *
251 * If the DTM Updater support is not necessary, the DTM Updater code can be
252 * removed:
253 * 1) Disable/Remove the file DTM_Updater_xxx.c inside the folder project
254 * DTM_Updater.
255 * 2) Option/Linker: Change the symbol definition from
256 * MEMORY_FLASH_APP_OFFSET=0x800 to MEMORY_FLASH_APP_OFFSET=0.
257 *
258 ****************************************************************************
259 ****************************************************************************
260 */
261
262 int main(void)
263 {
264 packed_crash_info_t crash_info;
265
266 /* System Init */
267 DTM_SystemInit();
268
269 /* Stack Initialization */
270 DTM_StackInit();
271
272 /* Transport Layer Init */
273 transport_layer_init();
274
275 /* Get crash info */
276 GET_CRASH_INFO(crash_info.crash_info);
277
278 #ifdef LL_ONLY
279 uint8_t Value = 1;
280 aci_hal_write_config_data(0x2C, 1, &Value);
281
282 #else
283 RESET_REASON_Type xResetReason;
284 uint8_t reset_event[] = {0x04,0xFF,0x03,0x01,0x00,0x01};
285
286 /* EVT_BLUE_INITIALIZED */
287 xResetReason = SysCtrl_GetWakeupResetReason();
288 if(xResetReason == RESET_WDG) {
289 reset_event[5] = RESET_REASON_WDG;
290 }
291 else if(xResetReason == RESET_LOCKUP) {
292 reset_event[5] = RESET_REASON_LOCKUP;
293 }
294 else if(xResetReason == RESET_BLE_BOR) {
295 reset_event[5] = RESET_REASON_BOR;
296 }
297 if((crash_info.crash_info.signature&0xFFFF0000) == ASSERT_SIGNATURE) { /* ASSERT_SIGNATURE: 0xBCEC0000 */
298 reset_event[5] = RESET_REASON_CRASH;
299 }
300 send_event(reset_event, sizeof(reset_event), 8);
301
302 #endif
303 if((crash_info.crash_info.signature&0xFFFF0000) == ASSERT_SIGNATURE) { /* ASSERT_SIGNATURE: 0xBCEC0000 */
304 uint8_t *ptr=(uint8_t *) &crash_info;
305 ptr[0] = 0x04;
306 ptr[1] = 0xFF;
307 ptr[5] = ptr[2]; // Remap ???
308 ptr[2] = 40;
309 ptr[3] = 0x03;
310 ptr[4] = 0x00;
311 crash_info.Debug_Data_Length = 0;
312 send_event(ptr, sizeof(crash_info), -1);
313 }
314
315 while(1) {
316 /* BlueNRG-1 stack tick */
317 BTLE_StackTick();
318 transport_layer_tick();
319 BlueNRG_Sleep(SLEEPMODE_NOTIMER, IO_WAKEUP_PIN, 0, 0); // 4: IO11 0: low level
320 }
321 }