OpenCores
URL https://opencores.org/ocsvn/sockit_owm/sockit_owm/trunk

Subversion Repositories sockit_owm

[/] [sockit_owm/] [trunk/] [HAL/] [inc/] [ownet.h] - Blame information for rev 3

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.