istream.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. *
  3. Copyright (c) Eicon Networks, 2002.
  4. *
  5. This source file is supplied for the use with
  6. Eicon Networks range of DIVA Server Adapters.
  7. *
  8. Eicon File Revision : 2.1
  9. *
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2, or (at your option)
  13. any later version.
  14. *
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY
  17. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. See the GNU General Public License for more details.
  19. *
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include "platform.h"
  26. #if defined(DIVA_ISTREAM) /* { */
  27. #include "pc.h"
  28. #include "pr_pc.h"
  29. #include "di_defs.h"
  30. #include "divasync.h"
  31. #include "di.h"
  32. #if !defined USE_EXTENDED_DEBUGS
  33. #include "dimaint.h"
  34. #else
  35. #define dprintf
  36. #endif
  37. #include "dfifo.h"
  38. int diva_istream_write(void *context,
  39. int Id,
  40. void *data,
  41. int length,
  42. int final,
  43. byte usr1,
  44. byte usr2);
  45. int diva_istream_read(void *context,
  46. int Id,
  47. void *data,
  48. int max_length,
  49. int *final,
  50. byte *usr1,
  51. byte *usr2);
  52. /* -------------------------------------------------------------------
  53. Does provide iStream interface to the client
  54. ------------------------------------------------------------------- */
  55. void diva_xdi_provide_istream_info(ADAPTER *a,
  56. diva_xdi_stream_interface_t *pi) {
  57. pi->provided_service = 0;
  58. }
  59. /* ------------------------------------------------------------------
  60. Does write the data from caller's buffer to the card's
  61. stream interface.
  62. If synchronous service was requested, then function
  63. does return amount of data written to stream.
  64. 'final' does indicate that piece of data to be written is
  65. final part of frame (necessary only by structured datatransfer)
  66. return 0 if zero lengh packet was written
  67. return -1 if stream is full
  68. ------------------------------------------------------------------ */
  69. int diva_istream_write(void *context,
  70. int Id,
  71. void *data,
  72. int length,
  73. int final,
  74. byte usr1,
  75. byte usr2) {
  76. ADAPTER *a = (ADAPTER *)context;
  77. int written = 0, to_write = -1;
  78. char tmp[4];
  79. byte *data_ptr = (byte *)data;
  80. for (;;) {
  81. a->ram_in_dw(a,
  82. #ifdef PLATFORM_GT_32BIT
  83. ULongToPtr(a->tx_stream[Id] + a->tx_pos[Id]),
  84. #else
  85. (void *)(a->tx_stream[Id] + a->tx_pos[Id]),
  86. #endif
  87. (dword *)&tmp[0],
  88. 1);
  89. if (tmp[0] & DIVA_DFIFO_READY) { /* No free blocks more */
  90. if (to_write < 0)
  91. return (-1); /* was not able to write */
  92. break; /* only part of message was written */
  93. }
  94. to_write = min(length, DIVA_DFIFO_DATA_SZ);
  95. if (to_write) {
  96. a->ram_out_buffer(a,
  97. #ifdef PLATFORM_GT_32BIT
  98. ULongToPtr(a->tx_stream[Id] + a->tx_pos[Id] + 4),
  99. #else
  100. (void *)(a->tx_stream[Id] + a->tx_pos[Id] + 4),
  101. #endif
  102. data_ptr,
  103. (word)to_write);
  104. length -= to_write;
  105. written += to_write;
  106. data_ptr += to_write;
  107. }
  108. tmp[1] = (char)to_write;
  109. tmp[0] = (tmp[0] & DIVA_DFIFO_WRAP) |
  110. DIVA_DFIFO_READY |
  111. ((!length && final) ? DIVA_DFIFO_LAST : 0);
  112. if (tmp[0] & DIVA_DFIFO_LAST) {
  113. tmp[2] = usr1;
  114. tmp[3] = usr2;
  115. }
  116. a->ram_out_dw(a,
  117. #ifdef PLATFORM_GT_32BIT
  118. ULongToPtr(a->tx_stream[Id] + a->tx_pos[Id]),
  119. #else
  120. (void *)(a->tx_stream[Id] + a->tx_pos[Id]),
  121. #endif
  122. (dword *)&tmp[0],
  123. 1);
  124. if (tmp[0] & DIVA_DFIFO_WRAP) {
  125. a->tx_pos[Id] = 0;
  126. } else {
  127. a->tx_pos[Id] += DIVA_DFIFO_STEP;
  128. }
  129. if (!length) {
  130. break;
  131. }
  132. }
  133. return (written);
  134. }
  135. /* -------------------------------------------------------------------
  136. In case of SYNCRONOUS service:
  137. Does write data from stream in caller's buffer.
  138. Does return amount of data written to buffer
  139. Final flag is set on return if last part of structured frame
  140. was received
  141. return 0 if zero packet was received
  142. return -1 if stream is empty
  143. return -2 if read buffer does not profide sufficient space
  144. to accommodate entire segment
  145. max_length should be at least 68 bytes
  146. ------------------------------------------------------------------- */
  147. int diva_istream_read(void *context,
  148. int Id,
  149. void *data,
  150. int max_length,
  151. int *final,
  152. byte *usr1,
  153. byte *usr2) {
  154. ADAPTER *a = (ADAPTER *)context;
  155. int read = 0, to_read = -1;
  156. char tmp[4];
  157. byte *data_ptr = (byte *)data;
  158. *final = 0;
  159. for (;;) {
  160. a->ram_in_dw(a,
  161. #ifdef PLATFORM_GT_32BIT
  162. ULongToPtr(a->rx_stream[Id] + a->rx_pos[Id]),
  163. #else
  164. (void *)(a->rx_stream[Id] + a->rx_pos[Id]),
  165. #endif
  166. (dword *)&tmp[0],
  167. 1);
  168. if (tmp[1] > max_length) {
  169. if (to_read < 0)
  170. return (-2); /* was not able to read */
  171. break;
  172. }
  173. if (!(tmp[0] & DIVA_DFIFO_READY)) {
  174. if (to_read < 0)
  175. return (-1); /* was not able to read */
  176. break;
  177. }
  178. to_read = min(max_length, (int)tmp[1]);
  179. if (to_read) {
  180. a->ram_in_buffer(a,
  181. #ifdef PLATFORM_GT_32BIT
  182. ULongToPtr(a->rx_stream[Id] + a->rx_pos[Id] + 4),
  183. #else
  184. (void *)(a->rx_stream[Id] + a->rx_pos[Id] + 4),
  185. #endif
  186. data_ptr,
  187. (word)to_read);
  188. max_length -= to_read;
  189. read += to_read;
  190. data_ptr += to_read;
  191. }
  192. if (tmp[0] & DIVA_DFIFO_LAST) {
  193. *final = 1;
  194. }
  195. tmp[0] &= DIVA_DFIFO_WRAP;
  196. a->ram_out_dw(a,
  197. #ifdef PLATFORM_GT_32BIT
  198. ULongToPtr(a->rx_stream[Id] + a->rx_pos[Id]),
  199. #else
  200. (void *)(a->rx_stream[Id] + a->rx_pos[Id]),
  201. #endif
  202. (dword *)&tmp[0],
  203. 1);
  204. if (tmp[0] & DIVA_DFIFO_WRAP) {
  205. a->rx_pos[Id] = 0;
  206. } else {
  207. a->rx_pos[Id] += DIVA_DFIFO_STEP;
  208. }
  209. if (*final) {
  210. if (usr1)
  211. *usr1 = tmp[2];
  212. if (usr2)
  213. *usr2 = tmp[3];
  214. break;
  215. }
  216. }
  217. return (read);
  218. }
  219. /* ---------------------------------------------------------------------
  220. Does check if one of streams had caused interrupt and does
  221. wake up corresponding application
  222. --------------------------------------------------------------------- */
  223. void pr_stream(ADAPTER *a) {
  224. }
  225. #endif /* } */