Skip to content

Commit 57420fc

Browse files
author
Filip Jagodzinski
committed
HAL: ResetReason: Add the get_capabilities function
Add the hal_reset_reason_get_capabilities() to ResetReason HAL API. Add a default, weak implementation, that every target can override.
1 parent b1b0673 commit 57420fc

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

hal/mbed_compat.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "i2c_api.h"
2020
#include "spi_api.h"
2121
#include "gpio_api.h"
22+
#include "reset_reason_api.h"
2223
#include "mbed_toolchain.h"
2324

2425
// To be re-implemented in the target layer if required
@@ -90,4 +91,15 @@ MBED_WEAK void spi_get_capabilities(PinName ssel, bool slave, spi_capabilities_t
9091
}
9192
}
9293

93-
#endif
94+
#endif
95+
96+
#if DEVICE_RESET_REASON
97+
// To be re-implemented in the target layer if required
98+
MBED_WEAK void hal_reset_reason_get_capabilities(reset_reason_capabilities_t *cap)
99+
{
100+
cap->reasons = (1 << RESET_REASON_PIN_RESET) | (1 << RESET_REASON_SOFTWARE);
101+
#if DEVICE_WATCHDOG
102+
cap->reasons |= 1 << RESET_REASON_WATCHDOG;
103+
#endif
104+
}
105+
#endif

hal/reset_reason_api.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ extern "C" {
4141
* some other part of the application may have cleared the value. Therefore,
4242
* though there may have been a reset reason in the registers when the system
4343
* started, the reason may not be available when the user comes to check it.
44+
* * The function ::hal_reset_reason_get_capabilities fills the given
45+
* `reset_reason_capabilities_t` instance.
4446
*
4547
* # Undefined behavior
4648
* * There is no guarantee that the function ::hal_reset_reason_get will
@@ -88,6 +90,12 @@ typedef enum {
8890
RESET_REASON_UNKNOWN /**< Unknown or unreadable reset reason **/
8991
} reset_reason_t;
9092

93+
/** Reset reason capabilities of the platform
94+
*/
95+
typedef struct {
96+
uint32_t reasons; /**< Supported reset reasons. Each bit represents a corresponding reset_reason_t value.**/
97+
} reset_reason_capabilities_t;
98+
9199
/** Fetch the reset reason for the last system reset.
92100
*
93101
* This function must return the contents of the system reset reason registers
@@ -137,6 +145,10 @@ uint32_t hal_reset_reason_get_raw(void);
137145
*/
138146
void hal_reset_reason_clear(void);
139147

148+
/** Fill the given reset_reason_capabilities_t instance according to platform capabilities.
149+
*/
150+
void hal_reset_reason_get_capabilities(reset_reason_capabilities_t *cap);
151+
140152
/**@}*/
141153

142154
#ifdef __cplusplus

0 commit comments

Comments
 (0)