twibus_avr.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (C) 2012 by Ole Reinhardt (ole.reinhardt@embedded-it.de)
  3. *
  4. * All rights reserved.
  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 THE COPYRIGHT HOLDERS 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 THE
  23. * COPYRIGHT OWNER 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. #ifndef _DEV_TWIBUS_AVR_H_
  35. #define _DEV_TWIBUS_AVR_H_
  36. #include <sys/types.h>
  37. #include <cfg/arch.h>
  38. typedef struct _NUTTWIICB NUTTWIICB;
  39. /*
  40. * Runtime Data container.
  41. * This is installed in heap at initializaton
  42. * of a bus.
  43. */
  44. struct _NUTTWIICB {
  45. /********** Master mode *********/
  46. /*! \brief Flag that interface is busy
  47. */
  48. volatile uint_fast8_t tw_if_busy;
  49. /*! \brief Bus slave address.
  50. */
  51. volatile uint_fast16_t tw_mm_sla;
  52. /*! \brief Bus current error condition.
  53. */
  54. volatile int_fast8_t tw_mm_err;
  55. /*! \brief Bus last error condition.
  56. */
  57. volatile int_fast8_t tw_mm_error;
  58. /*! \brief Bus transmission data buffer pointer.
  59. */
  60. const uint8_t *tw_mm_txbuf;
  61. /*! \brief Bus transmission data block length.
  62. */
  63. volatile uint_fast16_t tw_mm_txlen;
  64. /*! \brief Bus transmissinn position.
  65. */
  66. volatile uint_fast16_t tw_mm_txidx;
  67. /*! \brief Bus reception data buffer pointer.
  68. */
  69. uint8_t *tw_mm_rxbuf;
  70. /*! \brief Bus reception data block length.
  71. */
  72. volatile uint_fast16_t tw_mm_rxlen;
  73. /*! \brief Bus reception position.
  74. */
  75. volatile uint_fast16_t tw_mm_rxidx;
  76. /*! \brief Bus data direction.
  77. */
  78. volatile uint_fast8_t tw_mm_dir;
  79. /*! \brief Transmission Ongoing Mutex.
  80. */
  81. HANDLE tw_mm_mtx;
  82. /********** Slave mode *********/
  83. /*! \brief Slave address received.
  84. */
  85. uint_fast8_t tw_sm_sla;
  86. /*! \brief Current slave mode error.
  87. */
  88. volatile uint_fast8_t tw_sm_err;
  89. /*! \brief Last slave mode error.
  90. */
  91. volatile uint_fast8_t tw_sm_error;
  92. /*! \brief Pointer to the slave transmit buffer.
  93. */
  94. uint8_t *tw_sm_txbuf;
  95. /*! \brief Number of bytes to transmit in slave mode.
  96. */
  97. uint_fast16_t tw_sm_txlen;
  98. /*! \brief Current slave transmit buffer index.
  99. */
  100. volatile uint_fast16_t tw_sm_txidx;
  101. /*! \brief Pointer to the slave receive buffer.
  102. */
  103. uint8_t *tw_sm_rxbuf;
  104. /*! \brief Size of the master receive buffer.
  105. */
  106. volatile uint_fast16_t tw_sm_rxlen;
  107. /*! \brief Current slave receive buffer index.
  108. */
  109. volatile uint_fast16_t tw_sm_rxidx;
  110. /*! \brief Threads waiting for slave receive.
  111. */
  112. HANDLE tw_sm_rxmtx;
  113. /*! \brief Threads waiting for slave transmit done.
  114. */
  115. HANDLE tw_sm_txmtx;
  116. };
  117. extern NUTTWIBUS AVRTwiBus;
  118. #ifndef DEF_TWIBUS
  119. #define DEF_TWIBUS AVRTwiBus
  120. #endif
  121. #endif /* _DEV_TWIBUS_AVR_H_ */