-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NOTE: This commit requires a newt tool update (dfaede5fbdd0c9d798714abed77b54be2d26bc06). Upon application-triggered restart, execute each package's shutdown subprocedure. This feature is discussed here: https://lists.apache.org/thread.html/ebd53c9b56230184650ea57e5534d5bcfbfc170b97547a1a26f100b5@%3Cdev.mynewt.apache.org%3E
- Loading branch information
1 parent
dac1442
commit 7238b83
Showing
10 changed files
with
382 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Oops, something went wrong.