Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
363 johboh 1
/*********************************************************************
2
 *
3
 *               External serial data EEPROM Access Defs.
4
 *
5
 *********************************************************************
6
 * FileName:        XEEPROM.h
7
 * Dependencies:    None
8
 * Processor:       PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F
9
 * Complier:        Microchip C18 v3.02 or higher
10
 *                  Microchip C30 v2.01 or higher
11
 * Company:         Microchip Technology, Inc.
12
 *
13
 * Software License Agreement
14
 *
15
 * This software is owned by Microchip Technology Inc. ("Microchip")
16
 * and is supplied to you for use exclusively as described in the
17
 * associated software agreement.  This software is protected by
18
 * software and other intellectual property laws.  Any use in
19
 * violation of the software license may subject the user to criminal
20
 * sanctions as well as civil liability.  Copyright 2006 Microchip
21
 * Technology Inc.  All rights reserved.
22
 *
23
 * This software is provided "AS IS."  MICROCHIP DISCLAIMS ALL
24
 * WARRANTIES, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, NOT LIMITED
25
 * TO MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
26
 * INFRINGEMENT.  Microchip shall in no event be liable for special,
27
 * incidental, or consequential damages.
28
 *
29
 *
30
 * Author               Date        Comment
31
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32
 * Nilesh Rajbharti     5/20/02     Original (Rev. 1.0)
33
********************************************************************/
34
#ifndef XEEPROM_H
35
#define XEEPROM_H
36
 
37
#define EE_BAUD(CLOCK, BAUD)      ( ((CLOCK / BAUD) / 4) - 1 )
38
 
39
 
40
typedef enum _XEE_RESULT
41
{
42
    XEE_SUCCESS = 0,
43
    XEE_READY = 0,
44
    XEE_BUS_COLLISION,
45
    XEE_NAK,
46
    XEE_VERIFY_ERR,
47
    XEE_BUSY
48
} XEE_RESULT;
49
 
50
typedef unsigned short int XEE_ADDR;
51
 
52
 
53
/*********************************************************************
54
 * Function:        void XEEInit(unsigned char baud)
55
 *
56
 * PreCondition:    None
57
 *
58
 * Input:           baud    - SSPADD value for bit rate.
59
 *
60
 * Output:          None
61
 *
62
 * Side Effects:    None
63
 *
64
 * Overview:        Initialize I2C module to communicate to serial
65
 *                  EEPROM.
66
 *
67
 * Note:            None
68
 ********************************************************************/
69
void XEEInit(unsigned char baud);
70
 
71
 
72
 
73
/*********************************************************************
74
 * Function:        XEE_RESULT XEESetAddr(unsigned char control,
75
 *                                        XEE_ADDR address)
76
 *
77
 * PreCondition:    XEEInit() is already called.
78
 *
79
 * Input:           control     - data EEPROM control code
80
 *                  address     - address to be set
81
 *
82
 * Output:          XEE_SUCCESS if successful
83
 *                  other value if failed.
84
 *
85
 * Side Effects:    None
86
 *
87
 * Overview:        Modifies internal address counter of EEPROM.
88
 *
89
 * Note:            This function does not release the I2C bus.
90
 *                  User must close XEEClose() after this function
91
 *                  is called.
92
 ********************************************************************/
93
XEE_RESULT XEESetAddr(unsigned char control, XEE_ADDR address);
94
 
95
 
96
 
97
/*********************************************************************
98
 * Macro:           XEE_RESULT XEEBeginWrite(unsigned char control,
99
 *                                           XEE_ADDR address)
100
 *
101
 * PreCondition:    XEEInit() is already called.
102
 *
103
 * Input:           control     - data EEPROM control code
104
 *                  address     - address to where to write
105
 *
106
 * Output:          XEE_SUCCESS if successful
107
 *                  other value if failed.
108
 *
109
 * Side Effects:    None
110
 *
111
 * Overview:        Sets up internal address counter of EEPROM.
112
 *
113
 * Note:            This function does not release the I2C bus.
114
 *                  User must close XEEEndWrite() after this function
115
 *                  is called to relase the I2C bus.
116
 ********************************************************************/
117
#define XEEBeginWrite(control, address)     XEESetAddr(control, address)
118
 
119
 
120
 
121
/*********************************************************************
122
 * Function:        XEE_RESULT XEEWrite(unsigned char val)
123
 *
124
 * PreCondition:    XEEInit() && XEEBeginWrite() are already called.
125
 *
126
 * Input:           val to be written
127
 *
128
 * Output:          XEE_SUCCESS if successful
129
 *                  other value if failed.
130
 *
131
 * Side Effects:    None
132
 *
133
 * Overview:        Writes given value 'val' at current address.
134
 *                  Current address is set by XEEBeginWrite()
135
 *                  and is incremented by every XEEWrite().
136
 *
137
 * Note:            This function does not initiate the write cycle;
138
 *                  it simply loads given value into internal page buffer.
139
 *                  This function does not release the I2C bus.
140
 *                  User must close XEEEndWrite() after this function
141
 *                  is called to relase the I2C bus.
142
 ********************************************************************/
143
XEE_RESULT XEEWrite(unsigned char val);
144
 
145
 
146
 
147
/*********************************************************************
148
 * Function:        XEE_RESULT XEEEndWrite(void)
149
 *
150
 * PreCondition:    XEEInit() && XEEBeginWrite() are already called.
151
 *
152
 * Input:           None
153
 *
154
 * Output:          XEE_SUCCESS if successful
155
 *                  other value if failed.
156
 *
157
 * Side Effects:    None
158
 *
159
 * Overview:        Instructs EEPROM to begin write cycle.
160
 *
161
 * Note:            Call this function after either page full of bytes
162
 *                  written or no more bytes are left to load.
163
 *                  This function initiates the write cycle.
164
 *                  User must call for XEEWait() to ensure that write
165
 *                  cycle is finished before calling any other
166
 *                  routine.
167
 ********************************************************************/
168
XEE_RESULT XEEEndWrite(void);
169
 
170
 
171
/*********************************************************************
172
 * Function:        XEE_RESULT XEEBeginRead(unsigned char control,
173
 *                                          XEE_ADDR address)
174
 *
175
 * PreCondition:    XEEInit() is already called.
176
 *
177
 * Input:           control - EEPROM control and address code.
178
 *                  address - Address at which read is to be performed.
179
 *
180
 * Output:          XEE_SUCCESS if successful
181
 *                  other value if failed.
182
 *
183
 * Side Effects:    None
184
 *
185
 * Overview:        Sets internal address counter to given address.
186
 *                  Puts EEPROM in sequential read mode.
187
 *
188
 * Note:            This function does not release I2C bus.
189
 *                  User must call XEEEndRead() when read is not longer
190
 *                  needed; I2C bus will released after XEEEndRead()
191
 *                  is called.
192
 ********************************************************************/
193
XEE_RESULT XEEBeginRead(unsigned char control, XEE_ADDR address);
194
 
195
 
196
 
197
/*********************************************************************
198
 * Function:        XEE_RESULT XEERead(void)
199
 *
200
 * PreCondition:    XEEInit() && XEEBeginRead() are already called.
201
 *
202
 * Input:           None
203
 *
204
 * Output:          XEE_SUCCESS if successful
205
 *                  other value if failed.
206
 *
207
 * Side Effects:    None
208
 *
209
 * Overview:        Reads next byte from EEPROM; internal address
210
 *                  is incremented by one.
211
 *
212
 * Note:            This function does not release I2C bus.
213
 *                  User must call XEEEndRead() when read is not longer
214
 *                  needed; I2C bus will released after XEEEndRead()
215
 *                  is called.
216
 ********************************************************************/
217
unsigned char XEERead(void);
218
 
219
 
220
/*********************************************************************
221
 * Function:        XEE_RESULT XEEEndRead(void)
222
 *
223
 * PreCondition:    XEEInit() && XEEBeginRead() are already called.
224
 *
225
 * Input:           None
226
 *
227
 * Output:          XEE_SUCCESS if successful
228
 *                  other value if failed.
229
 *
230
 * Side Effects:    None
231
 *
232
 * Overview:        Ends sequential read cycle.
233
 *
234
 * Note:            This function ends seuential cycle that was in
235
 *                  progress.  It releases I2C bus.
236
 ********************************************************************/
237
XEE_RESULT XEEEndRead(void);
238
 
239
 
240
/*********************************************************************
241
 * Function:        XEE_RESULT XEEReadArray(unsigned char control,
242
 *                                          XEE_ADDR address,
243
 *                                          unsigned char *buffer,
244
 *                                          unsigned char length)
245
 *
246
 * PreCondition:    XEEInit() is already called.
247
 *
248
 * Input:           control     - EEPROM control and address code.
249
 *                  address     - Address from where array is to be read
250
 *                  buffer      - Caller supplied buffer to hold the data
251
 *                  length      - Number of bytes to read.
252
 *
253
 * Output:          XEE_SUCCESS if successful
254
 *                  other value if failed.
255
 *
256
 * Side Effects:    None
257
 *
258
 * Overview:        Reads desired number of bytes in sequential mode.
259
 *                  This function performs all necessary steps
260
 *                  and releases the bus when finished.
261
 *
262
 * Note:            None
263
 ********************************************************************/
264
XEE_RESULT XEEReadArray(unsigned char control,
265
                        XEE_ADDR address,
266
                        unsigned char *buffer,
267
                        unsigned char length);
268
 
269
 
270
 
271
/*********************************************************************
272
 * Function:        XEE_RESULT XEEIsBusy(unsigned char control)
273
 *
274
 * PreCondition:    XEEInit() is already called.
275
 *
276
 * Input:           control     - EEPROM control and address code.
277
 *
278
 * Output:          XEE_READY if EEPROM is not busy
279
 *                  XEE_BUSY if EEPROM is busy
280
 *                  other value if failed.
281
 *
282
 * Side Effects:    None
283
 *
284
 * Overview:        Requests ack from EEPROM.
285
 *
286
 * Note:            None
287
 ********************************************************************/
288
XEE_RESULT XEEIsBusy(unsigned char control);
289
 
290
 
291
 
292
#endif