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

DataChannelSimulation.cc 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "DataChannelSimulation.h"
  2. #include <iostream>
  3. #define REG_CONFIG_OFFSET 0
  4. #define REG_EMPTY_OFFSET 1
  5. #define REG_FULL_OFFSET 2
  6. #define REG_LEVEL_OFFSET 3
  7. #define REG_SINK_OFFSET 4
  8. #define REG_SOURCE_OFFSET 5
  9. #define REG_CLEAR_OFFSET 6
  10. DataChannelSimulation::DataChannelSimulation()
  11. : config ( 0 )
  12. {
  13. }
  14. DataChannelSimulation::~DataChannelSimulation() {
  15. }
  16. uint32_t DataChannelSimulation::read( uint32_t offset ) {
  17. switch ( offset ) {
  18. case REG_CONFIG_OFFSET: return config;
  19. case REG_EMPTY_OFFSET: return isEmpty();
  20. case REG_FULL_OFFSET: return isFull();
  21. case REG_LEVEL_OFFSET: return fifo.size();
  22. case REG_SOURCE_OFFSET: return read();
  23. }
  24. return static_cast< uint32_t >( -1 );
  25. }
  26. void DataChannelSimulation::write( uint32_t offset, uint32_t value ) {
  27. switch ( offset ) {
  28. case REG_CONFIG_OFFSET: config = value; break;
  29. case REG_SINK_OFFSET: write( value ); break;
  30. case REG_CLEAR_OFFSET: clear(); break;
  31. }
  32. }
  33. uint32_t DataChannelSimulation::read() {
  34. uint32_t value = static_cast< uint32_t >( -1 );
  35. if ( fifo.size() ) {
  36. value = fifo.front();
  37. fifo.pop_front();
  38. }
  39. return value;
  40. }
  41. void DataChannelSimulation::write( uint32_t value ) {
  42. if ( not isFull() ) {
  43. fifo.push_back( value );
  44. }
  45. }
  46. uint32_t DataChannelSimulation::isEmpty() const {
  47. return fifo.size() == 0;
  48. }
  49. uint32_t DataChannelSimulation::isFull() const {
  50. return fifo.size() == MAX_SIZE;
  51. }
  52. void DataChannelSimulation::clear() {
  53. fifo.clear();
  54. }