Modbus RTU/ASCII/TCP with lwip TCP working partial, but with errors (retransmitions)

Dependencies:   EthernetNetIf mbed

Committer:
tmav123
Date:
Mon Dec 05 22:49:02 2011 +0000
Revision:
0:f54e9507171b

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tmav123 0:f54e9507171b 1 /*
tmav123 0:f54e9507171b 2 * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
tmav123 0:f54e9507171b 3 * Copyright (c) 2006 Christian Walter <wolti@sil.at>
tmav123 0:f54e9507171b 4 * All rights reserved.
tmav123 0:f54e9507171b 5 *
tmav123 0:f54e9507171b 6 * Redistribution and use in source and binary forms, with or without
tmav123 0:f54e9507171b 7 * modification, are permitted provided that the following conditions
tmav123 0:f54e9507171b 8 * are met:
tmav123 0:f54e9507171b 9 * 1. Redistributions of source code must retain the above copyright
tmav123 0:f54e9507171b 10 * notice, this list of conditions and the following disclaimer.
tmav123 0:f54e9507171b 11 * 2. Redistributions in binary form must reproduce the above copyright
tmav123 0:f54e9507171b 12 * notice, this list of conditions and the following disclaimer in the
tmav123 0:f54e9507171b 13 * documentation and/or other materials provided with the distribution.
tmav123 0:f54e9507171b 14 * 3. The name of the author may not be used to endorse or promote products
tmav123 0:f54e9507171b 15 * derived from this software without specific prior written permission.
tmav123 0:f54e9507171b 16 *
tmav123 0:f54e9507171b 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
tmav123 0:f54e9507171b 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
tmav123 0:f54e9507171b 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
tmav123 0:f54e9507171b 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
tmav123 0:f54e9507171b 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
tmav123 0:f54e9507171b 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
tmav123 0:f54e9507171b 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
tmav123 0:f54e9507171b 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
tmav123 0:f54e9507171b 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
tmav123 0:f54e9507171b 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
tmav123 0:f54e9507171b 27 *
tmav123 0:f54e9507171b 28 * File: $Id: mbport.h,v 1.19 2010/06/06 13:54:40 wolti Exp $
tmav123 0:f54e9507171b 29 */
tmav123 0:f54e9507171b 30
tmav123 0:f54e9507171b 31 #ifndef _MB_PORT_H
tmav123 0:f54e9507171b 32 #define _MB_PORT_H
tmav123 0:f54e9507171b 33
tmav123 0:f54e9507171b 34 #ifdef __cplusplus
tmav123 0:f54e9507171b 35 PR_BEGIN_EXTERN_C
tmav123 0:f54e9507171b 36 #endif
tmav123 0:f54e9507171b 37
tmav123 0:f54e9507171b 38 /* ----------------------- Type definitions ---------------------------------*/
tmav123 0:f54e9507171b 39
tmav123 0:f54e9507171b 40 typedef enum
tmav123 0:f54e9507171b 41 {
tmav123 0:f54e9507171b 42 EV_READY, /*!< Startup finished. */
tmav123 0:f54e9507171b 43 EV_FRAME_RECEIVED, /*!< Frame received. */
tmav123 0:f54e9507171b 44 EV_EXECUTE, /*!< Execute function. */
tmav123 0:f54e9507171b 45 EV_FRAME_SENT /*!< Frame sent. */
tmav123 0:f54e9507171b 46 } eMBEventType;
tmav123 0:f54e9507171b 47
tmav123 0:f54e9507171b 48 /*! \ingroup modbus
tmav123 0:f54e9507171b 49 * \brief Parity used for characters in serial mode.
tmav123 0:f54e9507171b 50 *
tmav123 0:f54e9507171b 51 * The parity which should be applied to the characters sent over the serial
tmav123 0:f54e9507171b 52 * link. Please note that this values are actually passed to the porting
tmav123 0:f54e9507171b 53 * layer and therefore not all parity modes might be available.
tmav123 0:f54e9507171b 54 */
tmav123 0:f54e9507171b 55 typedef enum
tmav123 0:f54e9507171b 56 {
tmav123 0:f54e9507171b 57 MB_PAR_NONE, /*!< No parity. */
tmav123 0:f54e9507171b 58 MB_PAR_ODD, /*!< Odd parity. */
tmav123 0:f54e9507171b 59 MB_PAR_EVEN /*!< Even parity. */
tmav123 0:f54e9507171b 60 } eMBParity;
tmav123 0:f54e9507171b 61
tmav123 0:f54e9507171b 62 /* ----------------------- Supporting functions -----------------------------*/
tmav123 0:f54e9507171b 63 BOOL xMBPortEventInit( void );
tmav123 0:f54e9507171b 64
tmav123 0:f54e9507171b 65 BOOL xMBPortEventPost( eMBEventType eEvent );
tmav123 0:f54e9507171b 66
tmav123 0:f54e9507171b 67 BOOL xMBPortEventGet( /*@out@ */ eMBEventType * eEvent );
tmav123 0:f54e9507171b 68
tmav123 0:f54e9507171b 69 /* ----------------------- Serial port functions ----------------------------*/
tmav123 0:f54e9507171b 70
tmav123 0:f54e9507171b 71 BOOL xMBPortSerialInit( UCHAR ucPort, ULONG ulBaudRate,
tmav123 0:f54e9507171b 72 UCHAR ucDataBits, eMBParity eParity );
tmav123 0:f54e9507171b 73
tmav123 0:f54e9507171b 74 void vMBPortClose( void );
tmav123 0:f54e9507171b 75
tmav123 0:f54e9507171b 76 void xMBPortSerialClose( void );
tmav123 0:f54e9507171b 77
tmav123 0:f54e9507171b 78 void vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable );
tmav123 0:f54e9507171b 79
tmav123 0:f54e9507171b 80 BOOL xMBPortSerialGetByte( CHAR * pucByte );
tmav123 0:f54e9507171b 81
tmav123 0:f54e9507171b 82 BOOL xMBPortSerialPutByte( CHAR ucByte );
tmav123 0:f54e9507171b 83
tmav123 0:f54e9507171b 84 /* ----------------------- Timers functions ---------------------------------*/
tmav123 0:f54e9507171b 85 BOOL xMBPortTimersInit( USHORT usTimeOut50us );
tmav123 0:f54e9507171b 86
tmav123 0:f54e9507171b 87 void xMBPortTimersClose( void );
tmav123 0:f54e9507171b 88
tmav123 0:f54e9507171b 89 void vMBPortTimersEnable( void );
tmav123 0:f54e9507171b 90
tmav123 0:f54e9507171b 91 void vMBPortTimersDisable( void );
tmav123 0:f54e9507171b 92
tmav123 0:f54e9507171b 93 void vMBPortTimersDelay( USHORT usTimeOutMS );
tmav123 0:f54e9507171b 94
tmav123 0:f54e9507171b 95 /* ----------------------- Callback for the protocol stack ------------------*/
tmav123 0:f54e9507171b 96
tmav123 0:f54e9507171b 97 /*!
tmav123 0:f54e9507171b 98 * \brief Callback function for the porting layer when a new byte is
tmav123 0:f54e9507171b 99 * available.
tmav123 0:f54e9507171b 100 *
tmav123 0:f54e9507171b 101 * Depending upon the mode this callback function is used by the RTU or
tmav123 0:f54e9507171b 102 * ASCII transmission layers. In any case a call to xMBPortSerialGetByte()
tmav123 0:f54e9507171b 103 * must immediately return a new character.
tmav123 0:f54e9507171b 104 *
tmav123 0:f54e9507171b 105 * \return <code>TRUE</code> if a event was posted to the queue because
tmav123 0:f54e9507171b 106 * a new byte was received. The port implementation should wake up the
tmav123 0:f54e9507171b 107 * tasks which are currently blocked on the eventqueue.
tmav123 0:f54e9507171b 108 */
tmav123 0:f54e9507171b 109 extern BOOL( *pxMBFrameCBByteReceived ) ( void );
tmav123 0:f54e9507171b 110
tmav123 0:f54e9507171b 111 extern BOOL( *pxMBFrameCBTransmitterEmpty ) ( void );
tmav123 0:f54e9507171b 112
tmav123 0:f54e9507171b 113 extern BOOL( *pxMBPortCBTimerExpired ) ( void );
tmav123 0:f54e9507171b 114
tmav123 0:f54e9507171b 115 /* ----------------------- TCP port functions -------------------------------*/
tmav123 0:f54e9507171b 116 BOOL xMBTCPPortInit( USHORT usTCPPort );
tmav123 0:f54e9507171b 117
tmav123 0:f54e9507171b 118 void vMBTCPPortClose( void );
tmav123 0:f54e9507171b 119
tmav123 0:f54e9507171b 120 void vMBTCPPortDisable( void );
tmav123 0:f54e9507171b 121
tmav123 0:f54e9507171b 122 BOOL xMBTCPPortGetRequest( UCHAR **ppucMBTCPFrame, USHORT * usTCPLength );
tmav123 0:f54e9507171b 123
tmav123 0:f54e9507171b 124 BOOL xMBTCPPortSendResponse( const UCHAR *pucMBTCPFrame, USHORT usTCPLength );
tmav123 0:f54e9507171b 125
tmav123 0:f54e9507171b 126 #ifdef __cplusplus
tmav123 0:f54e9507171b 127 PR_END_EXTERN_C
tmav123 0:f54e9507171b 128 #endif
tmav123 0:f54e9507171b 129 #endif