bool generateErrorCorrectionCode(const byte* const data, int dataSize, byte* dest, int ecBlocks) { if (!data || !dest) { error("Cannot calculate Error correction, inputData or Dest is NULL"); return 0; } /* first get de Generator Polinomial */ const byte* genpoly = get_gp(ecBlocks); if (!genpoly) { error("Cannot calculate Error correction, coudn't retreive Generator Polynomial"); return false; } int totalSize = dataSize + ecBlocks; int i; byte* errorCorrection = (byte*)calloc(totalSize, sizeof(char)); /* put the data in the first elements of the errrCorrection Array */ for (i = 0; i < dataSize; i++) { errorCorrection[i] = data[i]; } /* for every element of data, add the alphas from the data-array with the generator polinomial, * and XOR its primitive Value with the current dataElement */ for (i = 0; i < dataSize; i++) { byte add = petoal(errorCorrection[i]); /* alpha value of first dataBlock that is not 0*/ int j; for (j = 0; j < ecBlocks+1; j++) { unsigned int alpha = add + genpoly[j]; if (alpha >255U) alpha -= 255U; // alpha mustn't overflow errorCorrection[j+i] = altope(alpha) ^ errorCorrection[j+i]; } } memcpy(dest, errorCorrection + dataSize, ecBlocks); //copy the errorCorrection Codes to the output Parameter free(errorCorrection); return true; }
int main() { char test2[] = "Lokalerstr"; char *str = test2; uint32_t i; // for (i = 0; i < 4; i++) // test2[i] = 'l'; // glob[0] = 'g'; // Initialize stuff uart_init(); // Say Hello! uart_putstr( "** Spike Test Firmware **\n" ); // Initialize TIC isr_init(); tic_init(); irq_set_mask( 0x00000002 ); irq_enable(); // Say Hello! uart_putstr( "Timer Interrupt instelled.\n" ); // Do some trivial tests uart_putstr( "Subroutine-Return Test: " ); test(); uart_putchar('\n'); uart_putstr( "Local-Pointer Test:" ); for (;*str; str++) { uart_putchar(*str); } uart_putchar('\n'); uart_putstr( "Global-Pointer Test:" ); str = glob; for (;*str; str++) { uart_putchar(*str); } uart_putchar('\n'); uart_putstr( "Stack Pointer : " ); writeint(get_sp()); uart_putchar('\n'); uart_putstr( "Global Pointer: " ); writeint(get_gp()); uart_putchar('\n'); uart_putstr( "Timer Test (1s): " ); for(i=0; i<4; i++) { uart_putstr("tic..."); msleep(1000); } uart_putchar('\n'); uart_putstr( "Timer Interrupt counter: " ); writeint( tic_msec ); uart_putchar('\n'); int val = tic_msec; uart_putstr( "Shift: " ); writeint( val ); uart_putstr(" <-> "); for(i=0; i<32; i++) { if (val & 0x80000000) uart_putchar( '1' ); else uart_putchar( '0' ); val <<= 1; } uart_putstr("\r\n"); uart_putstr( "GPIO Test..." ); gpio0->oe = 0x000000ff; for(;;) { for(i=0; i<8; i++) { uint32_t out1, out2; out1 = 0x01 << i; out2 = 0x80 >> i; gpio0->out = out1 | out2; msleep(100); } } /* uart_putstr( "Memory Dump: " ); uint32_t *start = (uint32_t *)0x40000000; uint32_t *end = (uint32_t *)0x40000100; uint32_t *p; for (p=start; p<end; p++) { if (((uint32_t)p & 12) == 0) { uart_putstr("\r\n["); writeint((uint32_t) p); uart_putchar(']'); } uart_putchar(' '); writeint(*p); } */ uart_putstr("Entering Echo Test...\n"); while (1) { uart_putchar(uart_getchar()); } }