Forking https://os.mbed.com/users/cam/code/Modbus/ to work for NUCLEO 64 boards

Fork of Cam's original FreeModbus port (https://os.mbed.com/users/cam/code/Modbus/)

Change: - Serial implementation to work for NUCLEO 64 boards and receive interrupts instead of timer. (see `portserial.cpp`)

Added: - Custom RTU mode. Allows for external implementation of packet receiving and sending. Sends and receives packets as whole frames (address + PDU) (i.e. this was added for a custom LoRa implementation). implement `xMBRTUCustGetPDU` and `xMBRTUCustSendResponse` (see `mbport.h`) and call `eMBRTUCustomInit( address )`. implementations need to be fully initialised as `eMBRTUCustomInit` only sets the address and nothing else.

Committer:
cam
Date:
Thu Apr 15 12:10:34 2010 +0000
Revision:
0:0453a0a7e500
Child:
3:4cda95d7b6c5

        

Who changed what in which revision?

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