iLLD_TC27xC
1.0
IfxFce_Crc.h
Go to the documentation of this file.
1
/**
2
* \file IfxFce_Crc.h
3
* \brief FCE CRC details
4
* \ingroup IfxLld_Fce
5
*
6
* \version iLLD_0_1_0_10
7
* \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
8
*
9
*
10
* IMPORTANT NOTICE
11
*
12
*
13
* Infineon Technologies AG (Infineon) is supplying this file for use
14
* exclusively with Infineon's microcontroller products. This file can be freely
15
* distributed within development tools that are supporting such microcontroller
16
* products.
17
*
18
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21
* INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
22
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23
*
24
*
25
* \defgroup IfxLld_Fce_Crc_Usage How to use the FCE CRC Interface driver?
26
* \ingroup IfxLld_Fce
27
*
28
* FCE gives CRC-x(x= 8,16,32) message signatures. Kernel 3 is used for CRC-8,Kernel 2 is used for CRC-16,Kernel 0 1nd Kernel 1 is used for CRC-32.
29
*
30
* In the following sections it will be described, how to integrate the driver into the application framework.
31
*
32
* \section IfxLld_Fce_Fce_Preparation Preparation
33
* \subsection IfxLld_Fce_Fce_Include Include Files
34
*
35
* Include following header file into your C code:
36
*
37
* \code
38
* #include <IfxFce_Crc.h>
39
* \endcode
40
*
41
* \subsection IfxLld_Fce_Crc_Variables Variables
42
*
43
* Declare the FCE and CRC handles as global variable in your C code:
44
* \code
45
* // used globally
46
* static IfxFce_Crc fce;
47
* static IfxFce_Crc_Crc fceCrc32_0;
48
* static IfxFce_Crc_Crc fceCrc32_1;
49
* static IfxFce_Crc_Crc fceCrc16;
50
* static IfxFce_Crc_Crc fceCrc8;
51
* \endcode
52
*
53
* \subsection IfxLld_Fce_Crc_Interrupt Interrupt Handler Installation
54
*
55
* See also \ref IfxLld_Cpu_Irq_Usage
56
*
57
* Define priorities for the Interrrupt handler. This is normally done in the Ifx_IntPrioDef.h file:
58
* \code
59
* // priorities are normally defined in Ifx_IntPrioDef.h
60
* #define IFX_INTPRIO_FCE 1
61
* \endcode
62
*
63
* Add the interrupt service routine to your C code which should do the error flag handling:
64
* \code
65
* IFX_INTERRUPT(fceISR, 0, IFX_INTPRIO_FCE)
66
* {
67
* {
68
* Ifx_FCE_STS interruptStatus = IfxFce_Crc_getInterruptStatus(&fceCrc32_0);
69
* if (interruptStatus.U )
70
* {
71
* if ( interruptStatus.B.CMF == 1)
72
* {
73
* // CRC Mismatch Error...!
74
* }
75
* if( interruptStatus.B.CEF == 1)
76
* {
77
* // Configuration Error...!
78
* }
79
* if ( interruptStatus.B.LEF == 1)
80
* {
81
* // Length Error...!
82
* }
83
* if ( interruptStatus.B.BEF == 1)
84
* {
85
* // Bus Error...!
86
* }
87
* }
88
* IfxFce_Crc_clearErrorFlags(&fceCrc32_0);
89
* }
90
*
91
* {
92
* Ifx_FCE_STS interruptStatus = IfxFce_Crc_getInterruptStatus(&fceCrc32_1);
93
* if (interruptStatus.U )
94
* {
95
* if ( interruptStatus.B.CMF == 1)
96
* {
97
* // CRC Mismatch Error...!
98
* }
99
* if( interruptStatus.B.CEF == 1)
100
* {
101
* // Configuration Error...!
102
* }
103
* if ( interruptStatus.B.LEF == 1)
104
* {
105
* // Length Error...!
106
* }
107
* if ( interruptStatus.B.BEF == 1)
108
* {
109
* // Bus Error...!
110
* }
111
* }
112
* IfxFce_Crc_clearErrorFlags(&fceCrc32_1);
113
* }
114
*
115
* {
116
* Ifx_FCE_STS interruptStatus = IfxFce_Crc_getInterruptStatus(&fceCrc16);
117
* if (interruptStatus.U )
118
* {
119
* if ( interruptStatus.B.CMF == 1)
120
* {
121
* // CRC Mismatch Error...!
122
* }
123
* if( interruptStatus.B.CEF == 1)
124
* {
125
* // Configuration Error...!
126
* }
127
* if ( interruptStatus.B.LEF == 1)
128
* {
129
* // Length Error...!
130
* }
131
* if ( interruptStatus.B.BEF == 1)
132
* {
133
* // Bus Error...!
134
* }
135
* }
136
* IfxFce_Crc_clearErrorFlags(&fceCrc16);
137
* }
138
*
139
* {
140
* Ifx_FCE_STS interruptStatus = IfxFce_Crc_getInterruptStatus(&fceCrc8);
141
* if (interruptStatus.U )
142
* {
143
* if ( interruptStatus.B.CMF == 1)
144
* {
145
* // CRC Mismatch Error...!
146
* }
147
* if( interruptStatus.B.CEF == 1)
148
* {
149
* // Configuration Error...!
150
* }
151
* if ( interruptStatus.B.LEF == 1)
152
* {
153
* // Length Error...!
154
* }
155
* if ( interruptStatus.B.BEF == 1)
156
* {
157
* // Bus Error...!
158
* }
159
* }
160
* IfxFce_Crc_clearErrorFlags(&fceCrc8);
161
* }
162
* }
163
* \endcode
164
*
165
* Finally install the interrupt handler in your initialisation function:
166
* \code
167
* // install interrupt handler
168
* IfxCpu_Irq_installInterruptHandler(&fceISR, IFX_INTPRIO_FCE);
169
* IfxCpu_enableInterrupts();
170
* \endcode
171
*
172
* \subsection IfxLld_Fce_Fce_InitCrc Module Initialisation
173
*
174
* The module initialisation can be done in the same function. Here an example for all CRC kernels:
175
* \code
176
* // create module config
177
* IfxFce_Crc_Config fceConfig;
178
* IfxFce_Crc_initModuleConfig(&fceConfig, &MODULE_FCE0);
179
*
180
* // ISR priorities and interrupt target
181
* fceConfig.isrPriority = IFX_INTPRIO_FCE;
182
* fceConfig.isrTypeOfService = (IfxSrc_Tos)IfxCpu_getCoreId();
183
*
184
* // initialize module
185
* //IfxFce_Crc fce; // defined globally
186
* IfxFce_Crc_initModule(&fce, &fceConfig);
187
*
188
* // initialize CRC kernels
189
* IfxFce_Crc_CrcConfig crcConfig;
190
* IfxFce_Crc_initCrcConfig(&crcConfig, &fce);
191
*
192
* //IfxFce_Crc_Crc fceCrc32_0; // defined globally
193
* IfxFce_Crc_initCrc(&fceCrc32_0, &crcConfig);
194
*
195
* //IfxFce_Crc_Crc fceCrc32_1; // defined globally
196
* crcConfig.crc32Kernel = IfxFce_Crc32Kernel_1;
197
* IfxFce_Crc_initCrc(&fceCrc32_1, &crcConfig);
198
* crcConfig.crc32Kernel = IfxFce_Crc32Kernel_0;
199
*
200
* //IfxFce_Crc_Crc fceCrc16; // defined globally
201
* crcConfig.crcMode = IfxFce_CrcMode_16;
202
* IfxFce_Crc_initCrc(&fceCrc16, &crcConfig);
203
*
204
* //IfxFce_Crc_Crc fceCrc8; // defined globally
205
* crcConfig.crcMode = IfxFce_CrcMode_8;
206
* IfxFce_Crc_initCrc(&fceCrc8, &crcConfig);
207
* \endcode
208
*
209
* \subsection IfxLld_Fce_Fce_calculateCrc CRC Calculation
210
*
211
* Now, all 4 FCE kernels are configured and can be used to calculate CRC values.
212
*
213
* In following examples, CRC is calculated over following array:
214
* \code
215
* #define CHECK_DATA_SIZE 25
216
* uint32 checkData[CHECK_DATA_SIZE] = {
217
* 0xbe9957bb,
218
* 0x1c706c1e,
219
* 0x14c3db3f,
220
* 0x7fb17a93,
221
* 0xb0d9d5a7,
222
* 0x768093e0,
223
* 0x88b206a0,
224
* 0xc51299e4,
225
* 0xe8a97d48,
226
* 0x89367f27,
227
* 0x70095984,
228
* 0xec030f75,
229
* 0xdc22f8d4,
230
* 0xd951407b,
231
* 0x34ae18c6,
232
* 0x4d47ba7d,
233
* 0x0e2e4622,
234
* 0x4a2e90d3,
235
* 0xdaec3752,
236
* 0xcd3ed11c,
237
* 0x36b416b7,
238
* 0x8ea28658,
239
* 0xdd37eee3,
240
* 0x23928b62,
241
* 0x84eb4b22,
242
* };
243
* \endcode
244
*
245
* Function calls:
246
* \code
247
* // Common usage:
248
* {
249
* uint32 fceCrc = IfxFce_Crc_calculateCrc32(&fceCrc32_0, checkData, CHECK_DATA_SIZE, 0x00000000);
250
*
251
* // -> CRC32 will be 0xd95def75
252
* }
253
*
254
* // Piecewise CRC calculation over two (more more) memory blocks.
255
* // Please note that the initial value requires a bytewise reflection, and an inversion whenever it's passed for the next calculation:
256
* {
257
* uint32 fceCrc;
258
*
259
* fceCrc = IfxFce_Crc_calculateCrc32(&fceCrc32_1, (uint32 *)&checkData[0], CHECK_DATA_SIZE-10, 0x00000000);
260
* fceCrc = IfxFce_Crc_calculateCrc32(&fceCrc32_1, (uint32 *)&checkData[CHECK_DATA_SIZE-10], 10, ~IfxFce_reflectCrc32(fceCrc, 32));
261
*
262
* // -> CRC32 will be 0xd95def75 (as well)
263
* }
264
*
265
* // using the CRC16 kernel
266
* {
267
* uint32 fceCrc;
268
*
269
* fceCrc = IfxFce_Crc_calculateCrc16(&fceCrc16, (uint16 *)checkData, CHECK_DATA_SIZE*2, 0x00000000);
270
*
271
* // -> CRC16 will be 0xda6f
272
* }
273
*
274
* // using the CRC8 kernel
275
* {
276
* uint32 fceCrc;
277
*
278
* fceCrc = IfxFce_Crc_calculateCrc8(&fceCrc8, (uint16 *)checkData, CHECK_DATA_SIZE*4, 0x00000000);
279
*
280
* // -> CRC8 will be 0x61
281
* }
282
* \endcode
283
*
284
* \subsection IfxLld_Fce_Fce_ErrorIRQ Error Interrupt on CRC mismatch
285
*
286
* By default, all error interrupts aside from the CRC mismatch interrupt (CMF) are enabled.
287
*
288
* In order to use the CMF interrupt as well, the appr. error flag has to be enabled during configuration:
289
* \code
290
* // initialize CRC kernel with CRC check enabled
291
* IfxFce_Crc_CrcConfig crcConfig;
292
* IfxFce_Crc_initCrcConfig(&crcConfig, &fce);
293
* crcConfig.enabledInterrupts.crcMismatch = TRUE;
294
* IfxFce_Crc_initCrc(&fceCrc32_0, &crcConfig);
295
* \endcode
296
*
297
* And the expected CRC value has to be written into the expectedCrc field of the handle before the CRC calculation is started.
298
*
299
* \code
300
* {
301
* // Expected CRC:
302
* fceCrc32_0.expectedCrc = 0xd95def75;
303
*
304
* // do calculation
305
* uint32 fceCrc = IfxFce_Crc_calculateCrc32(&fceCrc32_0, checkData, CHECK_DATA_SIZE, 0x00000000);
306
*
307
* // we can expect, that an error interrupt has been triggered if the CRC over checkData didn't match.
308
* }
309
* \endcode
310
*
311
* \defgroup IfxLld_Fce_Crc Crc
312
* \ingroup IfxLld_Fce
313
* \defgroup IfxLld_Fce_Crc_DataStructures Data Structures
314
* \ingroup IfxLld_Fce_Crc
315
* \defgroup IfxLld_Fce_Crc_Module Module Initialise Functions
316
* \ingroup IfxLld_Fce_Crc
317
* \defgroup IfxLld_Fce_Crc_Operative CRC Operation Functions
318
* \ingroup IfxLld_Fce_Crc
319
* \defgroup IfxLld_Fce_Crc_Interrupt Interrupt Status Function
320
* \ingroup IfxLld_Fce_Crc
321
*/
322
323
#ifndef IFXFCE_CRC_H
324
#define IFXFCE_CRC_H 1
325
326
/******************************************************************************/
327
/*----------------------------------Includes----------------------------------*/
328
/******************************************************************************/
329
330
#include "
Fce/Std/IfxFce.h
"
331
332
/******************************************************************************/
333
/*-----------------------------Data Structures--------------------------------*/
334
/******************************************************************************/
335
336
/** \addtogroup IfxLld_Fce_Crc_DataStructures
337
* \{ */
338
/** \brief Specifies the interrupt enable structure
339
*/
340
typedef
struct
341
{
342
boolean
crcMismatch
;
/**< \brief Specifies enabel/disable of CRC mismatch interrupt */
343
boolean
configError
;
/**< \brief Specifies enabel/disable of configuration error interrupt */
344
boolean
lengthError
;
/**< \brief Specifies enabel/disable of length error interrupt */
345
boolean
busError
;
/**< \brief Specifies enabel/disable of bus error interrupt */
346
}
IfxFce_Crc_EnabledInterrupts
;
347
348
/** \} */
349
350
/** \addtogroup IfxLld_Fce_Crc_DataStructures
351
* \{ */
352
/** \brief FCE Module Handle
353
*/
354
typedef
struct
355
{
356
Ifx_FCE *
fce
;
/**< \brief Pointer to FCE registers */
357
}
IfxFce_Crc
;
358
359
/** \brief Configuration structure of the module
360
*/
361
typedef
struct
362
{
363
Ifx_FCE *
fce
;
/**< \brief Pointer to FCE registers */
364
uint16
isrPriority
;
/**< \brief interrupt priority */
365
IfxSrc_Tos
isrTypeOfService
;
/**< \brief type of interrupt service */
366
}
IfxFce_Crc_Config
;
367
368
/** \brief Specifies the pointer to FCE module handler
369
*/
370
typedef
struct
371
{
372
Ifx_FCE *
fce
;
/**< \brief Specifies pointer to FCE module registers */
373
IfxFce_CrcMode
crcMode
;
/**< \brief Specifies the CRC mode */
374
uint32
expectedCrc
;
/**< \brief Specifies the expected CRC to be compared with resulted. */
375
IfxFce_Crc32Kernel
crc32Kernel
;
/**< \brief Specifies the kernel used for CRC-32 */
376
}
IfxFce_Crc_Crc
;
377
378
/** \brief Specifies the module configuration structure
379
*/
380
typedef
struct
381
{
382
Ifx_FCE *
fce
;
/**< \brief Specifies pointer to FCE module registers */
383
boolean
crcCheckCompared
;
/**< \brief Specifies whether CRC check comparision is enabled or not */
384
boolean
automaticLengthReload
;
/**< \brief Specifies the enable/disable of automatic length reload */
385
boolean
dataByteReflectionEnabled
;
/**< \brief Specifies enable/disable of input data byte wise reflection */
386
boolean
crc32BitReflectionEnabled
;
/**< \brief Specifies enable/disable of CRC 32-bit wise reflection */
387
uint32
expectedCrc
;
/**< \brief Specifies the expected CRC to be compared with resulted. */
388
IfxFce_CrcMode
crcMode
;
/**< \brief Specifies the CRC mode */
389
boolean
crcResultInverted
;
/**< \brief Specifies the XOR valueto get the final CRC */
390
IfxFce_Crc32Kernel
crc32Kernel
;
/**< \brief Specifies the kernel used for CRC-32 */
391
IfxFce_Crc_EnabledInterrupts
enabledInterrupts
;
/**< \brief Specifies the interrupt enable structure */
392
}
IfxFce_Crc_CrcConfig
;
393
394
/** \} */
395
396
/** \addtogroup IfxLld_Fce_Crc_Module
397
* \{ */
398
399
/******************************************************************************/
400
/*-------------------------Global Function Prototypes-------------------------*/
401
/******************************************************************************/
402
403
/** \brief Deinitialises the FCE module
404
* \param fce Specifies the pointer to FCE module handler
405
* \return None
406
*
407
* Reset the module
408
*
409
* \code
410
* IfxFce_Crc fce;
411
* //Deinitialise the module
412
* IfxFce_Crc_deInitModule(&fce);
413
* \endcode
414
*
415
*/
416
IFX_EXTERN
void
IfxFce_Crc_deInitModule
(
IfxFce_Crc_Crc
*fce);
417
418
/** \brief Initialise the FCE module for CRC computation according to CRC mode
419
* \param fceCrc Specifies the pointer to CRC handle
420
* \param crcConfig Specifies the FCE CRC configuration structure
421
* \return None
422
*
423
* Usage Example: see \ref IfxLld_Fce_Crc_Usage
424
*
425
*/
426
IFX_EXTERN
void
IfxFce_Crc_initCrc
(
IfxFce_Crc_Crc
*fceCrc,
const
IfxFce_Crc_CrcConfig
*crcConfig);
427
428
/** \brief Initialises the default CRC configuration buffer
429
* \param crcConfig Specifies the FCE CRC configuration structure
430
* \param fce Pointer to the FCE module handle
431
* \return None
432
*
433
* Usage Example: see \ref IfxLld_Fce_Crc_Usage
434
*
435
*/
436
IFX_EXTERN
void
IfxFce_Crc_initCrcConfig
(
IfxFce_Crc_CrcConfig
*crcConfig,
IfxFce_Crc
*fce);
437
438
/**
439
* \param fce module handle
440
* \param config predefined configuration structure of the module
441
* \return None
442
*/
443
IFX_EXTERN
void
IfxFce_Crc_initModule
(
IfxFce_Crc
*fce,
const
IfxFce_Crc_Config
*config);
444
445
/** \brief Fills the config structure with default values
446
* \param config configuration structure of the module
447
* \param fce pointer to FCE registers
448
* \return None
449
*
450
* Usage Example: see \ref IfxLld_Fce_Crc_Usage
451
*
452
*/
453
IFX_EXTERN
void
IfxFce_Crc_initModuleConfig
(
IfxFce_Crc_Config
*config, Ifx_FCE *fce);
454
455
/** \} */
456
457
/** \addtogroup IfxLld_Fce_Crc_Operative
458
* \{ */
459
460
/******************************************************************************/
461
/*-------------------------Global Function Prototypes-------------------------*/
462
/******************************************************************************/
463
464
/** \brief Calculate the XORed 16-bit CRC value and returns it. It takes the precomputed XORed and reversed.
465
* \param fce Specifies the pointer to FCE module handler
466
* \param crcData Length of the input data block
467
* \param crcDataLength Length of the input data block
468
* \param crcStartValue start value for CRC calculation
469
* \return Final CRC after XORed with XOR value.
470
*
471
* Usage Example: see \ref IfxLld_Fce_Crc_Usage
472
*
473
*/
474
IFX_EXTERN
uint16
IfxFce_Crc_calculateCrc16
(
IfxFce_Crc_Crc
*fce,
const
uint16
*crcData,
uint32
crcDataLength,
uint16
crcStartValue);
475
476
/** \brief Calculate the XORed 32-bit CRC value and returns it. It takes the precomputed XORed and reversed.
477
* \param fce Specifies the pointer to FCE module handler
478
* \param crcData pointer to the input data block
479
* \param crcDataLength Length of the input data block
480
* \param crcStartValue start value for CRC calculation
481
* \return Final CRC after XORed with XOR value.
482
*
483
* Usage Example: see \ref IfxLld_Fce_Crc_Usage
484
*
485
*/
486
IFX_EXTERN
uint32
IfxFce_Crc_calculateCrc32
(
IfxFce_Crc_Crc
*fce,
const
uint32
*crcData,
uint32
crcDataLength,
uint32
crcStartValue);
487
488
/** \brief Calculate the XORed 8-bit CRC value and returns it. It takes the precomputed XORed and reversed.
489
* \param fce Specifies the pointer to FCE module handler
490
* \param crcData Length of the input data block
491
* \param crcDataLength Length of the input data block
492
* \param crcStartValue start value for CRC calculation
493
* \return Final CRC after XORed with XOR value.
494
*
495
* Usage Example: see \ref IfxLld_Fce_Crc_Usage
496
*
497
*/
498
IFX_EXTERN
uint8
IfxFce_Crc_calculateCrc8
(
IfxFce_Crc_Crc
*fce,
const
uint8
*crcData,
uint32
crcDataLength,
uint8
crcStartValue);
499
500
/** \} */
501
502
/** \addtogroup IfxLld_Fce_Crc_Interrupt
503
* \{ */
504
505
/******************************************************************************/
506
/*-------------------------Global Function Prototypes-------------------------*/
507
/******************************************************************************/
508
509
/** \brief Clears the error flags
510
* \param fce Specifies the pointer to FCE module handler
511
* \return None
512
*
513
* Usage Example: see \ref IfxLld_Fce_Crc_Usage
514
*
515
*/
516
IFX_EXTERN
void
IfxFce_Crc_clearErrorFlags
(
IfxFce_Crc_Crc
*fce);
517
518
/** \brief Gets the current CRC interrupt status.
519
* \param fce Specifies the pointer to FCE module handler
520
* \return Current interrupt status
521
*
522
* Usage Example: see \ref IfxLld_Fce_Crc_Usage
523
*
524
*/
525
IFX_EXTERN
Ifx_FCE_STS
IfxFce_Crc_getInterruptStatus
(
IfxFce_Crc_Crc
*fce);
526
527
/** \} */
528
529
#endif
/* IFXFCE_CRC_H */
home
mclld
Libraries
release
iLLD_0_1_0_10
src
ifx
TC27xC
Fce
Crc
IfxFce_Crc.h
Generated by
1.8.4