1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2011, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
31 /** \addtogroup pit_module Working with PIT
\r
32 * The PIT driver provides the Interface for configuration the Periodic
\r
33 * Interval Timer (PIT) peripheral.
\r
36 * <li> Initialize the PIT with the desired period using PIT_Init().
\r
37 * Alternatively, the Periodic Interval Value (PIV) can be configured
\r
38 * manually using PIT_SetPIV(). </li>
\r
39 * <li> Start the PIT counting using PIT_Enable().
\r
40 * <li> Enable & disable the PIT interrupt using PIT_EnableIT() and
\r
41 * PIT_DisableIT(). </li>
\r
42 * <li> Retrieve the current status of the PIT using PIT_GetStatus(). </li>
\r
43 * <li> To get the current value of the internal counter and the number of ticks
\r
44 * that have occurred, use either PIT_GetPIVR() or PIT_GetPIIR() depending
\r
45 * on whether you want the values to be cleared or not. </li>
\r
48 * For more accurate information, please look at the PIT section of the
\r
61 * Implementation of PIT (Periodic Interval Timer) controller.
\r
64 /*------------------------------------------------------------------------------
\r
66 *------------------------------------------------------------------------------*/
\r
69 /*------------------------------------------------------------------------------
\r
70 * Exported functions
\r
71 *------------------------------------------------------------------------------*/
\r
74 * \brief Initialize the Periodic Interval Timer to generate a tick at the
\r
75 * specified period, given the current master clock frequency.
\r
77 * \param uperiod Period in uSecond.
\r
78 * \param pit_frequency Master clock frequency in MHz.
\r
81 void PIT_Init(uint32_t period, uint32_t pit_frequency)
\r
83 PIT->PIT_MR = period? (period * pit_frequency + 8) >> 4 : 0;
\r
84 PIT->PIT_MR |= PIT_MR_PITEN;
\r
88 * \brief Set the Periodic Interval Value of the PIT.
\r
90 * \param piv PIV value to set.
\r
92 void PIT_SetPIV(uint32_t piv)
\r
94 uint32_t dwMr = PIT->PIT_MR & (~PIT_MR_PIV_Msk);
\r
95 PIT->PIT_MR = dwMr | PIT_MR_PIV(piv);
\r
99 * \brief Enables the PIT if this is not already the case.
\r
102 void PIT_Enable(void)
\r
104 PIT->PIT_MR |= PIT_MR_PITEN;
\r
108 * \brief Disnables the PIT when PIV value is reached.
\r
111 void PIT_Disable(void)
\r
113 PIT->PIT_MR &= ~PIT_MR_PITEN;
\r
117 * \brief Enable the PIT periodic interrupt.
\r
120 void PIT_EnableIT(void)
\r
122 PIT->PIT_MR |= PIT_MR_PITIEN;
\r
126 * \brief Disables the PIT periodic interrupt.
\r
129 void PIT_DisableIT(void)
\r
131 PIT->PIT_MR &= ~PIT_MR_PITIEN;
\r
135 * \brief Returns the value of the PIT mode register.
\r
137 * \return PIT_MR value.
\r
139 uint32_t PIT_GetMode(void)
\r
141 return PIT->PIT_MR;
\r
145 * \brief Returns the value of the PIT status register, clearing it as a side effect.
\r
147 * \return PIT_SR value.
\r
149 uint32_t PIT_GetStatus(void)
\r
151 return PIT->PIT_SR;
\r
155 * \brief Returns the value of the PIT Image Register, to read PICNT and CPIV without
\r
156 * clearing the current values.
\r
158 * \return PIT_PIIR value.
\r
160 uint32_t PIT_GetPIIR(void)
\r
162 return PIT->PIT_PIIR;
\r
166 * \brief Returns the value of the PIT Value Register, clearing it as a side effect.
\r
168 * \return PITC_PIVR value.
\r
170 uint32_t PIT_GetPIVR(void)
\r
172 return PIT->PIT_PIVR;
\r