#include "pdma.h"

#define LEN 10000  // lenght of array

int mas[LEN] __attribute__ ((aligned (8))) = { 0 };  // source array
int dst_mas[LEN] __attribute__ ((aligned (8))) = { 0 };

int Flag_Corr = 0;  // ���� ������������ ������ �����

unsigned int CRC32(unsigned int len, unsigned int* buf)  // CRC32 checksum
{
  unsigned int crc_table[256];
  unsigned int crc, i, j;

        for (i = 0; i < 256; i++)
        {
          crc = i;
          for (j = 0; j < 8; j++)
                crc = crc & 1 ? (crc >> 1) ^ 0xedb88320ul : crc >> 1;
          crc_table[i] = crc;
        };
        crc = 0xfffffffful;
        while (len--)
                crc = crc_table[(crc ^ *buf++) & 0xff] ^ (crc >> 8);
        return crc ^ 0xfffffffful;
}

void ZeroArray(int *arr, int len)
{
  int i=0;
  for(i=0; i< len; i++) arr[i] = 0;
}

int main(void)
{
  // initialize of array
  int i;
  for(i=0; i<LEN; i++)
    mas[i] = i;
  unsigned int src_crc = 0;  // checksum of source
  src_crc = CRC32(LEN, (unsigned int*)mas);

  Flag_Corr = 0;
  ZeroArray(dst_mas, LEN);
  unsigned int dst_crc = 0;  // checksum of destination

  unsigned int size =  LEN*sizeof(int);
  pdma_copy(0, dst_mas, mas, size);
  dst_crc = CRC32(LEN, (unsigned int*)dst_mas);

  if (dst_crc == src_crc) Flag_Corr = 1;

  return 0;
}