source: rtems/bsps/arm/atsam/contrib/libraries/libchip/source/rstc.c @ 54aabb7

5
Last change on this file since 54aabb7 was 54aabb7, checked in by Sebastian Huber <sebastian.huber@…>, on 04/22/18 at 13:11:43

bsp/atsam: Move libraries to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/* ---------------------------------------------------------------------------- */
2/*                  Atmel Microcontroller Software Support                      */
3/*                       SAM Software Package License                           */
4/* ---------------------------------------------------------------------------- */
5/* Copyright (c) 2015, Atmel Corporation                                        */
6/*                                                                              */
7/* All rights reserved.                                                         */
8/*                                                                              */
9/* Redistribution and use in source and binary forms, with or without           */
10/* modification, are permitted provided that the following condition is met:    */
11/*                                                                              */
12/* - Redistributions of source code must retain the above copyright notice,     */
13/* this list of conditions and the disclaimer below.                            */
14/*                                                                              */
15/* Atmel's name may not be used to endorse or promote products derived from     */
16/* this software without specific prior written permission.                     */
17/*                                                                              */
18/* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR   */
19/* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
20/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE   */
21/* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,      */
22/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
23/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  */
24/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
25/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING         */
26/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
27/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
28/* ---------------------------------------------------------------------------- */
29
30/** \file */
31/*---------------------------------------------------------------------------
32 *         Headers
33 *---------------------------------------------------------------------------*/
34
35#include <chip.h>
36
37
38/*---------------------------------------------------------------------------
39 *         Exported functions
40 *---------------------------------------------------------------------------*/
41
42/**
43 * Configure the mode of the RSTC peripheral.
44 * The configuration is computed by the lib (RSTC_RMR_*).
45 * \param mr Desired mode configuration.
46 */
47void RSTC_ConfigureMode(uint32_t mr)
48{
49        Rstc *pHw = RSTC;
50        mr &= ~RSTC_MR_KEY_Msk;
51        pHw->RSTC_MR = mr | RSTC_MR_KEY_PASSWD;
52}
53
54/**
55 * Enable/Disable the detection of a low level on the pin NRST as User Reset
56 * \param enable 1 to enable & 0 to disable.
57 */
58void RSTC_SetUserResetEnable(uint8_t enable)
59{
60        Rstc *pHw = RSTC;
61        uint32_t mr = pHw->RSTC_MR & (~RSTC_MR_KEY_Msk);
62
63        if (enable)
64                mr |=  RSTC_MR_URSTEN;
65        else
66                mr &= ~RSTC_MR_URSTEN;
67
68        pHw->RSTC_MR = mr | RSTC_MR_KEY_PASSWD;
69}
70
71/**
72 * Enable/Disable the interrupt of a User Reset (USRTS bit in RSTC_RST).
73 * \param enable 1 to enable & 0 to disable.
74 */
75void RSTC_SetUserResetInterruptEnable(uint8_t enable)
76{
77        Rstc *pHw = RSTC;
78        uint32_t mr = pHw->RSTC_MR & (~RSTC_MR_KEY_Msk);
79
80        if (enable)
81                mr |=  RSTC_MR_URSTIEN;
82        else
83                mr &= ~RSTC_MR_URSTIEN;
84
85        pHw->RSTC_MR = mr | RSTC_MR_KEY_PASSWD;
86}
87
88/**
89 * Setup the external reset length. The length is asserted during a time of
90 * pow(2, powl+1) Slow Clock(32KHz). The duration is between 60us and 2s.
91 * \param powl   Power length defined.
92 */
93void RSTC_SetExtResetLength(uint8_t powl)
94{
95        Rstc *pHw = RSTC;
96        uint32_t mr = pHw->RSTC_MR;
97        mr &= ~(RSTC_MR_KEY_Msk | RSTC_MR_ERSTL_Msk);
98        mr |=  RSTC_MR_ERSTL(powl);
99        pHw->RSTC_MR = mr | RSTC_MR_KEY_PASSWD;
100}
101
102
103/**
104 * Resets the processor.
105 */
106void RSTC_ProcessorReset(void)
107{
108        Rstc *pHw = RSTC;
109        pHw->RSTC_CR = RSTC_CR_PROCRST | RSTC_CR_KEY_PASSWD;
110}
111
112
113/**
114 * Asserts the NRST pin for external resets.
115 */
116void RSTC_ExtReset(void)
117{
118        Rstc *pHw = RSTC;
119        pHw->RSTC_CR = RSTC_CR_EXTRST | RSTC_CR_KEY_PASSWD;
120}
121
122/**
123 * Return NRST pin level (1 or 0).
124 */
125uint8_t RSTC_GetNrstLevel(void)
126{
127        Rstc *pHw = RSTC;
128        return ((pHw->RSTC_SR & RSTC_SR_NRSTL) > 0);
129}
130
131/**
132 * Returns 1 if at least one high-to-low transition of NRST (User Reset) has
133 * been detected since the last read of RSTC_RSR.
134 */
135uint8_t RSTC_IsUserResetDetected(void)
136{
137        Rstc *pHw = RSTC;
138
139        if (pHw->RSTC_SR & RSTC_SR_URSTS)
140                return 1;
141
142        return 0;
143}
144
145/**
146 * Return 1 if a software reset command is being performed by the reset
147 * controller. The reset controller is busy.
148 */
149uint8_t RSTC_IsBusy(void)
150{
151        Rstc *pHw = RSTC;
152
153        if (pHw->RSTC_SR & RSTC_SR_SRCMP)
154                return 1;
155
156        return 0;
157}
158
159/**
160 * Get the status
161 */
162uint32_t RSTC_GetStatus(void)
163{
164        Rstc *pHw = RSTC;
165        return (pHw->RSTC_SR);
166}
167
Note: See TracBrowser for help on using the repository browser.