source: rtems/c/src/lib/libbsp/arm/atsam/libraries/libchip/source/rtt.c @ e1eeb883

5
Last change on this file since e1eeb883 was e1eeb883, checked in by Sebastian Huber <sebastian.huber@…>, on 01/12/16 at 14:34:31

bsp/atsam: Import SAM Software Package

Import selected files of the "SAM V71 / V70 / E70 / S70 Software
Package" obtained from the "SAMV71-XULT GNU Software Package 1.5".

Converted files via dos2unix before import.

Update #2529.

  • Property mode set to 100644
File size: 4.9 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/** \addtogroup rtt_module Working with RTT
31 *  \ingroup peripherals_module
32 * The RTT driver provides the interface to configure and use the RTT
33 * peripheral.
34 *
35 * The Real-time Timer is used to count elapsed seconds.\n
36 * This timer is clocked by the 32kHz system clock divided by a programmable
37 * 16-bit value. To be accurate, it is better to use an
38 * external 32kHz crystal instead of the internal 32kHz RC.\n
39 *
40 * To count elapsed seconds, the user could follow these few steps:
41 * <ul>
42 * <li>Programming PTPRES in RTT_MR to feeding the timer with a 1Hz signal.</li>
43 * <li>Writing the bit RTTRST in RTT_MR to restart the timer with new settings.
44 * </li>
45 * </ul>
46 *
47 * An alarm can be set to happen on second by setting alarm value in RTT_AR.
48 * Alarm occurrence can be detected by polling or interrupt.
49 *
50 * For more accurate information, please look at the RTT section of the
51 * Datasheet.
52 *
53 * Related files :\n
54 * \ref rtt.c\n
55 * \ref rtt.h.\n
56 */
57/*@{*/
58/*@}*/
59
60/**
61 * \file
62 *
63 * Implementation of Real Time Timer (RTT) controller.
64 *
65 */
66
67/*----------------------------------------------------------------------------
68 *        Headers
69 *----------------------------------------------------------------------------*/
70#include "chip.h"
71
72#include <assert.h>
73
74/*----------------------------------------------------------------------------
75 *        Exported functions
76 *----------------------------------------------------------------------------*/
77
78/**
79 * \brief Changes the prescaler value of the given RTT and restarts it.
80 *
81 * \note This function disables RTT interrupt sources.
82 *
83 * \param rtt  Pointer to a Rtt instance.
84 * \param prescaler  Prescaler value for the RTT.
85 */
86void RTT_SetPrescaler(Rtt *rtt, uint16_t prescaler)
87{
88        rtt->RTT_MR = (prescaler |  RTT_MR_RTTRST);
89}
90
91/**
92 * \brief Returns the current value of the RTT timer value.
93 *
94 * \param rtt  Pointer to a Rtt instance.
95 */
96uint32_t RTT_GetTime(Rtt *rtt)
97{
98        return rtt->RTT_VR;
99}
100
101/**
102 * \brief Enables the specified RTT interrupt sources.
103 *
104 * \param rtt  Pointer to a Rtt instance.
105 * \param sources  Bitmask of interrupts to enable.
106 */
107void RTT_EnableIT(Rtt *rtt, uint32_t sources)
108{
109        assert((sources & 0x0004FFFF) == 0);
110        rtt->RTT_MR |= sources;
111}
112
113/**
114 * \brief Returns the status register value of the given RTT.
115 *
116 * \param rtt  Pointer to an Rtt instance.
117 */
118uint32_t RTT_GetStatus(Rtt *rtt)
119{
120        return rtt->RTT_SR;
121}
122
123/**
124 * \brief Configures the RTT to generate an alarm at the given time.
125 *
126 * \param pRtt  Pointer to an Rtt instance.
127 * \param time  Alarm time.
128 */
129void RTT_SetAlarm(Rtt *pRtt, uint32_t time)
130{
131        assert(time > 0);
132
133        pRtt->RTT_AR = time - 1;
134}
Note: See TracBrowser for help on using the repository browser.