CARME-M4 BSP  V1.5
eeprom.c
Go to the documentation of this file.
1 
71 #ifdef __cplusplus
72 extern "C"
73 {
74 #endif /* __cplusplus */
75 
76 /*----- Header-Files -------------------------------------------------------*/
77 #include <stm32f4xx.h> /* Processor STM32F407IG */
78 #include <carme.h> /* CARME Module */
79 #include <i2c.h> /* CARME I2C definitions */
80 #include <eeprom.h> /* CARME EEPROM */
81 
82 /*----- Macros -------------------------------------------------------------*/
83 
84 /*----- Data types ---------------------------------------------------------*/
85 
86 /*----- Function prototypes ------------------------------------------------*/
87 
88 /*----- Data ---------------------------------------------------------------*/
89 
90 /*----- Implementation -----------------------------------------------------*/
107 ERROR_CODES CARME_EEPROM_Write(uint8_t *data, uint8_t nbrOfChar,
108  uint8_t startAddress) {
109 
110  uint8_t charstoWrite;
111  uint32_t timeout;
112  uint32_t i;
113 
114  /*Set timeout to ~6ms*/
115  timeout = 200000;
116 
117  if ((startAddress + nbrOfChar) > 0x07FF) {
119  }
120 
121  /*Align to Page*/
122  charstoWrite = startAddress % 8;
123  if (charstoWrite > 0) {
124  charstoWrite = 8 - charstoWrite;
126  startAddress, 1, (uint8_t *) data, charstoWrite);
127 
128  /*delay*/
129  for (i = 0; i < timeout; i++)
130  ;
131 
132  nbrOfChar -= charstoWrite;
133  data += charstoWrite;
134  startAddress += charstoWrite;
135  }
136 
137  while (nbrOfChar > 0) {
138  if (nbrOfChar > 8) {
139  charstoWrite = 8;
140  }
141  else {
142  charstoWrite = nbrOfChar;
143  }
144  /*Write the remaining bytes*/
146  startAddress, 1, (uint8_t *) data, charstoWrite);
147 
148  /*delay*/
149  for (i = 0; i < timeout; i++)
150  ;
151 
152  nbrOfChar -= charstoWrite;
153  data += charstoWrite;
154  startAddress += charstoWrite;
155 
156  }
157 
158  return CARME_NO_ERROR;
159 }
160 
175 ERROR_CODES CARME_EEPROM_Read(uint8_t *recdata, uint8_t nbrOfChar,
176  uint8_t startAddress) {
177 
178  if ((startAddress + nbrOfChar) > 0x07FF) {
180  }
181 
183  startAddress, 1, (uint8_t *) recdata, nbrOfChar)) {
185  }
186 
187  return CARME_NO_ERROR;
188 }
189 
190 #ifdef __cplusplus
191 }
192 #endif /* __cplusplus */
193 
uint8_t ERROR_CODES
Error variable.
Definition: carme.h:255
ERROR_CODES CARME_EEPROM_Write(uint8_t *data, uint8_t nbrOfChar, uint8_t startAddress)
Write an Array of 8-bit data to the Eeprom This Function can take several ms to perfrom. 5ms are needed for a Pagewrite (8 Byte).
Definition: eeprom.c:107
#define CARME_I2C_BOARD
Definition: i2c.h:81
#define CARME_EEPROM_I2C_ADDRESS
Definition: eeprom.h:95
EEPROM board support package for the CARME module.
ERROR_CODES CARME_I2C_Read(I2C_TypeDef *I2Cx, uint8_t addr, uint16_t reg, uint8_t twoByte, uint8_t *pdata, uint16_t count)
Read data from an I2C slave device on a specific register address.
Definition: i2c.c:312
#define CARME_ERROR_EEPROM_BUSY
The EEPROM is busy at the moment.
Definition: eeprom.h:93
#define CARME_ERROR_EEPROM_OVERFLOW
The end of the address range will be reached 0x07FF.
Definition: eeprom.h:92
#define CARME_NO_ERROR
Definition: carme.h:135
ERROR_CODES CARME_I2C_Write(I2C_TypeDef *I2Cx, uint8_t addr, uint16_t reg, uint8_t twoByte, uint8_t *pdata, uint16_t count)
Write data to an I2C slave device on a specific register address.
Definition: i2c.c:226
ERROR_CODES CARME_EEPROM_Read(uint8_t *recdata, uint8_t nbrOfChar, uint8_t startAddress)
Read an Array of char to the Eeprom.
Definition: eeprom.c:175
I2C board support package for the CARME module.