1 //---------------------------------------------------------------------------
\r
2 // Copyright (C) 2000 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 // ownet.h - Include file for 1-Wire Net library
\r
31 // History: 1.02 -> 1.03 Make sure uchar is not defined twice.
\r
32 // 1.03 -> 2.00 Changed 'MLan' to 'ow'.
\r
33 // 2.00 -> 2.01 Added error handling. Added circular-include check.
\r
34 // 2.01 -> 2.10 Added raw memory error handling and SMALLINT
\r
35 // 2.10 -> 3.00 Added memory bank functionality
\r
36 // Added file I/O operations
\r
42 //--------------------------------------------------------------//
\r
43 // Common Includes to ownet applications
\r
44 //--------------------------------------------------------------//
\r
48 //--------------------------------------------------------------//
\r
49 // Target Specific Information
\r
50 //--------------------------------------------------------------//
\r
51 //--------------------------------------------------------------//
\r
52 // Handhelds (PalmOS, WinCE)
\r
53 //--------------------------------------------------------------//
\r
55 //MC68K is the type of processor in the PILOT
\r
56 //Metrowerk's CodeWarrior defines this symbol
\r
59 #include <StringMgr.h>
\r
60 #define strcmp StrCompare
\r
62 #include <file_struc.h>
\r
66 //All of our projects had this flag defined by default (_WIN32_WCE),
\r
67 //but I'm not 100% positive that this is _the_ definitive
\r
68 //flag to use to identify a WinCE system.
\r
69 #include "WinCElnk.h"
\r
72 extern int sprintf(char *buffer, char *format,...);
\r
73 extern void fprintf(FILE *fp, char *format,...);
\r
74 extern void printf(char *format,...);
\r
78 #if !defined(_WIN32_WCE) && !defined(__MC68K__)
\r
84 #define exit(c) return
\r
85 typedef unsigned int ushort;
\r
86 typedef unsigned long ulong;
\r
87 #define SMALLINT uchar
\r
95 typedef unsigned int ushort;
\r
96 typedef unsigned long ulong;
\r
97 #define SMALLINT short
\r
98 #define main micro_main
\r
99 #define real_main main
\r
100 #define SMALL_MEMORY_TARGET
\r
104 //--------------------------------------------------------------//
\r
106 //--------------------------------------------------------------//
\r
109 // purpose of smallint is for compile-time changing of formal
\r
110 // parameters and return values of functions. For each target
\r
111 // machine, an integer is alleged to represent the most "simple"
\r
112 // number representable by that architecture. This should, in
\r
113 // most cases, produce optimal code for that particular arch.
\r
114 // BUT... The majority of compilers designed for embedded
\r
115 // processors actually keep an int at 16 bits, although the
\r
116 // architecture might only be comfortable with 8 bits.
\r
117 // The default size of smallint will be the same as that of
\r
118 // an integer, but this allows for easy overriding of that size.
\r
121 // In all cases where a smallint is used, it is assumed that
\r
122 // decreasing the size of this integer to something as low as
\r
123 // a single byte _will_not_ change the functionality of the
\r
124 // application. e.g. a loop counter that will iterate through
\r
125 // several kilobytes of data should not be SMALLINT. The most
\r
126 // common place you'll see smallint is for boolean return types.
\r
128 #define SMALLINT int
\r
131 // setting max baud
\r
133 // 0x02 = PARAMSET_19200
\r
134 #define MAX_BAUD 0x02
\r
136 // 0x06 = PARMSET_115200
\r
137 #define MAX_BAUD 0x06
\r
142 typedef unsigned char uchar;
\r
143 #if !defined(__MINGW32__) && (defined(__CYGWIN__) || defined(__GNUC__))
\r
144 typedef unsigned long ulong;
\r
145 //ushort already defined in sys/types.h
\r
146 #include <sys/types.h>
\r
148 #if defined(_WIN32) || defined(WIN32) || defined(__MC68K__) || defined(_WIN32_WCE) || defined(_DOS) || defined(_WINDOWS) || defined(__MINGW32__)
\r
149 typedef unsigned short ushort;
\r
150 typedef unsigned long ulong;
\r
154 #include <sys/types.h>
\r
157 //intent of ushort is 2 bytes unsigned.
\r
158 //for ds390 in sdcc, an int, not a short,
\r
160 typedef unsigned int ushort;
\r
165 #define WRITE_FUNCTION 1
\r
166 #define READ_FUNCTION 0
\r
169 // todo: investigate these and replace with new Error Handling library
\r
170 #define READ_ERROR -1
\r
171 #define INVALID_DIR -2
\r
173 #define WRITE_ERROR -4
\r
174 #define WRONG_TYPE -5
\r
175 #define FILE_TOO_BIG -6
\r
181 #ifndef MAX_PORTNUM
\r
182 #define MAX_PORTNUM 16
\r
186 #define MODE_NORMAL 0x00
\r
187 #define MODE_OVERDRIVE 0x01
\r
188 #define MODE_STRONG5 0x02
\r
189 #define MODE_PROGRAM 0x04
\r
190 #define MODE_BREAK 0x08
\r
193 #define LV_ALWAYS 2
\r
194 #define LV_OPTIONAL 1
\r
195 #define LV_VERBOSE 0
\r
197 //--------------------------------------------------------------//
\r
199 //--------------------------------------------------------------//
\r
200 extern int owGetErrorNum(void);
\r
201 extern int owHasErrors(void);
\r
203 //Clears the stack.
\r
204 #define OWERROR_CLEAR() while(owHasErrors()) owGetErrorNum();
\r
207 //Raises an exception with extra debug info
\r
208 #define OWERROR(err) owRaiseError(err,__LINE__,__FILE__)
\r
209 extern void owRaiseError(int,int,char*);
\r
210 #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err),__LINE__,__FILE__);return (ret);}
\r
212 //Raises an exception with just the error code
\r
213 #define OWERROR(err) owRaiseError(err)
\r
214 extern void owRaiseError(int);
\r
215 #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err));return (ret);}
\r
218 #ifdef SMALL_MEMORY_TARGET
\r
219 #define OWERROR_DUMP(fileno) /*no-op*/;
\r
221 //Prints the stack out to the given file.
\r
222 #define OWERROR_DUMP(fileno) while(owHasErrors()) owPrintErrorMsg(fileno);
\r
223 extern void owPrintErrorMsg(FILE *);
\r
224 extern void owPrintErrorMsgStd();
\r
225 extern char *owGetErrorMsg(int);
\r
228 #define OWERROR_NO_ERROR_SET 0
\r
229 #define OWERROR_NO_DEVICES_ON_NET 1
\r
230 #define OWERROR_RESET_FAILED 2
\r
231 #define OWERROR_SEARCH_ERROR 3
\r
232 #define OWERROR_ACCESS_FAILED 4
\r
233 #define OWERROR_DS2480_NOT_DETECTED 5
\r
234 #define OWERROR_DS2480_WRONG_BAUD 6
\r
235 #define OWERROR_DS2480_BAD_RESPONSE 7
\r
236 #define OWERROR_OPENCOM_FAILED 8
\r
237 #define OWERROR_WRITECOM_FAILED 9
\r
238 #define OWERROR_READCOM_FAILED 10
\r
239 #define OWERROR_BLOCK_TOO_BIG 11
\r
240 #define OWERROR_BLOCK_FAILED 12
\r
241 #define OWERROR_PROGRAM_PULSE_FAILED 13
\r
242 #define OWERROR_PROGRAM_BYTE_FAILED 14
\r
243 #define OWERROR_WRITE_BYTE_FAILED 15
\r
244 #define OWERROR_READ_BYTE_FAILED 16
\r
245 #define OWERROR_WRITE_VERIFY_FAILED 17
\r
246 #define OWERROR_READ_VERIFY_FAILED 18
\r
247 #define OWERROR_WRITE_SCRATCHPAD_FAILED 19
\r
248 #define OWERROR_COPY_SCRATCHPAD_FAILED 20
\r
249 #define OWERROR_INCORRECT_CRC_LENGTH 21
\r
250 #define OWERROR_CRC_FAILED 22
\r
251 #define OWERROR_GET_SYSTEM_RESOURCE_FAILED 23
\r
252 #define OWERROR_SYSTEM_RESOURCE_INIT_FAILED 24
\r
253 #define OWERROR_DATA_TOO_LONG 25
\r
254 #define OWERROR_READ_OUT_OF_RANGE 26
\r
255 #define OWERROR_WRITE_OUT_OF_RANGE 27
\r
256 #define OWERROR_DEVICE_SELECT_FAIL 28
\r
257 #define OWERROR_READ_SCRATCHPAD_VERIFY 29
\r
258 #define OWERROR_COPY_SCRATCHPAD_NOT_FOUND 30
\r
259 #define OWERROR_ERASE_SCRATCHPAD_NOT_FOUND 31
\r
260 #define OWERROR_ADDRESS_READ_BACK_FAILED 32
\r
261 #define OWERROR_EXTRA_INFO_NOT_SUPPORTED 33
\r
262 #define OWERROR_PG_PACKET_WITHOUT_EXTRA 34
\r
263 #define OWERROR_PACKET_LENGTH_EXCEEDS_PAGE 35
\r
264 #define OWERROR_INVALID_PACKET_LENGTH 36
\r
265 #define OWERROR_NO_PROGRAM_PULSE 37
\r
266 #define OWERROR_READ_ONLY 38
\r
267 #define OWERROR_NOT_GENERAL_PURPOSE 39
\r
268 #define OWERROR_READ_BACK_INCORRECT 40
\r
269 #define OWERROR_INVALID_PAGE_NUMBER 41
\r
270 #define OWERROR_CRC_NOT_SUPPORTED 42
\r
271 #define OWERROR_CRC_EXTRA_INFO_NOT_SUPPORTED 43
\r
272 #define OWERROR_READ_BACK_NOT_VALID 44
\r
273 #define OWERROR_COULD_NOT_LOCK_REDIRECT 45
\r
274 #define OWERROR_READ_STATUS_NOT_COMPLETE 46
\r
275 #define OWERROR_PAGE_REDIRECTION_NOT_SUPPORTED 47
\r
276 #define OWERROR_LOCK_REDIRECTION_NOT_SUPPORTED 48
\r
277 #define OWERROR_READBACK_EPROM_FAILED 49
\r
278 #define OWERROR_PAGE_LOCKED 50
\r
279 #define OWERROR_LOCKING_REDIRECTED_PAGE_AGAIN 51
\r
280 #define OWERROR_REDIRECTED_PAGE 52
\r
281 #define OWERROR_PAGE_ALREADY_LOCKED 53
\r
282 #define OWERROR_WRITE_PROTECTED 54
\r
283 #define OWERROR_NONMATCHING_MAC 55
\r
284 #define OWERROR_WRITE_PROTECT 56
\r
285 #define OWERROR_WRITE_PROTECT_SECRET 57
\r
286 #define OWERROR_COMPUTE_NEXT_SECRET 58
\r
287 #define OWERROR_LOAD_FIRST_SECRET 59
\r
288 #define OWERROR_POWER_NOT_AVAILABLE 60
\r
289 #define OWERROR_XBAD_FILENAME 61
\r
290 #define OWERROR_XUNABLE_TO_CREATE_DIR 62
\r
291 #define OWERROR_REPEAT_FILE 63
\r
292 #define OWERROR_DIRECTORY_NOT_EMPTY 64
\r
293 #define OWERROR_WRONG_TYPE 65
\r
294 #define OWERROR_BUFFER_TOO_SMALL 66
\r
295 #define OWERROR_NOT_WRITE_ONCE 67
\r
296 #define OWERROR_FILE_NOT_FOUND 68
\r
297 #define OWERROR_OUT_OF_SPACE 69
\r
298 #define OWERROR_TOO_LARGE_BITNUM 70
\r
299 #define OWERROR_NO_PROGRAM_JOB 71
\r
300 #define OWERROR_FUNC_NOT_SUP 72
\r
301 #define OWERROR_HANDLE_NOT_USED 73
\r
302 #define OWERROR_FILE_WRITE_ONLY 74
\r
303 #define OWERROR_HANDLE_NOT_AVAIL 75
\r
304 #define OWERROR_INVALID_DIRECTORY 76
\r
305 #define OWERROR_HANDLE_NOT_EXIST 77
\r
306 #define OWERROR_NONMATCHING_SNUM 78
\r
307 #define OWERROR_NON_PROGRAM_PARTS 79
\r
308 #define OWERROR_PROGRAM_WRITE_PROTECT 80
\r
309 #define OWERROR_FILE_READ_ERR 81
\r
310 #define OWERROR_ADDFILE_TERMINATED 82
\r
311 #define OWERROR_READ_MEMORY_PAGE_FAILED 83
\r
312 #define OWERROR_MATCH_SCRATCHPAD_FAILED 84
\r
313 #define OWERROR_ERASE_SCRATCHPAD_FAILED 85
\r
314 #define OWERROR_READ_SCRATCHPAD_FAILED 86
\r
315 #define OWERROR_SHA_FUNCTION_FAILED 87
\r
316 #define OWERROR_NO_COMPLETION_BYTE 88
\r
317 #define OWERROR_WRITE_DATA_PAGE_FAILED 89
\r
318 #define OWERROR_COPY_SECRET_FAILED 90
\r
319 #define OWERROR_BIND_SECRET_FAILED 91
\r
320 #define OWERROR_INSTALL_SECRET_FAILED 92
\r
321 #define OWERROR_VERIFY_SIG_FAILED 93
\r
322 #define OWERROR_SIGN_SERVICE_DATA_FAILED 94
\r
323 #define OWERROR_VERIFY_AUTH_RESPONSE_FAILED 95
\r
324 #define OWERROR_ANSWER_CHALLENGE_FAILED 96
\r
325 #define OWERROR_CREATE_CHALLENGE_FAILED 97
\r
326 #define OWERROR_BAD_SERVICE_DATA 98
\r
327 #define OWERROR_SERVICE_DATA_NOT_UPDATED 99
\r
328 #define OWERROR_CATASTROPHIC_SERVICE_FAILURE 100
\r
329 #define OWERROR_LOAD_FIRST_SECRET_FAILED 101
\r
330 #define OWERROR_MATCH_SERVICE_SIGNATURE_FAILED 102
\r
331 #define OWERROR_KEY_OUT_OF_RANGE 103
\r
332 #define OWERROR_BLOCK_ID_OUT_OF_RANGE 104
\r
333 #define OWERROR_PASSWORDS_ENABLED 105
\r
334 #define OWERROR_PASSWORD_INVALID 106
\r
335 #define OWERROR_NO_READ_ONLY_PASSWORD 107
\r
336 #define OWERROR_NO_READ_WRITE_PASSWORD 108
\r
337 #define OWERROR_OW_SHORTED 109
\r
338 #define OWERROR_ADAPTER_ERROR 110
\r
339 #define OWERROR_EOP_COPY_SCRATCHPAD_FAILED 111
\r
340 #define OWERROR_EOP_WRITE_SCRATCHPAD_FAILED 112
\r
341 #define OWERROR_HYGRO_STOP_MISSION_UNNECESSARY 113
\r
342 #define OWERROR_HYGRO_STOP_MISSION_ERROR 114
\r
343 #define OWERROR_PORTNUM_ERROR 115
\r
344 #define OWERROR_LEVEL_FAILED 116
\r
345 #define OWERROR_PASSWORD_NOT_SET 117
\r
346 #define OWERROR_LATCH_NOT_SET 118
\r
347 #define OWERROR_LIBUSB_OPEN_FAILED 119
\r
348 #define OWERROR_LIBUSB_DEVICE_ALREADY_OPENED 120
\r
349 #define OWERROR_LIBUSB_SET_CONFIGURATION_ERROR 121
\r
350 #define OWERROR_LIBUSB_CLAIM_INTERFACE_ERROR 122
\r
351 #define OWERROR_LIBUSB_SET_ALTINTERFACE_ERROR 123
\r
352 #define OWERROR_LIBUSB_NO_ADAPTER_FOUND 124
\r
354 // One Wire functions defined in ownetu.c
\r
355 SMALLINT owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only);
\r
356 SMALLINT owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only);
\r
357 void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read);
\r
358 void owFamilySearchSetup(int portnum, SMALLINT search_family);
\r
359 void owSkipFamily(int portnum);
\r
360 SMALLINT owAccess(int portnum);
\r
361 SMALLINT owVerify(int portnum, SMALLINT alarm_only);
\r
362 SMALLINT owOverdriveAccess(int portnum);
\r
365 // external One Wire functions defined in owsesu.c
\r
366 SMALLINT owAcquire(int portnum, char *port_zstr);
\r
367 int owAcquireEx(char *port_zstr);
\r
368 void owRelease(int portnum);
\r
370 // external One Wire functions defined in findtype.c
\r
371 // SMALLINT FindDevices(int,uchar FamilySN[][8],SMALLINT,int);
\r
373 // external One Wire functions from link layer owllu.c
\r
374 SMALLINT owTouchReset(int portnum);
\r
375 SMALLINT owTouchBit(int portnum, SMALLINT sendbit);
\r
376 SMALLINT owTouchByte(int portnum, SMALLINT sendbyte);
\r
377 SMALLINT owWriteByte(int portnum, SMALLINT sendbyte);
\r
378 SMALLINT owReadByte(int portnum);
\r
379 SMALLINT owSpeed(int portnum, SMALLINT new_speed);
\r
380 SMALLINT owLevel(int portnum, SMALLINT new_level);
\r
381 SMALLINT owProgramPulse(int portnum);
\r
382 SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte);
\r
383 SMALLINT owReadBytePower(int portnum);
\r
384 SMALLINT owHasPowerDelivery(int portnum);
\r
385 SMALLINT owHasProgramPulse(int portnum);
\r
386 SMALLINT owHasOverDrive(int portnum);
\r
387 SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse);
\r
388 // external One Wire global from owllu.c
\r
389 extern SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE;
\r
391 // external One Wire functions from transaction layer in owtrnu.c
\r
392 SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len);
\r
393 SMALLINT owReadPacketStd(int portnum, SMALLINT do_access, int start_page, uchar *read_buf);
\r
394 SMALLINT owWritePacketStd(int portnum, int start_page, uchar *write_buf,
\r
395 SMALLINT write_len, SMALLINT is_eprom, SMALLINT crc_type);
\r
396 SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd,
\r
397 SMALLINT crc_type, SMALLINT do_access);
\r
400 void msDelay(int len);
\r
401 long msGettick(void);
\r
403 // ioutil.c functions prototypes
\r
404 int EnterString(char *msg, char *buf, int min, int max);
\r
405 int EnterNum(char *msg, int numchars, long *value, long min, long max);
\r
406 int EnterHex(char *msg, int numchars, ulong *value);
\r
407 int ToHex(char ch);
\r
408 int getkeystroke(void);
\r
409 int key_abort(void);
\r
410 void ExitProg(char *msg, int exit_code);
\r
411 int getData(uchar *write_buff, int max_len, SMALLINT gethex);
\r
412 void PrintHex(uchar* buffer, int cnt);
\r
413 void PrintChars(uchar* buffer, int cnt);
\r
414 void PrintSerialNum(uchar* buffer);
\r
416 // external functions defined in crcutil.c
\r
417 void setcrc16(int portnum, ushort reset);
\r
418 ushort docrc16(int portnum, ushort cdata);
\r
419 void setcrc8(int portnum, uchar reset);
\r
420 uchar docrc8(int portnum, uchar x);
\r