PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
crc.c
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3 *
4 * This software is owned and published by:
5 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with Spansion
11 * components. This software is licensed by Spansion to be adapted only
12 * for use in systems utilizing Spansion components. Spansion shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. Spansion is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23 * WARRANTY OF NONINFRINGEMENT.
24 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30 * SAVINGS OR PROFITS,
31 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34 * FROM, THE SOFTWARE.
35 *
36 * This software may be replicated in part or whole for the licensed use,
37 * with the restriction that this Disclaimer and Copyright notice must be
38 * included with each copy of this software, whether used in part or whole,
39 * at all times.
40 */
41 /******************************************************************************/
52 /******************************************************************************/
53 /* Include files */
54 /******************************************************************************/
55 #include "crc.h"
56 
57 #if (defined(PDL_PERIPHERAL_CRC_ACTIVE))
58 
64 
65 /******************************************************************************/
66 /* Local pre-processor symbols/macros ('#define') */
67 /******************************************************************************/
68 
69 /******************************************************************************/
70 /* Global variable definitions (declared in header file with 'extern') */
71 /******************************************************************************/
72 
73 /******************************************************************************/
74 /* Local type definitions ('typedef') */
75 /******************************************************************************/
76 
77 /******************************************************************************/
78 /* Local function prototypes ('static') */
79 /******************************************************************************/
80 
81 /******************************************************************************/
82 /* Local variable definitions ('static') */
83 /******************************************************************************/
84 
85 /******************************************************************************/
86 /* Function implementation - global ('extern') and local ('static') */
87 /******************************************************************************/
88 
89 
102 {
103  en_result_t enResult;
104  stc_crc_crccr_field_t stcCRCCR; /* local preset of CRCCR */
105 
106  /* Check for valid pointers */
107  if (NULL == pstcConfig)
108  {
109  enResult = ErrorInvalidParameter;
110  }
111  else
112  {
113  enResult = Ok;
114  /* Check CRC mode select and setting */
115  switch (pstcConfig->enMode)
116  {
117  case Crc16:
118  /* Set CRC16 */
119  stcCRCCR.CRC32 = FALSE;
120  /* Mask the initial value for 16 bits */
121  pstcConfig->u32CrcInitValue &= 0x0000FFFF;
122  break;
123  case Crc32:
124  /* Set CRC32 */
125  stcCRCCR.CRC32 = TRUE;
126  break;
127  default:
128  enResult = ErrorInvalidParameter;
129  break;
130  }
131 
132  if (Ok == enResult)
133  {
134  /* XOR is executed finaly or not */
135  if (TRUE == pstcConfig->bFinalXor)
136  {
137  stcCRCCR.FXOR = TRUE;
138  }
139  else
140  {
141  stcCRCCR.FXOR = FALSE;
142  }
143  /* Bit order for CRC result */
144  if (TRUE == pstcConfig->bResultLsbFirst)
145  {
146  stcCRCCR.CRCLSF = TRUE;
147  }
148  else
149  {
150  stcCRCCR.CRCLSF = FALSE;
151  }
152  /* Byte order for CRC result */
153  if (TRUE == pstcConfig->bResultLittleEndian)
154  {
155  stcCRCCR.CRCLTE = TRUE;
156  }
157  else
158  {
159  stcCRCCR.CRCLTE = FALSE;
160  }
161  /* Bit order for DATA */
162  if (TRUE == pstcConfig->bDataLsbFirst)
163  {
164  stcCRCCR.LSBFST = TRUE;
165  }
166  else
167  {
168  stcCRCCR.LSBFST = FALSE;
169  }
170  /* Byte order for DATA */
171  if (TRUE == pstcConfig->bDataLittleEndian)
172  {
173  stcCRCCR.LTLEND = TRUE;
174  }
175  else
176  {
177  stcCRCCR.LTLEND = FALSE;
178  }
179  /* Initialize CRC configuration */
180  stcCRCCR.INIT = TRUE;
181 
182  /* Set the initial value */
183  FM4_CRC->CRCINIT = pstcConfig->u32CrcInitValue;
184  /* Write setting to CRC control register */
185  FM4_CRC->CRCCR_f = stcCRCCR;
186  }
187  }
188 
189  return (enResult);
190 } /* Crc_Init */
191 
192 
198 void Crc_DeInit(void)
199 {
200  /* clear hardware */
201  FM4_CRC->CRCIN = 0;
202  FM4_CRC->CRCCR = 0;
203 
204 } /* Crc_DeInit */
205 
213 void Crc_Push8(uint8_t u8DataToPush)
214 {
215  /* Caluculate CRC (Push 8bit data) */
216  FM4_CRC->CRCINLL = u8DataToPush;
217 
218 } /* Crc_Push8 */
219 
230 void Crc_Push16(uint16_t u16DataToPush)
231 {
232  /* Caluculate CRC (Push 16bit data) */
233  FM4_CRC->CRCINL = u16DataToPush;
234 
235 } /* Crc_Push16 */
236 
244 void Crc_Push32(uint32_t u32DataToPush)
245 {
246  /* Caluculate CRC (Push 32bit data) */
247  FM4_CRC->CRCIN = u32DataToPush;
248 
249 } /* Crc_Push32 */
250 
261 uint32_t Crc_ReadResult(void)
262 {
263  /* Return value of CRC result register */
264  return (FM4_CRC->CRCR);
265 } /* Crc_ReadResult */
266 
267 
269 
270 #endif /* #if (defined(PDL_PERIPHERAL_CRC_ACTIVE)) */
271 /******************************************************************************/
272 /* EOF (not truncated) */
273 /******************************************************************************/