I'm in the middle of building a debugger for my VM and I am starting to use
the interface to the debugger.  The format of the messages back and forth
from POSEr or the device, require a CRC16 checksum.  I've tried to find some
on the net and have had a very difficult time.  I found one, but I can't
seem to make it work.  Now I am not a C programmer so that I may not have
translated the code properly.  Would anyone have any info on how I can
compute this ?  Info a mere mortal could use.

Here is some code I found, but I don't think it works:


#include <stdlib.h>
#include <stdio.h>

unsigned int crc_16_table[16] = {
  0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401,
  0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400 };

unsigned short int get_crc_16 (int start, char *p, int n) {
  unsigned short int crc = start;
  int r;

  /* while there is more data to process */
  while (n-- > 0) {

    /* compute checksum of lower four bits of *p */
    r = crc_16_table[crc & 0xF];
    crc = (crc >> 4) & 0x0FFF;
    crc = crc ^ r ^ crc_16_table[*p & 0xF];

    /* now compute checksum of upper four bits of *p */
    r = crc_16_table[crc & 0xF];
    crc = (crc >> 4) & 0x0FFF;
    crc = crc ^ r ^ crc_16_table[(*p >> 4) & 0xF];

    /* next... */
    p++;
  }

  return(crc);
}

I can't seem to find tests to see what the result should be.  If anyone has
the source from the Palm ROMs, then maybe it's going to be more
understandble.

Thank you for any help,

-----------------------------
Eric Arseneau ([EMAIL PROTECTED])
Pocket Smalltalk Group
www.PocketSmalltalk.com
Smalltalk-80 for the Palm(R) Computing Platform

Reply via email to