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.

rand.c 1.7KB

1 year ago
10 months ago
1 year ago
10 months ago
1 year ago
10 months ago
1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "system/task_rand.h"
  2. #include "system/hardware_task.h"
  3. #include "system/data_channel.h"
  4. #include "system/float_word.h"
  5. #include <stdio.h>
  6. int task_rand_run( void * data )
  7. {
  8. rand_config * task = ( rand_config * ) data;
  9. uint32_t data_channel_base = task->base.sink;
  10. float seed = task->seed; //1.3
  11. float abs_min = task->abs_min; //0.125
  12. float abs_max = task->abs_max; //9.0
  13. float_word random_number;
  14. random_number.value = seed;
  15. uint32_t mask_bit_0 = 0x1;
  16. uint32_t mask_bit_1 = 0x2;
  17. uint32_t mask_bit_21 = 0x200000;
  18. uint32_t mask_bit_31 = 0x80000000;
  19. uint32_t exponent = 0;
  20. uint32_t shifted_exponent = 0;
  21. uint32_t shifted = 0;
  22. uint32_t shifted_modifiziert = 0;
  23. data_channel_clear( data_channel_base );
  24. for(uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i)
  25. {
  26. //Bits extrahieren:
  27. uint32_t bit_0 = (random_number.word & mask_bit_0) >> 0;
  28. uint32_t bit_1 = (random_number.word & mask_bit_1) >> 1;
  29. uint32_t bit_21 = (random_number.word & mask_bit_21) >> 21;
  30. uint32_t bit_31 = (random_number.word & mask_bit_31) >> 31;
  31. //XOR:
  32. uint32_t xor_result = bit_0 ^ bit_1 ^ bit_21 ^ bit_31;
  33. //Shifted:
  34. shifted = random_number.word >> 1;
  35. //shifted &= ~(0x80000000);
  36. shifted |= (xor_result << 31);
  37. printf("%08x %08x %d \n", random_number.word, shifted, xor_result);
  38. //Skalierung:
  39. #if 1
  40. exponent = (shifted >> 23) & 0xFF;
  41. if(exponent & (1 << 7)){
  42. exponent &= (0b10000001);
  43. }else{
  44. exponent |= (0b01111100);
  45. }
  46. shifted_modifiziert = shifted;
  47. shifted_exponent = exponent << 23;
  48. shifted_modifiziert &= 0x807FFFFF;
  49. shifted_modifiziert |= shifted_exponent;
  50. #endif
  51. random_number.word = shifted_modifiziert;
  52. data_channel_write( data_channel_base, random_number.word );
  53. random_number.word = shifted;
  54. }
  55. return 0;
  56. }