Project

General

Profile

Statistics
| Branch: | Revision:

root / freemodbus / modbus / include / mbport.h @ 20e5429c

History | View | Annotate | Download (4.83 KB)

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