Loesung des Praktikums Systementwurf - Bjarne Hoesch - Bernhard Schoeffel
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.

HardwareTaskSimulation.cc 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "HardwareTaskSimulation.h"
  2. #include "../../software/signal_processing/system/hardware_task.h"
  3. #include <chrono>
  4. #define REG_START_OFFSET 0
  5. #define REG_STATE_OFFSET 1
  6. #define REG_CYCLE_COUNT_OFFSET 2
  7. #define REG_CONFIG_0_OFFSET 3
  8. #define FREQ 200e6
  9. HardwareTaskSimulation::HardwareTaskSimulation( task_function function )
  10. : state( 0 ),
  11. cycleCount( 0 ),
  12. function( function ) {
  13. }
  14. uint32_t HardwareTaskSimulation::read( uint32_t offset ) const {
  15. switch ( offset ) {
  16. case REG_STATE_OFFSET: return state;
  17. case REG_CYCLE_COUNT_OFFSET: return cycleCount;
  18. case REG_CONFIG_0_OFFSET: return config[ 0 ];
  19. }
  20. return static_cast< uint32_t >( -1 );
  21. }
  22. void HardwareTaskSimulation::write( uint32_t offset, uint32_t value ) {
  23. switch ( offset ) {
  24. case REG_START_OFFSET: start(); break;
  25. case REG_CONFIG_0_OFFSET: config[ 0 ] = value; break;
  26. }
  27. }
  28. void HardwareTaskSimulation::start() {
  29. using namespace std::chrono;
  30. auto start = high_resolution_clock::now();
  31. state = HARDWARE_TASK_RUNNING;
  32. function( config );
  33. state = HARDWARE_TASK_DONE;
  34. auto stop = high_resolution_clock::now();
  35. auto time = duration_cast< duration< double > >( stop - start );
  36. cycleCount = static_cast< uint32_t >( time.count() * FREQ );
  37. }