SAMV71 Xplained Ultra Software Package 1.5

rtt.c

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- */
00002 /*                  Atmel Microcontroller Software Support                      */
00003 /*                       SAM Software Package License                           */
00004 /* ---------------------------------------------------------------------------- */
00005 /* Copyright (c) 2015, Atmel Corporation                                        */
00006 /*                                                                              */
00007 /* All rights reserved.                                                         */
00008 /*                                                                              */
00009 /* Redistribution and use in source and binary forms, with or without           */
00010 /* modification, are permitted provided that the following condition is met:    */
00011 /*                                                                              */
00012 /* - Redistributions of source code must retain the above copyright notice,     */
00013 /* this list of conditions and the disclaimer below.                            */
00014 /*                                                                              */
00015 /* Atmel's name may not be used to endorse or promote products derived from     */
00016 /* this software without specific prior written permission.                     */
00017 /*                                                                              */
00018 /* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR   */
00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE   */
00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,      */
00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  */
00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING         */
00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
00028 /* ---------------------------------------------------------------------------- */
00029 
00030 /** \addtogroup rtt_module Working with RTT
00031  *  \ingroup peripherals_module
00032  * The RTT driver provides the interface to configure and use the RTT
00033  * peripheral.
00034  *
00035  * The Real-time Timer is used to count elapsed seconds.\n
00036  * This timer is clocked by the 32kHz system clock divided by a programmable
00037  * 16-bit value. To be accurate, it is better to use an
00038  * external 32kHz crystal instead of the internal 32kHz RC.\n
00039  *
00040  * To count elapsed seconds, the user could follow these few steps:
00041  * <ul>
00042  * <li>Programming PTPRES in RTT_MR to feeding the timer with a 1Hz signal.</li>
00043  * <li>Writing the bit RTTRST in RTT_MR to restart the timer with new settings.
00044  * </li>
00045  * </ul>
00046  *
00047  * An alarm can be set to happen on second by setting alarm value in RTT_AR.
00048  * Alarm occurrence can be detected by polling or interrupt.
00049  *
00050  * For more accurate information, please look at the RTT section of the
00051  * Datasheet.
00052  *
00053  * Related files :\n
00054  * \ref rtt.c\n
00055  * \ref rtt.h.\n
00056  */
00057 /*@{*/
00058 /*@}*/
00059 
00060 /**
00061  * \file
00062  *
00063  * Implementation of Real Time Timer (RTT) controller.
00064  *
00065  */
00066 
00067 /*----------------------------------------------------------------------------
00068  *        Headers
00069  *----------------------------------------------------------------------------*/
00070 #include "chip.h"
00071 
00072 #include <assert.h>
00073 
00074 /*----------------------------------------------------------------------------
00075  *        Exported functions
00076  *----------------------------------------------------------------------------*/
00077 
00078 /**
00079  * \brief Changes the prescaler value of the given RTT and restarts it.
00080  *
00081  * \note This function disables RTT interrupt sources.
00082  *
00083  * \param rtt  Pointer to a Rtt instance.
00084  * \param prescaler  Prescaler value for the RTT.
00085  */
00086 void RTT_SetPrescaler(Rtt *rtt, uint16_t prescaler)
00087 {
00088     rtt->RTT_MR = (prescaler |  RTT_MR_RTTRST);
00089 }
00090 
00091 /**
00092  * \brief Returns the current value of the RTT timer value.
00093  *
00094  * \param rtt  Pointer to a Rtt instance.
00095  */
00096 uint32_t RTT_GetTime(Rtt *rtt)
00097 {
00098     return rtt->RTT_VR;
00099 }
00100 
00101 /**
00102  * \brief Enables the specified RTT interrupt sources.
00103  *
00104  * \param rtt  Pointer to a Rtt instance.
00105  * \param sources  Bitmask of interrupts to enable.
00106  */
00107 void RTT_EnableIT(Rtt *rtt, uint32_t sources)
00108 {
00109     assert((sources & 0x0004FFFF) == 0);
00110     rtt->RTT_MR |= sources;
00111 }
00112 
00113 /**
00114  * \brief Returns the status register value of the given RTT.
00115  *
00116  * \param rtt  Pointer to an Rtt instance.
00117  */
00118 uint32_t RTT_GetStatus(Rtt *rtt)
00119 {
00120     return rtt->RTT_SR;
00121 }
00122 
00123 /**
00124  * \brief Configures the RTT to generate an alarm at the given time.
00125  *
00126  * \param pRtt  Pointer to an Rtt instance.
00127  * \param time  Alarm time.
00128  */
00129 void RTT_SetAlarm(Rtt *pRtt, uint32_t time)
00130 {
00131     assert(time > 0);
00132 
00133     pRtt->RTT_AR = time - 1;
00134 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines