forked from vogelchr/radioclkd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial.h
85 lines (59 loc) · 1.65 KB
/
serial.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef SERIAL_H_
#define SERIAL_H_
#include "systime.h"
#include <sys/ioctl.h>
#include "timef.h"
#ifdef ENABLE_TIMEPPS
#include <sys/timepps.h>
#endif
//a serial device (serDevT) is an individual serial port, with several status control lines
//a modem status line (serLineT) is an individual status line on a serial port
typedef struct serDevS serDevT;
typedef struct serLineS serLineT;
struct serDevS
{
serDevT* next;
//full device name (including "/dev/")
char dev[64];
#define SERPORT_MODE_IWAIT (1)
#define SERPORT_MODE_POLL (2)
#define SERPORT_MODE_TIMEPPS (3)
#define SERPORT_MODE_GPIO (4)
int mode;
//which modem status lines to check - some of TIOCM_{RNG|DSR|CD|CTS}
int modemlines;
//-- runtime data
//once opened, the fd for this device
int fd;
#ifdef ENABLE_TIMEPPS
pps_handle_t ppshandle;
int ppslastassert;
int ppslastclear;
#endif
//the current and previous modem lines active - some of modemlines
int curlines;
int prevlines;
time_f eventtime;
};
struct serLineS
{
serLineT* next;
//one of TIOCM_{RNG|DSR|CD|CTS}
int line;
serDevT* dev;
int curstate;
time_f eventtime;
};
int serInit (void);
serLineT* serAddLine ( char* dev, int line, int mode );
//pass in NULL to get the first dev/line
//pass in dev/line to get next dev/line
//returns NULL at end of dev/line list
serDevT* serGetDev ( serDevT* prev );
serLineT* serGetLine ( serLineT* prev );
int serInitHardware ( serDevT* dev );
int serWaitForSerialChange ( serDevT* dev );
int serGetDevStatusLines ( serDevT* dev, time_f timef );
int serStoreDevStatusLines ( serDevT* dev, int lines, time_f time );
int serUpdateLinesForDevice ( serDevT* dev );
#endif