Mercurial > public > ostc_companion
comparison crcmodel.h @ 11:6fba58c4964b
Minor changes done by automatic style checker
| author | Ideenmodellierer |
|---|---|
| date | Mon, 12 Jan 2026 13:57:24 +0000 |
| parents | 115cfa4a3239 |
| children |
comparison
equal
deleted
inserted
replaced
| 10:9a3c1a6f9833 | 11:6fba58c4964b |
|---|---|
| 99 /* to the Rocksoft^tm Model CRC Algorithm, your CRC algorithm implementation */ | 99 /* to the Rocksoft^tm Model CRC Algorithm, your CRC algorithm implementation */ |
| 100 /* should behave identically to this package under those parameters. */ | 100 /* should behave identically to this package under those parameters. */ |
| 101 /* */ | 101 /* */ |
| 102 /******************************************************************************/ | 102 /******************************************************************************/ |
| 103 | 103 |
| 104 | |
| 105 | |
| 106 #ifndef CRC_MODEL_H | 104 #ifndef CRC_MODEL_H |
| 107 #define CRC_MODEL_H | 105 #define CRC_MODEL_H |
| 108 | |
| 109 | 106 |
| 110 #ifdef __cplusplus | 107 #ifdef __cplusplus |
| 111 extern "C" { | 108 extern "C" { |
| 112 #endif | 109 #endif |
| 113 /******************************************************************************/ | 110 /******************************************************************************/ |
| 118 | 115 |
| 119 #ifndef DONE_STYLE | 116 #ifndef DONE_STYLE |
| 120 | 117 |
| 121 #include <stdbool.h> | 118 #include <stdbool.h> |
| 122 | 119 |
| 123 typedef unsigned long ulong; | 120 typedef unsigned long ulong; |
| 124 typedef unsigned char * p_ubyte_; | 121 typedef unsigned char *p_ubyte_; |
| 125 | 122 |
| 126 #ifndef TRUE | 123 #ifndef TRUE |
| 127 #define FALSE 0 | 124 #define FALSE 0 |
| 128 #define TRUE 1 | 125 #define TRUE 1 |
| 129 #endif | 126 #endif |
| 130 | 127 |
| 131 /* Change to the second definition if you don't have prototypes. */ | 128 /* Change to the second definition if you don't have prototypes. */ |
| 132 #define P_(A) A | 129 #define P_(A) A |
| 133 /* #define P_(A) () */ | 130 /* #define P_(A) () */ |
| 143 /* ----------------------- */ | 140 /* ----------------------- */ |
| 144 /* The following type stores the context of an executing instance of the */ | 141 /* 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 */ | 142 /* model algorithm. Most of the fields are model parameters which must be */ |
| 146 /* set before the first initializing call to cm_ini. */ | 143 /* set before the first initializing call to cm_ini. */ |
| 147 typedef struct | 144 typedef struct |
| 148 { | 145 { |
| 149 int cm_width; /* Parameter: Width in bits [8,32]. */ | 146 int cm_width; /* Parameter: Width in bits [8,32]. */ |
| 150 ulong cm_poly; /* Parameter: The algorithm's polynomial. */ | 147 ulong cm_poly; /* Parameter: The algorithm's polynomial. */ |
| 151 ulong cm_init; /* Parameter: Initial register value. */ | 148 ulong cm_init; /* Parameter: Initial register value. */ |
| 152 bool cm_refin; /* Parameter: Reflect input bytes? */ | 149 bool cm_refin; /* Parameter: Reflect input bytes? */ |
| 153 bool cm_refot; /* Parameter: Reflect output CRC? */ | 150 bool cm_refot; /* Parameter: Reflect output CRC? */ |
| 154 ulong cm_xorot; /* Parameter: XOR this to output CRC. */ | 151 ulong cm_xorot; /* Parameter: XOR this to output CRC. */ |
| 155 | 152 |
| 156 ulong cm_reg; /* Context: Context during execution. */ | 153 ulong cm_reg; /* Context: Context during execution. */ |
| 157 } cm_t; | 154 } cm_t; |
| 158 typedef cm_t *p_cm_t; | 155 typedef cm_t *p_cm_t; |
| 159 | 156 |
| 160 /******************************************************************************/ | 157 /******************************************************************************/ |
| 161 | 158 |
| 162 /* Functions That Implement The Model */ | 159 /* Functions That Implement The Model */ |
| 165 | 162 |
| 166 void cm_ini P_((p_cm_t p_cm)); | 163 void cm_ini P_((p_cm_t p_cm)); |
| 167 /* Initializes the argument CRC model instance. */ | 164 /* Initializes the argument CRC model instance. */ |
| 168 /* All parameter fields must be set before calling this. */ | 165 /* All parameter fields must be set before calling this. */ |
| 169 | 166 |
| 170 void cm_nxt P_((p_cm_t p_cm,int ch)); | 167 void cm_nxt P_((p_cm_t p_cm, int ch)); |
| 171 /* Processes a single message byte [0,255]. */ | 168 /* Processes a single message byte [0,255]. */ |
| 172 | 169 |
| 173 void cm_blk P_((p_cm_t p_cm,p_ubyte_ blk_adr,ulong blk_len)); | 170 void cm_blk P_((p_cm_t p_cm, p_ubyte_ blk_adr, ulong blk_len)); |
| 174 /* Processes a block of message bytes. */ | 171 /* Processes a block of message bytes. */ |
| 175 | 172 |
| 176 ulong cm_crc P_((p_cm_t p_cm)); | 173 ulong cm_crc P_((p_cm_t p_cm)); |
| 177 /* Returns the CRC value for the message bytes processed so far. */ | 174 /* Returns the CRC value for the message bytes processed so far. */ |
| 178 | 175 |
| 181 /* Functions For Table Calculation */ | 178 /* Functions For Table Calculation */ |
| 182 /* ------------------------------- */ | 179 /* ------------------------------- */ |
| 183 /* The following function can be used to calculate a CRC lookup table. */ | 180 /* 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. */ | 181 /* It can also be used at run-time to create or check static tables. */ |
| 185 | 182 |
| 186 ulong cm_tab P_((p_cm_t p_cm,int index)); | 183 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. */ | 184 /* 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 */ | 185 /* 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 */ | 186 /* argument table index in the range [0,255] and returns the table entry in */ |
| 190 /* the bottom cm_width bytes of the return value. */ | 187 /* the bottom cm_width bytes of the return value. */ |
| 191 | 188 |
