Rev 256 | Rev 308 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 256 | Rev 264 | ||
---|---|---|---|
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 |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
8 | // + www.MikroKopter.com |
8 | // + www.MikroKopter.com |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
22 | // + eindeutig als Ursprung verlinkt werden |
22 | // + eindeutig als Ursprung verlinkt werden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
25 | // + Benutzung auf eigene Gefahr |
25 | // + Benutzung auf eigene Gefahr |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
29 | // + mit unserer Zustimmung zulässig |
29 | // + mit unserer Zustimmung zulässig |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + this list of conditions and the following disclaimer. |
34 | // + this list of conditions and the following disclaimer. |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + from this software without specific prior written permission. |
36 | // + from this software without specific prior written permission. |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
38 | // + for non-commercial use (directly or indirectly) |
38 | // + for non-commercial use (directly or indirectly) |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
40 | // + with our written permission |
40 | // + with our written permission |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
42 | // + clearly linked as origin |
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 |
43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
44 | // |
44 | // |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | #include <string.h> |
57 | #include <string.h> |
58 | #include <stdio.h> |
58 | #include <stdio.h> |
59 | #include "91x_lib.h" |
59 | #include "91x_lib.h" |
60 | #include "i2c.h" |
60 | #include "i2c.h" |
61 | #include "uart1.h" |
61 | #include "uart1.h" |
62 | #include "timer1.h" |
62 | #include "timer1.h" |
63 | #include "eeprom.h" |
63 | #include "eeprom.h" |
- | 64 | #include "led.h" |
|
64 | 65 | ||
65 | 66 | ||
66 | // The EEPROM M24C64 (64k) ist connected via I2C1 interface to the controller. |
67 | // The EEPROM M24C64 (64k) ist connected via I2C1 interface to the controller. |
67 | // The E0, E2, E3 pins are set to low. Therefore the slave adressbits b3, b2, b1 are 0. |
68 | // The E0, E2, E3 pins are set to low. Therefore the slave adressbits b3, b2, b1 are 0. |
68 | 69 | ||
69 | #define EEPROM_I2C_ADDRESS 0xA0 |
70 | #define EEPROM_I2C_ADDRESS 0xA0 |
70 | #define EEPROM_SIZE 65536L // 64k bytes |
71 | #define EEPROM_SIZE 65536L // 64k bytes |
71 | #define EEPROM_WRITE 1 |
72 | #define EEPROM_WRITE 1 |
72 | #define EEPROM_READ 0 |
73 | #define EEPROM_READ 0 |
73 | 74 | ||
74 | // timing |
75 | // timing |
75 | #define I2C_IDLE_TIMEOUT 150 // 150 ms |
76 | #define I2C_IDLE_TIMEOUT 150 // 150 ms |
76 | #define I2C_TRANSFER_TIMEOUT 150 // 150 ms |
77 | #define I2C_TRANSFER_TIMEOUT 150 // 150 ms |
77 | #define I2C_ACCESS_RETRYS 20 // retry 20 times |
78 | #define I2C_ACCESS_RETRYS 20 // retry 20 times |
78 | 79 | ||
79 | // globals for rx handler |
80 | // globals for rx handler |
80 | volatile u8 *EEPROM_pData = 0; |
81 | volatile u8 *EEPROM_pData = 0; |
81 | volatile u16 EEPROM_DataLen = 0; |
82 | volatile u16 EEPROM_DataLen = 0; |
82 | 83 | ||
83 | // rx data handler for eeprom data read access |
84 | // rx data handler for eeprom data read access |
84 | void EEPROM_RxDataHandler(u8* pRxBuffer, u8 RxBufferSize) |
85 | void EEPROM_RxDataHandler(u8* pRxBuffer, u8 RxBufferSize) |
85 | { // if number of byte are matching |
86 | { // if number of byte are matching |
86 | if((RxBufferSize == EEPROM_DataLen)) |
87 | if((RxBufferSize == EEPROM_DataLen)) |
87 | { //copy data from primary buffer to target buffer |
88 | { //copy data from primary buffer to target buffer |
88 | if(EEPROM_pData) memcpy((u8*)EEPROM_pData, pRxBuffer, EEPROM_DataLen); |
89 | if(EEPROM_pData) memcpy((u8*)EEPROM_pData, pRxBuffer, EEPROM_DataLen); |
89 | } |
90 | } |
90 | } |
91 | } |
91 | 92 | ||
92 | // ---------------------------------------------------------------------------------------- |
93 | // ---------------------------------------------------------------------------------------- |
93 | EEPROM_Result_t EEPROM_Transfer(u8 Direction, u16 Address, u8 *pData, u16 DataLen) |
94 | EEPROM_Result_t EEPROM_Transfer(u8 Direction, u16 Address, u8 *pData, u16 DataLen) |
94 | { |
95 | { |
95 | u16 i, TxBytes = 0; |
96 | u16 i, TxBytes = 0; |
96 | u8 retry = 0; |
97 | u8 retry = 0; |
97 | EEPROM_Result_t retval = EEPROM_ERROR_UNKNOWN; |
98 | EEPROM_Result_t retval = EEPROM_ERROR_UNKNOWN; |
98 | 99 | ||
99 | if(((u32)Address + (u32)DataLen) >= (EEPROM_SIZE - 1)) |
100 | if(((u32)Address + (u32)DataLen) >= (EEPROM_SIZE - 1)) |
100 | { |
101 | { |
101 | retval = EEPROM_ERROR_OUT_OF_ADDRESS_RANGE; |
102 | retval = EEPROM_ERROR_OUT_OF_ADDRESS_RANGE; |
102 | return(retval); |
103 | return(retval); |
103 | } |
104 | } |
104 | if((DataLen+2) > I2C_BUFFER_LEN) |
105 | if((DataLen+2) > I2C_BUFFER_LEN) |
105 | { |
106 | { |
106 | retval = EEPROM_I2C_BUFFER_OVERRUN; |
107 | retval = EEPROM_I2C_BUFFER_OVERRUN; |
107 | return(retval); |
108 | return(retval); |
108 | } |
109 | } |
109 | do |
110 | do |
110 | { |
111 | { |
111 | if(!I2C_LockBuffer(I2C_IDLE_TIMEOUT)) return EEPROM_ERROR_I2C_IDLE_TIMEOUT; |
112 | if(!I2C_LockBuffer(I2C_IDLE_TIMEOUT)) return EEPROM_ERROR_I2C_IDLE_TIMEOUT; |
112 | // buffer is now locked |
113 | // buffer is now locked |
113 | TxBytes = 0; |
114 | TxBytes = 0; |
114 | // transmitt address |
115 | // transmitt address |
115 | I2C_Buffer[TxBytes++] = (u8)(0x00FF & (Address>>8)); |
116 | I2C_Buffer[TxBytes++] = (u8)(0x00FF & (Address>>8)); |
116 | I2C_Buffer[TxBytes++] = (u8)(0x00FF & Address); |
117 | I2C_Buffer[TxBytes++] = (u8)(0x00FF & Address); |
117 | if(Direction == EEPROM_WRITE) |
118 | if(Direction == EEPROM_WRITE) |
118 | { // copy data to i2c transfer buffer |
119 | { // copy data to i2c transfer buffer |
119 | for(i = 0; i<DataLen;i++) |
120 | for(i = 0; i<DataLen;i++) |
120 | { |
121 | { |
121 | I2C_Buffer[TxBytes++] = pData[i]; |
122 | I2C_Buffer[TxBytes++] = pData[i]; |
122 | } |
123 | } |
123 | // prepare pointer to rx data |
124 | // prepare pointer to rx data |
124 | EEPROM_pData = 0; |
125 | EEPROM_pData = 0; |
125 | EEPROM_DataLen = 0; |
126 | EEPROM_DataLen = 0; |
126 | // start transmission |
127 | // start transmission |
127 | if(!I2C_Transmission(EEPROM_I2C_ADDRESS, TxBytes, 0, 0)) |
128 | if(!I2C_Transmission(EEPROM_I2C_ADDRESS, TxBytes, 0, 0)) |
128 | { |
129 | { |
129 | return(retval); |
130 | return(retval); |
130 | } |
131 | } |
131 | } |
132 | } |
132 | else // Direction == EEPROM_READ |
133 | else // Direction == EEPROM_READ |
133 | { |
134 | { |
134 | // prepare pointer to rx data |
135 | // prepare pointer to rx data |
135 | EEPROM_pData = pData; |
136 | EEPROM_pData = pData; |
136 | EEPROM_DataLen = DataLen; |
137 | EEPROM_DataLen = DataLen; |
137 | // start transmission |
138 | // start transmission |
138 | if(!I2C_Transmission(EEPROM_I2C_ADDRESS, TxBytes, &EEPROM_RxDataHandler, DataLen)) |
139 | if(!I2C_Transmission(EEPROM_I2C_ADDRESS, TxBytes, &EEPROM_RxDataHandler, DataLen)) |
139 | { |
140 | { |
140 | return(retval); |
141 | return(retval); |
141 | } |
142 | } |
142 | } |
143 | } |
143 | //wait for end of this transfer |
144 | //wait for end of this transfer |
144 | if(I2C_WaitForEndOfTransmission(I2C_TRANSFER_TIMEOUT)) |
145 | if(I2C_WaitForEndOfTransmission(I2C_TRANSFER_TIMEOUT)) |
145 | { |
146 | { |
146 | if(I2C_Error == I2C_ERROR_NONE) return(EEPROM_SUCCESS); |
147 | if(I2C_Error == I2C_ERROR_NONE) return(EEPROM_SUCCESS); |
147 | else retval = EEPROM_DATA_TRANSFER_INCOMPLETE; |
148 | else retval = EEPROM_DATA_TRANSFER_INCOMPLETE; |
148 | } |
149 | } |
149 | else// i2c transfer timed out |
150 | else// i2c transfer timed out |
150 | { |
151 | { |
151 | return(EEPROM_ERROR_I2C_TRANSFER_TIMEOUT); |
152 | return(EEPROM_ERROR_I2C_TRANSFER_TIMEOUT); |
152 | } |
153 | } |
153 | // or retry |
154 | // or retry |
154 | } while(++retry < I2C_ACCESS_RETRYS); |
155 | } while(++retry < I2C_ACCESS_RETRYS); |
155 | return(retval); |
156 | return(retval); |
156 | } |
157 | } |
157 | 158 | ||
158 | EEPROM_Result_t EEPROM_WriteBlock(u16 Address, u8 *pData, u16 DataLen) |
159 | EEPROM_Result_t EEPROM_WriteBlock(u16 Address, u8 *pData, u16 DataLen) |
159 | { |
160 | { |
160 | u16 len; |
161 | u16 len; |
161 | EEPROM_Result_t retval; |
162 | EEPROM_Result_t retval; |
162 | 163 | ||
163 | // there can be 32 bytes written in a single cycle if the adresses are locates in the same row |
164 | // there can be 32 bytes written in a single cycle if the adresses are locates in the same row |
164 | // i.e. the upper 11 bits of the addres are constant |
165 | // i.e. the upper 11 bits of the addres are constant |
165 | #define EEPROM_WRITE_BLOCK_SIZE 32 |
166 | #define EEPROM_WRITE_BLOCK_SIZE 32 |
166 | 167 | ||
167 | len = EEPROM_WRITE_BLOCK_SIZE - Address%EEPROM_WRITE_BLOCK_SIZE; // number of bytes to match the next row |
168 | len = EEPROM_WRITE_BLOCK_SIZE - Address%EEPROM_WRITE_BLOCK_SIZE; // number of bytes to match the next row |
168 | if(len >= DataLen) len = DataLen; // do not write more than neccesarry |
169 | if(len >= DataLen) len = DataLen; // do not write more than neccesarry |
169 | 170 | ||
170 | do |
171 | do |
171 | { |
172 | { |
172 | retval = EEPROM_Transfer(EEPROM_WRITE, Address, pData, len); |
173 | retval = EEPROM_Transfer(EEPROM_WRITE, Address, pData, len); |
173 | Address += len; // Address of the next row |
174 | Address += len; // Address of the next row |
174 | pData += len; // pointer to start of next data block |
175 | pData += len; // pointer to start of next data block |
175 | DataLen -= len; // reduce the number of to be transmitted |
176 | DataLen -= len; // reduce the number of to be transmitted |
176 | if(DataLen > EEPROM_WRITE_BLOCK_SIZE) len = EEPROM_WRITE_BLOCK_SIZE; // limit next block size to 32 |
177 | if(DataLen > EEPROM_WRITE_BLOCK_SIZE) len = EEPROM_WRITE_BLOCK_SIZE; // limit next block size to 32 |
177 | else len = DataLen; |
178 | else len = DataLen; |
178 | } |
179 | } |
179 | while(DataLen && (retval == EEPROM_SUCCESS)); // repeat until all data have been sent and no error has occured |
180 | while(DataLen && (retval == EEPROM_SUCCESS)); // repeat until all data have been sent and no error has occured |
180 | 181 | ||
181 | return(retval); |
182 | return(retval); |
182 | } |
183 | } |
183 | 184 | ||
184 | // a data block can be subsequently read after setting the start address once |
185 | // a data block can be subsequently read after setting the start address once |
185 | EEPROM_Result_t EEPROM_ReadBlock(u16 Address, u8 *pData, u16 DataLen) |
186 | EEPROM_Result_t EEPROM_ReadBlock(u16 Address, u8 *pData, u16 DataLen) |
186 | { |
187 | { |
187 | EEPROM_Result_t retval = EEPROM_ERROR_UNKNOWN; |
188 | EEPROM_Result_t retval = EEPROM_ERROR_UNKNOWN; |
188 | u16 AdrOffset = 0; |
189 | u16 AdrOffset = 0; |
189 | u16 RxLen; |
190 | u16 RxLen; |
190 | 191 | ||
191 | while(DataLen > 0) |
192 | while(DataLen > 0) |
192 | { |
193 | { |
193 | if(DataLen > I2C_BUFFER_LEN) RxLen = I2C_BUFFER_LEN; |
194 | if(DataLen > I2C_BUFFER_LEN) RxLen = I2C_BUFFER_LEN; |
194 | else RxLen = DataLen; |
195 | else RxLen = DataLen; |
195 | 196 | ||
196 | retval = EEPROM_Transfer(EEPROM_READ, Address+AdrOffset, &(pData[AdrOffset]), RxLen); |
197 | retval = EEPROM_Transfer(EEPROM_READ, Address+AdrOffset, &(pData[AdrOffset]), RxLen); |
197 | if(retval != EEPROM_SUCCESS) break; |
198 | if(retval != EEPROM_SUCCESS) break; |
198 | AdrOffset += RxLen; |
199 | AdrOffset += RxLen; |
199 | DataLen -= RxLen; |
200 | DataLen -= RxLen; |
200 | } |
201 | } |
201 | return(retval); |
202 | return(retval); |
- | 203 | } |
|
- | 204 | ||
- | 205 | u8 EEPROM_Init(void) |
|
- | 206 | { |
|
- | 207 | u8 data[20]; |
|
- | 208 | u8 i, retval = 0; |
|
- | 209 | UART1_PutString("\r\n EEprom init.."); |
|
- | 210 | // check if data can be read from eeprom |
|
- | 211 | for(i=0;i<10;i++) |
|
- | 212 | { |
|
- | 213 | UART1_Putchar('.'); |
|
- | 214 | if(EEPROM_SUCCESS == EEPROM_ReadBlock(0, data, 20)) retval = 1; |
|
- | 215 | if(retval) break; |
|
- | 216 | } |
|
- | 217 | if(retval) UART1_PutString("ok"); |
|
- | 218 | else UART1_PutString("failed"); |
|
- | 219 | return(retval); |
|
202 | } |
220 | } |
203 | 221 |