123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- /*
- ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
- 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.
- */
- /**
- * @file SAMA5D2x/sama_rstc.h
- * @brief SAMA RSTC helper driver header.
- *
- * @addtogroup SAMA5D2x_RSTC
- * @{
- */
- #ifndef _SAMA_RSTC_
- #define _SAMA_RSTC_
- /*===========================================================================*/
- /* Driver constants. */
- /*===========================================================================*/
- /**
- * @name RESET SOURCE MACROS
- * @{
- */
- /**
- * @brief No access allowed.
- */
- #define RSTC_GENERAL 0x0U
- /**
- * @brief Only write access allowed.
- */
- #define RSTC_WKUP 0x1U
- /**
- * @brief Only read access allowed.
- */
- #define RSTC_WDT 0x2U
- /**
- * @brief Read and Write access allowed.
- */
- #define RSTC_SOFT 0x3U
- /**
- * @brief Read and Write access allowed.
- */
- #define RSTC_USER 0x4U
- /** @} */
- /*===========================================================================*/
- /* Driver pre-compile time settings. */
- /*===========================================================================*/
- /*===========================================================================*/
- /* Derived constants and error checks. */
- /*===========================================================================*/
- /*===========================================================================*/
- /* Driver data structures and types. */
- /*===========================================================================*/
- /*===========================================================================*/
- /* Driver macros. */
- /*===========================================================================*/
- /**
- * @name Generic RSTC operations
- * @{
- */
- /**
- * @brief Enable/Disable the detection of a low level on the pin NRST
- * as User Reset.
- * @param[in] enable
- */
- #define rstcSetUserResetEnable(enable) { \
- if (enable) { \
- RSTC->RSTC_MR |= RSTC_MR_URSTEN | RSTC_MR_KEY_PASSWD; \
- } else { \
- RSTC->RSTC_MR &= ~RSTC_MR_URSTEN; \
- RSTC->RSTC_MR |= RSTC_MR_KEY_PASSWD; \
- } \
- }
- /**
- * @brief Enable/Disable the interrupt of a User Reset.
- * @param[in] enable
- */
- #define rstcSetUserResetInterruptEnable(enable) { \
- if (enable) { \
- RSTC->RSTC_MR |= RSTC_MR_URSTIEN | RSTC_MR_KEY_PASSWD; \
- } else { \
- RSTC->RSTC_MR &= ~RSTC_MR_URSTIEN; \
- RSTC->RSTC_MR |= RSTC_MR_KEY_PASSWD; \
- } \
- }
- /**
- * @brief Perform a processor and peripheral reset.
- *
- * @notapi
- */
- #define rstcResetProcessorAndPeripheral() { \
- RSTC->RSTC_CR = RSTC_CR_PERRST | RSTC_CR_PROCRST | RSTC_MR_KEY_PASSWD; \
- }
- /**
- * @brief Perform a processor reset.
- *
- * @notapi
- */
- #define rstcResetProcessor() { \
- RSTC->RSTC_CR = RSTC_CR_PROCRST | RSTC_CR_KEY_PASSWD; \
- }
- /**
- * @brief Perform a peripheral reset.
- *
- * @notapi
- */
- #define rstcResetPeripheral() { \
- RSTC->RSTC_CR = RSTC_CR_PERRST | RSTC_MR_KEY_PASSWD; \
- }
- /**
- * @brief Report the cause of the last processor reset.
- *
- * @param[out] status Cause of the reset
- *
- * @notapi
- */
- #define rstcGetStatus(status) { \
- uint32_t sr = RSTC->RSTC_SR & RSTC_SR_RSTTYP_Msk; \
- switch (sr) { \
- case RSTC_SR_RSTTYP_GENERAL_RST: \
- status = RSTC_GENERAL; \
- break; \
- case RSTC_SR_RSTTYP_WKUP_RST: \
- status = RSTC_WKUP; \
- break; \
- case RSTC_SR_RSTTYP_WDT_RST: \
- status = RSTC_WDT; \
- break; \
- case RSTC_SR_RSTTYP_SOFT_RST: \
- status = RSTC_SOFT; \
- break; \
- case RSTC_SR_RSTTYP_USER_RST: \
- status = RSTC_USER; \
- break; \
- default: \
- break; \
- } \
- }
- /** @} */
- /*===========================================================================*/
- /* External declarations. */
- /*===========================================================================*/
- #ifdef __cplusplus
- extern "C" {
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif /* SAMA_RSTC_H */
- /** @} */
|