1 /* ----------------------------------------------------------------------------
\r
2 * ATMEL Microcontroller Software Support
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2008, 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
30 //------------------------------------------------------------------------------
\r
32 //------------------------------------------------------------------------------
\r
37 //------------------------------------------------------------------------------
\r
39 //------------------------------------------------------------------------------
\r
41 //------------------------------------------------------------------------------
\r
42 /// Initialize the Periodic Interval Timer to generate a tick at the specified
\r
43 /// period, given the current master clock frequency.
\r
44 /// \param period Period in µsecond.
\r
45 /// \param pit_frequency Master clock frequency in MHz.
\r
46 //------------------------------------------------------------------------------
\r
47 void PIT_Init(unsigned int period, unsigned int pit_frequency)
\r
49 AT91C_BASE_PITC->PITC_PIMR = period? (period * pit_frequency + 8) >> 4 : 0;
\r
50 AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN;
\r
53 //------------------------------------------------------------------------------
\r
54 /// Set the Periodic Interval Value of the PIT.
\r
55 /// \param piv PIV value to set.
\r
56 //------------------------------------------------------------------------------
\r
57 void PIT_SetPIV(unsigned int piv)
\r
59 AT91C_BASE_PITC->PITC_PIMR = (AT91C_BASE_PITC->PITC_PIMR & AT91C_PITC_PIV)
\r
63 //------------------------------------------------------------------------------
\r
64 /// Enables the PIT if this is not already the case.
\r
65 //------------------------------------------------------------------------------
\r
66 void PIT_Enable(void)
\r
68 AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN;
\r
71 //----------------------------------------------------------------------------
\r
72 /// Enable the PIT periodic interrupt.
\r
73 //----------------------------------------------------------------------------
\r
74 void PIT_EnableIT(void)
\r
76 AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITIEN;
\r
79 //------------------------------------------------------------------------------
\r
80 /// Disables the PIT periodic interrupt.
\r
81 //------------------------------------------------------------------------------
\r
82 void PIT_DisableIT(void)
\r
84 AT91C_BASE_PITC->PITC_PIMR &= ~AT91C_PITC_PITIEN;
\r
87 //------------------------------------------------------------------------------
\r
88 /// Returns the value of the PIT mode register.
\r
89 /// \return PIT_MR value.
\r
90 //------------------------------------------------------------------------------
\r
91 unsigned int PIT_GetMode(void)
\r
93 return AT91C_BASE_PITC->PITC_PIMR;
\r
96 //------------------------------------------------------------------------------
\r
97 /// Returns the value of the PIT status register, clearing it as a side effect.
\r
98 /// \return PIT_SR value.
\r
99 //------------------------------------------------------------------------------
\r
100 unsigned int PIT_GetStatus(void)
\r
102 return AT91C_BASE_PITC->PITC_PISR;
\r
105 //------------------------------------------------------------------------------
\r
106 /// Returns the value of the PIT Image Register, to read PICNT and CPIV without
\r
107 /// clearing the current values.
\r
108 /// \return PIT_PIIR value.
\r
109 //------------------------------------------------------------------------------
\r
110 unsigned int PIT_GetPIIR(void)
\r
112 return AT91C_BASE_PITC->PITC_PIIR;
\r
115 //------------------------------------------------------------------------------
\r
116 /// Returns the value of the PIT Value Register, clearing it as a side effect.
\r
117 /// \return PIT_PIVR value.
\r
118 //------------------------------------------------------------------------------
\r
119 unsigned int PIT_GetPIVR(void)
\r
121 return AT91C_BASE_PITC->PITC_PIVR;
\r