anchao commented on code in PR #18068:
URL: https://github.com/apache/nuttx/pull/18068#discussion_r2719161930


##########
libs/libc/misc/lib_crc16h1021.c:
##########
@@ -0,0 +1,179 @@
+/****************************************************************************
+ * libs/libc/misc/lib_crc16h1021.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* [AUTOSAR_SWS_Crc_00002] The CRC module shall implement the CRC16 routine
+ * based on the CCITT-FALSE CRC16 Standard.
+ *
+ * CRC16 parameters:
+ * CRC result width: 16 bits
+ * Polynomial: 1021h
+ * Initial value: FFFFh
+ * Input data reflected: No
+ * Result data reflected: No
+ * XOR value: 0000h
+ *
+ * [AUTOSAR_SWS_Crc_00054] The Crc_CalculateCRC16 function of the CRC module
+ * shall provide the following CRC results:
+ *
+ * Data bytes (hexadecimal)    |   CRC
+ * 00 00 00 00                 |   84C0
+ * F2 01 83                    |   D374
+ * 0F AA 00 55                 |   2023
+ * 00 FF 55 11                 |   B8F9
+ * 33 22 55 AA BB CC DD EE FF  |   F53F
+ * 92 6B 55                    |   0745
+ * FF FF FF FF                 |   1D0F
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <stdint.h>
+
+#include <nuttx/crc16.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * CRC16 table generated with:
+ *
+ * #include <stdint.h>
+ *
+ * void generate_crc16_table(uint16_t poly, uint16_t *table)
+ * {
+ *   for (int i = 0; i < 256; i++)
+ *     {
+ *       uint16_t crc = (uint16_t)(i << 8);
+ *       for (uint8_t bit = 0; bit < 8; bit++)
+ *         {
+ *           if (crc & 0x8000)
+ *             {
+ *               crc = (crc << 1) ^ polynomial;
+ *             }
+ *           else
+ *             {
+ *               crc = crc << 1;
+ *             }
+ *         }
+ *       crcTable[i] = crc;
+ *     }
+ * }
+ *
+ * int main()
+ * {
+ *   uint16_t crc16_table[256];
+ *   const uint8_t poly = 0x2F;
+ *
+ *   generate_crc16_table(poly, crc16_table);
+ *
+ *   printf("CRC16 Static Table (Poly 0x%02X):\n", poly);
+ *   for (int i = 0; i < 256; i++)
+ *     {
+ *       if (i % 16 == 0) printf("\n");
+ *       printf("0x%02X, ", crc16_table[i]);
+ *     }
+ *
+ *   return 0;
+ * }
+ *
+ ****************************************************************************/
+
+static uint16_t g_crc16_tab[256] =

Review Comment:
   1. add const
   2. move duplicate crc table to separate file



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to