1 //---------------------------------------------------------------------------
\r
2 // Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.
\r
4 // Permission is hereby granted, free of charge, to any person obtaining a
\r
5 // copy of this software and associated documentation files (the "Software"),
\r
6 // to deal in the Software without restriction, including without limitation
\r
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
\r
8 // and/or sell copies of the Software, and to permit persons to whom the
\r
9 // Software is furnished to do so, subject to the following conditions:
\r
11 // The above copyright notice and this permission notice shall be included
\r
12 // in all copies or substantial portions of the Software.
\r
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
\r
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
\r
17 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
\r
18 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
\r
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
\r
20 // OTHER DEALINGS IN THE SOFTWARE.
\r
22 // Except as contained in this notice, the name of Dallas Semiconductor
\r
23 // shall not be used except as stated in the Dallas Semiconductor
\r
25 //---------------------------------------------------------------------------
\r
27 // TMEXLnk.C - Link module to call on TMEX low-level functions to
\r
28 // excersize the general 1-Wire Net functions.
\r
29 // (Requires TMEX 3.11 or newer)
\r
33 // History: 1.00 -> 1.01 Return values in owLevel corrected.
\r
34 // Added function msDelay.
\r
35 // 1.02 -> 1.03 Add msGettick, always return owLevel success
\r
36 // to hide adapters (DS9097E) that do not have
\r
37 // power delivery capabilities.
\r
38 // 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for
\r
40 // 2.10 -> 3.00 Added owReadBitPower and owWriteBytePower
\r
43 #include <windows.h>
\r
45 // external TMEX variables
\r
46 extern long SessionHandle[MAX_PORTNUM];
\r
47 extern uchar StateBuffer[MAX_PORTNUM][5120];
\r
48 extern "C" short far pascal TMTouchByte(long, short);
\r
49 extern "C" short far pascal TMTouchReset(long);
\r
50 extern "C" short far pascal TMTouchBit(long, short);
\r
51 extern "C" short far pascal TMProgramPulse(long);
\r
52 extern "C" short far pascal TMOneWireCom(long, short, short);
\r
53 extern "C" short far pascal TMOneWireLevel(long, short, short, short);
\r
56 SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE = FALSE; // for compatibility purposes
\r
58 //--------------------------------------------------------------------------
\r
59 // Reset all of the devices on the 1-Wire Net and return the result.
\r
61 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
62 // indicate the symbolic port number.
\r
64 // Returns: TRUE(1): presense pulse(s) detected, device(s) reset
\r
65 // FALSE(0): no presense pulses detected
\r
67 SMALLINT owTouchReset(int portnum)
\r
71 // Assume valid Session
\r
72 result = TMTouchReset(SessionHandle[portnum]);
\r
74 // success if the normal or alarm presence
\r
75 if ((result == 1) || (result == 2))
\r
82 //--------------------------------------------------------------------------
\r
83 // Send 1 bit of communication to the 1-Wire Net and return the
\r
84 // result 1 bit read from the 1-Wire Net. The parameter 'sendbit'
\r
85 // least significant bit is used and the least significant bit
\r
86 // of the result is the return bit.
\r
88 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
89 // indicate the symbolic port number.
\r
90 // 'sendbit' - the least significant bit is the bit to send
\r
92 // Returns: 0: 0 bit read from sendbit
\r
93 // 1: 1 bit read from sendbit
\r
95 SMALLINT owTouchBit(int portnum, SMALLINT sendbit)
\r
97 // Assume valid Session
\r
98 return TMTouchBit(SessionHandle[portnum],(short)sendbit);
\r
101 //--------------------------------------------------------------------------
\r
102 // Send 8 bits of communication to the 1-Wire Net and verify that the
\r
103 // 8 bits read from the 1-Wire Net is the same (write operation).
\r
104 // The parameter 'sendbyte' least significant 8 bits are used.
\r
106 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
107 // indicate the symbolic port number.
\r
108 // 'sendbyte' - 8 bits to send (least significant byte)
\r
110 // Returns: TRUE: bytes written and echo was the same
\r
111 // FALSE: echo was not the same
\r
113 SMALLINT owTouchByte(int portnum, SMALLINT sendbyte)
\r
115 // Assume valid Session
\r
116 return TMTouchByte(SessionHandle[portnum],(short)sendbyte);
\r
119 //--------------------------------------------------------------------------
\r
120 // Send 8 bits of communication to the MicroLAN and verify that the
\r
121 // 8 bits read from the MicroLAN is the same (write operation).
\r
122 // The parameter 'sendbyte' least significant 8 bits are used.
\r
124 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
125 // indicate the symbolic port number.
\r
126 // 'sendbyte' - 8 bits to send (least significant byte)
\r
128 // Returns: TRUE: bytes written and echo was the same
\r
129 // FALSE: echo was not the same
\r
131 SMALLINT owWriteByte(int portnum, SMALLINT sendbyte)
\r
133 return (owTouchByte(portnum,sendbyte) == sendbyte) ? TRUE : FALSE;
\r
136 //--------------------------------------------------------------------------
\r
137 // Send 8 bits of read communication to the 1-Wire Net and and return the
\r
138 // result 8 bits read from the 1-Wire Net.
\r
140 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
141 // indicate the symbolic port number.
\r
143 // Returns: TRUE: 8 bytes read from 1-Wire Net
\r
144 // FALSE: the 8 bytes were not read
\r
146 SMALLINT owReadByte(int portnum)
\r
148 return owTouchByte(portnum,0xFF);
\r
151 //--------------------------------------------------------------------------
\r
152 // Set the 1-Wire Net communucation speed.
\r
154 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
155 // indicate the symbolic port number.
\r
156 // 'new_speed' - new speed defined as
\r
157 // MODE_NORMAL 0x00
\r
158 // MODE_OVERDRIVE 0x01
\r
160 // Returns: current 1-Wire Net speed
\r
162 SMALLINT owSpeed(int portnum, SMALLINT new_speed)
\r
164 return TMOneWireCom(SessionHandle[portnum],0,(short)new_speed);
\r
167 //--------------------------------------------------------------------------
\r
168 // Set the 1-Wire Net line level. The values for new_level are
\r
171 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
172 // indicate the symbolic port number.
\r
173 // 'new_level' - new level defined as
\r
174 // MODE_NORMAL 0x00
\r
175 // MODE_STRONG5 0x02
\r
176 // MODE_PROGRAM 0x04
\r
177 // MODE_BREAK 0x08 (not supported)
\r
179 // Returns: current 1-Wire Net level
\r
181 SMALLINT owLevel(int portnum, SMALLINT new_level)
\r
184 int docheck = FALSE;
\r
186 // check for DS2480 bug
\r
187 if (((SessionHandle[portnum] & 0x0F0) == 0x050) &&
\r
188 (TMOneWireLevel(SessionHandle[portnum],1,0,0) == 1))
\r
194 rslt = TMOneWireLevel(SessionHandle[portnum],0,0,0);
\r
195 // test code for DS2480 bug
\r
197 TMTouchBit(SessionHandle[portnum],1);
\r
200 rslt = TMOneWireLevel(SessionHandle[portnum],0,1,0);
\r
203 rslt = TMOneWireLevel(SessionHandle[portnum],0,3,0);
\r
206 rslt = TMOneWireLevel(SessionHandle[portnum],0,2,0);
\r
212 // Assume TMEX can do it so always return NewLevel
\r
216 //--------------------------------------------------------------------------
\r
217 // This procedure creates a fixed 480 microseconds 12 volt pulse
\r
218 // on the 1-Wire Net for programming EPROM iButtons.
\r
220 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
221 // indicate the symbolic port number.
\r
223 // Returns: TRUE successful
\r
224 // FALSE program voltage not available
\r
226 SMALLINT owProgramPulse(int portnum)
\r
228 return TMProgramPulse(SessionHandle[portnum]);
\r
231 //--------------------------------------------------------------------------
\r
233 // Delay for at least 'len' ms
\r
235 void msDelay(int len)
\r
240 //--------------------------------------------------------------------------
\r
241 // Get the current millisecond tick count. Does not have to represent
\r
242 // an actual time, it just needs to be an incrementing timer.
\r
244 long msGettick(void)
\r
246 return GetTickCount();
\r
249 //--------------------------------------------------------------------------
\r
250 // Send 8 bits of communication to the 1-Wire Net and verify that the
\r
251 // 8 bits read from the 1-Wire Net is the same (write operation).
\r
252 // The parameter 'sendbyte' least significant 8 bits are used. After the
\r
253 // 8 bits are sent change the level of the 1-Wire net.
\r
255 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
\r
256 // OpenCOM to indicate the port number.
\r
257 // 'sendbyte' - 8 bits to send (least significant byte)
\r
259 // Returns: TRUE: bytes written and echo was the same
\r
260 // FALSE: echo was not the same
\r
262 SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte)
\r
264 // prime for power delivery after byte
\r
265 TMOneWireLevel(SessionHandle[portnum],0,1,2);
\r
267 // send the byte and start strong pullup
\r
268 if(TMTouchByte(SessionHandle[portnum],(short)sendbyte) != sendbyte)
\r
270 TMOneWireLevel(SessionHandle[portnum],0,0,0);
\r
277 //--------------------------------------------------------------------------
\r
278 // Read 8 bits of communication to the 1-Wire Net and verify that the
\r
279 // 8 bits read from the 1-Wire Net is the same (write operation).
\r
280 // The parameter 'sendbyte' least significant 8 bits are used. After the
\r
281 // 8 bits are read change the level of the 1-Wire net.
\r
283 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
\r
284 // OpenCOM to indicate the port number.
\r
285 // 'sendbyte' - 8 bits to send (least significant byte)
\r
287 // Returns: TRUE: bytes written and echo was the same
\r
288 // FALSE: echo was not the same
\r
290 SMALLINT owReadBytePower(int portnum)
\r
292 SMALLINT sendbyte = 0xFF;
\r
294 // prime for power delivery after byte
\r
295 TMOneWireLevel(SessionHandle[portnum],0,1,2);
\r
297 // send the byte and start strong pullup
\r
298 return TMTouchByte(SessionHandle[portnum],(short)sendbyte);
\r
301 //--------------------------------------------------------------------------
\r
302 // Send 1 bit of communication to the 1-Wire Net and verify that the
\r
303 // response matches the 'applyPowerResponse' bit and apply power delivery
\r
304 // to the 1-Wire net. Note that some implementations may apply the power
\r
305 // first and then turn it off if the response is incorrect.
\r
307 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
\r
308 // OpenCOM to indicate the port number.
\r
309 // 'applyPowerResponse' - 1 bit response to check, if correct then start
\r
312 // Returns: TRUE: bit written and response correct, strong pullup now on
\r
313 // FALSE: response incorrect
\r
315 SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse)
\r
317 // prime for power delivery after bit
\r
318 TMOneWireLevel(SessionHandle[portnum],0,1,1);
\r
320 // send the byte and start strong pullup
\r
321 if(TMTouchBit(SessionHandle[portnum],0x01) != applyPowerResponse)
\r
323 TMOneWireLevel(SessionHandle[portnum],0,0,0);
\r
330 //--------------------------------------------------------------------------
\r
331 // This procedure indicates wether the adapter can deliver power.
\r
333 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
\r
334 // OpenCOM to indicate the port number.
\r
336 // Returns: TRUE because all userial adapters have over drive.
\r
338 SMALLINT owHasPowerDelivery(int portnum)
\r
343 //--------------------------------------------------------------------------
\r
344 // This procedure indicates wether the adapter can deliver power.
\r
346 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
\r
347 // OpenCOM to indicate the port number.
\r
349 // Returns: TRUE because all userial adapters have over drive.
\r
351 SMALLINT owHasOverDrive(int portnum)
\r
356 //--------------------------------------------------------------------------
\r
357 // This procedure creates a fixed 480 microseconds 12 volt pulse
\r
358 // on the 1-Wire Net for programming EPROM iButtons.
\r
360 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
\r
361 // OpenCOM to indicate the port number.
\r
363 // Returns: TRUE program volatage available
\r
364 // FALSE program voltage not available
\r
365 SMALLINT owHasProgramPulse(int portnum)
\r
367 return TMProgramPulse(SessionHandle[portnum]);
\r