mbport.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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: mbport.h,v 1.17 2006/12/07 22:10:34 wolti Exp $
  29. * mbport.h,v 1.60 2013/08/17 11:42:56 Armink Add Master Functions $
  30. */
  31. #ifndef _MB_PORT_H
  32. #define _MB_PORT_H
  33. #ifdef __cplusplus
  34. PR_BEGIN_EXTERN_C
  35. #endif
  36. /* ----------------------- Type definitions ---------------------------------*/
  37. typedef enum
  38. {
  39. EV_READY, /*!< Startup finished. */
  40. EV_FRAME_RECEIVED, /*!< Frame received. */
  41. EV_EXECUTE, /*!< Execute function. */
  42. EV_FRAME_SENT /*!< Frame sent. */
  43. } eMBEventType;
  44. typedef enum
  45. {
  46. EV_MASTER_READY, /*!< Startup finished. */
  47. EV_MASTER_FRAME_RECEIVED, /*!< Frame received. */
  48. EV_MASTER_EXECUTE, /*!< Execute function. */
  49. EV_MASTER_FRAME_SENT, /*!< Frame sent. */
  50. EV_MASTER_ERROR_PROCESS /*!< Frame error process*/
  51. } eMBMasterEventType;
  52. /*! \ingroup modbus
  53. * \brief Parity used for characters in serial mode.
  54. *
  55. * The parity which should be applied to the characters sent over the serial
  56. * link. Please note that this values are actually passed to the porting
  57. * layer and therefore not all parity modes might be available.
  58. */
  59. typedef enum
  60. {
  61. MB_PAR_NONE, /*!< No parity. */
  62. MB_PAR_ODD, /*!< Odd parity. */
  63. MB_PAR_EVEN /*!< Even parity. */
  64. } eMBParity;
  65. /* ----------------------- Supporting functions -----------------------------*/
  66. BOOL xMBPortEventInit( void );
  67. BOOL xMBPortEventPost( eMBEventType eEvent );
  68. BOOL xMBPortEventGet( /*@out@ */ eMBEventType * eEvent );
  69. BOOL xMBMasterPortEventInit( void );
  70. BOOL xMBMasterPortEventPost( eMBMasterEventType eEvent );
  71. BOOL xMBMasterPortEventGet( /*@out@ */ eMBMasterEventType * eEvent );
  72. /* ----------------------- Serial port functions ----------------------------*/
  73. BOOL xMBPortSerialInit( UCHAR ucPort, ULONG ulBaudRate,
  74. UCHAR ucDataBits, eMBParity eParity );
  75. void vMBPortClose( void );
  76. void xMBPortSerialClose( void );
  77. void vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable );
  78. INLINE BOOL xMBPortSerialGetByte( CHAR * pucByte );
  79. INLINE BOOL xMBPortSerialPutByte( CHAR ucByte );
  80. BOOL xMBMasterPortSerialInit( UCHAR ucPort, ULONG ulBaudRate,
  81. UCHAR ucDataBits, eMBParity eParity );
  82. void vMBMasterPortClose( void );
  83. void xMBMasterPortSerialClose( void );
  84. void vMBMasterPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable );
  85. INLINE BOOL xMBMasterPortSerialGetByte( CHAR * pucByte );
  86. INLINE BOOL xMBMasterPortSerialPutByte( CHAR ucByte );
  87. /* ----------------------- Timers functions ---------------------------------*/
  88. BOOL xMBPortTimersInit( USHORT usTimeOut50us );
  89. void xMBPortTimersClose( void );
  90. INLINE void vMBPortTimersEnable( void );
  91. INLINE void vMBPortTimersDisable( void );
  92. BOOL xMBMasterPortTimersInit( USHORT usTimeOut50us );
  93. void xMBMasterPortTimersClose( void );
  94. INLINE void vMBMasterPortTimersT35Enable( void );
  95. INLINE void vMBMasterPortTimersConvertDelayEnable( void );
  96. INLINE void vMBMasterPortTimersRespondTimeoutEnable( void );
  97. INLINE void vMBMasterPortTimersDisable( void );
  98. /* ----------------------- Callback for the protocol stack ------------------*/
  99. /*!
  100. * \brief Callback function for the porting layer when a new byte is
  101. * available.
  102. *
  103. * Depending upon the mode this callback function is used by the RTU or
  104. * ASCII transmission layers. In any case a call to xMBPortSerialGetByte()
  105. * must immediately return a new character.
  106. *
  107. * \return <code>TRUE</code> if a event was posted to the queue because
  108. * a new byte was received. The port implementation should wake up the
  109. * tasks which are currently blocked on the eventqueue.
  110. */
  111. extern BOOL( *pxMBFrameCBByteReceived ) ( void );
  112. extern BOOL( *pxMBFrameCBTransmitterEmpty ) ( void );
  113. extern BOOL( *pxMBPortCBTimerExpired ) ( void );
  114. extern BOOL( *pxMBMasterFrameCBByteReceived ) ( void );
  115. extern BOOL( *pxMBMasterFrameCBTransmitterEmpty ) ( void );
  116. extern BOOL( *pxMBMasterPortCBTimerExpired ) ( void );
  117. /* ----------------------- TCP port functions -------------------------------*/
  118. BOOL xMBTCPPortInit( USHORT usTCPPort );
  119. void vMBTCPPortClose( void );
  120. void vMBTCPPortDisable( void );
  121. BOOL xMBTCPPortGetRequest( UCHAR **ppucMBTCPFrame, USHORT * usTCPLength );
  122. BOOL xMBTCPPortSendResponse( const UCHAR *pucMBTCPFrame, USHORT usTCPLength );
  123. #ifdef __cplusplus
  124. PR_END_EXTERN_C
  125. #endif
  126. #endif