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.

task.c 1.6KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "task.h"
  2. #include "task_base_config.h"
  3. #include "binding.h"
  4. #include "hardware_task.h"
  5. #include "hardware_timestamp.h"
  6. #include <stdio.h>
  7. #include <system.h>
  8. int task_configure_and_run_hardware( void * task );
  9. int task_run_software( void * task );
  10. int task_bind( void * task, uint32_t binding ) {
  11. task_base_config * base = ( task_base_config * ) task;
  12. base->binding = binding;
  13. return 0;
  14. }
  15. int task_run( void * task ) {
  16. task_base_config * base = ( task_base_config * ) task;
  17. base->cycle_count = 0;
  18. int ret = 0;
  19. if ( base->binding == BINDING_HW ) {
  20. ret = task_configure_and_run_hardware( task );
  21. }
  22. else {
  23. ret = task_run_software( task );
  24. }
  25. return ret;
  26. }
  27. uint32_t task_get_cycle_count( const void * task ) {
  28. task_base_config * base = ( task_base_config * ) task;
  29. if ( base->binding == BINDING_HW ) {
  30. return hardware_task_get_cycle_count( base->hardware );
  31. }
  32. return base->cycle_count;
  33. }
  34. int task_configure_and_run_hardware( void * task ) {
  35. task_base_config * base = ( task_base_config * ) task;
  36. if ( base->configure != NULL ) {
  37. base->configure( task );
  38. }
  39. hardware_task_start( base->hardware );
  40. while ( hardware_task_get_state( base->hardware ) != HARDWARE_TASK_DONE );
  41. return 0;
  42. }
  43. int task_run_software( void * task ) {
  44. task_base_config * base = ( task_base_config * ) task;
  45. hardware_timestamp_start( HARDWARE_TIMESTAMP_BASE );
  46. int ret = base->software( task );
  47. base->cycle_count = hardware_timestamp( HARDWARE_TIMESTAMP_BASE );
  48. return ret;
  49. }