Modified version of ModbusTCP

Dependencies:   EthernetNetIf mbed

Committer:
paleskyjp
Date:
Thu Mar 15 15:28:14 2012 +0000
Revision:
3:d7d7c67f21fa
Parent:
0:62be54b8975d
eMBRegCoilsCB was corrected.
(Implementation of writing single coil was wrong.)

Who changed what in which revision?

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