mbport.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
  3. * Copyright (c) 2006-2018 Christian Walter <cwalter@embedded-solutions.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. */
  29. #ifndef _MB_PORT_H
  30. #define _MB_PORT_H
  31. #ifdef __cplusplus
  32. PR_BEGIN_EXTERN_C
  33. #endif
  34. /* ----------------------- Type definitions ---------------------------------*/
  35. typedef enum
  36. {
  37. EV_READY, /*!< Startup finished. */
  38. EV_FRAME_RECEIVED, /*!< Frame received. */
  39. EV_EXECUTE, /*!< Execute function. */
  40. EV_FRAME_SENT /*!< Frame sent. */
  41. } eMBEventType;
  42. /*! \ingroup modbus
  43. * \brief Parity used for characters in serial mode.
  44. *
  45. * The parity which should be applied to the characters sent over the serial
  46. * link. Please note that this values are actually passed to the porting
  47. * layer and therefore not all parity modes might be available.
  48. */
  49. typedef enum
  50. {
  51. MB_PAR_NONE = 0, /*!< No parity. */
  52. MB_PAR_ODD, /*!< Odd parity. */
  53. MB_PAR_EVEN /*!< Even parity. */
  54. } eMBParity;
  55. #define MB_RX_SET gpio_bits_reset(GPIOD, GPIO_PINS_10)
  56. #define MB_TX_SET gpio_bits_set(GPIOD, GPIO_PINS_10)
  57. /* ----------------------- Supporting functions -----------------------------*/
  58. BOOL xMBPortEventInit( void );
  59. BOOL xMBPortEventPost( eMBEventType eEvent );
  60. BOOL xMBPortEventGet( /*@out@ */ eMBEventType * eEvent );
  61. /* ----------------------- Serial port functions ----------------------------*/
  62. BOOL xMBPortSerialInit( UCHAR ucPort, ULONG ulBaudRate,
  63. UCHAR ucDataBits, eMBParity eParity, unsigned int stop_bit );
  64. void vMBPortClose( void );
  65. void xMBPortSerialClose( void );
  66. void vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable );
  67. BOOL xMBPortSerialGetByte( CHAR * pucByte );
  68. BOOL xMBPortSerialPutByte( CHAR ucByte );
  69. /* ----------------------- Timers functions ---------------------------------*/
  70. BOOL xMBPortTimersInit( USHORT usTimeOut50us );
  71. void xMBPortTimersClose( void );
  72. void vMBPortTimersEnable( void );
  73. void vMBPortTimersDisable( void );
  74. void vMBPortTimersDelay( USHORT usTimeOutMS );
  75. /* ----------------------- Callback for the protocol stack ------------------*/
  76. /*!
  77. * \brief Callback function for the porting layer when a new byte is
  78. * available.
  79. *
  80. * Depending upon the mode this callback function is used by the RTU or
  81. * ASCII transmission layers. In any case a call to xMBPortSerialGetByte()
  82. * must immediately return a new character.
  83. *
  84. * \return <code>TRUE</code> if a event was posted to the queue because
  85. * a new byte was received. The port implementation should wake up the
  86. * tasks which are currently blocked on the eventqueue.
  87. */
  88. extern BOOL( *pxMBFrameCBByteReceived ) ( void );
  89. extern BOOL( *pxMBFrameCBTransmitterEmpty ) ( void );
  90. extern BOOL( *pxMBPortCBTimerExpired ) ( void );
  91. /* ----------------------- TCP port functions -------------------------------*/
  92. BOOL xMBTCPPortInit( USHORT usTCPPort );
  93. void vMBTCPPortClose( void );
  94. void vMBTCPPortDisable( void );
  95. BOOL xMBTCPPortGetRequest( UCHAR **ppucMBTCPFrame, USHORT * usTCPLength );
  96. BOOL xMBTCPPortSendResponse( const UCHAR *pucMBTCPFrame, USHORT usTCPLength );
  97. #ifdef __cplusplus
  98. PR_END_EXTERN_C
  99. #endif
  100. #endif