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.

test_crc.c 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "test_crc.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. task_base_config * base = ( task_base_config * ) task;
  20. printf( " %s %s %s ...", __func__, base->name, binding_to_string( binding ) );
  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_level_eq( output_channel_base, 1 ) ) {
  34. return 1;
  35. }
  36. uint32_t output = 0;
  37. data_channel_read( output_channel_base, & output );
  38. uint32_t * expected_crc = ( uint32_t * ) expected;
  39. if ( ! assert_eq( expected_crc[ 0 ], output ) ) {
  40. return 1;
  41. }
  42. printf( TEST_OK "\n" );
  43. printf( " cycles: %" PRIu32 "\n", cycle_count );
  44. return 0;
  45. }