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.

test_task.c 2.3KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "test_task.h"
  2. #include "../../software/signal_processing/system/task.h"
  3. #include "../../software/signal_processing/system/task_sine.h"
  4. #include "../../software/signal_processing/system/binding.h"
  5. #include "../../software/signal_processing/system/data_channel.h"
  6. #include "../../software/signal_processing/system/float_word.h"
  7. #include "data_channel/test_data_channel.h"
  8. #include "device_test.h"
  9. #include <stdio.h>
  10. #include <system.h>
  11. void write_input_data( uint32_t base, uint32_t binding, void * data ) {
  12. if ( data == NULL ) return;
  13. DataChannelBinding data_channel_binding = { .sink = BINDING_SW, .source = binding };
  14. data_channel_clear( base );
  15. data_channel_bind( base, & data_channel_binding );
  16. data_channel_write_all( base, data, DATA_CHANNEL_DEPTH );
  17. }
  18. int test_task( uint32_t binding, void * task, void * input_a, void * input_b, void * expected, float epsilon ) {
  19. printf( " %s %s ...", __func__, binding_to_string( binding ) );
  20. task_base_config * base = ( task_base_config * ) task;
  21. uint32_t output_channel_base = base->sink;
  22. write_input_data( base->sources[ 0 ], binding, input_a );
  23. write_input_data( base->sources[ 1 ], binding, input_b );
  24. task_bind( task, binding );
  25. DataChannelBinding channel_binding = { .sink = binding, .source = BINDING_SW };
  26. data_channel_clear( output_channel_base );
  27. data_channel_bind( output_channel_base, & channel_binding );
  28. if ( ! assert_data_channel_empty( output_channel_base ) ) {
  29. return 1;
  30. }
  31. task_run( task );
  32. uint32_t cycle_count = task_get_cycle_count( task );
  33. if ( ! assert_data_channel_full( output_channel_base ) ) {
  34. return 1;
  35. }
  36. if ( ! assert_data_channel_level_eq( output_channel_base, 0 ) ) {
  37. return 1;
  38. }
  39. float_word output[ DATA_CHANNEL_DEPTH ];
  40. for ( uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i ) {
  41. data_channel_read( output_channel_base, & output[ i ].word );
  42. }
  43. print_results_for_python( cycle_count, output, DATA_CHANNEL_DEPTH );
  44. float * expected_sine = ( float * ) expected;
  45. for ( uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i ) {
  46. if ( ! assert_float_near( expected_sine[ i ], output[ i ].value, epsilon ) ) {
  47. return 1;
  48. }
  49. }
  50. printf( TEST_OK "\n" );
  51. printf( " cycles: %" PRIu32 "\n", cycle_count );
  52. return 0;
  53. }