comparison crcmodel.h @ 5:115cfa4a3239 default tip

Added icon upload function for OSTC 4/5 For the upload the same process as the one for the firmware update is used => CRC functionality has been copied from the ostc_pack SW
author Ideenmodellierer
date Tue, 30 Dec 2025 21:41:02 +0100
parents
children
comparison
equal deleted inserted replaced
4:e30f00f760d3 5:115cfa4a3239
1 ///////////////////////////////////////////////////////////////////////////////
2 /// -*- coding: UTF-8 -*-
3 ///
4 /// \file Discovery/Inc/crcmodel.h
5 /// \brief Rocksoft CRC Model Algorithm
6 /// \author Ross Williams (ross@guest.adelaide.edu.au.) and Heinrichs Weikamp
7 /// \date 3 June 1993
8 ///
9 /// \details
10 ///
11 /// This is the header (.h) file for the reference
12 /// implementation of the Rocksoft^tm Model CRC Algorithm. For more
13 /// information on the Rocksoft^tm Model CRC Algorithm, see the document
14 /// titled "A Painless Guide to CRC Error Detection Algorithms" by Ross
15 /// Williams (ross@guest.adelaide.edu.au.). This document is likely to be in
16 /// "ftp.adelaide.edu.au/pub/rocksoft".
17 ///
18 /// Note: Rocksoft is a trademark of Rocksoft Pty Ltd, Adelaide, Australia.
19 ///
20 /// $Id$
21 ///////////////////////////////////////////////////////////////////////////////
22 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh
23 ///
24 /// This program is free software: you can redistribute it and/or modify
25 /// it under the terms of the GNU General Public License as published by
26 /// the Free Software Foundation, either version 3 of the License, or
27 /// (at your option) any later version.
28 ///
29 /// This program is distributed in the hope that it will be useful,
30 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
31 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 /// GNU General Public License for more details.
33 ///
34 /// You should have received a copy of the GNU General Public License
35 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
36 //////////////////////////////////////////////////////////////////////////////
37
38 /******************************************************************************/
39 /* Start of crcmodel.h */
40 /******************************************************************************/
41 /* */
42 /* Author : Ross Williams (ross@guest.adelaide.edu.au.). */
43 /* Date : 3 June 1993. */
44 /* Status : Public domain. */
45 /* */
46 /* Description : This is the header (.h) file for the reference */
47 /* implementation of the Rocksoft^tm Model CRC Algorithm. For more */
48 /* information on the Rocksoft^tm Model CRC Algorithm, see the document */
49 /* titled "A Painless Guide to CRC Error Detection Algorithms" by Ross */
50 /* Williams (ross@guest.adelaide.edu.au.). This document is likely to be in */
51 /* "ftp.adelaide.edu.au/pub/rocksoft". */
52 /* */
53 /* Note: Rocksoft is a trademark of Rocksoft Pty Ltd, Adelaide, Australia. */
54 /* */
55 /******************************************************************************/
56 /* */
57 /* How to Use This Package */
58 /* ----------------------- */
59 /* Step 1: Declare a variable of type cm_t. Declare another variable */
60 /* (p_cm say) of type p_cm_t and initialize it to point to the first */
61 /* variable (e.g. p_cm_t p_cm = &cm_t). */
62 /* */
63 /* Step 2: Assign values to the parameter fields of the structure. */
64 /* If you don't know what to assign, see the document cited earlier. */
65 /* For example: */
66 /* p_cm->cm_width = 16; */
67 /* p_cm->cm_poly = 0x8005L; */
68 /* p_cm->cm_init = 0L; */
69 /* p_cm->cm_refin = TRUE; */
70 /* p_cm->cm_refot = TRUE; */
71 /* p_cm->cm_xorot = 0L; */
72 /* Note: Poly is specified without its top bit (18005 becomes 8005). */
73 /* Note: Width is one bit less than the raw poly width. */
74 /* */
75 /* Step 3: Initialize the instance with a call cm_ini(p_cm); */
76 /* */
77 /* Step 4: Process zero or more message bytes by placing zero or more */
78 /* successive calls to cm_nxt. Example: cm_nxt(p_cm,ch); */
79 /* */
80 /* Step 5: Extract the CRC value at any time by calling crc = cm_crc(p_cm); */
81 /* If the CRC is a 16-bit value, it will be in the bottom 16 bits. */
82 /* */
83 /******************************************************************************/
84 /* */
85 /* Design Notes */
86 /* ------------ */
87 /* PORTABILITY: This package has been coded very conservatively so that */
88 /* it will run on as many machines as possible. For example, all external */
89 /* identifiers have been restricted to 6 characters and all internal ones to */
90 /* 8 characters. The prefix cm (for Crc Model) is used as an attempt to avoid */
91 /* namespace collisions. This package is endian independent. */
92 /* */
93 /* EFFICIENCY: This package (and its interface) is not designed for */
94 /* speed. The purpose of this package is to act as a well-defined reference */
95 /* model for the specification of CRC algorithms. If you want speed, cook up */
96 /* a specific table-driven implementation as described in the document cited */
97 /* above. This package is designed for validation only; if you have found or */
98 /* implemented a CRC algorithm and wish to describe it as a set of parameters */
99 /* to the Rocksoft^tm Model CRC Algorithm, your CRC algorithm implementation */
100 /* should behave identically to this package under those parameters. */
101 /* */
102 /******************************************************************************/
103
104
105
106 #ifndef CRC_MODEL_H
107 #define CRC_MODEL_H
108
109
110 #ifdef __cplusplus
111 extern "C" {
112 #endif
113 /******************************************************************************/
114
115 /* The following definitions are extracted from my style header file which */
116 /* would be cumbersome to distribute with this package. The DONE_STYLE is the */
117 /* idempotence symbol used in my style header file. */
118
119 #ifndef DONE_STYLE
120
121 #include <stdbool.h>
122
123 typedef unsigned long ulong;
124 typedef unsigned char * p_ubyte_;
125
126 #ifndef TRUE
127 #define FALSE 0
128 #define TRUE 1
129 #endif
130
131 /* Change to the second definition if you don't have prototypes. */
132 #define P_(A) A
133 /* #define P_(A) () */
134
135 /* Uncomment this definition if you don't have void. */
136 /* typedef int void; */
137
138 #endif
139
140 /******************************************************************************/
141
142 /* CRC Model Abstract Type */
143 /* ----------------------- */
144 /* The following type stores the context of an executing instance of the */
145 /* model algorithm. Most of the fields are model parameters which must be */
146 /* set before the first initializing call to cm_ini. */
147 typedef struct
148 {
149 int cm_width; /* Parameter: Width in bits [8,32]. */
150 ulong cm_poly; /* Parameter: The algorithm's polynomial. */
151 ulong cm_init; /* Parameter: Initial register value. */
152 bool cm_refin; /* Parameter: Reflect input bytes? */
153 bool cm_refot; /* Parameter: Reflect output CRC? */
154 ulong cm_xorot; /* Parameter: XOR this to output CRC. */
155
156 ulong cm_reg; /* Context: Context during execution. */
157 } cm_t;
158 typedef cm_t *p_cm_t;
159
160 /******************************************************************************/
161
162 /* Functions That Implement The Model */
163 /* ---------------------------------- */
164 /* The following functions animate the cm_t abstraction. */
165
166 void cm_ini P_((p_cm_t p_cm));
167 /* Initializes the argument CRC model instance. */
168 /* All parameter fields must be set before calling this. */
169
170 void cm_nxt P_((p_cm_t p_cm,int ch));
171 /* Processes a single message byte [0,255]. */
172
173 void cm_blk P_((p_cm_t p_cm,p_ubyte_ blk_adr,ulong blk_len));
174 /* Processes a block of message bytes. */
175
176 ulong cm_crc P_((p_cm_t p_cm));
177 /* Returns the CRC value for the message bytes processed so far. */
178
179 /******************************************************************************/
180
181 /* Functions For Table Calculation */
182 /* ------------------------------- */
183 /* The following function can be used to calculate a CRC lookup table. */
184 /* It can also be used at run-time to create or check static tables. */
185
186 ulong cm_tab P_((p_cm_t p_cm,int index));
187 /* Returns the i'th entry for the lookup table for the specified algorithm. */
188 /* The function examines the fields cm_width, cm_poly, cm_refin, and the */
189 /* argument table index in the range [0,255] and returns the table entry in */
190 /* the bottom cm_width bytes of the return value. */
191
192 /******************************************************************************/
193
194 #ifdef __cplusplus
195 }
196 #endif
197 #endif // CRC_MODEL_H