]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained/libchip_samv7/source/icm.c
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained / libchip_samv7 / source / icm.c
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2013, 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 ICMLL 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 /** \addtogroup icm_module Working with ICM\r
31  * The TWI driver provides the interface to True Random Number Generator (ICM) passes the American NIST Special Publication 800-22 and Diehard\r
32  Random Tests Suites.\r
33  The ICM may be used as an entropy source for seeding an NIST approved DRNG (Deterministic RNG) as required by\r
34  FIPS PUB 140-2 and 140-3. use the TWI\r
35  * peripheral.\r
36  *\r
37  * \section Usage\r
38  * <ul>\r
39  * <li> Configures a TWI peripheral to operate in master mode, at the given\r
40  * frequency (in Hz) using TWI_Configure(). </li>\r
41  * <li> Sends a STOP condition on the TWI using TWI_Stop().</li>\r
42  * <li> Starts a read operation on the TWI bus with the specified slave using\r
43  * TWI_StartRead(). Data must then be read using TWI_ReadByte() whenever\r
44  * a byte is available (poll using TWI_ByteReceived()).</li>\r
45  * <li> Starts a write operation on the TWI to access the selected slave using\r
46  * TWI_StartWrite(). A byte of data must be provided to start the write;\r
47  * other bytes are written next.</li>\r
48  * <li> Sends a byte of data to one of the TWI slaves on the bus using TWI_WriteByte().\r
49  * This function must be called once before TWI_StartWrite() with the first byte of data\r
50  * to send, then it ICMll be called repeatedly after that to send the remaining bytes.</li>\r
51  * <li> Check if a byte has been received and can be read on the given TWI\r
52  * peripheral using TWI_ByteReceived().<\r
53  * Check if a byte has been sent using TWI_ByteSent().</li>\r
54  * <li> Check if the current transmission is complete (the STOP has been sent)\r
55  * using TWI_TransferComplete().</li>\r
56  * <li> Enables & disable the selected interrupts sources on a TWI peripheral\r
57  * using TWI_EnableIt() and TWI_DisableIt().</li>\r
58  * <li> Get current status register of the given TWI peripheral using\r
59  * TWI_GetStatus(). Get current status register of the given TWI peripheral, but\r
60  * masking interrupt sources which are not currently enabled using\r
61  * TWI_GetMaskedStatus().</li>\r
62  * </ul>\r
63  * For more accurate information, please look at the TWI section of the\r
64  * Datasheet.\r
65  *\r
66  * Related files :\n\r
67  * \ref twi.c\n\r
68  * \ref twi.h.\n\r
69  */\r
70 /*@{*/\r
71 /*@}*/\r
72 \r
73 /**\r
74  * \file\r
75  *\r
76  * Implementation of True Random Number Generator (ICM)\r
77  *\r
78  */\r
79 \r
80 /*----------------------------------------------------------------------------\r
81  *        Headers\r
82  *----------------------------------------------------------------------------*/\r
83 \r
84 #include "chip.h"\r
85 \r
86 /*----------------------------------------------------------------------------\r
87  *        Exported functions\r
88  *----------------------------------------------------------------------------*/\r
89 \r
90 /**\r
91  * \brief Enable ICM, the ICM controller is activated\r
92  */\r
93 void ICM_Enable(void)\r
94 {\r
95     ICM->ICM_CTRL = ICM_CTRL_ENABLE;\r
96 }\r
97 \r
98 /**\r
99  * \brief Disable ICM, if a region is active, this region is terminated\r
100  */\r
101 void ICM_Disable(void)\r
102 {\r
103     ICM->ICM_CTRL = ICM_CTRL_DISABLE;\r
104 }\r
105 \r
106 /**\r
107  * \brief Resets the ICM controller.\r
108  */\r
109 void ICM_SoftReset(void)\r
110 {\r
111     ICM->ICM_CTRL = ICM_CTRL_SWRST;\r
112 }\r
113 \r
114 /**\r
115  * \brief Recompute Internal hash.\r
116  * \param region, When REHASH[region] is set to one, the region digest is re-computed. \r
117  * \note This bit is only available when Region monitoring is disabled.\r
118  */\r
119 void ICM_ReComputeHash(uint8_t region)\r
120 {\r
121     ICM->ICM_CTRL = ICM_CTRL_REHASH(region);\r
122 }\r
123 \r
124 /**\r
125  * \brief Enable region monitoring for given region\r
126  * \param region, When bit RMEN[region] is set to one, the monitoring of Region is activated.\r
127  */\r
128 void ICM_EnableMonitor(uint8_t region)\r
129 {\r
130     ICM->ICM_CTRL = ICM_CTRL_RMEN(region);\r
131 }\r
132 \r
133 /**\r
134  * \brief Disable region monitoring for given region\r
135  * \param region, When bit RMDIS[region] is set to one, the monitoring of Region is disabled.\r
136  */\r
137 void ICM_DisableMonitor(uint8_t region)\r
138 {\r
139     ICM->ICM_CTRL = ICM_CTRL_RMDIS(region);\r
140 }\r
141 \r
142 /**\r
143  * \brief Configures an ICM peripheral with the specified parameters.\r
144  *  \param mode  Desired value for the ICM mode register (see the datasheet).\r
145  */\r
146 void ICM_Configure(uint32_t mode)\r
147 {\r
148     ICM->ICM_CFG = mode; \r
149 }\r
150 \r
151 /**\r
152  * \brief Enables the selected interrupts sources on a ICM peripheral.\r
153  * \param sources  Bitwise OR of selected interrupt sources.\r
154  */\r
155 void ICM_EnableIt(uint32_t sources)\r
156 {\r
157     ICM->ICM_IER = sources;\r
158 }\r
159 \r
160 /**\r
161  * \brief Disables the selected interrupts sources on a ICM peripheral.\r
162  * \param sources  Bitwise OR of selected interrupt sources.\r
163  */\r
164 void ICM_DisableIt(uint32_t sources)\r
165 {\r
166     ICM->ICM_IDR = sources;\r
167 }\r
168 \r
169 /**\r
170  * \brief Get the current interrupt status register of the given ICM peripheral.\r
171  * \return  ICM status register.\r
172  */\r
173 uint32_t ICM_GetIntStatus(void)\r
174 {\r
175     return ICM->ICM_ISR;\r
176 }\r
177 \r
178 /**\r
179  * \brief Get the current status register of the given ICM peripheral.\r
180  * \return  ICM status register.\r
181  */\r
182 uint32_t ICM_GetStatus(void)\r
183 {\r
184     return ICM->ICM_SR;\r
185 }\r
186 \r
187 \r
188 /**\r
189  * \brief Get the undefined access status register of the given ICM peripheral.\r
190  * \return  ICM status register.\r
191  */\r
192 uint32_t ICM_GetUStatus(void)\r
193 {\r
194     return ICM->ICM_UASR;\r
195 }\r
196 \r
197 /**\r
198  * \brief Set descriptor area start address register.\r
199  * \param addr start address\r
200  * \note The start address is a multiple of the total size of the data structure (64 bytes).\r
201  */\r
202 void ICM_SetDescStartAddress(uint32_t addr)\r
203 {\r
204     ICM->ICM_DSCR = addr;\r
205 }\r
206 \r
207 /**\r
208  * \brief Set hash area start address register.\r
209  * \param addr start address\r
210  * \note This field points at the Hash memory location. The address must be a multiple of 128 bytes.\r
211  */\r
212 void ICM_SetHashStartAddress(uint32_t addr)\r
213 {\r
214     ICM->ICM_HASH = addr;\r
215 }\r
216 \r
217 /**\r
218  * \brief Set ICM user initial Hash value register.\r
219  * \param val Initial Hash Value\r
220  */\r
221 void ICM_SetInitHashValue(uint32_t val)\r
222 {\r
223     ICM->ICM_UIHVAL[0] = ICM_UIHVAL_VAL(val);\r
224 }\r
225 \r