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