Amend reset reason driver API

- Change API to match C++ API throughout drivers
- Amend HAL API documentation to be more specific
pull/10657/head
Steven Cartmell 2017-11-28 12:01:48 +00:00 committed by Filip Jagodzinski
parent 366893ae71
commit 3c18dcb882
4 changed files with 111 additions and 88 deletions

View File

@ -14,30 +14,31 @@
* limitations under the License.
*/
#include "mbed_reset_reason.h"
#include "ResetReason.h"
#if DEVICE_RESET_REASON
#ifdef DEVICE_RESET_REASON
namespace mbed {
reset_reason_t mbed_reset_reason_get(void)
reset_reason_t ResetReason::get()
{
// 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();
// 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();
// Call get raw to cache the reset reason before clearing the registers.
hal_reset_reason_get_raw();
hal_reset_reason_clear();
// Call get raw to cache the reset reason before clearing the registers.
ResetReason::get_raw();
return reason;
hal_reset_reason_clear();
return reason;
}
uint32_t mbed_reset_reason_get_raw(void)
uint32_t ResetReason::get_raw()
{
const static uint32_t reason = hal_reset_reason_get_raw();
const static uint32_t reason = hal_reset_reason_get_raw();
return reason;
return reason;
}
} // namespace mbed

77
drivers/ResetReason.h Normal file
View File

@ -0,0 +1,77 @@
/** \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
#ifdef DEVICE_RESET_REASON
#include "reset_reason_api.h"
namespace mbed
{
/** \addtogroup drivers */
/** @{*/
/**
* \defgroup reset_reason reset reason functions
* @{
*/
class ResetReason
{
public:
/** Get the platform-independent reason code for the last system reset.
*
* Example:
* @code
* const reset_reason_t reason = ResetReason::get();
*
* if (reason == RESET_REASON_WATCHDOG) {
* std::cout << "Watchdog reset" << std::endl;
* rollback();
* }
* @endcode
*/
static reset_reason_t get();
/** 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 ResetReason::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 (ResetReason::get() == RESET_REASON_PLATFORM) {
* const uint32_t platform_reason = ResetReason::get_raw();
* }
* @endcode
*/
static uint32_t get_raw();
};
/**@}*/
/**@}*/
} // namespace mbed
/**@}*/
#endif // DEVICE_RESET_REASON
#endif // MBED_RESET_REASON_H

View File

@ -1,75 +0,0 @@
/** \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"
#include <stdint.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);
/** 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);
/**@}*/
/**@}*/
} // namespace mbed
#endif // DEVICE_RESET_REASON
/**@}*/
#endif // MBED_RESET_REASON_H

View File

@ -42,6 +42,17 @@ typedef enum {
} reset_reason_t;
/** Fetch the reset reason for the last system reset
*
* This function must return the contents of the system reset reason registers
* cast to an appropriate platform independent reset reason. If multiple reset
* reasons are set this function should return RESET_REASON_MULTIPLE. If the
* reset reason does not match any existing platform independent value this
* function should return RESET_REASON_PLATFORM. If no reset reason can be
* determined this function should return RESET_REASON_UNKNOWN.
*
* This function is not idempotent, there is no guarantee that the system
* reset reason will not be cleared between calls to this function altering the
* return value between calls.
*
* Note: Some platforms contain reset reason registers that persist through
* system resets. If the registers haven't been cleared before calling this
@ -54,6 +65,15 @@ reset_reason_t hal_reset_reason_get(void);
/** Fetch the raw platform specific reset reason register value
*
* This function must return the raw contents of the system reset reason
* registers cast to a uint32_t value. If the platform contains reset reasons
* that span multiple registers/addresses the value should be concatenated into
* the return type.
*
* This function is not idempotent, there is no guarantee that the system
* reset reason will not be cleared between calls to this function altering the
* return value between calls.
*
* @return value containing the reset reason register for the given platform.
* If the platform contains reset reasons across multiple registers they