GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> PBI / dev > doc_gather / linux-gcc


Interface   Data Structures   File List   Data Fields   Globals  

Fletcher.h File Reference

Implements the Fletcher checksum algorithm via a series of macros. More...


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.


Detailed Description

Implements the Fletcher checksum algorithm via a series of macros.

Author:
JJRussell - russell@slac.stanford.edu

   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

  1. It is reasonably fast
  2. It works on 16-bit data
  3. It can never produce 0 as a checksum value, so 0 can be used to indicate a not computed checksum

This is implemented as a series of macros so that it may be embedded in other code.

Usage
There are 4 macros
  1. FletcherDeclare
  2. FletcherInitialize
  3. FletcherUpdate
  4. FletcherFinialize
plus one convenience macro that, in effect combines FletcherDeclare and FletchInitialize
  1. FletcherConstruct

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 Documentation

#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               \
Declares and initializes the variables needed to implement the Fletcher Checksum.

Parameters:
_prefix The prefix used to uniquely identify the variables
This macro is more for convenience, essentially combining FletcherDeclare and FletchInitialize.

#define FletcherDeclare ( _prefix   ) 

Value:

unsigned int _prefix ## sum1;                  \
    unsigned int _prefix ## sum2;                  \
    int          _prefix ## cnt                    \
Declares the variables needed to implement the Fletcher Checksum.

Parameters:
_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))
Finalizes the Fletcher checksum, producing one 32-bit result.

Parameters:
_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
Initializes the specified set of Fletcher variables. These must have been declared by FletcherDeclare.

Parameters:
_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;                                                \
  }
Updates the specified set of Fletcher variables with val.

Parameters:
_prefix The prefix used to uniquely identify the variables
_val The 16 bit value used to update the checksum


Generated on Thu Aug 4 14:20:46 2011 by  doxygen 1.5.8