Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use generated sysdown() function #1447

Merged
merged 1 commit into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions kernel/os/include/os/mynewt.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define H_OS_MYNEWT_

#include "syscfg/syscfg.h"
#include "sysdown/sysdown.h"
#include "sysinit/sysinit.h"
#include "sysflash/sysflash.h"
#include "os/os.h"
Expand Down
11 changes: 11 additions & 0 deletions kernel/os/include/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ void os_init(int (*fn)(int argc, char **argv));
*/
void os_start(void);

/**
* Reboots the system.
*/
void os_reboot(int reason);

/**
* Performs a system reset. This is typically done at the end of a reboot
* procedure.
*/
void os_system_reset(void);

#include "os/endian.h"
#include "os/os_callout.h"
#include "os/os_cfg.h"
Expand Down
3 changes: 2 additions & 1 deletion kernel/os/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:

pkg.deps:
- "@apache-mynewt-core/sys/sysinit"
- "@apache-mynewt-core/sys/sys"
- "@apache-mynewt-core/sys/sysdown"
- "@apache-mynewt-core/sys/sysinit"
- "@apache-mynewt-core/util/mem"

pkg.req_apis:
Expand Down
18 changes: 18 additions & 0 deletions kernel/os/src/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "hal/hal_os_tick.h"
#include "hal/hal_bsp.h"
#include "hal/hal_system.h"
#include "hal/hal_watchdog.h"

#if MYNEWT_VAL(RTT)
Expand Down Expand Up @@ -257,6 +258,23 @@ os_start(void)
#endif
}

void
os_reboot(int reason)
{
sysdown(reason);
}

void
os_system_reset(void)
{
/* Tickle watchdog just before re-entering bootloader. Depending on what
* the system has been doing lately, the watchdog timer might be close to
* firing.
*/
hal_watchdog_tickle();
hal_system_reset();
}

void
os_pkg_init(void)
{
Expand Down
8 changes: 1 addition & 7 deletions mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,7 @@ nmgr_datetime_set(struct mgmt_cbuf *cb)
static void
nmgr_reset_tmo(struct os_event *ev)
{
/*
* Tickle watchdog just before re-entering bootloader.
* Depending on what system has been doing lately, watchdog
* timer might be close to firing.
*/
hal_watchdog_tickle();
hal_system_reset();
os_reboot(HAL_RESET_REQUESTED);
}

static int
Expand Down
3 changes: 2 additions & 1 deletion sys/shell/src/shell_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ shell_os_reset_cmd(int argc, char **argv)
}
#endif
os_time_delay(OS_TICKS_PER_SEC / 10);
hal_system_reset();
os_reboot(HAL_RESET_REQUESTED);
return 0;
}

#if MYNEWT_VAL(SHELL_CMD_HELP)
Expand Down
118 changes: 118 additions & 0 deletions sys/sysdown/include/sysdown/sysdown.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#ifndef H_SYSDOWN_
#define H_SYSDOWN_

#include <inttypes.h>
#include <assert.h>
#include <stdbool.h>
#include "syscfg/syscfg.h"

#ifdef __cplusplus
extern "C" {
#endif

#define SYSDOWN_COMPLETE 0
#define SYSDOWN_IN_PROGRESS 1

/**
* Whether the system is currently shutting down
*/
extern bool sysdown_active;

typedef int sysdown_fn(int reason);
typedef void sysdown_panic_fn(const char *file, int line, const char *func,
const char *expr, const char *msg);
typedef void sysdown_complete_fn(int status, void *arg);

extern sysdown_fn * const sysdown_cbs[];
extern sysdown_panic_fn *sysdown_panic_cb;

void sysdown_panic_set(sysdown_panic_fn *panic_fn);

#if MYNEWT_VAL(SYSDOWN_PANIC_MESSAGE)

#if MYNEWT_VAL(SYSDOWN_PANIC_FILE_LINE)
#define SYSDOWN_PANIC_MSG(msg) sysdown_panic_cb(__FILE__, __LINE__, 0, 0, msg)
#else
#define SYSDOWN_PANIC_MSG(msg) sysdown_panic_cb(0, 0, 0, 0, msg)
#endif

#else

#if MYNEWT_VAL(SYSDOWN_PANIC_FILE_LINE)
#define SYSDOWN_PANIC_MSG(msg) sysdown_panic_cb(__FILE__, __LINE__, 0, 0, 0)
#else
#define SYSDOWN_PANIC_MSG(msg) sysdown_panic_cb(0, 0, 0, 0, 0)
#endif

#endif

#define SYSDOWN_PANIC() SYSDOWN_PANIC_MSG(NULL)

#define SYSDOWN_ASSERT_MSG(rc, msg) do \
{ \
if (!(rc)) { \
SYSDOWN_PANIC_MSG(msg); \
} \
} while (0)

#define SYSDOWN_ASSERT(rc) SYSDOWN_ASSERT_MSG(rc, NULL)

/**
* Asserts that system shutdown is in progress. This macro is used to ensure
* packages don't get shut down a second time after system shutdown has
* completed.
*/
#if MYNEWT_VAL(SYSDOWN_CONSTRAIN_DOWN)
#define SYSDOWN_ASSERT_ACTIVE() assert(sysdown_active)
#else
#define SYSDOWN_ASSERT_ACTIVE()
#endif

/**
* @brief Performs a controlled shutdown and reset of the system.
*
* This function executes each package's shutdown sequence, then triggers a
* reboot.
*
* @param reason The reason for the shutdown. One of the
* HAL_RESET_[...] codes or an
* implementation-defined value.
*
* @return
*/
int sysdown(int reason);

/**
* @brief Signals completion of an in-progress sysdown subprocedure.
*
* If a sysdown subprocedure needs to perform additional work after its
* callback finishes, it returns SYSDOWN_IN_PROGRESS. Later, when the
* subprocedure completes, it signals its completion asynchronously with a call
* to this function.
*/
void sysdown_release(void);

#ifdef __cplusplus
}
#endif

#endif
27 changes: 27 additions & 0 deletions sys/sysdown/pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

pkg.name: sys/sysdown
pkg.description: Package for kicking off a controlled system shutdown.
pkg.author: "Apache Mynewt <dev@mynewt.apache.org>"
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:

pkg.deps:
- "@apache-mynewt-core/kernel/os"