summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@lamia.panaceas.james.local>2015-09-04 11:19:00 +0100
committerroot <root@lamia.panaceas.james.local>2015-09-04 11:19:00 +0100
commitcb0b3bc0b7aa2c45196a791a607bd37defc07a02 (patch)
treeba11fc6acbf6713bbc9bdd8a63c2f8ce15cd33cf
parentaa24fbf26e3ff7c201bd6032030f47b49c6be5f5 (diff)
downloadbootloader-cb0b3bc0b7aa2c45196a791a607bd37defc07a02.tar.gz
bootloader-cb0b3bc0b7aa2c45196a791a607bd37defc07a02.tar.bz2
bootloader-cb0b3bc0b7aa2c45196a791a607bd37defc07a02.zip
add timeout modeHEADmaster
-rw-r--r--Makefile8
-rw-r--r--main.c16
-rw-r--r--sdk-config/sdk/libraries/bootloader_dfu/dfu_bank_internal.h87
3 files changed, 104 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 192bdde..c17d8a8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,11 @@
PROG=main
DEFINES =
+
+#if not defined then we use a timer
+#DEFINES += -DBOOTLOADER_BUTTON=BSP_BUTTON_1
+
+
DEFINES += -DSWI_DISABLE0
#DEFINES += -DBOARD_PCA10028
DEFINES += -DBOARD_BLE400
@@ -61,10 +66,9 @@ DEV_TYPE=0xFFFF
SD_REQ=0xFFFE
-LINKER_SCRIPT=dfu_gcc_nrf51.ld #sdk/toolchain/gcc/s130.ld
+LINKER_SCRIPT=dfu_gcc_nrf51.ld
INCLUDES += -Isdk-config -I${SDK} -I.
-#INCLUDES += -Iconfig
OOCD=openocd
OOCD_CFG=openocd.cfg
diff --git a/main.c b/main.c
index c5ee04b..9d26afa 100644
--- a/main.c
+++ b/main.c
@@ -50,9 +50,9 @@
#include <sdk/drivers_nrf/pstorage/config/pstorage_platform.h>
#include <sdk/softdevice/s130/headers/nrf_mbr.h>
-#if BUTTONS_NUMBER < 1
-#error "Not enough buttons on board"
-#endif
+//#if BUTTONS_NUMBER < 1
+//#error "Not enough buttons on board"
+//#endif
#if LEDS_NUMBER < 1
#error "Not enough LEDs on board"
@@ -60,7 +60,7 @@
#define IS_SRVC_CHANGED_CHARACT_PRESENT 1 /**< Include the service_changed characteristic. For DFU this should normally be the case. */
-#define BOOTLOADER_BUTTON BSP_BUTTON_1 /**< Button used to enter SW update mode. */
+//#define BOOTLOADER_BUTTON BSP_BUTTON_1 /**< Button used to enter SW update mode. */
#define UPDATE_IN_PROGRESS_LED BSP_LED_2 /**< Led used to indicate that DFU is active. */
#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
@@ -111,10 +111,11 @@ static void timers_init(void)
*/
static void buttons_init(void)
{
+#if defined(BOOTLOADER_BUTTON)
nrf_gpio_cfg_sense_input(BOOTLOADER_BUTTON,
BUTTON_PULL,
NRF_GPIO_PIN_SENSE_LOW);
-
+#endif
}
@@ -229,7 +230,12 @@ int main(void)
}
dfu_start = app_reset;
+
+#if defined(BOOTLOADER_BUTTON)
dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0) ? true: false);
+#else
+ dfu_start |= true;
+#endif
if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START)))
{
diff --git a/sdk-config/sdk/libraries/bootloader_dfu/dfu_bank_internal.h b/sdk-config/sdk/libraries/bootloader_dfu/dfu_bank_internal.h
new file mode 100644
index 0000000..af3c548
--- /dev/null
+++ b/sdk-config/sdk/libraries/bootloader_dfu/dfu_bank_internal.h
@@ -0,0 +1,87 @@
+/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+/**@file
+ *
+ * @defgroup dfu_bank_internal Device Firmware Update internal header for bank handling in DFU.
+ * @{
+ *
+ * @brief Device Firmware Update Bank handling module interface.
+ *
+ * @details This header is intended for shared definition and functions between single and dual bank
+ * implementations used for DFU support. It is not supposed to be used for external access
+ * to the DFU module.
+ *
+ */
+#ifndef DFU_BANK_INTERNAL_H__
+#define DFU_BANK_INTERNAL_H__
+
+#include <sdk/libraries/bootloader_dfu/dfu_types.h>
+
+/**@brief States of the DFU state machine. */
+typedef enum
+{
+ DFU_STATE_INIT_ERROR, /**< State for: dfu_init(...) error. */
+ DFU_STATE_IDLE, /**< State for: idle. */
+ DFU_STATE_PREPARING, /**< State for: preparing, indicates that the flash is being erased and no data packets can be processed. */
+ DFU_STATE_RDY, /**< State for: ready. */
+ DFU_STATE_RX_INIT_PKT, /**< State for: receiving initialization packet. */
+ DFU_STATE_RX_DATA_PKT, /**< State for: receiving data packet. */
+ DFU_STATE_VALIDATE, /**< State for: validate. */
+ DFU_STATE_WAIT_4_ACTIVATE /**< State for: waiting for dfu_image_activate(). */
+} dfu_state_t;
+
+#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
+#define DFU_TIMEOUT_INTERVAL APP_TIMER_TICKS(10000, APP_TIMER_PRESCALER) /**< DFU timeout interval in units of timer ticks. */
+
+#define IS_UPDATING_SD(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_SD) /**< Macro for determining if a SoftDevice update is ongoing. */
+#define IS_UPDATING_BL(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_BL) /**< Macro for determining if a Bootloader update is ongoing. */
+#define IS_UPDATING_APP(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_APP) /**< Macro for determining if a Application update is ongoing. */
+#define IMAGE_WRITE_IN_PROGRESS() (m_data_received > 0) /**< Macro for determining if an image write is in progress. */
+#define IS_WORD_SIZED(SIZE) ((SIZE & (sizeof(uint32_t) - 1)) == 0) /**< Macro for checking that the provided is word sized. */
+
+/**@cond NO_DOXYGEN */
+static uint32_t m_data_received; /**< Amount of received data. */
+/**@endcond */
+
+/**@brief Type definition of function used for preparing of the bank before receiving of a
+ * software image.
+ *
+ * @param[in] image_size Size of software image being received.
+ */
+typedef void (*dfu_bank_prepare_t)(uint32_t image_size);
+
+/**@brief Type definition of function used for handling clear complete of the bank before
+ * receiving of a software image.
+ */
+typedef void (*dfu_bank_cleared_t)(void);
+
+/**@brief Type definition of function used for activating of the software image received.
+ *
+ * @return NRF_SUCCESS If the image has been successfully activated any other NRF_ERROR code in
+ * case of a failure.
+ */
+typedef uint32_t (*dfu_bank_activate_t)(void);
+
+/**@brief Structure for holding of function pointers for needed prepare and activate procedure for
+ * the requested update procedure.
+ */
+typedef struct
+{
+ dfu_bank_prepare_t prepare; /**< Function pointer to the prepare function called on start of update procedure. */
+ dfu_bank_cleared_t cleared; /**< Function pointer to the cleared function called after prepare function completes. */
+ dfu_bank_activate_t activate; /**< Function pointer to the activate function called on finalizing the update procedure. */
+} dfu_bank_func_t;
+
+#endif // DFU_BANK_INTERNAL_H__
+
+/** @} */