-
Notifications
You must be signed in to change notification settings - Fork 0
/
owlib.h
216 lines (181 loc) · 6.74 KB
/
owlib.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
* owlib.h
*
* Created on: 19 ÿíâ. 2014 ã.
* Author: dbkrasn
*/
#ifndef OWLIB_H_
#define OWLIB_H_
#include <fakedevices.h>
// definitions
#define FALSE 0
#define TRUE 1
#define WRITE_FUNCTION 0
#define READ_FUNCTION 1
// Mode Commands
#define MODE_DATA 0xE1
#define MODE_COMMAND 0xE3
#define MODE_STOP_PULSE 0xF1
// Return byte value
#define RB_CHIPID_MASK 0x1C
#define RB_RESET_MASK 0x03
#define RB_1WIRESHORT 0x00
#define RB_PRESENCE 0x01
#define RB_ALARMPRESENCE 0x02
#define RB_NOPRESENCE 0x03
#define RB_BIT_MASK 0x03
#define RB_BIT_ONE 0x03
#define RB_BIT_ZERO 0x00
// Masks for all bit ranges
#define CMD_MASK 0x80
#define FUNCTSEL_MASK 0x60
#define BITPOL_MASK 0x10
#define SPEEDSEL_MASK 0x0C
#define MODSEL_MASK 0x02
#define PARMSEL_MASK 0x70
#define PARMSET_MASK 0x0E
// Command or config bit
#define CMD_COMM 0x81
#define CMD_CONFIG 0x01
// Function select bits
#define FUNCTSEL_BIT 0x00
#define FUNCTSEL_SEARCHON 0x30
#define FUNCTSEL_SEARCHOFF 0x20
#define FUNCTSEL_RESET 0x40
#define FUNCTSEL_CHMOD 0x60
// Bit polarity/Pulse voltage bits
#define BITPOL_ONE 0x10
#define BITPOL_ZERO 0x00
#define BITPOL_5V 0x00
#define BITPOL_12V 0x10
// One Wire speed bits
#define SPEEDSEL_STD 0x00
#define SPEEDSEL_FLEX 0x04
#define SPEEDSEL_OD 0x08
#define SPEEDSEL_PULSE 0x0C
// Data/Command mode select bits
#define MODSEL_DATA 0x00
#define MODSEL_COMMAND 0x02
// 5V Follow Pulse select bits
#define PRIME5V_TRUE 0x02
#define PRIME5V_FALSE 0x00
// Parameter select bits
#define PARMSEL_PARMREAD 0x00
#define PARMSEL_SLEW 0x10
#define PARMSEL_12VPULSE 0x20
#define PARMSEL_5VPULSE 0x30
#define PARMSEL_WRITE1LOW 0x40
#define PARMSEL_SAMPLEOFFSET 0x50
#define PARMSEL_ACTIVEPULLUPTIME 0x60
#define PARMSEL_BAUDRATE 0x70
// Pull down slew rate.
#define PARMSET_Slew15Vus 0x00
#define PARMSET_Slew2p2Vus 0x02
#define PARMSET_Slew1p65Vus 0x04
#define PARMSET_Slew1p37Vus 0x06
#define PARMSET_Slew1p1Vus 0x08
#define PARMSET_Slew0p83Vus 0x0A
#define PARMSET_Slew0p7Vus 0x0C
#define PARMSET_Slew0p55Vus 0x0E
// 12V programming pulse time table
#define PARMSET_32us 0x00
#define PARMSET_64us 0x02
#define PARMSET_128us 0x04
#define PARMSET_256us 0x06
#define PARMSET_512us 0x08
#define PARMSET_1024us 0x0A
#define PARMSET_2048us 0x0C
#define PARMSET_infinite 0x0E
// 5V strong pull up pulse time table
#define PARMSET_16p4ms 0x00
#define PARMSET_65p5ms 0x02
#define PARMSET_131ms 0x04
#define PARMSET_262ms 0x06
#define PARMSET_524ms 0x08
#define PARMSET_1p05s 0x0A
#define PARMSET_dynamic 0x0C
#define PARMSET_infinite 0x0E
// Write 1 low time
#define PARMSET_Write8us 0x00
#define PARMSET_Write9us 0x02
#define PARMSET_Write10us 0x04
#define PARMSET_Write11us 0x06
#define PARMSET_Write12us 0x08
#define PARMSET_Write13us 0x0A
#define PARMSET_Write14us 0x0C
#define PARMSET_Write15us 0x0E
// Data sample offset and Write 0 recovery time
#define PARMSET_SampOff3us 0x00
#define PARMSET_SampOff4us 0x02
#define PARMSET_SampOff5us 0x04
#define PARMSET_SampOff6us 0x06
#define PARMSET_SampOff7us 0x08
#define PARMSET_SampOff8us 0x0A
#define PARMSET_SampOff9us 0x0C
#define PARMSET_SampOff10us 0x0E
// Active pull up on time
#define PARMSET_PullUp0p0us 0x00
#define PARMSET_PullUp0p5us 0x02
#define PARMSET_PullUp1p0us 0x04
#define PARMSET_PullUp1p5us 0x06
#define PARMSET_PullUp2p0us 0x08
#define PARMSET_PullUp2p5us 0x0A
#define PARMSET_PullUp3p0us 0x0C
#define PARMSET_PullUp3p5us 0x0E
// Baud rate bits
#define PARMSET_9600 0x00
#define PARMSET_19200 0x02
#define PARMSET_57600 0x04
#define PARMSET_115200 0x06
// DS2480B program voltage available
#define DS2480BPROG_MASK 0x20
// mode bit flags
#define MODE_NORMAL 0x00
#define MODE_OVERDRIVE 0x01
#define MODE_STRONG5 0x02
#define MODE_PROGRAM 0x04
#define MODE_BREAK 0x08
#define MAX_BAUD PARMSET_115200
// Basic 1-Wire functions
int OWReset();
unsigned char OWTouchBit(unsigned char sendbit);
unsigned char OWTouchByte(unsigned char sendbyte);
void OWWriteByte(unsigned char byte_value);
void OWWriteBit(unsigned char bit_value);
unsigned char OWReadBit();
unsigned char OWReadByte();
int OWBlock(unsigned char *tran_buf, int tran_len);
int OWSearch();
int OWFirst();
int OWNext();
int OWVerify();
void OWTargetSetup(unsigned char family_code);
void OWFamilySkipSetup();
// Extended 1-Wire functions
int OWSpeed(int new_speed);
int OWLevel(int level);
int OWProgramPulse(void);
int OWWriteBytePower(int sendbyte);
int OWReadBitPower(int applyPowerResponse);
// DS2480B utility functions
int DS2480B_Detect(void);
int DS2480B_ChangeBaud(unsigned char newbaud);
// UART connectivity functions (Win32 implementation)
void FlushCOM(void);
int WriteOWI(int outlen, unsigned char *outbuf);
int ReadOWI(int inlen, unsigned char *inbuf);
void BreakCOM(void);
void SetBaudCOM(unsigned char new_baud);
void msDelay(int len);
int OpenCOM();
void CloseCOM(void);
// misc utility functions
unsigned char docrc8(unsigned char value);
int bitacc(int op, int state, int loc, unsigned char *buf);
// search state
unsigned char getROM_NO(int);
void OWInit();
int OWSearchROM(unsigned char* address);
int OWMatchROM(unsigned char* address);
void OWReadROM(unsigned char* address);
#endif /* OWLIB_H_ */