Repository: incubator-mynewt-core Updated Branches: refs/heads/develop c61c02610 -> d1e8e11cf
MYNEWT-513 sysinit - Configure panic fn at runtime Previously, sysinit had a syscfg setting which specified the name of a panic function. This was bad, since the newt can't verify that the name corresponds to an actual C function of the correct type. Now, the panic function is configured at runtime. 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/d1e8e11c Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d1e8e11c Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d1e8e11c Branch: refs/heads/develop Commit: d1e8e11cfd233416febc66d7c0bdb2bd3808b80c Parents: c61c026 Author: Christopher Collins <[email protected]> Authored: Fri Dec 16 16:40:21 2016 -0800 Committer: Christopher Collins <[email protected]> Committed: Tue Jan 3 14:02:49 2017 -0800 ---------------------------------------------------------------------- sys/sysinit/include/sysinit/sysinit.h | 17 ++++++----------- sys/sysinit/src/sysinit.c | 22 ++++++++++++++++++++++ sys/sysinit/syscfg.yml | 4 ---- 3 files changed, 28 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d1e8e11c/sys/sysinit/include/sysinit/sysinit.h ---------------------------------------------------------------------- diff --git a/sys/sysinit/include/sysinit/sysinit.h b/sys/sysinit/include/sysinit/sysinit.h index 13d8ed8..4b250c0 100644 --- a/sys/sysinit/include/sysinit/sysinit.h +++ b/sys/sysinit/include/sysinit/sysinit.h @@ -21,6 +21,7 @@ #define H_SYSINIT_ #include <inttypes.h> +#include <assert.h> #include "syscfg/syscfg.h" #if MYNEWT_VAL(SPLIT_APPLICATION) @@ -38,17 +39,11 @@ void sysinit_end(void); typedef void sysinit_panic_fn(const char *file, int line); -/* By default, a panic triggers an assertion failure. If the project overrides - * the sysinit panic function setting, the specified function gets called - * instead. - */ -#ifndef MYNEWT_VAL_SYSINIT_PANIC_FN -#include <assert.h> -#define SYSINIT_PANIC() assert(0) -#else -void MYNEWT_VAL(SYSINIT_PANIC_FN)(const char *file, int line); -#define SYSINIT_PANIC() MYNEWT_VAL(SYSINIT_PANIC_FN)(__FILE__, __LINE__) -#endif +extern sysinit_panic_fn *sysinit_panic_cb; + +void sysinit_panic_set(sysinit_panic_fn *panic_fn); + +#define SYSINIT_PANIC() sysinit_panic_cb(__FILE__, __LINE__) #define SYSINIT_PANIC_ASSERT(rc) do \ { \ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d1e8e11c/sys/sysinit/src/sysinit.c ---------------------------------------------------------------------- diff --git a/sys/sysinit/src/sysinit.c b/sys/sysinit/src/sysinit.c index e8430d0..4e560c7 100644 --- a/sys/sysinit/src/sysinit.c +++ b/sys/sysinit/src/sysinit.c @@ -17,10 +17,32 @@ * under the License. */ +#include <stddef.h> +#include <limits.h> +#include "os/os_fault.h" #include "sysinit/sysinit.h" +static void sysinit_panic_dflt(const char *file, int line); +sysinit_panic_fn *sysinit_panic_cb = sysinit_panic_dflt; + uint8_t sysinit_active; +static void +sysinit_panic_dflt(const char *file, int line) +{ + __assert_func(file, line, NULL, NULL); +} + +/** + * Sets the sysinit panic function; i.e., the function which executes when + * initialization fails. By default, a panic triggers a failed assertion. + */ +void +sysinit_panic_set(sysinit_panic_fn *panic_cb) +{ + sysinit_panic_cb = panic_cb; +} + void sysinit_start(void) { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d1e8e11c/sys/sysinit/syscfg.yml ---------------------------------------------------------------------- diff --git a/sys/sysinit/syscfg.yml b/sys/sysinit/syscfg.yml index 09ece65..74dbc29 100644 --- a/sys/sysinit/syscfg.yml +++ b/sys/sysinit/syscfg.yml @@ -19,10 +19,6 @@ # Package: sys/sysinit syscfg.defs: - SYSINIT_PANIC_FN: - description: 'TBD' - value: - SYSINIT_CONSTRAIN_INIT: description: Only allow packages to be initialized by sysinit. value: 1
