unix_devs.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef _DEV_UNIX_DEVS_H_
  2. #define _DEV_UNIX_DEVS_H_
  3. /*
  4. * Copyright (C) 2000-2004 by ETH Zurich
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ETH ZURICH AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ETH ZURICH
  23. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. */
  35. /* unix_devs.h - a nut/os device driver for native unix devices
  36. *
  37. * 2004.04.01 Matthias Ringwald <matthias.ringwald@inf.ethz.ch>
  38. *
  39. */
  40. /*
  41. * $Log: unix_devs.h,v $
  42. * Revision 1.8 2005/08/02 17:46:48 haraldkipp
  43. * Major API documentation update.
  44. *
  45. * Revision 1.7 2005/04/04 19:35:06 freckle
  46. * added socket redirection feature for unix emulation uarts. Every nut/os
  47. * uart device can now be mapped to a TCP/IP socket using the
  48. * "-u{0/1/2} hostname:port" command line option
  49. *
  50. * Revision 1.6 2004/08/09 21:31:30 freckle
  51. * Added include/dev/unix_devs.h changes
  52. *
  53. * Revision 1.5 2004/08/05 12:13:56 freckle
  54. * Added unix emulation hook in NutThreadYield to safely process
  55. * NutPostEventAsync calls occuring in non Nut/OS threads.
  56. * Rewrote the unix read function again using the new unix NutThreadYield hook
  57. * to call the NutPostEventAsync function safely (fast & correct).
  58. * _write(nf, 0, 0) aka fflush is ignored on unix emulation.
  59. *
  60. * Revision 1.4 2004/06/22 09:00:00 freckle
  61. * Further work on unix_dev emulation. Multiple parallel reads don't block
  62. * each other. Still, dead-locks occure.
  63. * STDIO is set to non-blocking.
  64. *
  65. * Revision 1.3 2004/06/21 10:57:25 freckle
  66. * dev/unix_devs.c: read operation is using extra pthread to only block the
  67. * current thread instead of all threads
  68. *
  69. * Revision 1.2 2004/04/16 17:50:35 freckle
  70. * Implemented the most common _IOCTL calls
  71. * Added block read functionality to read call
  72. *
  73. * Revision 1.1 2004/04/07 12:13:57 haraldkipp
  74. * Matthias Ringwald's *nix emulation added
  75. *
  76. */
  77. #include <pthread.h>
  78. #include <sys/device.h>
  79. #include <dev/netbuf.h>
  80. #ifdef __cplusplus
  81. extern "C" {
  82. #endif
  83. /*!
  84. * \addtogroup xgNutArchUnix
  85. */
  86. /*@{*/
  87. // int UnixDevIOCTL(NUTDEVICE * dev, int req, void *conf);
  88. /*
  89. * Available devices.
  90. */
  91. extern NUTDEVICE devUart0;
  92. extern NUTDEVICE devUart1;
  93. extern NUTDEVICE devUart2;
  94. extern NUTDEVICE devUsartAvr0;
  95. extern NUTDEVICE devUsartAvr1;
  96. extern NUTDEVICE devUsartAvr2;
  97. extern NUTDEVICE devDebug0;
  98. extern NUTDEVICE devDebug1;
  99. extern NUTDEVICE devDebug2;
  100. /*!
  101. * \struct _UNIXDCB unix_d evs.h dev/unix_devs.h
  102. * \brief UNIX devices low level information structure.
  103. *
  104. */
  105. struct _UNIXDCB {
  106. /*! \brief Mode flags.
  107. */
  108. u_long dcb_modeflags;
  109. /*! \brief Status flags.
  110. */
  111. u_long dcb_statusflags;
  112. /*! \brief Read timeout.
  113. */
  114. u_long dcb_rtimeout;
  115. /*! \brief Write timeout.
  116. */
  117. u_long dcb_wtimeout;
  118. /*! \brief Last EOL character.
  119. */
  120. u_char dcb_last_eol;
  121. /*! \brief Native file descriptor
  122. */
  123. int dcb_fd;
  124. /*! \brief File is Socket
  125. */
  126. u_char dcb_socket;
  127. /*! \brief Queue of threads waiting for a character in the input buffer.
  128. */
  129. HANDLE dcb_rx_rdy;
  130. /*! \brief Mutex to protect rx trigger
  131. */
  132. pthread_mutex_t dcb_rx_mutex;
  133. /*! \brief Conditional Variable to trigger read thread
  134. */
  135. pthread_cond_t dcb_rx_trigger;
  136. };
  137. /*!
  138. * USART device low level information type.
  139. */
  140. typedef struct _UNIXDCB UNIXDCB;
  141. /*@}*/
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. #endif