-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserial.h
95 lines (76 loc) · 2.15 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
86
87
88
89
90
91
92
93
94
/*
* This file is part of the Bus Pirate project (http://code.google.com/p/the-bus-pirate/).
*
* Written and maintained by the Bus Pirate project and http://dangerousprototypes.com
*
* To the extent possible under law, the project has
* waived all copyright and related or neighboring rights to Bus Pirate. This
* work is published from United States.
*
* For details see: http://creativecommons.org/publicdomain/zero/1.0/.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
* OS independent serial interface
*
* Heavily based on Pirate-Loader:
* http://the-bus-pirate.googlecode.com/svn/trunk/bootloader-v4/pirate-loader/source/pirate-loader.c
*
*/
#ifndef MYSERIAL_H_
#define MYSERIAL_H_
/*
#ifdef WIN32
#include <windows.h>
#include <time.h>
#define O_NOCTTY 0
#define O_NDELAY 0
#define B115200 115200
#define B921600 921600
#define OS WINDOWS
int write(int fd, const void* buf, int len);
int read(int fd, void* buf, int len);
int close(int fd);
int open(const char* path, unsigned long flags);
int __stdcall select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfs, const struct timeval* timeout);
#else
#include <unistd.h>
#include <termios.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/time.h>
#ifdef MACOSX
#include <IOKit/serial/ioss.h>
#include <sys/ioctl.h>
#define B1500000 1500000
#define B1000000 1000000
#define B921600 921600
#endif
#endif
*/
#include <stdint.h>
#ifndef READ_RETRY
#define READ_RETRY 3
#endif
#ifdef _WIN32
#include <windows.h>
#include <time.h>
#define B115200 115200
#define B921600 921600
// typedef unsigned long speed_t;
#else
#include <termios.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/time.h>
#endif
int serial_setup(int fd, unsigned long speed);
int serial_write(int fd, const char *buf, int size);
int serial_write(int fd, char *buf, int size);
int serial_read(int fd, char *buf, int size, int retry_limit);
int serial_open(char *port);
int serial_close(int fd);
#endif