From b3ea790449c7709b2334fee5ff9c976b9c101ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Sat, 11 Jun 2016 22:56:58 +0200 Subject: [PATCH] cc2538: sys-ctrl: Provide last reset cause MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add functions providing the last reset cause, one as an integer (ID), and one as a string. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/dev/sys-ctrl.c | 20 ++++++++++++++++++++ cpu/cc2538/dev/sys-ctrl.h | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/cpu/cc2538/dev/sys-ctrl.c b/cpu/cc2538/dev/sys-ctrl.c index c2e8777ad..92592b942 100644 --- a/cpu/cc2538/dev/sys-ctrl.c +++ b/cpu/cc2538/dev/sys-ctrl.c @@ -50,6 +50,26 @@ #define SYS_CTRL_OSCS SYS_CTRL_CLOCK_CTRL_OSC32K #endif /*---------------------------------------------------------------------------*/ +int +sys_ctrl_get_reset_cause(void) +{ + return (REG(SYS_CTRL_CLOCK_STA) & SYS_CTRL_CLOCK_STA_RST) >> + SYS_CTRL_CLOCK_STA_RST_S; +} +/*---------------------------------------------------------------------------*/ +const char * +sys_ctrl_get_reset_cause_str(void) +{ + static const char *reset_cause[] = { + "POR", + "External reset", + "WDT", + "CLD or software reset" + }; + + return reset_cause[sys_ctrl_get_reset_cause()]; +} +/*---------------------------------------------------------------------------*/ void sys_ctrl_init() { diff --git a/cpu/cc2538/dev/sys-ctrl.h b/cpu/cc2538/dev/sys-ctrl.h index 3fda071fe..22dece434 100644 --- a/cpu/cc2538/dev/sys-ctrl.h +++ b/cpu/cc2538/dev/sys-ctrl.h @@ -115,6 +115,11 @@ #define SYS_CTRL_CLOCK_STA_OSC32K_CALDIS 0x02000000 #define SYS_CTRL_CLOCK_STA_OSC32K 0x01000000 #define SYS_CTRL_CLOCK_STA_RST 0x00C00000 +#define SYS_CTRL_CLOCK_STA_RST_S 22 +#define SYS_CTRL_CLOCK_STA_RST_POR 0 +#define SYS_CTRL_CLOCK_STA_RST_EXT 1 +#define SYS_CTRL_CLOCK_STA_RST_WDT 2 +#define SYS_CTRL_CLOCK_STA_RST_CLD_SW 3 #define SYS_CTRL_CLOCK_STA_SOURCE_CHANGE 0x00100000 #define SYS_CTRL_CLOCK_STA_XOSC_STB 0x00080000 #define SYS_CTRL_CLOCK_STA_HSOSC_STB 0x00040000 @@ -302,6 +307,17 @@ /** \name SysCtrl functions * @{ */ + +/** \brief Gets the cause of the last reset + * \return A \c SYS_CTRL_CLOCK_STA_RST_x reset cause + */ +int sys_ctrl_get_reset_cause(void); + +/** \brief Gets a string describing the cause of the last reset + * \return Last reset cause as a string + */ +const char *sys_ctrl_get_reset_cause_str(void); + /** \brief Initialises the System Control Driver. The main purpose of this * function is to power up and select clocks and oscillators * \note This function depends on ioc_init() having been called beforehand. */