| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
crc.c
Go to the documentation of this file.
1 /*
2 * @brief Cyclic Redundancy Check (CRC) generator example.
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 #include "board.h"
33
59 /*****************************************************************************
60 * Private types/enumerations/variables
61 ****************************************************************************/
62
63 /* CRC data test patterns */
64 static const uint8_t bytes[] = {0x38, 0x38, 0x38, 0x38};
65 static const uint16_t words[] = {0x3534, 0x3534, 0x3534, 0x3534};
66 static const uint32_t dwords[] = {0x33323130, 0x33323130, 0x33323130, 0x33323130};
67 static const uint32_t expect[] = {0x56AB, 0x7A89, 0xD7D6, 0x7D27, 0xA6669D7D};
68
69 #define TICKRATE_HZ (10) /* 10 ticks per second */
70 static volatile uint32_t ticks;
71
72 /*****************************************************************************
73 * Public types/enumerations/variables
74 ****************************************************************************/
75
76 /*****************************************************************************
77 * Private functions
78 ****************************************************************************/
79
80 /*****************************************************************************
81 * Public functions
82 ****************************************************************************/
83
88 void SysTick_Handler(void)
89 {
90 ticks++;
91 __SEV();
92 }
93
99 int main(void)
100 {
101 uint32_t result[6], gencrc;
102
103 /* Board Initialization */
104 Board_Init();
105
106 /* Chip Initialization */
107 Chip_CRC_Init();
108
109 /* Enable SysTick Timer */
110 SysTick_Config(SystemCoreClock / TICKRATE_HZ);
111
112 /* Loop tests with occasional forced error */
113 while (1) {
114 result[0] = Chip_CRC_CRC8(&bytes[0], 1);
115 result[1] = Chip_CRC_CRC8(bytes, (sizeof(bytes) / sizeof(bytes[0])));
116 result[2] = Chip_CRC_CRC16(&words[0], 1);
117 if (ticks % 2 == 0) {
118 /* introduce bit errors on every other tick */
119 result[2] -= 1;
120 }
121 result[3] = Chip_CRC_CRC16(words, (sizeof(words) / sizeof(words[0])));
122 result[4] = Chip_CRC_CRC32(&dwords[0], 1);
123 result[5] = Chip_CRC_CRC32(dwords, (sizeof(dwords) / sizeof(dwords[0])));
124
125 gencrc = Chip_CRC_CRC32((uint32_t *) result, 5);
126 result[0] = Chip_CRC_CRC32((uint32_t *) expect, 5);
127 if (result[0] != gencrc) {
128 Board_LED_Set(0, true);
129 }
130 else {
131 Board_LED_Set(0, false);
132 }
133
134 /* Wait for tick */
135 __WFE();
136 }
137 return 0;
138 }
139