mirror of https://github.com/ARMmbed/mbed-os.git
Add function to fetch platform specific reset reason register values
parent
1ec22fee05
commit
6b3d790fc1
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#if DEVICE_RESET_REASON
|
#if DEVICE_RESET_REASON
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -39,8 +41,7 @@ typedef enum {
|
||||||
RESET_REASON_UNKNOWN /**< Unknown or unreadable reset reason **/
|
RESET_REASON_UNKNOWN /**< Unknown or unreadable reset reason **/
|
||||||
} reset_reason_t;
|
} 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
|
* Note: Some platforms contain reset reason registers that persist through
|
||||||
* system resets. If the registers haven't been cleared before calling this
|
* 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);
|
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
|
* 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
|
* between system resets on certain platforms so the registers should be cleared
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,20 @@ reset_reason_t mbed_reset_reason_get(void)
|
||||||
// this function resets it.
|
// this function resets it.
|
||||||
const static reset_reason_t reason = hal_reset_reason_get();
|
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();
|
hal_reset_reason_clear();
|
||||||
|
|
||||||
return reason;
|
return reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t mbed_reset_reason_get_raw(void)
|
||||||
|
{
|
||||||
|
const static uint32_t reason = hal_reset_reason_get_raw();
|
||||||
|
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
||||||
#endif // DEVICE_RESET_REASON
|
#endif // DEVICE_RESET_REASON
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
#include "reset_reason_api.h"
|
#include "reset_reason_api.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
/** \addtogroup platform */
|
/** \addtogroup platform */
|
||||||
/** @{*/
|
/** @{*/
|
||||||
|
|
@ -44,6 +46,23 @@ namespace mbed {
|
||||||
*/
|
*/
|
||||||
reset_reason_t mbed_reset_reason_get(void);
|
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);
|
||||||
|
|
||||||
/**@}*/
|
/**@}*/
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,13 @@ reset_reason_t hal_reset_reason_get(void)
|
||||||
return RESET_REASON_UNKNOWN;
|
return RESET_REASON_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t hal_reset_reason_get_raw(void)
|
||||||
|
{
|
||||||
|
return (RCM_GetPreviousResetSources(RCM) & kRCM_SourceAll);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void hal_reset_reason_clear(void)
|
void hal_reset_reason_clear(void)
|
||||||
{
|
{
|
||||||
#if (defined(FSL_FEATURE_RCM_HAS_SSRS) && FSL_FEATURE_RCM_HAS_SSRS)
|
#if (defined(FSL_FEATURE_RCM_HAS_SSRS) && FSL_FEATURE_RCM_HAS_SSRS)
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,13 @@ reset_reason_t hal_reset_reason_get(void)
|
||||||
return RESET_REASON_UNKNOWN;
|
return RESET_REASON_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t hal_reset_reason_get_raw(void)
|
||||||
|
{
|
||||||
|
return RCC->CSR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void hal_reset_reason_clear(void)
|
void hal_reset_reason_clear(void)
|
||||||
{
|
{
|
||||||
__HAL_RCC_CLEAR_RESET_FLAGS();
|
__HAL_RCC_CLEAR_RESET_FLAGS();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue