Add function to fetch platform specific reset reason register values

pull/10657/head
Steven Cartmell 2017-11-27 15:55:00 +00:00 committed by Filip Jagodzinski
parent 1ec22fee05
commit 6b3d790fc1
5 changed files with 56 additions and 4 deletions

View File

@ -20,6 +20,8 @@
#if DEVICE_RESET_REASON
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -39,8 +41,7 @@ typedef enum {
RESET_REASON_UNKNOWN /**< Unknown or unreadable reset reason **/
} reset_reason_t;
/**
* Fetch the reset reason for the last system reset
/** Fetch the reset reason for the last system reset
*
* Note: Some platforms contain reset reason registers that persist through
* system resets. If the registers haven't been cleared before calling this
@ -51,8 +52,16 @@ typedef enum {
*/
reset_reason_t hal_reset_reason_get(void);
/**
* Clear the reset reason from registers
/** Fetch the raw platform specific reset reason register value
*
* @return value containing the reset reason register for the given platform.
* If the platform contains reset reasons across multiple registers they
* will be concatenated here.
*/
uint32_t hal_reset_reason_get_raw(void);
/** Clear the reset reason from registers
*
* Reset the value of the reset status registers, the reset reason will persist
* between system resets on certain platforms so the registers should be cleared

View File

@ -26,10 +26,20 @@ reset_reason_t mbed_reset_reason_get(void)
// this function resets it.
const static reset_reason_t reason = hal_reset_reason_get();
// Call get raw to cache the reset reason before clearing the registers.
hal_reset_reason_get_raw();
hal_reset_reason_clear();
return reason;
}
uint32_t mbed_reset_reason_get_raw(void)
{
const static uint32_t reason = hal_reset_reason_get_raw();
return reason;
}
} // namespace mbed
#endif // DEVICE_RESET_REASON

View File

@ -22,6 +22,8 @@
#include "reset_reason_api.h"
#include <stdint.h>
namespace mbed {
/** \addtogroup platform */
/** @{*/
@ -44,6 +46,23 @@ namespace mbed {
*/
reset_reason_t mbed_reset_reason_get(void);
/** Get the platform specific reason code for the last system reset.
*
* Platform specific reasons that are not covered by the reset_reason_t enum
* will cause the mbed_reset_reason_get function to return RESET_REASON_PLATFORM
* In order to get the actual reason the register value must be fetched directly
* using this function and interpreted in a platform specific manner.
*
* Example:
* @code
* if (mbed_reset_reason_get() == RESET_REASON_PLATFORM) {
* const uint32_t platform_reason = mbed_reset_reason_get_raw();
* }
* @endcode
*/
uint32_t mbed_reset_reason_get_raw(void);
/**@}*/
/**@}*/

View File

@ -74,6 +74,13 @@ reset_reason_t hal_reset_reason_get(void)
return RESET_REASON_UNKNOWN;
}
uint32_t hal_reset_reason_get_raw(void)
{
return (RCM_GetPreviousResetSources(RCM) & kRCM_SourceAll);
}
void hal_reset_reason_clear(void)
{
#if (defined(FSL_FEATURE_RCM_HAS_SSRS) && FSL_FEATURE_RCM_HAS_SSRS)

View File

@ -51,6 +51,13 @@ reset_reason_t hal_reset_reason_get(void)
return RESET_REASON_UNKNOWN;
}
uint32_t hal_reset_reason_get_raw(void)
{
return RCC->CSR;
}
void hal_reset_reason_clear(void)
{
__HAL_RCC_CLEAR_RESET_FLAGS();