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
// owerr.c - Library functions for error handling with 1-Wire library
38
#ifndef SIZE_OWERROR_STACK
39
#ifdef SMALL_MEMORY_TARGET
40
//for small memory, only hole 1 error
41
#define SIZE_OWERROR_STACK 1
43
#define SIZE_OWERROR_STACK 10
47
//---------------------------------------------------------------------------
49
//---------------------------------------------------------------------------
51
// Error Struct for holding error information.
52
// In DEBUG, this will also hold the line number and filename.
62
// Ring-buffer used for stack.
63
// In case of overflow, deepest error is over-written.
64
static owErrorStruct owErrorStack[SIZE_OWERROR_STACK];
66
// Stack pointer to top-most error.
67
static int owErrorPointer = 0;
70
//---------------------------------------------------------------------------
71
// Functions Definitions
72
//---------------------------------------------------------------------------
73
int owGetErrorNum(void);
74
void owClearError(void);
75
int owHasErrors(void);
77
void owRaiseError(int,int,char*);
79
void owRaiseError(int);
81
#ifndef SMALL_MEMORY_TARGET
82
void owPrintErrorMsg(FILE *);
83
void owPrintErrorMsgStd();
84
char *owGetErrorMsg(int);
88
//--------------------------------------------------------------------------
89
// The 'owGetErroNum' returns the error code of the top-most error on the
90
// error stack. NOTE: This function has the side effect of popping the
91
// current error off the stack. All successive calls to 'owGetErrorNum'
92
// will further clear the error stack.
94
// For list of error codes, see 'ownet.h'
96
// Returns: int : The error code of the top-most error on the stack
98
int owGetErrorNum(void)
100
int i = owErrorStack[ owErrorPointer ].owErrorNum;
101
owErrorStack[ owErrorPointer ].owErrorNum = 0;
103
owErrorPointer = SIZE_OWERROR_STACK - 1;
105
owErrorPointer = (owErrorPointer - 1);
109
//--------------------------------------------------------------------------
110
// The 'owClearError' clears all the errors.
112
void owClearError(void)
114
owErrorStack[ owErrorPointer ].owErrorNum = 0;
117
//--------------------------------------------------------------------------
118
// The 'owHasErrors' is a boolean test function which tests whether or not
119
// a valid error is waiting on the stack.
121
// Returns: TRUE (1) : When there are errors on the stack.
122
// FALSE (0): When stack's errors are set to 0, or NO_ERROR_SET.
124
int owHasErrors(void)
126
if(owErrorStack[ owErrorPointer ].owErrorNum)
133
//--------------------------------------------------------------------------
134
// The 'owRaiseError' is the method for raising an error onto the error
137
// Arguments: int err - the error code you wish to raise.
138
// int lineno - DEBUG only - the line number where it was raised
139
// char* filename - DEBUG only - the file name where it occured.
141
void owRaiseError(int err, int lineno, char* filename)
143
owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;
144
owErrorStack[ owErrorPointer ].owErrorNum = err;
145
owErrorStack[ owErrorPointer ].lineno = lineno;
146
owErrorStack[ owErrorPointer ].filename = filename;
149
//--------------------------------------------------------------------------
150
// The 'owRaiseError' is the method for raising an error onto the error
153
// Arguments: int err - the error code you wish to raise.
155
void owRaiseError(int err)
157
owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;
158
owErrorStack[ owErrorPointer ].owErrorNum = err;
163
// SMALL_MEMORY_TARGET - embedded microcontrollers, where these
164
// messaging functions might not make any sense.
165
#ifndef SMALL_MEMORY_TARGET
166
//Array of meaningful error messages to associate with codes.
167
//Not used on targets with low memory (i.e. PIC).
168
static char *owErrorMsg[103] =
170
/*000*/ "No Error Was Set",
171
/*001*/ "No Devices found on 1-Wire Network",
172
/*002*/ "1-Wire Net Reset Failed",
173
/*003*/ "Search ROM Error: Couldn't locate next device on 1-Wire",
174
/*004*/ "Access Failed: Could not select device",
175
/*005*/ "DS2480B Adapter Not Detected",
176
/*006*/ "DS2480B: Wrong Baud",
177
/*007*/ "DS2480B: Bad Response",
178
/*008*/ "Open COM Failed",
179
/*009*/ "Write COM Failed",
180
/*010*/ "Read COM Failed",
181
/*011*/ "Data Block Too Large",
182
/*012*/ "Block Transfer failed",
183
/*013*/ "Program Pulse Failed",
184
/*014*/ "Program Byte Failed",
185
/*015*/ "Write Byte Failed",
186
/*016*/ "Read Byte Failed",
187
/*017*/ "Write Verify Failed",
188
/*018*/ "Read Verify Failed",
189
/*019*/ "Write Scratchpad Failed",
190
/*020*/ "Copy Scratchpad Failed",
191
/*021*/ "Incorrect CRC Length",
192
/*022*/ "CRC Failed",
193
/*023*/ "Failed to acquire a necessary system resource",
194
/*024*/ "Failed to initialize system resource",
195
/*025*/ "Data too long to fit on specified device.",
196
/*026*/ "Read exceeds memory bank end.",
197
/*027*/ "Write exceeds memory bank end.",
198
/*028*/ "Device select failed",
199
/*029*/ "Read Scratch Pad verify failed.",
200
/*030*/ "Copy scratchpad complete not found",
201
/*031*/ "Erase scratchpad complete not found",
202
/*032*/ "Address read back from scrachpad was incorrect",
203
/*033*/ "Read page with extra-info not supported by this memory bank",
204
/*034*/ "Read page packet with extra-info not supported by this memory bank",
205
/*035*/ "Length of packet requested exceeds page size",
206
/*036*/ "Invalid length in packet",
207
/*037*/ "Program pulse required but not available",
208
/*038*/ "Trying to access a read-only memory bank",
209
/*039*/ "Current bank is not general purpose memory",
210
/*040*/ "Read back from write compare is incorrect, page may be locked",
211
/*041*/ "Invalid page number for this memory bank",
212
/*042*/ "Read page with CRC not supported by this memory bank",
213
/*043*/ "Read page with CRC and extra-info not supported by this memory bank",
214
/*044*/ "Read back from write incorrect, could not lock page",
215
/*045*/ "Read back from write incorrect, could not lock redirect byte",
216
/*046*/ "The read of the status was not completed.",
217
/*047*/ "Page redirection not supported by this memory bank",
218
/*048*/ "Lock Page redirection not supported by this memory bank",
219
/*049*/ "Read back byte on EPROM programming did not match.",
220
/*050*/ "Can not write to a page that is locked.",
221
/*051*/ "Can not lock a redirected page that has already been locked.",
222
/*052*/ "Trying to redirect a locked redirected page.",
223
/*053*/ "Trying to lock a page that is already locked.",
224
/*054*/ "Trying to write to a memory bank that is write protected.",
225
/*055*/ "Error due to not matching MAC.",
226
/*056*/ "Memory Bank is write protected.",
227
/*057*/ "Secret is write protected, can not Load First Secret.",
228
/*058*/ "Error in Reading Scratchpad after Computing Next Secret.",
229
/*059*/ "Load Error from Loading First Secret.",
230
/*060*/ "Power delivery required but not available",
231
/*061*/ "Not a valid file name.",
232
/*062*/ "Unable to Create a Directory in this part.",
233
/*063*/ "That file already exists.",
234
/*064*/ "The directory is not empty.",
235
/*065*/ "The wrong type of part for this operation.",
236
/*066*/ "The max len for this file is too small.",
237
/*067*/ "This is not a write once bank.",
238
/*068*/ "The file can not be found.",
239
/*069*/ "There is not enough space availabe.",
240
/*070*/ "There is not a page to match that bit in the bitmap.",
241
/*071*/ "There are no jobs for EPROM parts.",
242
/*072*/ "Function not supported to modify attributes.",
243
/*073*/ "Handle is not in use.",
244
/*074*/ "Tring to read a write only file.",
245
/*075*/ "There is no handle available for use.",
246
/*076*/ "The directory provided is an invalid directory.",
247
/*077*/ "Handle does not exist.",
248
/*078*/ "Serial Number did not match with current job.",
249
/*079*/ "Can not program EPROM because a non-EPROM part on the network.",
250
/*080*/ "Write protect redirection byte is set.",
251
/*081*/ "There is an inappropriate directory length.",
252
/*082*/ "The file has already been terminated.",
253
/*083*/ "Failed to read memory page of iButton part.",
254
/*084*/ "Failed to match scratchpad of iButton part.",
255
/*085*/ "Failed to erase scratchpad of iButton part.",
256
/*086*/ "Failed to read scratchpad of iButton part.",
257
/*087*/ "Failed to execute SHA function on SHA iButton.",
258
/*088*/ "SHA iButton did not return a status completion byte.",
259
/*089*/ "Write data page failed.",
260
/*090*/ "Copy secret into secret memory pages failed.",
261
/*091*/ "Bind unique secret to iButton failed.",
262
/*092*/ "Could not install secret into user token.",
263
/*093*/ "Transaction Incomplete: signature did not match.",
264
/*094*/ "Transaction Incomplete: could not sign service data.",
265
/*095*/ "User token did not provide a valid authentication response.",
266
/*096*/ "Failed to answer a challenge on the user token.",
267
/*097*/ "Failed to create a challenge on the coprocessor.",
268
/*098*/ "Transaction Incomplete: service data was not valid.",
269
/*099*/ "Transaction Incomplete: service data was not updated.",
270
/*100*/ "Unrecoverable, catastrophic service failure occured.",
271
/*101*/ "Load First Secret from scratchpad data failed.",
272
/*102*/ "Failed to match signature of user's service data."
275
char *owGetErrorMsg(int err)
277
return owErrorMsg[err];
280
//--------------------------------------------------------------------------
281
// The 'owPrintErrorMsg' is the method for printing an error from the stack.
282
// The destination for the print is specified by the argument, fileno, which
283
// can be stderr, stdout, or a log file. In non-debug mode, the output is
285
// Error num: Error msg
287
// In debug-mode, the output is of the form:
288
// Error num: filename line#: Error msg
290
// NOTE: This function has the side-effect of popping the error off the stack.
292
// Arguments: FILE*: the destination for printing.
294
void owPrintErrorMsg(FILE *fileno)
297
int l = owErrorStack[ owErrorPointer ].lineno;
298
char *f = owErrorStack[ owErrorPointer ].filename;
299
int err = owGetErrorNum();
300
fprintf(fileno,"Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);
302
int err = owGetErrorNum();
303
fprintf(fileno,"Error %d: %s\r\n",err,owErrorMsg[err]);
307
// Same as above, except uses default printf output
308
void owPrintErrorMsgStd()
311
int l = owErrorStack[ owErrorPointer ].lineno;
312
char *f = owErrorStack[ owErrorPointer ].filename;
313
int err = owGetErrorNum();
314
printf("Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);
316
int err = owGetErrorNum();
317
printf("Error %d: %s\r\n",err,owErrorMsg[err]);