xnut.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright (c) 2005 FOCUS Software Engineering Pty Ltd <www.focus-sw.com>
  3. * Copyright (c) 2005 proconX <www.proconx.com>
  4. *
  5. * $Id: xnut.h,v 1.2 2005/10/19 09:27:39 hwmaier Exp $
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the name of the copyright holders nor the names of
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  24. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  27. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  28. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  30. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. * For additional information see http://www.ethernut.de/
  34. */
  35. #ifndef _CFG_XNUT_H_
  36. #define _CFG_XNUT_H_
  37. #ifndef _XNUT_XXX_H_INCLUDED
  38. # define _XNUT_XXX_H_INCLUDED "cfg/xnut.h"
  39. #else
  40. # error "Attempt to include more than one <xnut-xxx.h> file"
  41. #endif
  42. #include <cfg/os.h>
  43. #include <cfg/memory.h>
  44. #include <cfg/arch.h>
  45. #include <cfg/eeprom.h>
  46. #include <arch/avr.h>
  47. #include <cfg/arch/avrpio.h>
  48. /* Validate F_CPU setting */
  49. #if F_CPU == 1000000UL
  50. # error "F_CPU is set to avr-lib default 1 MHz! Please include <avr/delay.h> after <xnut.h>"
  51. #endif
  52. #define F_CPU NUT_CPU_FREQ
  53. /*!
  54. * \defgroup xgXnutCfg XNUT-100 & XNUT-105 DIN-rail SBC
  55. * \ingroup xgConfigAvr
  56. * \brief DIN-rail mounted Single Board Computer in enclosure with
  57. * 2 x RS-232, 2 x RS-485, 1 x RS-422 interfaces (software configurable),
  58. * CAN port (XNUT-105) and 10-30 V (24 V) switch mode power supply.
  59. * The <A href="http://www.proconx.com/xnut100">XNUT-100</A> and
  60. * <A href="http://www.proconx.com/xnut105">XNUT-105</A>
  61. * modules have been specifically designed for industrial communication
  62. * tasks such as Monitoring & Controlling serial devices,
  63. * gathering sensor data, Gateway Applications and Protocol Conversion.
  64. */
  65. //@{
  66. /*****************************************************************************
  67. * LED control macros
  68. *****************************************************************************/
  69. /**
  70. * @defgroup xnutLed LED Control Macros
  71. *
  72. * @brief Functions to drive the XNUT status LED S1 (LED3) and S2 (LED4).
  73. */
  74. //@{
  75. /** Switch LED S1 off */
  76. #define LED_S1_OFF() PORTF &= ~_BV(2); PORTF &= ~_BV(3);
  77. /** Switch LED S1 red */
  78. #define LED_S1_RED() PORTF &= ~_BV(2); PORTF |= _BV(3);
  79. /** Switch LED S1 green */
  80. #define LED_S1_GREEN() PORTF |= _BV(2); PORTF &= ~_BV(3);
  81. /** Switch LED S2 off */
  82. #define LED_S2_OFF() PORTF &= ~_BV(0); PORTF &= ~_BV(1);
  83. /** Switch LED S2 red */
  84. #define LED_S2_RED() PORTF &= ~_BV(0); PORTF |= _BV(1);
  85. /** Switch LED S2 green */
  86. #define LED_S2_GREEN() PORTF |= _BV(0); PORTF &= ~_BV(1);
  87. //@}
  88. /*****************************************************************************
  89. * UART control macros
  90. *****************************************************************************/
  91. /**
  92. * @defgroup xnutSer UART Control Macros
  93. *
  94. * @brief Functions to control UART modes
  95. */
  96. //@{
  97. /**
  98. * Configure Ser 0 to operate in RS232 mode.
  99. *
  100. * In RS232 mode receiption from SUB-D connector J9 is enabled
  101. * and the receiver on connector J6-2/3 is disabled.
  102. */
  103. #define SER0_RS232_MODE() (PORTB |= _BV(0))
  104. /**
  105. * Configure Ser 0 to operate in RS485 mode.
  106. *
  107. * In RS485 mode receiption from connector J6-2/3 is enabled
  108. * and the receiver on SUB-D connector J9 is disabled.
  109. */
  110. #define SER0_RS485_MODE() (PORTB &= ~_BV(0))
  111. /**
  112. * Switches the RS485 line driver of Ser 0 on.
  113. *
  114. * RS485 is a half-duplex link and the line driver must be switched off to
  115. * allow receiption of data.
  116. */
  117. #define SER0_RS485_DRV_ON() (PORTB |= _BV(1))
  118. /**
  119. * Switches the RS485 line driver of Ser 0 off.
  120. */
  121. #define SER0_RS485_DRV_OFF() (PORTB &= ~_BV(1))
  122. /**
  123. * Configure Ser 1 to operate in RS232 mode.
  124. *
  125. * In RS232 mode receiption from SUB-D connector J7 is enabled
  126. * and the receiver on connector J6-5/6 is disabled.
  127. */
  128. #define SER1_RS232_MODE() (PORTB |= _BV(2))
  129. /**
  130. * Configure Ser 1 to operate in RS485 mode.
  131. *
  132. * In RS485 mode receiption from connector J6-5/6 is enabled
  133. * and the receiver on SUB-D connector J7 is disabled.
  134. */
  135. #define SER1_RS485_MODE() (PORTB &= ~_BV(2))
  136. /**
  137. * Switches the RS485 line driver of Ser 1 on.
  138. *
  139. * RS485 is a half-duplex link and the line driver must be switched off to
  140. * allow receiption of data.
  141. */
  142. #define SER1_RS485_DRV_ON() (PORTB |= _BV(3))
  143. /**
  144. * Switches the RS485 line driver of Ser 1 off.
  145. */
  146. #define SER1_RS485_DRV_OFF() (PORTB &= ~_BV(3))
  147. /**
  148. * Returns the status of the RS232 CD signal input
  149. * of Ser 0 on SUB-D connector J9
  150. *
  151. * @return 1 if CD is asserted
  152. */
  153. #define SER0_GET_CD() bit_is_set(PINB, 6)
  154. /**
  155. * Returns the status of the RS232 RI signal input
  156. * of Ser 0 on SUB-D connector J9
  157. *
  158. * @return 1 if RI is asserted
  159. */
  160. #define SER0_GET_RI() bit_is_set(PINB, 7)
  161. /**
  162. * Returns the status of the RS232 CTS signal input
  163. * of Ser 0 on SUB-D connector J9
  164. *
  165. * @return 1 if CTS is asserted
  166. */
  167. #define SER0_GET_CTS() bit_is_set(PINE, 6)
  168. /**
  169. * Asserts the RS232 RTS signal output of Ser 0 on SUB-D connector J9
  170. */
  171. #define SER0_SET_RTS() (PORTB |= _BV(4))
  172. /**
  173. * Clears the RS232 RTS signal output of Ser 0 on SUB-D connector J9
  174. */
  175. #define SER0_CLR_RTS() (PORTB &= ~_BV(4))
  176. //@}
  177. //@}
  178. #endif // ifdef ..._H_INCLUDED