~ubuntu-branches/debian/jessie/digitemp/jessie

« back to all changes in this revision

Viewing changes to userial/ds9097/owerr.c

  • Committer: Bazaar Package Importer
  • Author(s): Jesus Roncero
  • Date: 2004-09-01 01:34:37 UTC
  • Revision ID: james.westby@ubuntu.com-20040901013437-eicsrrd40dr371u0
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
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
#ifndef _WIN32_WCE
 
34
#include <stdio.h>
 
35
#endif
 
36
#include "ownet.h"
 
37
 
 
38
#ifndef SIZE_OWERROR_STACK
 
39
   #ifdef SMALL_MEMORY_TARGET
 
40
      //for small memory, only hole 1 error
 
41
      #define SIZE_OWERROR_STACK 1
 
42
   #else
 
43
      #define SIZE_OWERROR_STACK 10
 
44
   #endif
 
45
#endif
 
46
 
 
47
//---------------------------------------------------------------------------
 
48
// Variables
 
49
//---------------------------------------------------------------------------
 
50
 
 
51
// Error Struct for holding error information.
 
52
// In DEBUG, this will also hold the line number and filename.
 
53
typedef struct
 
54
{
 
55
   int owErrorNum;
 
56
#ifdef DEBUG
 
57
   int lineno;
 
58
   char *filename;
 
59
#endif
 
60
} owErrorStruct;
 
61
 
 
62
// Ring-buffer used for stack.
 
63
// In case of overflow, deepest error is over-written.
 
64
static owErrorStruct owErrorStack[SIZE_OWERROR_STACK];
 
65
 
 
66
// Stack pointer to top-most error.
 
67
static int owErrorPointer = 0;
 
68
 
 
69
 
 
70
//---------------------------------------------------------------------------
 
71
// Functions Definitions
 
72
//---------------------------------------------------------------------------
 
73
int owGetErrorNum(void);
 
74
void owClearError(void);
 
75
int owHasErrors(void);
 
76
#ifdef DEBUG
 
77
   void owRaiseError(int,int,char*);
 
78
#else
 
79
   void owRaiseError(int);
 
80
#endif
 
81
#ifndef SMALL_MEMORY_TARGET
 
82
   void owPrintErrorMsg(FILE *);
 
83
   void owPrintErrorMsgStd();
 
84
   char *owGetErrorMsg(int);
 
85
#endif
 
86
 
 
87
 
 
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.
 
93
//
 
94
// For list of error codes, see 'ownet.h'
 
95
//
 
96
// Returns:   int :  The error code of the top-most error on the stack
 
97
//
 
98
int owGetErrorNum(void)
 
99
{
 
100
   int i = owErrorStack[ owErrorPointer ].owErrorNum;
 
101
   owErrorStack[ owErrorPointer ].owErrorNum = 0;
 
102
   if(!owErrorPointer)
 
103
      owErrorPointer = SIZE_OWERROR_STACK - 1;
 
104
   else
 
105
      owErrorPointer = (owErrorPointer - 1);
 
106
   return i;
 
107
}
 
108
 
 
109
//--------------------------------------------------------------------------
 
110
// The 'owClearError' clears all the errors.
 
111
//
 
112
void owClearError(void)
 
113
{
 
114
   owErrorStack[ owErrorPointer ].owErrorNum = 0;
 
115
}
 
116
 
 
117
//--------------------------------------------------------------------------
 
118
// The 'owHasErrors' is a boolean test function which tests whether or not
 
119
// a valid error is waiting on the stack.
 
120
//
 
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.
 
123
//
 
124
int owHasErrors(void)
 
125
{
 
126
   if(owErrorStack[ owErrorPointer ].owErrorNum)
 
127
      return 1; //TRUE
 
128
   else
 
129
      return 0; //FALSE
 
130
}
 
131
 
 
132
#ifdef DEBUG
 
133
   //--------------------------------------------------------------------------
 
134
   // The 'owRaiseError' is the method for raising an error onto the error
 
135
   // stack.
 
136
   //
 
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.
 
140
   //
 
141
   void owRaiseError(int err, int lineno, char* filename)
 
142
   {
 
143
      owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;
 
144
      owErrorStack[ owErrorPointer ].owErrorNum = err;
 
145
      owErrorStack[ owErrorPointer ].lineno = lineno;
 
146
      owErrorStack[ owErrorPointer ].filename = filename;
 
147
   }
 
148
#else
 
149
   //--------------------------------------------------------------------------
 
150
   // The 'owRaiseError' is the method for raising an error onto the error
 
151
   // stack.
 
152
   //
 
153
   // Arguments:  int err - the error code you wish to raise.
 
154
   //
 
155
   void owRaiseError(int err)
 
156
   {
 
157
      owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;
 
158
      owErrorStack[ owErrorPointer ].owErrorNum = err;
 
159
   }
 
160
#endif
 
161
 
 
162
 
 
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] =
 
169
   {
 
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."
 
273
   };
 
274
 
 
275
   char *owGetErrorMsg(int err)
 
276
   {
 
277
      return owErrorMsg[err];
 
278
   }
 
279
 
 
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
 
284
   // of the form:
 
285
   // Error num: Error msg
 
286
   //
 
287
   // In debug-mode, the output is of the form:
 
288
   // Error num: filename line#: Error msg
 
289
   //
 
290
   // NOTE: This function has the side-effect of popping the error off the stack.
 
291
   //
 
292
   // Arguments:  FILE*: the destination for printing.
 
293
   //
 
294
   void owPrintErrorMsg(FILE *fileno)
 
295
   {
 
296
   #ifdef DEBUG
 
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]);
 
301
   #else
 
302
      int err = owGetErrorNum();
 
303
      fprintf(fileno,"Error %d: %s\r\n",err,owErrorMsg[err]);
 
304
   #endif
 
305
   }
 
306
 
 
307
   // Same as above, except uses default printf output
 
308
   void owPrintErrorMsgStd()
 
309
   {
 
310
   #ifdef DEBUG
 
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]);
 
315
   #else
 
316
      int err = owGetErrorNum();
 
317
      printf("Error %d: %s\r\n",err,owErrorMsg[err]);
 
318
   #endif
 
319
   }
 
320
#endif
 
321