]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pit/pit.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / CORTEX_AT91SAM3U256_IAR / AT91Lib / peripherals / pit / pit.c
1 /* ----------------------------------------------------------------------------\r
2  *         ATMEL Microcontroller Software Support \r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2008, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\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
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\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
16  *\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
28  */\r
29 \r
30 //------------------------------------------------------------------------------\r
31 //         Headers\r
32 //------------------------------------------------------------------------------\r
33 \r
34 #include "pit.h"\r
35 #include <board.h>\r
36 \r
37 //------------------------------------------------------------------------------\r
38 //         Global functions\r
39 //------------------------------------------------------------------------------\r
40 \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
48 {\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
51 }\r
52 \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
58 {\r
59     AT91C_BASE_PITC->PITC_PIMR = (AT91C_BASE_PITC->PITC_PIMR & AT91C_PITC_PIV)\r
60                                  | piv;\r
61 }\r
62 \r
63 //------------------------------------------------------------------------------\r
64 /// Enables the PIT if this is not already the case.\r
65 //------------------------------------------------------------------------------\r
66 void PIT_Enable(void)\r
67 {\r
68     AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN;\r
69 }\r
70 \r
71 //----------------------------------------------------------------------------\r
72 /// Enable the PIT periodic interrupt.\r
73 //----------------------------------------------------------------------------\r
74 void PIT_EnableIT(void)\r
75 {\r
76     AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITIEN;\r
77 }\r
78 \r
79 //------------------------------------------------------------------------------\r
80 /// Disables the PIT periodic interrupt.\r
81 //------------------------------------------------------------------------------\r
82 void PIT_DisableIT(void)\r
83 {\r
84     AT91C_BASE_PITC->PITC_PIMR &= ~AT91C_PITC_PITIEN;\r
85 }\r
86 \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
92 {\r
93     return AT91C_BASE_PITC->PITC_PIMR;\r
94 }\r
95 \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
101 {\r
102     return AT91C_BASE_PITC->PITC_PISR;\r
103 }\r
104 \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
111 {\r
112     return AT91C_BASE_PITC->PITC_PIIR;\r
113 }\r
114 \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
120 {\r
121     return AT91C_BASE_PITC->PITC_PIVR;\r
122 }\r