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