mbconfig.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
  3. * Copyright (c) 2006 Christian Walter <wolti@sil.at>
  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. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. The name of the author may not be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * File: $Id: mbconfig.h,v 1.15 2010/06/06 13:54:40 wolti Exp $
  29. * $Id: mbconfig.h,v 1.60 2013/08/13 21:19:55 Armink Add Master Functions $
  30. */
  31. #ifndef _MB_CONFIG_H
  32. #define _MB_CONFIG_H
  33. #include "sdkconfig.h" // for KConfig options
  34. #ifdef __cplusplus
  35. PR_BEGIN_EXTERN_C
  36. #endif
  37. /* ----------------------- Defines ------------------------------------------*/
  38. /*! \defgroup modbus_cfg Modbus Configuration
  39. *
  40. * Most modules in the protocol stack are completly optional and can be
  41. * excluded. This is specially important if target resources are very small
  42. * and program memory space should be saved.<br>
  43. *
  44. * All of these settings are available in the file <code>mbconfig.h</code>
  45. */
  46. /*! \addtogroup modbus_cfg
  47. * @{
  48. */
  49. /*! \brief If Modbus Master ASCII support is enabled. */
  50. #define MB_MASTER_ASCII_ENABLED ( CONFIG_FMB_COMM_MODE_ASCII_EN )
  51. /*! \brief If Modbus Master RTU support is enabled. */
  52. #define MB_MASTER_RTU_ENABLED ( CONFIG_FMB_COMM_MODE_RTU_EN )
  53. /*! \brief If Modbus Master TCP support is enabled. */
  54. #define MB_MASTER_TCP_ENABLED ( CONFIG_FMB_COMM_MODE_TCP_EN )
  55. /*! \brief If Modbus Slave ASCII support is enabled. */
  56. #define MB_SLAVE_ASCII_ENABLED ( CONFIG_FMB_COMM_MODE_ASCII_EN )
  57. /*! \brief If Modbus Slave RTU support is enabled. */
  58. #define MB_SLAVE_RTU_ENABLED ( CONFIG_FMB_COMM_MODE_RTU_EN )
  59. /*! \brief If Modbus Slave TCP support is enabled. */
  60. #define MB_TCP_ENABLED ( CONFIG_FMB_COMM_MODE_TCP_EN )
  61. #if !CONFIG_FMB_COMM_MODE_ASCII_EN && !CONFIG_FMB_COMM_MODE_RTU_EN && !MB_MASTER_TCP_ENABLED && !MB_TCP_ENABLED
  62. #error "None of Modbus communication mode is enabled. Please enable one of (ASCII, RTU, TCP) mode in Kconfig."
  63. #endif
  64. /*! \brief This option defines the number of data bits per ASCII character.
  65. *
  66. * A parity bit is added before the stop bit which keeps the actual byte size at 10 bits.
  67. */
  68. #ifdef CONFIG_FMB_SERIAL_ASCII_BITS_PER_SYMB
  69. #define MB_ASCII_BITS_PER_SYMB ( CONFIG_FMB_SERIAL_ASCII_BITS_PER_SYMB )
  70. #endif
  71. /*! \brief The character timeout value for Modbus ASCII.
  72. *
  73. * The character timeout value is not fixed for Modbus ASCII and is therefore
  74. * a configuration option. It should be set to the maximum expected delay
  75. * time of the network.
  76. */
  77. #ifdef CONFIG_FMB_SERIAL_ASCII_TIMEOUT_RESPOND_MS
  78. #define MB_ASCII_TIMEOUT_MS ( CONFIG_FMB_SERIAL_ASCII_TIMEOUT_RESPOND_MS )
  79. #endif
  80. /*! \brief Timeout to wait in ASCII prior to enabling transmitter.
  81. *
  82. * If defined the function calls vMBPortSerialDelay with the argument
  83. * MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS to allow for a delay before
  84. * the serial transmitter is enabled. This is required because some
  85. * targets are so fast that there is no time between receiving and
  86. * transmitting the frame. If the master is to slow with enabling its
  87. * receiver then he will not receive the response correctly.
  88. */
  89. #ifndef MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS
  90. #define MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS ( 0 )
  91. #endif
  92. /*! \brief Maximum number of Modbus functions codes the protocol stack
  93. * should support.
  94. *
  95. * The maximum number of supported Modbus functions must be greater than
  96. * the sum of all enabled functions in this file and custom function
  97. * handlers. If set to small adding more functions will fail.
  98. */
  99. #define MB_FUNC_HANDLERS_MAX ( 16 )
  100. /*! \brief Number of bytes which should be allocated for the <em>Report Slave ID
  101. * </em>command.
  102. *
  103. * This number limits the maximum size of the additional segment in the
  104. * report slave id function. See eMBSetSlaveID( ) for more information on
  105. * how to set this value. It is only used if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
  106. * is set to <code>1</code>.
  107. */
  108. #define MB_FUNC_OTHER_REP_SLAVEID_BUF ( 32 )
  109. /*! \brief If the <em>Report Slave ID</em> function should be enabled. */
  110. #define MB_FUNC_OTHER_REP_SLAVEID_ENABLED ( CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORT )
  111. /*! \brief If the <em>Read Input Registers</em> function should be enabled. */
  112. #define MB_FUNC_READ_INPUT_ENABLED ( 1 )
  113. /*! \brief If the <em>Read Holding Registers</em> function should be enabled. */
  114. #define MB_FUNC_READ_HOLDING_ENABLED ( 1 )
  115. /*! \brief If the <em>Write Single Register</em> function should be enabled. */
  116. #define MB_FUNC_WRITE_HOLDING_ENABLED ( 1 )
  117. /*! \brief If the <em>Write Multiple registers</em> function should be enabled. */
  118. #define MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED ( 1 )
  119. /*! \brief If the <em>Read Coils</em> function should be enabled. */
  120. #define MB_FUNC_READ_COILS_ENABLED ( 1 )
  121. /*! \brief If the <em>Write Coils</em> function should be enabled. */
  122. #define MB_FUNC_WRITE_COIL_ENABLED ( 1 )
  123. /*! \brief If the <em>Write Multiple Coils</em> function should be enabled. */
  124. #define MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED ( 1 )
  125. /*! \brief If the <em>Read Discrete Inputs</em> function should be enabled. */
  126. #define MB_FUNC_READ_DISCRETE_INPUTS_ENABLED ( 1 )
  127. /*! \brief If the <em>Read/Write Multiple Registers</em> function should be enabled. */
  128. #define MB_FUNC_READWRITE_HOLDING_ENABLED ( 1 )
  129. /*! \brief Check the option to place timer handler into IRAM */
  130. #define MB_PORT_TIMER_ISR_IN_IRAM ( CONFIG_FMB_TIMER_ISR_IN_IRAM )
  131. /*! @} */
  132. #ifdef __cplusplus
  133. PR_END_EXTERN_C
  134. #endif
  135. #if MB_MASTER_RTU_ENABLED || MB_MASTER_ASCII_ENABLED || MB_MASTER_TCP_ENABLED
  136. /*! \brief If master send a broadcast frame, the master will wait time of convert to delay,
  137. * then master can send other frame */
  138. #define MB_MASTER_DELAY_MS_CONVERT ( CONFIG_FMB_MASTER_DELAY_MS_CONVERT )
  139. /*! \brief If master send a frame which is not broadcast,the master will wait sometime for slave.
  140. * And if slave is not respond in this time,the master will process this timeout error.
  141. * Then master can send other frame */
  142. #define MB_MASTER_TIMEOUT_MS_RESPOND ( CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND )
  143. /*! \brief The total slaves in Modbus Master system.
  144. * \note : The slave ID must be continuous from 1.*/
  145. #define MB_MASTER_TOTAL_SLAVE_NUM ( 247 )
  146. #endif
  147. #endif