Lösung des Praktikums Systementwurf
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.

Hardware.cc 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "Hardware.h"
  2. #include "../../software/signal_processing_bsp/system.h"
  3. #include "../../software/signal_processing/system/task_sine.h"
  4. #include "../../software/signal_processing/system/task_rand.h"
  5. #include "../../software/signal_processing/system/task_add.h"
  6. #include "../../software/signal_processing/system/task_fft.h"
  7. #include "../../software/signal_processing/system/task_crc.h"
  8. Hardware * Hardware::instance = nullptr;
  9. Hardware * Hardware::getInstance() {
  10. if ( Hardware::instance == nullptr ) {
  11. Hardware::instance = new Hardware();
  12. }
  13. return Hardware::instance;
  14. }
  15. Hardware::~Hardware() {
  16. for ( uint32_t i = 0; i < 7; ++i ) {
  17. delete dataChannel[ i ];
  18. }
  19. }
  20. void Hardware::write( uint32_t base, uint32_t offset, uint32_t value ) {
  21. switch ( base ) {
  22. case DATA_CHANNEL_0_BASE: dataChannel[ 0 ]->write( offset, value ); break;
  23. case DATA_CHANNEL_1_BASE: dataChannel[ 1 ]->write( offset, value ); break;
  24. case DATA_CHANNEL_2_BASE: dataChannel[ 2 ]->write( offset, value ); break;
  25. case DATA_CHANNEL_3_BASE: dataChannel[ 3 ]->write( offset, value ); break;
  26. case DATA_CHANNEL_4_BASE: dataChannel[ 4 ]->write( offset, value ); break;
  27. case DATA_CHANNEL_5_BASE: dataChannel[ 5 ]->write( offset, value ); break;
  28. case DATA_CHANNEL_6_BASE: dataChannel[ 6 ]->write( offset, value ); break;
  29. case HARDWARE_TASK_0_BASE: task[ 0 ]->write( offset, value ); break;
  30. case HARDWARE_TASK_1_BASE: task[ 1 ]->write( offset, value ); break;
  31. case HARDWARE_TASK_2_BASE: task[ 2 ]->write( offset, value ); break;
  32. case HARDWARE_TASK_3_BASE: task[ 3 ]->write( offset, value ); break;
  33. case HARDWARE_TASK_4_BASE: task[ 4 ]->write( offset, value ); break;
  34. case HARDWARE_TASK_5_BASE: task[ 5 ]->write( offset, value ); break;
  35. case HARDWARE_TASK_6_BASE: task[ 6 ]->write( offset, value ); break;
  36. };
  37. }
  38. uint32_t Hardware::read( uint32_t base, uint32_t offset ) {
  39. switch ( base ) {
  40. case DATA_CHANNEL_0_BASE: return dataChannel[ 0 ]->read( offset );
  41. case DATA_CHANNEL_1_BASE: return dataChannel[ 1 ]->read( offset );
  42. case DATA_CHANNEL_2_BASE: return dataChannel[ 2 ]->read( offset );
  43. case DATA_CHANNEL_3_BASE: return dataChannel[ 3 ]->read( offset );
  44. case DATA_CHANNEL_4_BASE: return dataChannel[ 4 ]->read( offset );
  45. case DATA_CHANNEL_5_BASE: return dataChannel[ 5 ]->read( offset );
  46. case DATA_CHANNEL_6_BASE: return dataChannel[ 6 ]->read( offset );
  47. case HARDWARE_TASK_0_BASE: return task[ 0 ]->read( offset );
  48. case HARDWARE_TASK_1_BASE: return task[ 1 ]->read( offset );
  49. case HARDWARE_TASK_2_BASE: return task[ 2 ]->read( offset );
  50. case HARDWARE_TASK_3_BASE: return task[ 3 ]->read( offset );
  51. case HARDWARE_TASK_4_BASE: return task[ 4 ]->read( offset );
  52. case HARDWARE_TASK_5_BASE: return task[ 5 ]->read( offset );
  53. case HARDWARE_TASK_6_BASE: return task[ 6 ]->read( offset );
  54. default: return -1;
  55. };
  56. }
  57. Hardware::Hardware() {
  58. task.push_back( new HardwareTaskSimulation( task_sine_run ) );
  59. task.push_back( new HardwareTaskSimulation( task_sine_run ) );
  60. task.push_back( new HardwareTaskSimulation( task_rand_run ) );
  61. task.push_back( new HardwareTaskSimulation( task_add_run ) );
  62. task.push_back( new HardwareTaskSimulation( task_add_run ) );
  63. task.push_back( new HardwareTaskSimulation( task_fft_run ) );
  64. task.push_back( new HardwareTaskSimulation( task_crc_run ) );
  65. for ( uint32_t i = 0; i < 7; ++i ) {
  66. dataChannel.push_back( new DataChannelSimulation() );
  67. }
  68. }