1 /*
2 * @brief Cyclic Redundancy Check (CRC) generator example.
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2013
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
34 /*****************************************************************************
35 * Private types/enumerations/variables
36 ****************************************************************************/
37
38 /* CRC data test patterns */
39 static const uint8_t bytes[] = {0x38, 0x38, 0x38, 0x38};
40 static const uint16_t words[] = {0x3534, 0x3534, 0x3534, 0x3534};
41 static const uint32_t dwords[] = {0x33323130, 0x33323130, 0x33323130, 0x33323130};
42 static const uint32_t expect[] = {0x56AB, 0x7A89, 0xD7D6, 0x7D27, 0xA6669D7D};
43
44 #define TICKRATE_HZ (10) /* 10 ticks per second */
45 static volatile uint32_t ticks;
46
47 /*****************************************************************************
48 * Public types/enumerations/variables
49 ****************************************************************************/
50
51 /*****************************************************************************
52 * Private functions
53 ****************************************************************************/
54
55 /*****************************************************************************
56 * Public functions
57 ****************************************************************************/
58
59 /**
60 * @brief Handle interrupt from SysTick timer
61 * @return Nothing
62 */
SysTick_Handler(void)63 void SysTick_Handler(void)
64 {
65 ticks++;
66 __SEV();
67 }
68
69 /**
70 * @brief Application main function
71 * @return Does not return
72 * @note This function will not return.
73 */
main(void)74 int main(void)
75 {
76 uint32_t result[6], gencrc;
77
78 /* Board Initialization */
79 SystemCoreClockUpdate();
80 Board_Init();
81
82 /* Chip Initialization */
83 Chip_CRC_Init();
84
85 /* Enable SysTick Timer */
86 SysTick_Config(SystemCoreClock / TICKRATE_HZ);
87
88 /* Loop tests with occasional forced error */
89 while (1) {
90 result[0] = Chip_CRC_CRC8(&bytes[0], 1);
91 result[1] = Chip_CRC_CRC8(bytes, (sizeof(bytes) / sizeof(bytes[0])));
92 result[2] = Chip_CRC_CRC16(&words[0], 1);
93 if (ticks % 2 == 0) {
94 /* introduce bit errors on every other tick */
95 result[2] -= 1;
96 }
97 result[3] = Chip_CRC_CRC16(words, (sizeof(words) / sizeof(words[0])));
98 result[4] = Chip_CRC_CRC32(&dwords[0], 1);
99 result[5] = Chip_CRC_CRC32(dwords, (sizeof(dwords) / sizeof(dwords[0])));
100
101 gencrc = Chip_CRC_CRC32((uint32_t *) result, 5);
102 result[0] = Chip_CRC_CRC32((uint32_t *) expect, 5);
103 if (result[0] != gencrc) {
104 Board_LED_Set(0, true);
105 }
106 else {
107 Board_LED_Set(0, false);
108 }
109
110 /* Wait for tick */
111 __WFE();
112 }
113 return 0;
114 }
115