xnut.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Copyright (c) 2005-2007 proconX Pty Ltd <www.proconx.com>
  3. *
  4. * $Id: xnut.h 4477 2012-08-20 17:50:01Z haraldkipp $
  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 _CFG_XNUT_H_
  35. #define _CFG_XNUT_H_
  36. #ifndef _XNUT_XXX_H_INCLUDED
  37. # define _XNUT_XXX_H_INCLUDED "cfg/xnut.h"
  38. #else
  39. # error "Attempt to include more than one <xnut-xxx.h> file"
  40. #endif
  41. #include <cfg/os.h>
  42. #include <cfg/memory.h>
  43. #include <cfg/arch.h>
  44. #include <cfg/eeprom.h>
  45. #include <arch/avr.h>
  46. #include <cfg/arch/avrpio.h>
  47. /* Validate F_CPU setting */
  48. #if F_CPU == 1000000UL
  49. # error "F_CPU is set to avr-lib default 1 MHz! Please include <avr/delay.h> after <xnut.h>"
  50. #endif
  51. #define F_CPU NUT_CPU_FREQ
  52. /*!
  53. * \defgroup xgXnutCfg XNUT-100 & XNUT-105 DIN-rail SBC
  54. * \ingroup xgConfigAvr
  55. * \brief DIN-rail mounted Single Board Computer in enclosure with
  56. * 2 x RS-232, 2 x RS-485, 1 x RS-422 interfaces (software configurable),
  57. * CAN port (XNUT-105) and 10-30 V (24 V) switch mode power supply.
  58. * The <A href="http://www.proconx.com/xnut100">XNUT-100</A> and
  59. * <A href="http://www.proconx.com/xnut105">XNUT-105</A>
  60. * modules have been specifically designed for industrial communication
  61. * tasks such as Monitoring & Controlling serial devices,
  62. * gathering sensor data, Gateway Applications and Protocol Conversion.
  63. */
  64. //@{
  65. /*****************************************************************************
  66. * LED control macros
  67. *****************************************************************************/
  68. /**
  69. * @defgroup xnutLed LED Control Macros
  70. *
  71. * @brief Functions to drive the XNUT status LED S1 (LED3) and S2 (LED4).
  72. */
  73. //@{
  74. /** Switch LED S1 off */
  75. #define LED_S1_OFF() do {PORTF &= ~_BV(2); PORTF &= ~_BV(3);} while(0)
  76. /** Switch LED S1 red */
  77. #define LED_S1_RED() do {PORTF &= ~_BV(2); PORTF |= _BV(3);} while(0)
  78. /** Toggle LED S1 between red and off */
  79. #define LED_S1_RED_TOGGLE() do {PORTF &= ~_BV(2); PORTF ^= _BV(3);} while(0)
  80. /** Switch LED S1 green */
  81. #define LED_S1_GREEN() do {PORTF |= _BV(2); PORTF &= ~_BV(3);} while(0)
  82. /** Toggle LED S1 between green and off */
  83. #define LED_S1_GREEN_TOGGLE() do {PORTF ^= _BV(2); PORTF &= ~_BV(3);} while(0)
  84. #define LED_S1_RED_GREEN_TOGGLE() do {PORTF ^= _BV(2); if (bit_is_set(PORTF, 2)) \
  85. PORTF &= ~_BV(3); else PORTF |= _BV(3);} while(0)
  86. /** Switch LED S2 off */
  87. #define LED_S2_OFF() do {PORTF &= ~_BV(0); PORTF &= ~_BV(1);} while(0)
  88. /** Switch LED S2 red */
  89. #define LED_S2_RED() do {PORTF &= ~_BV(0); PORTF |= _BV(1);} while(0)
  90. /** Toggle LED S2 between red and off */
  91. #define LED_S2_RED_TOGGLE() do {PORTF &= ~_BV(0); PORTF ^= _BV(1);} while(0)
  92. /** Switch LED S2 green */
  93. #define LED_S2_GREEN() do {PORTF |= _BV(0); PORTF &= ~_BV(1);} while(0)
  94. /** Toggle LED S2 between green and off */
  95. #define LED_S2_GREEN_TOGGLE() do {PORTF ^= _BV(0); PORTF &= ~_BV(1);} while(0)
  96. #define LED_S2_RED_GREEN_TOGGLE() do {PORTF ^= _BV(0); if (bit_is_set(PORTF, 0)) \
  97. PORTF &= ~_BV(1); else PORTF |= _BV(1);} while(0)
  98. //@}
  99. /*****************************************************************************
  100. * UART control macros
  101. *****************************************************************************/
  102. /**
  103. * @defgroup xnutSer UART Control Macros
  104. *
  105. * @brief Functions to control UART modes
  106. */
  107. //@{
  108. /**
  109. * Configure Ser 0 to operate in RS232 mode.
  110. *
  111. * In RS232 mode receiption from SUB-D connector J9 is enabled
  112. * and the receiver on connector J6-2/3 is disabled.
  113. */
  114. #define SER0_RS232_MODE() (PORTB |= _BV(0))
  115. /**
  116. * Configure Ser 0 to operate in RS485 mode.
  117. *
  118. * In RS485 mode receiption from connector J6-2/3 is enabled
  119. * and the receiver on SUB-D connector J9 is disabled.
  120. */
  121. #define SER0_RS485_MODE() (PORTB &= ~_BV(0))
  122. /**
  123. * Switches the RS485 line driver of Ser 0 on.
  124. *
  125. * RS485 is a half-duplex link and the line driver must be switched off to
  126. * allow receiption of data.
  127. */
  128. #define SER0_RS485_DRV_ON() (PORTB |= _BV(1))
  129. /**
  130. * Switches the RS485 line driver of Ser 0 off.
  131. */
  132. #define SER0_RS485_DRV_OFF() (PORTB &= ~_BV(1))
  133. /**
  134. * Configure Ser 1 to operate in RS232 mode.
  135. *
  136. * In RS232 mode receiption from SUB-D connector J7 is enabled
  137. * and the receiver on connector J6-5/6 is disabled.
  138. */
  139. #define SER1_RS232_MODE() (PORTB |= _BV(2))
  140. /**
  141. * Configure Ser 1 to operate in RS485 mode.
  142. *
  143. * In RS485 mode receiption from connector J6-5/6 is enabled
  144. * and the receiver on SUB-D connector J7 is disabled.
  145. */
  146. #define SER1_RS485_MODE() (PORTB &= ~_BV(2))
  147. /**
  148. * Switches the RS485 line driver of Ser 1 on.
  149. *
  150. * RS485 is a half-duplex link and the line driver must be switched off to
  151. * allow receiption of data.
  152. */
  153. #define SER1_RS485_DRV_ON() (PORTB |= _BV(3))
  154. /**
  155. * Switches the RS485 line driver of Ser 1 off.
  156. */
  157. #define SER1_RS485_DRV_OFF() (PORTB &= ~_BV(3))
  158. /**
  159. * Returns the status of the RS232 CD signal input
  160. * of Ser 0 on SUB-D connector J9
  161. *
  162. * @return 1 if CD is asserted
  163. */
  164. #define SER0_GET_CD() bit_is_set(PINB, 6)
  165. /**
  166. * Returns the status of the RS232 RI signal input
  167. * of Ser 0 on SUB-D connector J9
  168. *
  169. * @return 1 if RI is asserted
  170. */
  171. #define SER0_GET_RI() bit_is_clear(PINB, 7)
  172. /**
  173. * Returns the status of the RS232 CTS signal input
  174. * of Ser 0 on SUB-D connector J9
  175. *
  176. * @return 1 if CTS is asserted
  177. */
  178. #define SER0_GET_CTS() bit_is_clear(PINE, 6)
  179. /**
  180. * Returns the status of the RS232 DSR signal input of Ser 0 on
  181. * SUB-D connector J9
  182. *
  183. * @note Feature only available for devices with serial number
  184. * 224 upwards (since PCB Revision C)
  185. * @return 1 if DSR is asserted
  186. */
  187. #define SER0_GET_DSR() bit_is_clear(PINE, 4)
  188. /**
  189. * Asserts the RS232 RTS signal output of Ser 0 on SUB-D connector J9
  190. */
  191. #define SER0_SET_RTS() (PORTB &= ~_BV(4))
  192. /**
  193. * Clears the RS232 RTS signal output of Ser 0 on SUB-D connector J9
  194. */
  195. #define SER0_CLR_RTS() (PORTB |= _BV(4))
  196. /**
  197. * Asserts the RS232 DTR signal output of Ser 0 on SUB-D
  198. * connector J9
  199. *
  200. * @note Feature only available for devices with serial number
  201. * 224 upwards (since PCB Revision C)
  202. */
  203. #define SER0_SET_DTR() (PORTB &= ~_BV(5))
  204. /**
  205. * Clears the RS232 DTR signal output of Ser 0 on SUB-D
  206. * connector J9
  207. *
  208. * @note Feature only available for devices with serial number
  209. * 224 upwards (since PCB Revision C)
  210. */
  211. #define SER0_CLR_DTR() (PORTB |= _BV(5))
  212. //@}
  213. //@}
  214. #endif // ifdef ..._H_INCLUDED