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.

data_channel.c 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "data_channel.h"
  2. #include <system.h>
  3. #include <stdio.h>
  4. #include <io.h>
  5. const uint32_t DATA_CHANNEL_DEPTH = 1024;
  6. const uint32_t DATA_CHANNEL_COUNT = 7;
  7. const uint32_t DATA_CHANNEL_BASE_LIST[] = {
  8. DATA_CHANNEL_0_BASE,
  9. DATA_CHANNEL_1_BASE,
  10. DATA_CHANNEL_2_BASE,
  11. DATA_CHANNEL_3_BASE,
  12. DATA_CHANNEL_4_BASE,
  13. DATA_CHANNEL_5_BASE,
  14. DATA_CHANNEL_6_BASE
  15. };
  16. #define REG_BINDING_OFFSET 0
  17. #define BINDING_SINK_POS 0
  18. #define BINDING_SOURCE_POS 1
  19. #define REG_EMPTY_OFFSET 1
  20. #define REG_FULL_OFFSET 2
  21. #define REG_LEVEL_OFFSET 3
  22. #define REG_SINK_OFFSET 4
  23. #define REG_SOURCE_OFFSET 5
  24. #define REG_CLEAR_OFFSET 6
  25. void data_channel_bind( uint32_t base, const DataChannelBinding * binding ) {
  26. uint32_t value = binding->sink << BINDING_SINK_POS |
  27. binding->source << BINDING_SOURCE_POS;
  28. IOWR( base, REG_BINDING_OFFSET, value );
  29. }
  30. uint32_t data_channel_get_binding( uint32_t base ) {
  31. return IORD( base, REG_BINDING_OFFSET );
  32. }
  33. uint32_t data_channel_is_empty( uint32_t base ) {
  34. return IORD( base, REG_EMPTY_OFFSET );
  35. }
  36. uint32_t data_channel_is_full( uint32_t base ) {
  37. return IORD( base, REG_FULL_OFFSET );
  38. }
  39. uint32_t data_channel_level( uint32_t base ) {
  40. return IORD( base, REG_LEVEL_OFFSET );
  41. }
  42. void data_channel_clear( uint32_t base ) {
  43. IOWR( base, REG_CLEAR_OFFSET, 1 );
  44. }
  45. int data_channel_write( uint32_t base, uint32_t value ) {
  46. if ( data_channel_is_full( base ) ) {
  47. return 1;
  48. }
  49. IOWR( base, REG_SINK_OFFSET, value );
  50. return 0;
  51. }
  52. int data_channel_write_all( uint32_t base, const uint32_t * data, uint32_t len ) {
  53. for ( uint32_t i = 0; i < len; ++i ) {
  54. int ret = data_channel_write( base, data[ i ] );
  55. if ( ret ) return ret;
  56. }
  57. return 0;
  58. }
  59. int data_channel_read( uint32_t base, uint32_t * value ) {
  60. if ( data_channel_is_empty( base ) ) {
  61. return 1;
  62. }
  63. * value = IORD( base, REG_SOURCE_OFFSET );
  64. return 0;
  65. }
  66. int data_channel_read_all( uint32_t base, void * buffer ) {
  67. int i;
  68. for ( i = 0; i < DATA_CHANNEL_DEPTH; ++i ) {
  69. int ret = data_channel_read( base, buffer + i );
  70. if ( ret ) {
  71. break;
  72. }
  73. }
  74. return i;
  75. }
  76. uint32_t data_channel_base_from_number( uint32_t channel ) {
  77. return DATA_CHANNEL_BASE_LIST[ channel ];
  78. }