unix_devs.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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$
  42. * Revision 1.9 2008/08/11 06:59:59 haraldkipp
  43. * BSD types replaced by stdint types (feature request #1282721).
  44. *
  45. * Revision 1.8 2005/08/02 17:46:48 haraldkipp
  46. * Major API documentation update.
  47. *
  48. * Revision 1.7 2005/04/04 19:35:06 freckle
  49. * added socket redirection feature for unix emulation uarts. Every nut/os
  50. * uart device can now be mapped to a TCP/IP socket using the
  51. * "-u{0/1/2} hostname:port" command line option
  52. *
  53. * Revision 1.6 2004/08/09 21:31:30 freckle
  54. * Added include/dev/unix_devs.h changes
  55. *
  56. * Revision 1.5 2004/08/05 12:13:56 freckle
  57. * Added unix emulation hook in NutThreadYield to safely process
  58. * NutPostEventAsync calls occuring in non Nut/OS threads.
  59. * Rewrote the unix read function again using the new unix NutThreadYield hook
  60. * to call the NutPostEventAsync function safely (fast & correct).
  61. * _write(nf, 0, 0) aka fflush is ignored on unix emulation.
  62. *
  63. * Revision 1.4 2004/06/22 09:00:00 freckle
  64. * Further work on unix_dev emulation. Multiple parallel reads don't block
  65. * each other. Still, dead-locks occure.
  66. * STDIO is set to non-blocking.
  67. *
  68. * Revision 1.3 2004/06/21 10:57:25 freckle
  69. * dev/unix_devs.c: read operation is using extra pthread to only block the
  70. * current thread instead of all threads
  71. *
  72. * Revision 1.2 2004/04/16 17:50:35 freckle
  73. * Implemented the most common _IOCTL calls
  74. * Added block read functionality to read call
  75. *
  76. * Revision 1.1 2004/04/07 12:13:57 haraldkipp
  77. * Matthias Ringwald's *nix emulation added
  78. *
  79. */
  80. #include <pthread.h>
  81. #include <sys/device.h>
  82. #include <dev/netbuf.h>
  83. #ifdef __cplusplus
  84. extern "C" {
  85. #endif
  86. /*!
  87. * \addtogroup xgNutArchUnix
  88. */
  89. /*@{*/
  90. // int UnixDevIOCTL(NUTDEVICE * dev, int req, void *conf);
  91. /*
  92. * Available devices.
  93. */
  94. extern NUTDEVICE devUart0;
  95. extern NUTDEVICE devUart1;
  96. extern NUTDEVICE devUart2;
  97. extern NUTDEVICE devUsartAvr0;
  98. extern NUTDEVICE devUsartAvr1;
  99. extern NUTDEVICE devUsartAvr2;
  100. extern NUTDEVICE devDebug0;
  101. extern NUTDEVICE devDebug1;
  102. extern NUTDEVICE devDebug2;
  103. /*!
  104. * \struct _UNIXDCB unix_d evs.h dev/unix_devs.h
  105. * \brief UNIX devices low level information structure.
  106. *
  107. */
  108. struct _UNIXDCB {
  109. /*! \brief Mode flags.
  110. */
  111. uint32_t dcb_modeflags;
  112. /*! \brief Status flags.
  113. */
  114. uint32_t dcb_statusflags;
  115. /*! \brief Read timeout.
  116. */
  117. uint32_t dcb_rtimeout;
  118. /*! \brief Write timeout.
  119. */
  120. uint32_t dcb_wtimeout;
  121. /*! \brief Last EOL character.
  122. */
  123. uint8_t dcb_last_eol;
  124. /*! \brief Native file descriptor
  125. */
  126. int dcb_fd;
  127. /*! \brief File is Socket
  128. */
  129. uint8_t dcb_socket;
  130. /*! \brief Queue of threads waiting for a character in the input buffer.
  131. */
  132. HANDLE dcb_rx_rdy;
  133. /*! \brief Mutex to protect rx trigger
  134. */
  135. pthread_mutex_t dcb_rx_mutex;
  136. /*! \brief Conditional Variable to trigger read thread
  137. */
  138. pthread_cond_t dcb_rx_trigger;
  139. };
  140. /*!
  141. * USART device low level information type.
  142. */
  143. typedef struct _UNIXDCB UNIXDCB;
  144. /*@}*/
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif