avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] Storing table in flash


From: Preston Wilson
Subject: Re: [avr-chat] Storing table in flash
Date: Sat, 12 Jan 2008 09:40:15 -0500
User-agent: Microsoft-Entourage/11.3.6.070618

"Kreyl" wrote:

>   I'm  writing  table-based  crc16  calculation algoritm. So, I should
> store this table somewhere.
> 
>   Is that enough:
> 
> const uint16_t CRC16_8005_TABLE [256] = {
> 0x0000,0x8005,0x800f,0x000a,0x801b,0x001e,0x0014,0x8011,0x8033,0x0036,0x003c,
> ...
> };
> 
>   Or I need to use somewhat from <avr/pgmspace.h>? If so, how should I
> do that?

Have you looked at avr-libc's crc16 routines?  They are in util/crc16.h and
are written in inline assembly, but they include the equivalent C code above
the function definition.

This is the the code from the comments/documentation for crc16_update(),
which is the routine that I think is equivalent to the one your are
implementing (depends upon how the bits are shifted in [lsb vs msb first]
and the initial value [0x0000 vs 0xffff]):

uint16_t
crc16_update(uint16_t crc, uint8_t a)
{
    int i;

    crc ^= a;
    for (i = 0; i < 8; ++i)
    {
        if (crc & 1)
            crc = (crc >> 1) ^ 0xA001;
        else
            crc = (crc >> 1);
    }

    return crc;
}

And to answer your question, you can use the table as you have defined it if
you have enough memory to do that, but as the routine above shows, crc16
checksums can be done in a much more space efficient manner.

-Preston






reply via email to

[Prev in Thread] Current Thread [Next in Thread]