Browse Source

Add crc initialisation tables and helper functions for hashfast driver.

nfactor-troky
Con Kolivas 11 years ago
parent
commit
45c8d60790
  1. 14
      cgminer.c
  2. 76
      driver-hashfast.c
  3. 5
      driver-hashfast.h

14
cgminer.c

@ -54,6 +54,12 @@ @@ -54,6 +54,12 @@
#include "bench_block.h"
#include "scrypt.h"
#if defined(unix) || defined(__APPLE__)
#include <errno.h>
#include <fcntl.h>
#include <sys/wait.h>
#endif
#ifdef USE_AVALON
#include "driver-avalon.h"
#endif
@ -62,10 +68,8 @@ @@ -62,10 +68,8 @@
#include "driver-bflsc.h"
#endif
#if defined(unix) || defined(__APPLE__)
#include <errno.h>
#include <fcntl.h>
#include <sys/wait.h>
#ifdef USE_HASHFAST
#include "driver-hashfast.h"
#endif
#if defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_AVALON) || defined(USE_MODMINER)
@ -7858,6 +7862,8 @@ int main(int argc, char *argv[]) @@ -7858,6 +7862,8 @@ int main(int argc, char *argv[])
#endif
#ifdef USE_HASHFAST
hf_init_crc8();
hf_init_crc32();
hashfast_drv.drv_detect();
#endif

76
driver-hashfast.c

@ -17,6 +17,82 @@ @@ -17,6 +17,82 @@
#include "driver-hashfast.h"
////////////////////////////////////////////////////////////////////////////////
// Support for the CRC's used in header (CRC-8) and packet body (CRC-32)
////////////////////////////////////////////////////////////////////////////////
#define GP8 0x107 /* x^8 + x^2 + x + 1 */
#define DI8 0x07
static unsigned char crc8_table[256]; /* CRC-8 table */
static uint32_t crc32_table[256]; /* CRC-32 table */
void hf_init_crc8(void)
{
int i,j;
unsigned char crc;
for (i = 0; i < 256; i++) {
crc = i;
for (j = 0; j < 8; j++)
crc = (crc << 1) ^ ((crc & 0x80) ? DI8 : 0);
crc8_table[i] = crc & 0xFF;
}
}
static unsigned char __maybe_unused hf_crc8(unsigned char *h)
{
int i;
unsigned char crc;
h++; // Preamble not included
for (i = 1, crc = 0xff; i < 7; i++)
crc = crc8_table[crc ^ *h++];
return crc;
}
#define DI32 0x04c11db7L
void hf_init_crc32(void)
{
uint32_t i, j;
uint32_t crc;
for (i = 0; i < 256; i++){
crc = i << 24;
for (j = 0; j < 8; j++) {
if (crc & 0x80000000L)
crc = (crc << 1) ^ DI32;
else
crc = (crc << 1);
}
crc32_table[i] = crc;
}
}
static uint32_t __maybe_unused hf_crc32(unsigned char *p, int len, int plug_in)
{
uint32_t crc = 0xffffffffU, crc_sav;
uint32_t i;
while (len--) {
i = ((crc >> 24) ^ *p++) & 0xff;
crc = (crc << 8) ^ crc32_table[i];
}
crc_sav = crc;
applog(LOG_DEBUG, "hf_crc32: crc is 0x%08x", crc);
if (plug_in) {
for (i = 0; i < 4; i++, crc >>= 8)
*p++ = crc & 0xff;
}
return crc_sav;
}
static hf_info_t **hashfast_infos;
struct device_drv hashfast_drv;

5
driver-hashfast.h

@ -216,7 +216,10 @@ typedef struct hf_info_t { @@ -216,7 +216,10 @@ typedef struct hf_info_t {
#define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
ASSERT1(sizeof(uint32_t) == 4);
extern hf_info_t **hashfast_info;
hf_info_t **hashfast_info;
void hf_init_crc8(void);
void hf_init_crc32(void);
#endif /* USE_HASHFAST */
#endif /* HASHFAST_H */

Loading…
Cancel
Save