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.

task_sine.c 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "task_sine.h"
  2. #include "hardware_task.h"
  3. #include "sine_config.h"
  4. #include "data_channel.h"
  5. #include "float_word.h"
  6. #include <math.h>
  7. #include <stdio.h>
  8. #include <limits.h>
  9. #include <system.h>
  10. #define REG_STEP_SIZE_OFFSET 0
  11. #define REG_PHASE_OFFSET 1
  12. #define REG_AMPLITUDE_OFFSET 2
  13. sine_config SINE_CONFIG = {
  14. .base = {
  15. .name = "sine",
  16. .binding = BINDING_SW,
  17. .software = task_sine_run,
  18. .configure = task_sine_configure,
  19. .hardware = HARDWARE_TASK_0_BASE,
  20. .sources = { 0, 0 },
  21. .sink = DATA_CHANNEL_0_BASE,
  22. .cycle_count = 0 },
  23. .samples_per_periode = 32,
  24. .phase = 0.0,
  25. .amplitude = 4.0 };
  26. sine_config COSINE_CONFIG = {
  27. .base = { .name = "cosine",
  28. .binding = BINDING_SW,
  29. .software = task_sine_run,
  30. .configure = task_sine_configure,
  31. .hardware = HARDWARE_TASK_1_BASE,
  32. .sources = { 0, 0 },
  33. .sink = DATA_CHANNEL_1_BASE,
  34. .cycle_count = 0 },
  35. .samples_per_periode = 200,
  36. .phase = M_PI / 2.0,
  37. .amplitude = 2.0 };
  38. uint32_t to_hardware_step_size( uint32_t steps ) {
  39. return UINT_MAX / steps + 1;
  40. }
  41. uint32_t to_hardware_phase( float phase ) {
  42. return ( phase / ( 2.0 * M_PI ) ) * UINT_MAX;
  43. }
  44. int task_sine_configure( void * data ) {
  45. sine_config * task = ( sine_config * ) data;
  46. uint32_t base = task->base.hardware;
  47. float_word amplitude;
  48. amplitude.value = task->amplitude;
  49. hardware_task_set_config( base, REG_STEP_SIZE_OFFSET,
  50. to_hardware_step_size( task->samples_per_periode ) );
  51. hardware_task_set_config( base, REG_PHASE_OFFSET,
  52. to_hardware_phase( task->phase ) );
  53. hardware_task_set_config( base, REG_AMPLITUDE_OFFSET, amplitude.word );
  54. return 0;
  55. }