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