1 |
2 |
iztok |
//---------------------------------------------------------------------------
|
2 |
|
|
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
|
3 |
|
|
//
|
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:
|
10 |
|
|
//
|
11 |
|
|
// The above copyright notice and this permission notice shall be included
|
12 |
|
|
// in all copies or substantial portions of the Software.
|
13 |
|
|
//
|
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.
|
21 |
|
|
//
|
22 |
|
|
// Except as contained in this notice, the name of Dallas Semiconductor
|
23 |
|
|
// shall not be used except as stated in the Dallas Semiconductor
|
24 |
|
|
// Branding Policy.
|
25 |
|
|
//---------------------------------------------------------------------------
|
26 |
|
|
//
|
27 |
|
|
// owerr.c - Library functions for error handling with 1-Wire library
|
28 |
|
|
//
|
29 |
|
|
// Version: 1.00
|
30 |
|
|
//
|
31 |
|
|
|
32 |
|
|
#include <string.h>
|
33 |
|
|
#include <stdio.h>
|
34 |
|
|
#include "ownet.h"
|
35 |
|
|
|
36 |
|
|
#ifndef SIZE_OWERROR_STACK
|
37 |
3 |
iztok |
#ifdef SOCKIT_OWM_ERR_SMALL
|
38 |
|
|
//for small memory, only hold 1 error
|
39 |
2 |
iztok |
#define SIZE_OWERROR_STACK 1
|
40 |
|
|
#else
|
41 |
|
|
#define SIZE_OWERROR_STACK 10
|
42 |
|
|
#endif
|
43 |
|
|
#endif
|
44 |
|
|
|
45 |
|
|
//---------------------------------------------------------------------------
|
46 |
|
|
// Variables
|
47 |
|
|
//---------------------------------------------------------------------------
|
48 |
|
|
|
49 |
|
|
// Error Struct for holding error information.
|
50 |
|
|
// In DEBUG, this will also hold the line number and filename.
|
51 |
|
|
typedef struct
|
52 |
|
|
{
|
53 |
|
|
int owErrorNum;
|
54 |
|
|
#ifdef DEBUG
|
55 |
|
|
int lineno;
|
56 |
|
|
char *filename;
|
57 |
|
|
#endif
|
58 |
|
|
} owErrorStruct;
|
59 |
|
|
|
60 |
|
|
// Ring-buffer used for stack.
|
61 |
|
|
// In case of overflow, deepest error is over-written.
|
62 |
|
|
static owErrorStruct owErrorStack[SIZE_OWERROR_STACK];
|
63 |
|
|
|
64 |
|
|
// Stack pointer to top-most error.
|
65 |
|
|
static int owErrorPointer = 0;
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
//---------------------------------------------------------------------------
|
69 |
|
|
// Functions Definitions
|
70 |
|
|
//---------------------------------------------------------------------------
|
71 |
|
|
int owGetErrorNum(void);
|
72 |
|
|
void owClearError(void);
|
73 |
|
|
int owHasErrors(void);
|
74 |
|
|
#ifdef DEBUG
|
75 |
|
|
void owRaiseError(int,int,char*);
|
76 |
|
|
#else
|
77 |
|
|
void owRaiseError(int);
|
78 |
|
|
#endif
|
79 |
3 |
iztok |
#ifndef SOCKIT_OWM_ERR_SMALL
|
80 |
2 |
iztok |
void owPrintErrorMsg(FILE *);
|
81 |
|
|
void owPrintErrorMsgStd();
|
82 |
|
|
char *owGetErrorMsg(int);
|
83 |
|
|
#endif
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
//--------------------------------------------------------------------------
|
87 |
|
|
// The 'owGetErroNum' returns the error code of the top-most error on the
|
88 |
|
|
// error stack. NOTE: This function has the side effect of popping the
|
89 |
|
|
// current error off the stack. All successive calls to 'owGetErrorNum'
|
90 |
|
|
// will further clear the error stack.
|
91 |
|
|
//
|
92 |
|
|
// For list of error codes, see 'ownet.h'
|
93 |
|
|
//
|
94 |
|
|
// Returns: int : The error code of the top-most error on the stack
|
95 |
|
|
//
|
96 |
|
|
int owGetErrorNum(void)
|
97 |
|
|
{
|
98 |
|
|
int i = owErrorStack[ owErrorPointer ].owErrorNum;
|
99 |
|
|
owErrorStack[ owErrorPointer ].owErrorNum = 0;
|
100 |
|
|
if(!owErrorPointer)
|
101 |
|
|
owErrorPointer = SIZE_OWERROR_STACK - 1;
|
102 |
|
|
else
|
103 |
|
|
owErrorPointer = (owErrorPointer - 1);
|
104 |
|
|
return i;
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
//--------------------------------------------------------------------------
|
108 |
|
|
// The 'owClearError' clears all the errors.
|
109 |
|
|
//
|
110 |
|
|
void owClearError(void)
|
111 |
|
|
{
|
112 |
|
|
owErrorStack[ owErrorPointer ].owErrorNum = 0;
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
//--------------------------------------------------------------------------
|
116 |
|
|
// The 'owHasErrors' is a boolean test function which tests whether or not
|
117 |
|
|
// a valid error is waiting on the stack.
|
118 |
|
|
//
|
119 |
|
|
// Returns: TRUE (1) : When there are errors on the stack.
|
120 |
|
|
// FALSE (0): When stack's errors are set to 0, or NO_ERROR_SET.
|
121 |
|
|
//
|
122 |
|
|
int owHasErrors(void)
|
123 |
|
|
{
|
124 |
|
|
if(owErrorStack[ owErrorPointer ].owErrorNum)
|
125 |
|
|
return 1; //TRUE
|
126 |
|
|
else
|
127 |
|
|
return 0; //FALSE
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
#ifdef DEBUG
|
131 |
|
|
//--------------------------------------------------------------------------
|
132 |
|
|
// The 'owRaiseError' is the method for raising an error onto the error
|
133 |
|
|
// stack.
|
134 |
|
|
//
|
135 |
|
|
// Arguments: int err - the error code you wish to raise.
|
136 |
|
|
// int lineno - DEBUG only - the line number where it was raised
|
137 |
|
|
// char* filename - DEBUG only - the file name where it occured.
|
138 |
|
|
//
|
139 |
|
|
void owRaiseError(int err, int lineno, char* filename)
|
140 |
|
|
{
|
141 |
|
|
owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;
|
142 |
|
|
owErrorStack[ owErrorPointer ].owErrorNum = err;
|
143 |
|
|
owErrorStack[ owErrorPointer ].lineno = lineno;
|
144 |
|
|
owErrorStack[ owErrorPointer ].filename = filename;
|
145 |
|
|
}
|
146 |
|
|
#else
|
147 |
|
|
//--------------------------------------------------------------------------
|
148 |
|
|
// The 'owRaiseError' is the method for raising an error onto the error
|
149 |
|
|
// stack.
|
150 |
|
|
//
|
151 |
|
|
// Arguments: int err - the error code you wish to raise.
|
152 |
|
|
//
|
153 |
|
|
void owRaiseError(int err)
|
154 |
|
|
{
|
155 |
|
|
owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;
|
156 |
|
|
owErrorStack[ owErrorPointer ].owErrorNum = err;
|
157 |
|
|
}
|
158 |
|
|
#endif
|
159 |
|
|
|
160 |
|
|
|
161 |
3 |
iztok |
// SOCKIT_OWM_ERR_SMALL - embedded microcontrollers, where these
|
162 |
2 |
iztok |
// messaging functions might not make any sense.
|
163 |
3 |
iztok |
#ifndef SOCKIT_OWM_ERR_SMALL
|
164 |
2 |
iztok |
//Array of meaningful error messages to associate with codes.
|
165 |
|
|
//Not used on targets with low memory (i.e. PIC).
|
166 |
|
|
static char *owErrorMsg[125] =
|
167 |
|
|
{
|
168 |
|
|
/*000*/ "No Error Was Set",
|
169 |
|
|
/*001*/ "No Devices found on 1-Wire Network",
|
170 |
|
|
/*002*/ "1-Wire Net Reset Failed",
|
171 |
|
|
/*003*/ "Search ROM Error: Couldn't locate next device on 1-Wire",
|
172 |
|
|
/*004*/ "Access Failed: Could not select device",
|
173 |
|
|
/*005*/ "DS2480B Adapter Not Detected",
|
174 |
|
|
/*006*/ "DS2480B: Wrong Baud",
|
175 |
|
|
/*007*/ "DS2480B: Bad Response",
|
176 |
|
|
/*008*/ "Open COM Failed",
|
177 |
|
|
/*009*/ "Write COM Failed",
|
178 |
|
|
/*010*/ "Read COM Failed",
|
179 |
|
|
/*011*/ "Data Block Too Large",
|
180 |
|
|
/*012*/ "Block Transfer failed",
|
181 |
|
|
/*013*/ "Program Pulse Failed",
|
182 |
|
|
/*014*/ "Program Byte Failed",
|
183 |
|
|
/*015*/ "Write Byte Failed",
|
184 |
|
|
/*016*/ "Read Byte Failed",
|
185 |
|
|
/*017*/ "Write Verify Failed",
|
186 |
|
|
/*018*/ "Read Verify Failed",
|
187 |
|
|
/*019*/ "Write Scratchpad Failed",
|
188 |
|
|
/*020*/ "Copy Scratchpad Failed",
|
189 |
|
|
/*021*/ "Incorrect CRC Length",
|
190 |
|
|
/*022*/ "CRC Failed",
|
191 |
|
|
/*023*/ "Failed to acquire a necessary system resource",
|
192 |
|
|
/*024*/ "Failed to initialize system resource",
|
193 |
|
|
/*025*/ "Data too long to fit on specified device.",
|
194 |
|
|
/*026*/ "Read exceeds memory bank end.",
|
195 |
|
|
/*027*/ "Write exceeds memory bank end.",
|
196 |
|
|
/*028*/ "Device select failed",
|
197 |
|
|
/*029*/ "Read Scratch Pad verify failed.",
|
198 |
|
|
/*030*/ "Copy scratchpad complete not found",
|
199 |
|
|
/*031*/ "Erase scratchpad complete not found",
|
200 |
|
|
/*032*/ "Address read back from scrachpad was incorrect",
|
201 |
|
|
/*033*/ "Read page with extra-info not supported by this memory bank",
|
202 |
|
|
/*034*/ "Read page packet with extra-info not supported by this memory bank",
|
203 |
|
|
/*035*/ "Length of packet requested exceeds page size",
|
204 |
|
|
/*036*/ "Invalid length in packet",
|
205 |
|
|
/*037*/ "Program pulse required but not available",
|
206 |
|
|
/*038*/ "Trying to access a read-only memory bank",
|
207 |
|
|
/*039*/ "Current bank is not general purpose memory",
|
208 |
|
|
/*040*/ "Read back from write compare is incorrect, page may be locked",
|
209 |
|
|
/*041*/ "Invalid page number for this memory bank",
|
210 |
|
|
/*042*/ "Read page with CRC not supported by this memory bank",
|
211 |
|
|
/*043*/ "Read page with CRC and extra-info not supported by this memory bank",
|
212 |
|
|
/*044*/ "Read back from write incorrect, could not lock page",
|
213 |
|
|
/*045*/ "Read back from write incorrect, could not lock redirect byte",
|
214 |
|
|
/*046*/ "The read of the status was not completed.",
|
215 |
|
|
/*047*/ "Page redirection not supported by this memory bank",
|
216 |
|
|
/*048*/ "Lock Page redirection not supported by this memory bank",
|
217 |
|
|
/*049*/ "Read back byte on EPROM programming did not match.",
|
218 |
|
|
/*050*/ "Can not write to a page that is locked.",
|
219 |
|
|
/*051*/ "Can not lock a redirected page that has already been locked.",
|
220 |
|
|
/*052*/ "Trying to redirect a locked redirected page.",
|
221 |
|
|
/*053*/ "Trying to lock a page that is already locked.",
|
222 |
|
|
/*054*/ "Trying to write to a memory bank that is write protected.",
|
223 |
|
|
/*055*/ "Error due to not matching MAC.",
|
224 |
|
|
/*056*/ "Memory Bank is write protected.",
|
225 |
|
|
/*057*/ "Secret is write protected, can not Load First Secret.",
|
226 |
|
|
/*058*/ "Error in Reading Scratchpad after Computing Next Secret.",
|
227 |
|
|
/*059*/ "Load Error from Loading First Secret.",
|
228 |
|
|
/*060*/ "Power delivery required but not available",
|
229 |
|
|
/*061*/ "Not a valid file name.",
|
230 |
|
|
/*062*/ "Unable to Create a Directory in this part.",
|
231 |
|
|
/*063*/ "That file already exists.",
|
232 |
|
|
/*064*/ "The directory is not empty.",
|
233 |
|
|
/*065*/ "The wrong type of part for this operation.",
|
234 |
|
|
/*066*/ "The max len for this file is too small.",
|
235 |
|
|
/*067*/ "This is not a write once bank.",
|
236 |
|
|
/*068*/ "The file can not be found.",
|
237 |
|
|
/*069*/ "There is not enough space available.",
|
238 |
|
|
/*070*/ "There is not a page to match that bit in the bitmap.",
|
239 |
|
|
/*071*/ "There are no jobs for EPROM parts.",
|
240 |
|
|
/*072*/ "Function not supported to modify attributes.",
|
241 |
|
|
/*073*/ "Handle is not in use.",
|
242 |
|
|
/*074*/ "Tring to read a write only file.",
|
243 |
|
|
/*075*/ "There is no handle available for use.",
|
244 |
|
|
/*076*/ "The directory provided is an invalid directory.",
|
245 |
|
|
/*077*/ "Handle does not exist.",
|
246 |
|
|
/*078*/ "Serial Number did not match with current job.",
|
247 |
|
|
/*079*/ "Can not program EPROM because a non-EPROM part on the network.",
|
248 |
|
|
/*080*/ "Write protect redirection byte is set.",
|
249 |
|
|
/*081*/ "There is an inappropriate directory length.",
|
250 |
|
|
/*082*/ "The file has already been terminated.",
|
251 |
|
|
/*083*/ "Failed to read memory page of iButton part.",
|
252 |
|
|
/*084*/ "Failed to match scratchpad of iButton part.",
|
253 |
|
|
/*085*/ "Failed to erase scratchpad of iButton part.",
|
254 |
|
|
/*086*/ "Failed to read scratchpad of iButton part.",
|
255 |
|
|
/*087*/ "Failed to execute SHA function on SHA iButton.",
|
256 |
|
|
/*088*/ "SHA iButton did not return a status completion byte.",
|
257 |
|
|
/*089*/ "Write data page failed.",
|
258 |
|
|
/*090*/ "Copy secret into secret memory pages failed.",
|
259 |
|
|
/*091*/ "Bind unique secret to iButton failed.",
|
260 |
|
|
/*092*/ "Could not install secret into user token.",
|
261 |
|
|
/*093*/ "Transaction Incomplete: signature did not match.",
|
262 |
|
|
/*094*/ "Transaction Incomplete: could not sign service data.",
|
263 |
|
|
/*095*/ "User token did not provide a valid authentication response.",
|
264 |
|
|
/*096*/ "Failed to answer a challenge on the user token.",
|
265 |
|
|
/*097*/ "Failed to create a challenge on the coprocessor.",
|
266 |
|
|
/*098*/ "Transaction Incomplete: service data was not valid.",
|
267 |
|
|
/*099*/ "Transaction Incomplete: service data was not updated.",
|
268 |
|
|
/*100*/ "Unrecoverable, catastrophic service failure occured.",
|
269 |
|
|
/*101*/ "Load First Secret from scratchpad data failed.",
|
270 |
|
|
/*102*/ "Failed to match signature of user's service data.",
|
271 |
|
|
/*103*/ "Subkey out of range for the DS1991.",
|
272 |
|
|
/*104*/ "Block ID out of range for the DS1991",
|
273 |
|
|
/*105*/ "Password is enabled",
|
274 |
|
|
/*106*/ "Password is invalid",
|
275 |
|
|
/*107*/ "This memory bank has no read only password",
|
276 |
|
|
/*108*/ "This memory bank has no read/write password",
|
277 |
|
|
/*109*/ "1-Wire is shorted",
|
278 |
|
|
/*110*/ "Error communicating with 1-Wire adapter",
|
279 |
|
|
/*111*/ "CopyScratchpad failed: Ending Offset must go to end of page",
|
280 |
|
|
/*112*/ "WriteScratchpad failed: Ending Offset must go to end of page",
|
281 |
|
|
/*113*/ "Mission can not be stopped while one is not in progress",
|
282 |
|
|
/*114*/ "Error stopping the mission",
|
283 |
|
|
/*115*/ "Port number is outside (0,MAX_PORTNUM) interval",
|
284 |
|
|
/*116*/ "Level of the 1-Wire was not changed",
|
285 |
|
|
/*117*/ "Both the Read Only and Read Write Passwords must be set",
|
286 |
|
|
/*118*/ "Failure to change latch state."
|
287 |
|
|
/*119*/ "Could not open usb port through libusb",
|
288 |
|
|
/*120*/ "Libusb DS2490 port already opened",
|
289 |
|
|
/*121*/ "Failed to set libusb configuration",
|
290 |
|
|
/*122*/ "Failed to claim libusb interface",
|
291 |
|
|
/*123*/ "Failed to set libusb altinterface",
|
292 |
|
|
/*124*/ "No adapter found at this port number"
|
293 |
|
|
};
|
294 |
|
|
|
295 |
|
|
char *owGetErrorMsg(int err)
|
296 |
|
|
{
|
297 |
|
|
return owErrorMsg[err];
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
//--------------------------------------------------------------------------
|
301 |
|
|
// The 'owPrintErrorMsg' is the method for printing an error from the stack.
|
302 |
|
|
// The destination for the print is specified by the argument, fileno, which
|
303 |
|
|
// can be stderr, stdout, or a log file. In non-debug mode, the output is
|
304 |
|
|
// of the form:
|
305 |
|
|
// Error num: Error msg
|
306 |
|
|
//
|
307 |
|
|
// In debug-mode, the output is of the form:
|
308 |
|
|
// Error num: filename line#: Error msg
|
309 |
|
|
//
|
310 |
|
|
// NOTE: This function has the side-effect of popping the error off the stack.
|
311 |
|
|
//
|
312 |
|
|
// Arguments: FILE*: the destination for printing.
|
313 |
|
|
//
|
314 |
|
|
void owPrintErrorMsg(FILE *filenum)
|
315 |
|
|
{
|
316 |
|
|
#ifdef DEBUG
|
317 |
|
|
int l = owErrorStack[ owErrorPointer ].lineno;
|
318 |
|
|
char *f = owErrorStack[ owErrorPointer ].filename;
|
319 |
|
|
int err = owGetErrorNum();
|
320 |
|
|
fprintf(filenum,"Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);
|
321 |
|
|
#else
|
322 |
|
|
int err = owGetErrorNum();
|
323 |
|
|
fprintf(filenum,"Error %d: %s\r\n",err,owErrorMsg[err]);
|
324 |
|
|
#endif
|
325 |
|
|
}
|
326 |
|
|
|
327 |
|
|
// Same as above, except uses default printf output
|
328 |
|
|
void owPrintErrorMsgStd()
|
329 |
|
|
{
|
330 |
|
|
#ifdef DEBUG
|
331 |
|
|
int l = owErrorStack[ owErrorPointer ].lineno;
|
332 |
|
|
char *f = owErrorStack[ owErrorPointer ].filename;
|
333 |
|
|
int err = owGetErrorNum();
|
334 |
|
|
printf("Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);
|
335 |
|
|
#else
|
336 |
|
|
int err = owGetErrorNum();
|
337 |
|
|
printf("Error %d: %s\r\n",err,owErrorMsg[err]);
|
338 |
|
|
#endif
|
339 |
|
|
}
|
340 |
|
|
#endif
|
341 |
|
|
|