BLE FOTA APP

Dependencies:   BLE_API mbed

It doesn't work with the default FOTA bootloader. It use NVIC_SystemReset() to enter a bootloader.

Committer:
yihui
Date:
Fri Oct 10 03:36:28 2014 +0000
Revision:
1:a607cd9655d7
use NVIC_SystemReset() to run bootloader

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 1:a607cd9655d7 1 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
yihui 1:a607cd9655d7 2 *
yihui 1:a607cd9655d7 3 * The information contained herein is property of Nordic Semiconductor ASA.
yihui 1:a607cd9655d7 4 * Terms and conditions of usage are described in detail in NORDIC
yihui 1:a607cd9655d7 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
yihui 1:a607cd9655d7 6 *
yihui 1:a607cd9655d7 7 * Licensees are granted free, non-transferable use of the information. NO
yihui 1:a607cd9655d7 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
yihui 1:a607cd9655d7 9 * the file.
yihui 1:a607cd9655d7 10 *
yihui 1:a607cd9655d7 11 */
yihui 1:a607cd9655d7 12
yihui 1:a607cd9655d7 13 #include <string.h>
yihui 1:a607cd9655d7 14 #include <stdint.h>
yihui 1:a607cd9655d7 15 #include <stdbool.h>
yihui 1:a607cd9655d7 16 #include <nrf51.h>
yihui 1:a607cd9655d7 17 #include "ble_error_log.h"
yihui 1:a607cd9655d7 18 #include "app_util.h"
yihui 1:a607cd9655d7 19 #include "app_error.h"
yihui 1:a607cd9655d7 20 #include "nrf_gpio.h"
yihui 1:a607cd9655d7 21 #include "pstorage.h"
yihui 1:a607cd9655d7 22
yihui 1:a607cd9655d7 23
yihui 1:a607cd9655d7 24 // Made static to avoid the error_log to go on the stack.
yihui 1:a607cd9655d7 25 static ble_error_log_data_t m_ble_error_log; /**< . */
yihui 1:a607cd9655d7 26 //lint -esym(526,__Vectors)
yihui 1:a607cd9655d7 27 extern uint32_t * __Vectors; /**< The initialization vector holds the address to __initial_sp that will be used when fetching the stack. */
yihui 1:a607cd9655d7 28
yihui 1:a607cd9655d7 29 static void fetch_stack(ble_error_log_data_t * error_log)
yihui 1:a607cd9655d7 30 {
yihui 1:a607cd9655d7 31 // KTOWN: Temporarily removed 06022014
yihui 1:a607cd9655d7 32 /*
yihui 1:a607cd9655d7 33 uint32_t * p_stack;
yihui 1:a607cd9655d7 34 uint32_t * initial_sp;
yihui 1:a607cd9655d7 35 uint32_t length;
yihui 1:a607cd9655d7 36
yihui 1:a607cd9655d7 37 initial_sp = (uint32_t *) __Vectors;
yihui 1:a607cd9655d7 38 p_stack = (uint32_t *) GET_SP();
yihui 1:a607cd9655d7 39
yihui 1:a607cd9655d7 40 length = ((uint32_t) initial_sp) - ((uint32_t) p_stack);
yihui 1:a607cd9655d7 41 memcpy(error_log->stack_info,
yihui 1:a607cd9655d7 42 p_stack,
yihui 1:a607cd9655d7 43 (length > STACK_DUMP_LENGTH) ? STACK_DUMP_LENGTH : length);
yihui 1:a607cd9655d7 44 */
yihui 1:a607cd9655d7 45 }
yihui 1:a607cd9655d7 46
yihui 1:a607cd9655d7 47 uint32_t ble_error_log_write(uint32_t err_code, const uint8_t * p_message, uint16_t line_number)
yihui 1:a607cd9655d7 48 {
yihui 1:a607cd9655d7 49 m_ble_error_log.failure = true;
yihui 1:a607cd9655d7 50 m_ble_error_log.err_code = err_code;
yihui 1:a607cd9655d7 51 m_ble_error_log.line_number = line_number;
yihui 1:a607cd9655d7 52
yihui 1:a607cd9655d7 53 strncpy((char *)m_ble_error_log.message, (const char *)p_message, ERROR_MESSAGE_LENGTH - 1);
yihui 1:a607cd9655d7 54 m_ble_error_log.message[ERROR_MESSAGE_LENGTH - 1] = '\0';
yihui 1:a607cd9655d7 55
yihui 1:a607cd9655d7 56 fetch_stack(&m_ble_error_log);
yihui 1:a607cd9655d7 57
yihui 1:a607cd9655d7 58 // Write to flash removed, to be redone.
yihui 1:a607cd9655d7 59
yihui 1:a607cd9655d7 60 return NRF_SUCCESS;
yihui 1:a607cd9655d7 61 }