Studentenversion des ESY6/A Praktikums "signal_processing".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

crc.c 946B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "system/task_crc.h"
  2. #include "system/data_channel.h"
  3. #include "system/float_word.h"
  4. //#include <zlib.h> /* c-library for crc32() */
  5. #include <stddef.h> /* for "size_t" */
  6. uint32_t crc32(const char *s,size_t n) {
  7. uint32_t crc=0xFFFFFFFF;
  8. for(size_t i=0;i<n;i++)
  9. {
  10. char ch=s[i];
  11. for(size_t j=0;j<8;j++) {
  12. uint32_t b=(ch^crc)&1;
  13. crc>>=1;
  14. if(b) crc=crc^0xEDB88320;
  15. ch>>=1;
  16. }
  17. }
  18. return ~crc;
  19. }
  20. int task_crc_run( void * task ) {
  21. // TODO
  22. crc_config * crc = ( crc_config * ) task;
  23. uint32_t data_channel_base = crc->base.sink;
  24. data_channel_clear( data_channel_base);
  25. float_word crc_res;
  26. float_word crc_input;
  27. for ( uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i )
  28. {
  29. data_channel_read(crc->base.sources[0], (uint32_t*)&crc_input.value);
  30. crc_res.word = crc32((const void *)&crc_input, sizeof(crc_input));
  31. }
  32. data_channel_write( data_channel_base, crc_res.word );
  33. return 0;
  34. }