GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> PBI / dev > doc_gather / linux-gcc
Defines | |
#define | FletcherDeclare(_prefix) |
Declares the variables needed to implement the Fletcher Checksum. | |
#define | FletcherInitialize(_prefix) |
Initializes the specified set of Fletcher variables. These must have been declared by FletcherDeclare. | |
#define | FletcherConstruct(_prefix) |
Declares and initializes the variables needed to implement the Fletcher Checksum. | |
#define | _FletcherReduce(_prefix) |
#define | FletcherUpdate(_prefix, _val) |
Updates the specified set of Fletcher variables with val. | |
#define | FletcherFinalize(_prefix) |
Finalizes the Fletcher checksum, producing one 32-bit result. |
CVS $Id: Fletcher.h,v 1.1 2007/02/13 02:04:47 russell Exp $
The Fletcher checksum is well documented elsewhere. The reasons it was picked here are
This is implemented as a series of macros so that it may be embedded in other code.
The first parameter of each macro is an prefix to uniquely identify the set of 3 variables needed compute the Fletcher checksum. The update macro takes, as a second parameter, the value used in updating the checksum.
A trivial example would be
unsigned int fetcher_compute (const unsigned short int *array, int cnt) { FletcherDeclare (fcs); FletcherInitialize (fcs); while (--cnt >= 0) { FletcherUpdate (fcs, *array++) } return FletchFinalize (fcs); }
Note that this would not be a very good implementation for something this trivial. The reason is that there is a check buried in the FletcherUpdate macro. But the point of these macros is to able to compute a checksum when the data is not a neatly organized array.
#define _FletcherReduce | ( | _prefix | ) |
Value:
_prefix ## sum1 = (_prefix ## sum1 &0xffff) + (_prefix ## sum1 >> 16), \ _prefix ## sum2 = (_prefix ## sum2 &0xffff) + (_prefix ## sum2 >> 16) \
#define FletcherConstruct | ( | _prefix | ) |
Value:
unsigned int _prefix ## sum1 = 0xffff; \ unsigned int _prefix ## sum2 = 0xffff; \ int _prefix ## cnt = 0 \
_prefix | The prefix used to uniquely identify the variables |
#define FletcherDeclare | ( | _prefix | ) |
Value:
unsigned int _prefix ## sum1; \ unsigned int _prefix ## sum2; \ int _prefix ## cnt \
_prefix | The prefix used to uniquely identify the variables |
#define FletcherFinalize | ( | _prefix | ) |
Value:
( ((_prefix ## cnt) ? _FletcherReduce(_prefix) : 0), \ _FletcherReduce (_prefix), \ ((_prefix ## sum2 << 16) | _prefix ## sum1))
_prefix | A prefix used to make the local names used by this macro unique |
#define FletcherInitialize | ( | _prefix | ) |
Value:
_prefix ## sum1 = 0xffff; \ _prefix ## sum2 = 0xffff; \ _prefix ## cnt = 0
_prefix | The prefix used to uniquely identify the variables |
#define FletcherUpdate | ( | _prefix, | |||
_val | ) |
Value:
_prefix ## sum1 += (_val); \
_prefix ## sum2 += _prefix ## sum1; \
_prefix ## cnt += 1; \
if (_prefix ## cnt == 360) \
{ \
_FletcherReduce(_prefix); \
_prefix ## cnt = 0; \
}
_prefix | The prefix used to uniquely identify the variables | |
_val | The 16 bit value used to update the checksum |