mbgtools-lx  4.2.8
mbgserio.h
Go to the documentation of this file.
1 
2 /**************************************************************************
3  *
4  * $Id: mbgserio.h 1.8.1.1 2018/05/29 08:18:56 martin TRASH $
5  *
6  * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
7  *
8  * Description:
9  * Definitions and prototypes for mbgserio.c.
10  *
11  * -----------------------------------------------------------------------
12  * $Log: mbgserio.h $
13  * Revision 1.8.1.1 2018/05/29 08:18:56 martin
14  * Removed conditional _USE_MBG_TSTR stuff.
15  * Revision 1.8 2017/07/06 07:41:00 martin
16  * Renamed SERIAL_IO_STATUS to MBGSERIO_DEV,
17  * and renamed some fields of the structure.
18  * Defined default device names for serial ports
19  * depending on the target system.
20  * Check preprocessor symbol _USE_MBG_TSTR instead
21  * of _USE_CHK_TSTR.
22  * Check for MBG_TGT_POSIX instead of MBG_TGT_UNIX.
23  * Updated function prototypes.
24  * Revision 1.7 2013/02/01 16:10:45 martin
25  * Got rid of _mbg_open/close/read/write() macros.
26  * Functions are now used instead.
27  * Updated function prototypes.
28  * Revision 1.6 2011/08/23 10:15:25Z martin
29  * Updated function prototypes.
30  * Revision 1.5 2011/08/04 09:48:55 martin
31  * Support flushing output.
32  * Re-ordered some definitions.
33  * Revision 1.4 2009/09/01 10:54:29 martin
34  * Include mbg_tmo.h for the new portable timeout functions.
35  * Added symbols for return codes in case of an error.
36  * Code cleanup.
37  * Revision 1.3 2009/04/01 14:17:31 martin
38  * Cleanup for CVI.
39  * Revision 1.2 2008/09/04 15:11:36Z martin
40  * Preliminary support for device lists.
41  * Updated function prototypes.
42  * Revision 1.1 2007/11/12 16:48:02 martin
43  * Initial revision.
44  *
45  **************************************************************************/
46 
47 #ifndef _MBGSERIO_H
48 #define _MBGSERIO_H
49 
50 
51 /* Other headers to be included */
52 
53 #include <mbg_tgt.h>
54 #include <mbg_tmo.h>
55 #include <mbgerror.h>
56 
57 #include <stdlib.h>
58 #include <string.h>
59 
60 #if defined( MBG_TGT_POSIX )
61  #include <termios.h>
62 #endif
63 
64 #if !defined( _USE_SELECT_FOR_SERIAL_IO )
65  #if defined( MBG_TGT_POSIX )
66  #define _USE_SELECT_FOR_SERIAL_IO 1
67  #else
68  #define _USE_SELECT_FOR_SERIAL_IO 0
69  #endif
70 #endif
71 
72 
73 #ifdef _MBGSERIO
74  #define _ext
75  #define _DO_INIT
76 #else
77  #define _ext extern
78 #endif
79 
80 
81 /* Start of header body */
82 
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
87 #if !defined( DEFAULT_SERIAL_DEVICE_NAME )
88  // For applications which 2 serial ports we also define
89  // default names for the second port to be used.
90  #if defined( MBG_TGT_WIN32 ) || defined( MBG_TGT_DOS )
91  #define DEFAULT_SERIAL_DEVICE_NAME "COM1"
92  #define DEFAULT_SERIAL_DEVICE_NAME_2 "COM2"
93  #elif defined( MBG_TGT_LINUX )
94  #define DEFAULT_SERIAL_DEVICE_NAME "/dev/ttyS0"
95  #define DEFAULT_SERIAL_DEVICE_NAME_2 "/dev/ttyS1"
96  #elif defined( MBG_TGT_FREEBSD )
97  // Call-in ports are named /dev/ttyuN where N is the port number, starting from zero.
98  // Generally, the call-in port is used for terminals. Call-in ports require that
99  // the serial line assert the "Data Carrier Detect" signal to work correctly.
100  // Call-out ports are named /dev/cuauN on FreeBSD versions 8.X and higher
101  // and /dev/cuadN on FreeBSD versions 7.X and lower. Call-out ports are usually
102  // not used for terminals, but are used for modems. The call-out port can be used if
103  // the serial cable or the terminal does not support the "Data Carrier Detect" signal.
104  #if ( __FreeBSD__ > 7 )
105  #define DEFAULT_SERIAL_DEVICE_NAME "/dev/cuau0"
106  #define DEFAULT_SERIAL_DEVICE_NAME_2 "/dev/cuau1"
107  #else
108  #define DEFAULT_SERIAL_DEVICE_NAME "/dev/cuad0"
109  #define DEFAULT_SERIAL_DEVICE_NAME_2 "/dev/cuad1"
110  #endif
111  #elif defined( MBG_TGT_NETBSD )
112  // The ttyXX devices are traditional dial-in devices;
113  // the dtyXX devices are used for dial-out. See tty(4).
114  #define DEFAULT_SERIAL_DEVICE_NAME "/dev/dty00"
115  #define DEFAULT_SERIAL_DEVICE_NAME_2 "/dev/dty01"
116  #else
117  #error DEFAULT_SERIAL_DEVICE_NAME needs to be defined for this target.
118  #endif
119 #endif
120 
121 
122 /*
123  * The following macros control parts of the build process.
124  * The default values are suitable for most cases but can be
125  * overridden by global definitions, if required.
126  */
127 
128 #if _IS_MBG_FIRMWARE
129 
130  // This handle type in not used by the firmware.
131  // However, we define it to avoid build errors.
132  typedef int MBG_HANDLE;
133 
134 #else
135 
136  #if defined( MBG_TGT_CVI )
137 
138  #include <rs232.h>
139 
140  #elif defined( MBG_TGT_WIN32 )
141 
142  #include <io.h>
143 
144  #elif defined( MBG_TGT_DOS )
145 
146  #if defined( _USE_V24TOOLS )
147  #include <v24tools.h>
148  #endif
149 
150  #endif
151 
152 #endif
153 
154 
155 
156 typedef struct _MBG_STR_LIST
157 {
158  char *s;
160 
161 } MBG_STR_LIST;
162 
163 
164 
165 typedef struct
166 {
168 
170 
171  #if defined( MBG_TGT_WIN32 )
172  DCB org_dcb;
173  int org_dcb_has_been_read;
174 
175  COMMTIMEOUTS org_commtimeouts;
176  int org_commtimeouts_have_been_read;
177 
178  COMMPROP comm_prop;
179  int comm_prop_have_been_read;
180  #endif
181 
182  #if defined( MBG_TGT_POSIX )
183  struct termios org_tio;
185  #endif
186 
187 } MBGSERIO_DEV;
188 
189 
190 
191 /* ----- function prototypes begin ----- */
192 
193 /* This section was generated automatically */
194 /* by MAKEHDR, do not remove the comments. */
195 
208 
218  _NO_MBG_API_ATTR int _MBG_API mbgserio_open( MBGSERIO_DEV **pp_mdev, const char *dev_name ) ;
219 
227  _NO_MBG_API_ATTR int _MBG_API mbgserio_set_parms( MBGSERIO_DEV *mdev, uint32_t baud_rate, const char *framing ) ;
228 
229  _NO_MBG_API_ATTR int _MBG_API mbgserio_read( MBGSERIO_DEV *mdev, void *buffer, unsigned int count ) ;
230  _NO_MBG_API_ATTR int _MBG_API mbgserio_write( MBGSERIO_DEV *mdev, const void *buffer, unsigned int count ) ;
232  _NO_MBG_API_ATTR int _MBG_API mbgserio_read_wait( MBGSERIO_DEV *mdev, void *buffer, uint count ) ;
233 
234 /* ----- function prototypes end ----- */
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 
240 /* End of header body */
241 
242 #undef _ext
243 #undef _DO_INIT
244 
245 #endif /* _MBGSERIO_H */
void mbgserio_flush_tx(MBGSERIO_DEV *mdev)
int MBG_PORT_HANDLE
Definition: mbg_tgt.h:967
int mbgserio_read_wait(MBGSERIO_DEV *mdev, void *buffer, uint count)
static char * dev_name
Definition: mbgctrl.c:131
void mbgserio_free_str_list(MBG_STR_LIST *list)
int mbgserio_write(MBGSERIO_DEV *mdev, const void *buffer, unsigned int count)
int mbgserio_open(MBGSERIO_DEV **pp_mdev, const char *dev_name)
Open a serial port and set up a MBGSERIO_DEV structure.
#define _NO_MBG_API_ATTR
Definition: mbg_tgt.h:1032
ulong poll_timeout
The default timeout when waiting for data.
Definition: mbgserio.h:169
int mbgserio_setup_port_str_list(MBG_STR_LIST **list, int max_devs)
int org_tio_has_been_read
Definition: mbgserio.h:184
struct _MBG_STR_LIST MBG_STR_LIST
struct _MBG_STR_LIST * next
Definition: mbgserio.h:159
int MBG_HANDLE
Definition: mbg_tgt.h:966
static int max_devs
#define _MBG_API
Definition: mbg_tgt.h:1020
MBG_PORT_HANDLE port_handle
the handle that will be used for the device
Definition: mbgserio.h:167
int mbgserio_read(MBGSERIO_DEV *mdev, void *buffer, unsigned int count)
int mbgserio_close(MBGSERIO_DEV **pp_mdev)
Close a serial port specified by a MBGSERIO_DEV structure.
unsigned int uint
Definition: words.h:287
int mbgserio_set_parms(MBGSERIO_DEV *mdev, uint32_t baud_rate, const char *framing)
unsigned long ulong
Definition: words.h:292
char * s
Definition: mbgserio.h:158