Studentenversion 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.

test_data_channel.c 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #include "test_data_channel.h"
  2. #include "../device_test.h"
  3. #include "../../software/signal_processing/system/data_channel.h"
  4. #include <system.h>
  5. #include <stdio.h>
  6. #include <inttypes.h>
  7. int assert_data_channel_binding_eq( uint32_t base, uint32_t expected ) {
  8. uint32_t binding = data_channel_get_binding( base );
  9. if ( binding != expected ) {
  10. printf( TEST_FAIL " assert_data_channel_binding_eq %" PRIu32 " != %" PRIu32 "\n", expected, binding );
  11. }
  12. return binding;
  13. }
  14. int assert_data_channel_empty( uint32_t base ) {
  15. uint32_t empty = data_channel_is_empty( base );
  16. if ( ! empty ) {
  17. printf( TEST_FAIL " assert_data_channel_empty\n" );
  18. }
  19. return empty;
  20. }
  21. int assert_not_empty( uint32_t base ) {
  22. uint32_t empty = data_channel_is_empty( base );
  23. if ( empty ) {
  24. printf( TEST_FAIL " assert_not_empty\n" );
  25. }
  26. return ! empty;
  27. }
  28. int assert_data_channel_full( uint32_t base ) {
  29. uint32_t full = data_channel_is_full( base );
  30. if ( ! full ) {
  31. printf( TEST_FAIL " assert_data_channel_full\n" );
  32. }
  33. return full;
  34. }
  35. int assert_not_full( uint32_t base ) {
  36. uint32_t full = data_channel_is_full( base );
  37. if ( full ) {
  38. printf( TEST_FAIL " assert_not_full\n" );
  39. }
  40. return ! full;
  41. }
  42. int assert_data_channel_level_eq( uint32_t base, uint32_t expected ) {
  43. uint32_t level = data_channel_level( base );
  44. if ( level != expected ) {
  45. printf( TEST_FAIL " assert_data_channel_level_eq %" PRIu32 " != %" PRIu32 "\n", expected, level );
  46. }
  47. return level == expected;
  48. }
  49. int assert_data_channel_read_eq( uint32_t base, uint32_t expected ) {
  50. uint32_t readdata;
  51. int ret = data_channel_read( base, & readdata );
  52. if ( ret ) {
  53. printf( TEST_FAIL " %s data_channel empty\n", __func__ );
  54. return 0;
  55. }
  56. if ( readdata != expected ) {
  57. printf( TEST_FAIL " %s %" PRIu32 " != %" PRIu32 "\n", __func__, expected, readdata );
  58. return 0;
  59. }
  60. return 1;
  61. }
  62. int test_data_channel_reset_values( uint32_t channel ) {
  63. printf( " %s %" PRIu32 " ...", __func__, channel );
  64. uint32_t base = data_channel_base_from_number( channel );
  65. data_channel_clear( base );
  66. if ( ! assert_data_channel_empty( base ) ) {
  67. return 1;
  68. }
  69. if ( ! assert_not_full( base ) ) {
  70. return 1;
  71. }
  72. if ( ! assert_data_channel_level_eq( base, 0 ) ) {
  73. return 1;
  74. }
  75. printf( TEST_OK "\n" );
  76. return 0;
  77. }
  78. int test_data_channel_sw_single_write_read( uint32_t channel ) {
  79. printf( " %s %" PRIu32 " ...", __func__, channel );
  80. uint32_t base = data_channel_base_from_number( channel );
  81. DataChannelBinding binding = { BINDING_SW, BINDING_SW };
  82. data_channel_bind( base, & binding );
  83. uint32_t value = 0xa5a5f00f;
  84. data_channel_write( base, value );
  85. if ( ! assert_data_channel_level_eq( base, 1 ) ) {
  86. return 1;
  87. }
  88. if ( ! assert_data_channel_read_eq( base, value ) ) {
  89. return 1;
  90. }
  91. printf( TEST_OK "\n" );
  92. return 0;
  93. }
  94. int test_data_channel_sw_fill_read( uint32_t channel ) {
  95. printf( " %s ...", __func__ );
  96. uint32_t base = data_channel_base_from_number( channel );
  97. DataChannelBinding binding = { BINDING_SW, BINDING_SW };
  98. data_channel_bind( base, & binding );
  99. data_channel_clear( base );
  100. if ( ! assert_data_channel_empty( base ) ) {
  101. return 1;
  102. }
  103. printf( " write ..." );
  104. for ( uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i ) {
  105. if ( ! assert_data_channel_level_eq( base, i ) ) {
  106. return 1;
  107. }
  108. data_channel_write( base, i );
  109. }
  110. if ( ! assert_data_channel_full( base ) ) {
  111. return 1;
  112. }
  113. if ( ! assert_data_channel_level_eq( base, 0 ) ) {
  114. return 1;
  115. }
  116. printf( " read ..." );
  117. for ( uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i ) {
  118. assert_data_channel_read_eq( base, i );
  119. if ( ! assert_data_channel_level_eq( base, DATA_CHANNEL_DEPTH - i - 1 ) ) {
  120. return 1;
  121. }
  122. }
  123. if ( ! assert_data_channel_empty( base ) ) {
  124. return 1;
  125. }
  126. if ( ! assert_data_channel_level_eq( base, 0 ) ) {
  127. return 1;
  128. }
  129. printf( TEST_OK "\n" );
  130. return 0;
  131. }
  132. int test_data_channel_sw_fill_clear( uint32_t channel ) {
  133. printf( " %s ...", __func__ );
  134. uint32_t base = data_channel_base_from_number( channel );
  135. DataChannelBinding binding = { BINDING_SW, BINDING_SW };
  136. data_channel_bind( base, & binding );
  137. if ( ! assert_data_channel_empty( base ) ) {
  138. return 1;
  139. }
  140. for ( uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i ) {
  141. if ( ! assert_data_channel_level_eq( base, i ) ) {
  142. return 1;
  143. }
  144. data_channel_write( base, i );
  145. }
  146. if ( ! assert_data_channel_full( base ) ) {
  147. return 1;
  148. }
  149. if ( ! assert_data_channel_level_eq( base, 0 ) ) {
  150. return 1;
  151. }
  152. data_channel_clear( base );
  153. if ( ! assert_data_channel_empty( base ) ) {
  154. return 1;
  155. }
  156. if ( ! assert_data_channel_level_eq( base, 0 ) ) {
  157. return 1;
  158. }
  159. printf( TEST_OK "\n" );
  160. return 0;
  161. }
  162. int test_data_channel( uint32_t channel ) {
  163. int ret = 0;
  164. ret |= test_data_channel_reset_values( channel );
  165. ret |= test_data_channel_sw_single_write_read( channel );
  166. ret |= test_data_channel_sw_fill_read( channel );
  167. ret |= test_data_channel_sw_fill_clear( channel );
  168. return ret;
  169. }
  170. int test_data_channels( void ) {
  171. printf( "%s\n", __func__ );
  172. int ret = 0;
  173. for ( uint32_t i = 0; i < DATA_CHANNEL_COUNT; ++i ) {
  174. ret |= test_data_channel( i );
  175. }
  176. printf( TEST_DONE );
  177. return ret;
  178. }