Subversion Repositories NaviCtrl

Rev

Rev 312 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 312 Rev 360
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
-
 
6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
-
 
7
// + FOR NON COMMERCIAL USE ONLY
-
 
8
// + www.MikroKopter.com
5
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
7
// + Software Nutzungsbedingungen (english version: see below)
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
13
// + bzgl. der Nutzungsbedingungen aufzunehmen.
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
15
// + Verkauf von Luftbildaufnahmen, usw.
-
 
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
22
// + eindeutig als Ursprung verlinkt werden
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
25
// + Benutzung auf eigene Gefahr
22
// + des Mitverschuldens offen.
-
 
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
-
 
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
-
 
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
29
// + mit unserer Zustimmung zulässig
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
-
 
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
32
// + Software LICENSING TERMS
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
34
// + this list of conditions and the following disclaimer.
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
36
// +     from this software without specific prior written permission.
37
// + The Software may only be used with the Licensor's products.
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
38
// +     for non-commercial use (directly or indirectly)
-
 
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// +     with our written permission
40
// + agreement shall be the property of the Licensor.
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
42
// +     clearly linked as origin
-
 
43
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
44
//
-
 
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43
// + The customer shall be responsible for taking reasonable precautions
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
55
// +  POSSIBILITY OF SUCH DAMAGE.
53
// + #### END OF LICENSING TERMS ####
-
 
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
#include <string.h>
56
#include <string.h>
58
#include <stdio.h>
57
#include <stdio.h>
59
#include "91x_lib.h"
58
#include "91x_lib.h"
60
#include "i2c.h"
59
#include "i2c.h"
61
#include "uart1.h"
60
#include "uart1.h"
62
#include "timer1.h"
61
#include "timer1.h"
63
#include "eeprom.h"
62
#include "eeprom.h"
64
#include "led.h"
63
#include "led.h"
65
 
64
 
66
 
65
 
67
// The EEPROM M24C64 (64k) ist connected via I2C1 interface to the controller.
66
// The EEPROM M24C64 (64k) ist connected via I2C1 interface to the controller.
68
// The E0, E2, E3 pins are set to low. Therefore the slave adressbits b3, b2, b1 are 0.
67
// The E0, E2, E3 pins are set to low. Therefore the slave adressbits b3, b2, b1 are 0.
69
 
68
 
70
#define EEPROM_I2C_ADDRESS      0xA0
69
#define EEPROM_I2C_ADDRESS      0xA0
71
#define EEPROM_SIZE                     65536L  // 64k bytes
70
#define EEPROM_SIZE                     65536L  // 64k bytes
72
#define EEPROM_WRITE            1
71
#define EEPROM_WRITE            1
73
#define EEPROM_READ                     0
72
#define EEPROM_READ                     0
74
 
73
 
75
// timing
74
// timing
76
#define I2C_IDLE_TIMEOUT                150 // 150 ms
75
#define I2C_IDLE_TIMEOUT                150 // 150 ms
77
#define I2C_TRANSFER_TIMEOUT    150 // 150 ms
76
#define I2C_TRANSFER_TIMEOUT    150 // 150 ms
78
#define I2C_ACCESS_RETRYS               20      // retry 20 times
77
#define I2C_ACCESS_RETRYS               20      // retry 20 times
79
 
78
 
80
// globals for rx handler
79
// globals for rx handler
81
volatile u8     *EEPROM_pData = 0;
80
volatile u8     *EEPROM_pData = 0;
82
volatile u16 EEPROM_DataLen = 0;
81
volatile u16 EEPROM_DataLen = 0;
83
 
82
 
84
// rx data handler for eeprom data read access
83
// rx data handler for eeprom data read access
85
void EEPROM_RxDataHandler(u8* pRxBuffer, u8 RxBufferSize)
84
void EEPROM_RxDataHandler(u8* pRxBuffer, u8 RxBufferSize)
86
{       // if number of byte are matching
85
{       // if number of byte are matching
87
        if((RxBufferSize == EEPROM_DataLen))
86
        if((RxBufferSize == EEPROM_DataLen))
88
        {       //copy data from primary buffer to target buffer 
87
        {       //copy data from primary buffer to target buffer 
89
                if(EEPROM_pData) memcpy((u8*)EEPROM_pData, pRxBuffer, EEPROM_DataLen);
88
                if(EEPROM_pData) memcpy((u8*)EEPROM_pData, pRxBuffer, EEPROM_DataLen);
90
        }        
89
        }        
91
}
90
}
92
 
91
 
93
// ----------------------------------------------------------------------------------------
92
// ----------------------------------------------------------------------------------------
94
EEPROM_Result_t EEPROM_Transfer(u8 Direction, u16 Address, u8 *pData, u16 DataLen)
93
EEPROM_Result_t EEPROM_Transfer(u8 Direction, u16 Address, u8 *pData, u16 DataLen)
95
{
94
{
96
        u16 i, TxBytes = 0;
95
        u16 i, TxBytes = 0;
97
        u8 retry = 0;
96
        u8 retry = 0;
98
        EEPROM_Result_t retval = EEPROM_ERROR_UNKNOWN;
97
        EEPROM_Result_t retval = EEPROM_ERROR_UNKNOWN;
99
 
98
 
100
        if(((u32)Address + (u32)DataLen) >= (EEPROM_SIZE - 1))
99
        if(((u32)Address + (u32)DataLen) >= (EEPROM_SIZE - 1))
101
        {
100
        {
102
                retval = EEPROM_ERROR_OUT_OF_ADDRESS_RANGE;
101
                retval = EEPROM_ERROR_OUT_OF_ADDRESS_RANGE;
103
                return(retval);
102
                return(retval);
104
        }
103
        }
105
        if((DataLen+2) > I2C_BUFFER_LEN)
104
        if((DataLen+2) > I2C_BUFFER_LEN)
106
        {
105
        {
107
                retval = EEPROM_I2C_BUFFER_OVERRUN;
106
                retval = EEPROM_I2C_BUFFER_OVERRUN;
108
                return(retval);
107
                return(retval);
109
        }
108
        }
110
        do
109
        do
111
        {
110
        {
112
                if(!I2C_LockBuffer(I2C_IDLE_TIMEOUT)) return EEPROM_ERROR_I2C_IDLE_TIMEOUT;
111
                if(!I2C_LockBuffer(I2C_IDLE_TIMEOUT)) return EEPROM_ERROR_I2C_IDLE_TIMEOUT;
113
                // buffer is now locked
112
                // buffer is now locked
114
                TxBytes = 0;
113
                TxBytes = 0;
115
                // transmitt address
114
                // transmitt address
116
                I2C_Buffer[TxBytes++] = (u8)(0x00FF & (Address>>8));
115
                I2C_Buffer[TxBytes++] = (u8)(0x00FF & (Address>>8));
117
                I2C_Buffer[TxBytes++] = (u8)(0x00FF & Address);
116
                I2C_Buffer[TxBytes++] = (u8)(0x00FF & Address);
118
                if(Direction == EEPROM_WRITE)
117
                if(Direction == EEPROM_WRITE)
119
                {       // copy data to i2c transfer buffer
118
                {       // copy data to i2c transfer buffer
120
                        for(i = 0; i<DataLen;i++)
119
                        for(i = 0; i<DataLen;i++)
121
                        {
120
                        {
122
                                I2C_Buffer[TxBytes++] = pData[i];
121
                                I2C_Buffer[TxBytes++] = pData[i];
123
                        }
122
                        }
124
                        // prepare pointer to rx data
123
                        // prepare pointer to rx data
125
                        EEPROM_pData = 0;
124
                        EEPROM_pData = 0;
126
                        EEPROM_DataLen = 0;
125
                        EEPROM_DataLen = 0;
127
                        // start transmission
126
                        // start transmission
128
                        if(!I2C_Transmission(EEPROM_I2C_ADDRESS, TxBytes, 0, 0))
127
                        if(!I2C_Transmission(EEPROM_I2C_ADDRESS, TxBytes, 0, 0))
129
                        {
128
                        {
130
                                return(retval);
129
                                return(retval);
131
                        }
130
                        }
132
                }
131
                }
133
                else // Direction == EEPROM_READ
132
                else // Direction == EEPROM_READ
134
                {
133
                {
135
                        // prepare pointer to rx data
134
                        // prepare pointer to rx data
136
                        EEPROM_pData = pData;
135
                        EEPROM_pData = pData;
137
                        EEPROM_DataLen = DataLen;
136
                        EEPROM_DataLen = DataLen;
138
                        // start transmission
137
                        // start transmission
139
                        if(!I2C_Transmission(EEPROM_I2C_ADDRESS, TxBytes, &EEPROM_RxDataHandler, DataLen))
138
                        if(!I2C_Transmission(EEPROM_I2C_ADDRESS, TxBytes, &EEPROM_RxDataHandler, DataLen))
140
                        {
139
                        {
141
                                return(retval);
140
                                return(retval);
142
                        }
141
                        }
143
                }
142
                }
144
                //wait for end of this transfer
143
                //wait for end of this transfer
145
                if(I2C_WaitForEndOfTransmission(I2C_TRANSFER_TIMEOUT))
144
                if(I2C_WaitForEndOfTransmission(I2C_TRANSFER_TIMEOUT))
146
                {
145
                {
147
                        if(I2C_Error == I2C_ERROR_NONE) return(EEPROM_SUCCESS);
146
                        if(I2C_Error == I2C_ERROR_NONE) return(EEPROM_SUCCESS);
148
                        else retval = EEPROM_DATA_TRANSFER_INCOMPLETE;
147
                        else retval = EEPROM_DATA_TRANSFER_INCOMPLETE;
149
                }
148
                }
150
                else// i2c transfer timed out
149
                else// i2c transfer timed out
151
                {
150
                {
152
                        return(EEPROM_ERROR_I2C_TRANSFER_TIMEOUT);     
151
                        return(EEPROM_ERROR_I2C_TRANSFER_TIMEOUT);     
153
                }
152
                }
154
                // or retry             
153
                // or retry             
155
        } while(++retry < I2C_ACCESS_RETRYS);
154
        } while(++retry < I2C_ACCESS_RETRYS);
156
        return(retval);
155
        return(retval);
157
}
156
}
158
 
157
 
159
EEPROM_Result_t EEPROM_WriteBlock(u16 Address, u8 *pData, u16 DataLen)
158
EEPROM_Result_t EEPROM_WriteBlock(u16 Address, u8 *pData, u16 DataLen)
160
{
159
{
161
        u16 len;
160
        u16 len;
162
        EEPROM_Result_t retval;
161
        EEPROM_Result_t retval;
163
 
162
 
164
        // there can be 32 bytes written in a single cycle if the adresses are locates in the same row
163
        // there can be 32 bytes written in a single cycle if the adresses are locates in the same row
165
        // i.e. the upper 11 bits of the addres are constant
164
        // i.e. the upper 11 bits of the addres are constant
166
        #define EEPROM_WRITE_BLOCK_SIZE 32
165
        #define EEPROM_WRITE_BLOCK_SIZE 32
167
 
166
 
168
        len = EEPROM_WRITE_BLOCK_SIZE - Address%EEPROM_WRITE_BLOCK_SIZE; // number of bytes to match the next row
167
        len = EEPROM_WRITE_BLOCK_SIZE - Address%EEPROM_WRITE_BLOCK_SIZE; // number of bytes to match the next row
169
        if(len >= DataLen) len = DataLen; // do not write more than neccesarry
168
        if(len >= DataLen) len = DataLen; // do not write more than neccesarry
170
 
169
 
171
        do
170
        do
172
        {
171
        {
173
                retval = EEPROM_Transfer(EEPROM_WRITE, Address, pData, len);
172
                retval = EEPROM_Transfer(EEPROM_WRITE, Address, pData, len);
174
                Address += len; // Address of the next row
173
                Address += len; // Address of the next row
175
                pData += len;   // pointer to start of next data block
174
                pData += len;   // pointer to start of next data block
176
                DataLen -= len; // reduce the number of to be transmitted
175
                DataLen -= len; // reduce the number of to be transmitted
177
                if(DataLen > EEPROM_WRITE_BLOCK_SIZE) len = EEPROM_WRITE_BLOCK_SIZE; // limit next block size to 32
176
                if(DataLen > EEPROM_WRITE_BLOCK_SIZE) len = EEPROM_WRITE_BLOCK_SIZE; // limit next block size to 32
178
                else len = DataLen;
177
                else len = DataLen;
179
        }
178
        }
180
        while(DataLen && (retval == EEPROM_SUCCESS)); // repeat until all data have been sent and no error has occured
179
        while(DataLen && (retval == EEPROM_SUCCESS)); // repeat until all data have been sent and no error has occured
181
 
180
 
182
        return(retval);
181
        return(retval);
183
}
182
}
184
 
183
 
185
// a data block can be subsequently read after setting the start address once
184
// a data block can be subsequently read after setting the start address once
186
EEPROM_Result_t EEPROM_ReadBlock(u16 Address, u8 *pData, u16 DataLen)
185
EEPROM_Result_t EEPROM_ReadBlock(u16 Address, u8 *pData, u16 DataLen)
187
{
186
{
188
        EEPROM_Result_t retval = EEPROM_ERROR_UNKNOWN;
187
        EEPROM_Result_t retval = EEPROM_ERROR_UNKNOWN;
189
        u16 AdrOffset = 0;
188
        u16 AdrOffset = 0;
190
        u16 RxLen;
189
        u16 RxLen;
191
 
190
 
192
        while(DataLen > 0)
191
        while(DataLen > 0)
193
        {
192
        {
194
                if(DataLen > I2C_BUFFER_LEN) RxLen = I2C_BUFFER_LEN;
193
                if(DataLen > I2C_BUFFER_LEN) RxLen = I2C_BUFFER_LEN;
195
                else RxLen = DataLen;
194
                else RxLen = DataLen;
196
           
195
           
197
                retval = EEPROM_Transfer(EEPROM_READ, Address+AdrOffset, &(pData[AdrOffset]), RxLen);
196
                retval = EEPROM_Transfer(EEPROM_READ, Address+AdrOffset, &(pData[AdrOffset]), RxLen);
198
                if(retval != EEPROM_SUCCESS) break;
197
                if(retval != EEPROM_SUCCESS) break;
199
                AdrOffset += RxLen;
198
                AdrOffset += RxLen;
200
                DataLen -= RxLen;
199
                DataLen -= RxLen;
201
        }
200
        }
202
        return(retval);
201
        return(retval);
203
}
202
}
204
 
203
 
205
u8 EEPROM_Init(void)
204
u8 EEPROM_Init(void)
206
{
205
{
207
        u8 data[20];
206
        u8 data[20];
208
        u8 i, retval = 0;
207
        u8 i, retval = 0;
209
        UART1_PutString("\r\n EEprom init..");
208
        UART1_PutString("\r\n EEprom init..");
210
        // check if data can be read from eeprom
209
        // check if data can be read from eeprom
211
        for(i=0;i<10;i++)
210
        for(i=0;i<10;i++)
212
        {
211
        {
213
                UART1_Putchar('.');
212
                UART1_Putchar('.');
214
                if(EEPROM_SUCCESS == EEPROM_ReadBlock(0, data, 20)) retval = 1;
213
                if(EEPROM_SUCCESS == EEPROM_ReadBlock(0, data, 20)) retval = 1;
215
                if(retval) break;              
214
                if(retval) break;              
216
        }
215
        }
217
        if(retval)  UART1_PutString("ok");
216
        if(retval)  UART1_PutString("ok");
218
        else            UART1_PutString("failed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
217
        else            UART1_PutString("failed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
219
        return(retval);
218
        return(retval);
220
}
219
}
221
 
220