hal; add hal_system_restart(), which allows you to restart the system with a new entry point.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/12fdc5cf Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/12fdc5cf Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/12fdc5cf Branch: refs/heads/develop Commit: 12fdc5cfb5fc274a515c46bc50acee5ad2b91dfb Parents: a09cc95 Author: Marko Kiiskila <[email protected]> Authored: Wed Jan 25 14:08:40 2017 -0800 Committer: Marko Kiiskila <[email protected]> Committed: Wed Jan 25 14:32:31 2017 -0800 ---------------------------------------------------------------------- hw/hal/include/hal/hal_system.h | 5 ++++ hw/mcu/nordic/nrf51xxx/src/hal_system_start.c | 27 ++++++++++++++++++++ hw/mcu/nordic/nrf52xxx/src/hal_system_start.c | 29 +++++++++++++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/12fdc5cf/hw/hal/include/hal/hal_system.h ---------------------------------------------------------------------- diff --git a/hw/hal/include/hal/hal_system.h b/hw/hal/include/hal/hal_system.h index 24436b9..3b3c90d 100644 --- a/hw/hal/include/hal/hal_system.h +++ b/hw/hal/include/hal/hal_system.h @@ -35,6 +35,11 @@ void hal_system_reset(void) __attribute((noreturn)); void hal_system_start(void *img_start) __attribute((noreturn)); /* + * Called by split app loader to start the app program. + */ +void hal_system_restart(void *img_start) __attribute((noreturn)); + +/* * Returns non-zero if there is a HW debugger attached. */ int hal_debugger_connected(void); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/12fdc5cf/hw/mcu/nordic/nrf51xxx/src/hal_system_start.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_system_start.c b/hw/mcu/nordic/nrf51xxx/src/hal_system_start.c index 9152edc..9aa0c73 100644 --- a/hw/mcu/nordic/nrf51xxx/src/hal_system_start.c +++ b/hw/mcu/nordic/nrf51xxx/src/hal_system_start.c @@ -20,6 +20,7 @@ #include <stddef.h> #include <inttypes.h> #include <mcu/cortex_m0.h> +#include <mcu/nrf51_hal.h> /** * Boots the image described by the supplied image header. @@ -46,3 +47,29 @@ hal_system_start(void *img_start) /* Jump to image. */ fn(); } + +/** + * Boots the image described by the supplied image header. + * This routine is used in split-app scenario when loader decides + * that it wants to run the app instead. + * + * @param hdr The header for the image to boot. + */ +void +hal_system_restart(void *img_start) +{ + int i; + int sr; + + /* + * Disable interrupts, and leave the disabled. + * They get re-enabled when system starts coming back again. + */ + __HAL_DISABLE_INTERRUPTS(sr); + for (i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++) { + NVIC->ICER[i] = 0xffffffff; + } + (void)sr; + + hal_system_start(img_start); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/12fdc5cf/hw/mcu/nordic/nrf52xxx/src/hal_system_start.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_system_start.c b/hw/mcu/nordic/nrf52xxx/src/hal_system_start.c index 4a9e0fa..09e8613 100644 --- a/hw/mcu/nordic/nrf52xxx/src/hal_system_start.c +++ b/hw/mcu/nordic/nrf52xxx/src/hal_system_start.c @@ -20,6 +20,7 @@ #include <stddef.h> #include <inttypes.h> #include <mcu/cortex_m4.h> +#include <mcu/nrf52_hal.h> /** * Boots the image described by the supplied image header. @@ -33,7 +34,7 @@ hal_system_start(void *img_start) uint32_t base0entry; uint32_t jump_addr; - jump_fn *fn; + register jump_fn *fn; /* First word contains initial MSP value. */ __set_MSP(*(uint32_t *)img_start); @@ -46,3 +47,29 @@ hal_system_start(void *img_start) /* Jump to image. */ fn(); } + +/** + * Boots the image described by the supplied image header. + * This routine is used in split-app scenario when loader decides + * that it wants to run the app instead. + * + * @param hdr The header for the image to boot. + */ +void +hal_system_restart(void *img_start) +{ + int i; + int sr; + + /* + * Disable interrupts, and leave the disabled. + * They get re-enabled when system starts coming back again. + */ + __HAL_DISABLE_INTERRUPTS(sr); + for (i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++) { + NVIC->ICER[i] = 0xffffffff; + } + (void)sr; + + hal_system_start(img_start); +}
