Add Reset Reason platform API

pull/10657/head
Steven Cartmell 2017-11-27 10:26:22 +00:00 committed by Filip Jagodzinski
parent 8a97101988
commit 41878bc3de
3 changed files with 95 additions and 2 deletions

View File

@ -32,6 +32,8 @@ typedef enum {
RESET_REASON_WATCHDOG, /**< Set when a running watchdog timer fails to be refreshed */
RESET_REASON_LOCKUP, /**< Set when the core is locked because of an unrecoverable exception */
RESET_REASON_WAKE_LOW_POWER, /**< Set when waking from deep sleep mode */
RESET_REASON_ACCESS_ERROR, /**< Umbrella value that encompasses any access related reset */
RESET_REASON_BOOT_ERROR, /**< Umbrella value that encompasses any boot related reset */
RESET_REASON_MULTIPLE, /**< Set if multiple reset reasons are set within the board. Occurs when the reset reason registers aren't cleared between resets */
RESET_REASON_PLATFORM, /**< Platform specific reset reason not captured in this enum */
RESET_REASON_UNKNOWN /**< Unknown or unreadable reset reason **/
@ -47,7 +49,7 @@ typedef enum {
*
* @return enum containing the last reset reason for the board.
*/
reset_reason_t hal_reset_reason_get(void);
reset_reason_t hal_reset_reason_get(void);
/**
* Clear the reset reason from registers
@ -57,7 +59,7 @@ typedef enum {
* before the system resets. Failing to do so may make it difficult to determine
* the cause of any subsequent system resets.
*/
void hal_reset_reason_clear(void);
void hal_reset_reason_clear(void);
/**@}*/

View File

@ -0,0 +1,35 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
* Licensed 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.
*/
#include "mbed_reset_reason.h"
#if DEVICE_RESET_REASON
namespace mbed {
reset_reason_t mbed_reset_reason_get(void)
{
// Store the reason statically so it can be accessed after the first call to
// this function resets it.
const static reset_reason_t reason = hal_reset_reason_get();
hal_reset_reason_clear();
return reason;
}
} // namespace mbed
#endif // DEVICE_RESET_REASON

View File

@ -0,0 +1,56 @@
/** \addtogroup hal */
/** @{*/
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
* Licensed 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 MBED_RESET_REASON_H
#define MBED_RESET_REASON_H
#if DEVICE_RESET_REASON
#include "reset_reason_api.h"
namespace mbed {
/** \addtogroup platform */
/** @{*/
/**
* \defgroup reset_reason reset reason functions
* @{
*/
/** Get the platform-independent reason code for the last system reset.
*
* Example:
* @code
* const reset_reason_t reason = mbed_reset_reason_get();
*
* if (reason == RESET_REASON_WATCHDOG) {
* std::cout << "Watchdog reset" << std::endl;
* rollback();
* }
* @endcode
*/
reset_reason_t mbed_reset_reason_get(void);
/**@}*/
/**@}*/
} // namespace mbed
#endif // DEVICE_RESET_REASON
/**@}*/
#endif // MBED_RESET_REASON_H