Rev 483 | Rev 526 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 483 | Rev 489 | ||
---|---|---|---|
Line 54... | Line 54... | ||
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | #include <string.h> |
56 | #include <string.h> |
57 | #include <stdio.h> |
57 | #include <stdio.h> |
58 | #include "91x_lib.h" |
58 | #include "91x_lib.h" |
59 | #include "i2c1.h" |
59 | #include "i2c.h" |
60 | #include "uart1.h" |
60 | #include "uart1.h" |
61 | #include "timer1.h" |
61 | #include "timer1.h" |
62 | #include "eeprom.h" |
62 | #include "eeprom.h" |
63 | #include "led.h" |
63 | #include "led.h" |
Line -... | Line 64... | ||
- | 64 | ||
64 | 65 | ||
- | 66 | ||
- | 67 | // The EEPROM M24C64 (64k) ist connected via I2C1 interface to the controller. |
|
65 | 68 | #define EEPROM_I2C I2C1 |
|
Line 66... | Line 69... | ||
66 | // The EEPROM M24C64 (64k) ist connected via I2C1 interface to the controller. |
69 | |
67 | // The E0, E2, E3 pins are set to low. Therefore the slave adressbits b3, b2, b1 are 0. |
70 | // The E0, E2, E3 pins are set to low. Therefore the slave adressbits b3, b2, b1 are 0. |
68 | 71 | ||
Line 90... | Line 93... | ||
90 | } |
93 | } |
Line 91... | Line 94... | ||
91 | 94 | ||
92 | // ---------------------------------------------------------------------------------------- |
95 | // ---------------------------------------------------------------------------------------- |
93 | EEPROM_Result_t EEPROM_Transfer(u8 Direction, u16 Address, u8 *pData, u16 DataLen) |
96 | EEPROM_Result_t EEPROM_Transfer(u8 Direction, u16 Address, u8 *pData, u16 DataLen) |
94 | { |
97 | { |
95 | u16 i, TxBytes = 0; |
98 | u16 i; |
96 | u8 retry = 0; |
99 | u8 retry = 0; |
Line 97... | Line 100... | ||
97 | EEPROM_Result_t retval = EEPROM_ERROR_UNKNOWN; |
100 | EEPROM_Result_t retval = EEPROM_ERROR_UNKNOWN; |
98 | 101 | ||
99 | if(((u32)Address + (u32)DataLen) >= (EEPROM_SIZE - 1)) |
102 | if(((u32)Address + (u32)DataLen) >= (EEPROM_SIZE - 1)) |
100 | { |
103 | { |
101 | retval = EEPROM_ERROR_OUT_OF_ADDRESS_RANGE; |
104 | retval = EEPROM_ERROR_OUT_OF_ADDRESS_RANGE; |
102 | return(retval); |
105 | return(retval); |
103 | } |
106 | } |
104 | if((DataLen+2) > I2C1_BUFFER_LEN) |
107 | if((DataLen+2) > I2C_BUFFER_LEN) |
105 | { |
108 | { |
106 | retval = EEPROM_I2C_BUFFER_OVERRUN; |
109 | retval = EEPROM_I2C_BUFFER_OVERRUN; |
107 | return(retval); |
110 | return(retval); |
108 | } |
111 | } |
109 | do |
112 | do |
110 | { |
113 | { |
111 | if(!I2C1_LockBuffer(I2C_IDLE_TIMEOUT)) return EEPROM_ERROR_I2C_IDLE_TIMEOUT; |
114 | if(!I2CBus_LockBuffer(EEPROM_I2C, I2C_IDLE_TIMEOUT)) return EEPROM_ERROR_I2C_IDLE_TIMEOUT; |
- | 115 | // buffer is now locked |
|
112 | // buffer is now locked |
116 | u8 TxBytes = 0; |
113 | TxBytes = 0; |
117 | u8 TxData[255]; |
114 | // transmitt address |
118 | // transmitt address |
115 | I2C1_Buffer[TxBytes++] = (u8)(0x00FF & (Address>>8)); |
119 | TxData[TxBytes++] = (u8)(0x00FF & (Address>>8)); |
116 | I2C1_Buffer[TxBytes++] = (u8)(0x00FF & Address); |
120 | TxData[TxBytes++] = (u8)(0x00FF & Address); |
117 | if(Direction == EEPROM_WRITE) |
121 | if(Direction == EEPROM_WRITE) |
118 | { // copy data to i2c transfer buffer |
122 | { // copy data to i2c transfer buffer |
119 | for(i = 0; i<DataLen;i++) |
123 | for(i = 0; i<DataLen;i++) |
120 | { |
124 | { |
121 | I2C1_Buffer[TxBytes++] = pData[i]; |
125 | TxData[TxBytes++] = pData[i]; |
122 | } |
126 | } |
123 | // prepare pointer to rx data |
127 | // prepare pointer to rx data |
124 | EEPROM_pData = 0; |
128 | EEPROM_pData = 0; |
125 | EEPROM_DataLen = 0; |
129 | EEPROM_DataLen = 0; |
126 | // start transmission |
130 | // start transmission |
127 | if(!I2C1_Transmission(EEPROM_I2C_ADDRESS, TxBytes, 0, 0)) |
131 | if(!I2CBus_Transmission(EEPROM_I2C, EEPROM_I2C_ADDRESS, TxData, TxBytes, 0, 0)) |
128 | { |
132 | { |
129 | return(retval); |
133 | return(retval); |
130 | } |
134 | } |
131 | } |
135 | } |
132 | else // Direction == EEPROM_READ |
136 | else // Direction == EEPROM_READ |
133 | { |
137 | { |
134 | // prepare pointer to rx data |
138 | // prepare pointer to rx data |
135 | EEPROM_pData = pData; |
139 | EEPROM_pData = pData; |
136 | EEPROM_DataLen = DataLen; |
140 | EEPROM_DataLen = DataLen; |
137 | // start transmission |
141 | // start transmission |
138 | if(!I2C1_Transmission(EEPROM_I2C_ADDRESS, TxBytes, &EEPROM_RxDataHandler, DataLen)) |
142 | if(!I2CBus_Transmission(EEPROM_I2C, EEPROM_I2C_ADDRESS, TxData, TxBytes, &EEPROM_RxDataHandler, DataLen)) |
139 | { |
143 | { |
140 | return(retval); |
144 | return(retval); |
141 | } |
145 | } |
142 | } |
146 | } |
143 | //wait for end of this transfer |
147 | //wait for end of this transfer |
144 | if(I2C1_WaitForEndOfTransmission(I2C_TRANSFER_TIMEOUT)) |
148 | if(I2CBus_WaitForEndOfTransmission(EEPROM_I2C, I2C_TRANSFER_TIMEOUT)) |
145 | { |
149 | { |
146 | if(I2C1_Error == I2C_ERROR_NONE) return(EEPROM_SUCCESS); |
150 | if(I2CBus(EEPROM_I2C)->Error == I2C_ERROR_NONE) return(EEPROM_SUCCESS); |
147 | else retval = EEPROM_DATA_TRANSFER_INCOMPLETE; |
151 | else retval = EEPROM_DATA_TRANSFER_INCOMPLETE; |
148 | } |
152 | } |
149 | else// i2c transfer timed out |
153 | else// i2c transfer timed out |
Line 188... | Line 192... | ||
188 | u16 AdrOffset = 0; |
192 | u16 AdrOffset = 0; |
189 | u16 RxLen; |
193 | u16 RxLen; |
Line 190... | Line 194... | ||
190 | 194 | ||
191 | while(DataLen > 0) |
195 | while(DataLen > 0) |
192 | { |
196 | { |
193 | if(DataLen > I2C1_BUFFER_LEN) RxLen = I2C1_BUFFER_LEN; |
197 | if(DataLen > I2C_BUFFER_LEN) RxLen = I2C_BUFFER_LEN; |
Line 194... | Line 198... | ||
194 | else RxLen = DataLen; |
198 | else RxLen = DataLen; |
195 | 199 | ||
196 | retval = EEPROM_Transfer(EEPROM_READ, Address+AdrOffset, &(pData[AdrOffset]), RxLen); |
200 | retval = EEPROM_Transfer(EEPROM_READ, Address+AdrOffset, &(pData[AdrOffset]), RxLen); |