F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
TableGenerator.c
Go to the documentation of this file.
1 // Copyright 2025 California Institute of Technology
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // SPDX-License-Identifier: Apache-2.0
16 
17 /*
18  This file contains a CRC32 table generator based on the implementation from
19  https://create.stephan-brumme.com/crc32/#sarwate.
20 
21  Here is the original software license:
22 
23  This software is provided 'as-is', without any express or implied
24  warranty. In no event will the authors be held liable for any damages
25  arising from the use of this software.
26 
27  Permission is granted to anyone to use this software for any purpose,
28  including commercial applications, and to alter it and redistribute it
29  freely, subject to the following restrictions:
30 
31  1. The origin of this software must not be misrepresented; you must not
32  claim that you wrote the original software. If you use this software
33  in a product, an acknowledgment in the product documentation would be
34  appreciated but is not required.
35  2. Altered source versions must be plainly marked as such, and must not be
36  misrepresented as being the original software.
37  3. This notice may not be removed or altered from any source distribution.
38 */
39 
40 #include <stdint.h>
41 #include <stdio.h>
42 
43 int main(int argc, char* argv[]) {
44  uint32_t polynomial = 0xEDB88320;
45 
46  uint32_t Crc32Lookup[4][0x100];
47 
48  for (uint32_t i = 0; i < 0x100; i++) {
49  uint32_t crc = i;
50  for (uint32_t j = 0; j < 8; j++) {
51  crc = (crc >> 1) ^ (-(uint32_t)(crc & 1) & polynomial);
52  }
53  Crc32Lookup[0][i] = crc;
54  }
55  for (uint32_t i = 0; i < 0x100; i++) {
56  Crc32Lookup[1][i] = (Crc32Lookup[0][i] >> 8) ^ Crc32Lookup[0][Crc32Lookup[0][i] & 0xFF];
57  Crc32Lookup[2][i] = (Crc32Lookup[1][i] >> 8) ^ Crc32Lookup[0][Crc32Lookup[1][i] & 0xFF];
58  Crc32Lookup[3][i] = (Crc32Lookup[2][i] >> 8) ^ Crc32Lookup[0][Crc32Lookup[2][i] & 0xFF];
59  }
60 
61  for (uint32_t k = 0; k < 4; k++) {
62  printf("static const U32 crc32_ieee802_3_lookup%d[256] = {", k);
63  for (uint32_t i = 0; i < 0x100; i++) {
64  if (i % 4 == 0) {
65  printf("\n ");
66  }
67  printf(" 0x%08X,", Crc32Lookup[k][i]);
68  }
69  printf("\n};\n");
70  }
71  return 0;
72 }
int main(int argc, char *argv[])