aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal
diff options
context:
space:
mode:
authorFabien Poussin <fabien.poussin@gmail.com>2018-03-20 16:04:08 +0100
committerFabien Poussin <fabien.poussin@gmail.com>2018-03-20 16:04:08 +0100
commitd4d384557df0e8e7a8071553448b0c42849f98c0 (patch)
tree9724b2cd51920cfa09a8b619405768cde54f7a15 /os/hal
parent7a4c7975c2b0932dbc2a81efb999a748f64359a4 (diff)
downloadChibiOS-Contrib-d4d384557df0e8e7a8071553448b0c42849f98c0.tar.gz
ChibiOS-Contrib-d4d384557df0e8e7a8071553448b0c42849f98c0.tar.bz2
ChibiOS-Contrib-d4d384557df0e8e7a8071553448b0c42849f98c0.zip
Fixes for #138
Diffstat (limited to 'os/hal')
-rw-r--r--os/hal/src/hal_ee24xx.c24
-rw-r--r--os/hal/src/hal_ee25xx.c26
2 files changed, 24 insertions, 26 deletions
diff --git a/os/hal/src/hal_ee24xx.c b/os/hal/src/hal_ee24xx.c
index 164530e..725258c 100644
--- a/os/hal/src/hal_ee24xx.c
+++ b/os/hal/src/hal_ee24xx.c
@@ -202,7 +202,7 @@ static void __fitted_write(void *ip, const uint8_t *data, size_t len, uint32_t *
msg_t status = MSG_RESET;
- osalDbgAssert(len != 0, "something broken in hi level part");
+ osalDbgAssert(len > 0, "len must be greater than 0");
status = eeprom_write(((I2CEepromFileStream *)ip)->cfg,
eepfs_getposition(ip), data, len);
@@ -214,15 +214,15 @@ static void __fitted_write(void *ip, const uint8_t *data, size_t len, uint32_t *
/**
* @brief Write data to EEPROM.
- * @details Only one EEPROM page can be written at once. So fucntion
+ * @details Only one EEPROM page can be written at once. So function
* splits large data chunks in small EEPROM transactions if needed.
- * @note To achieve the maximum effectivity use write operations
+ * @note To achieve the maximum efficiency use write operations
* aligned to EEPROM page boundaries.
*/
static size_t write(void *ip, const uint8_t *bp, size_t n) {
- size_t len = 0; /* bytes to be written at one trasaction */
- uint32_t written; /* total bytes successfully written */
+ size_t len = 0; /* bytes to be written per transaction */
+ uint32_t written = 0; /* total bytes successfully written */
uint16_t pagesize;
uint32_t firstpage;
uint32_t lastpage;
@@ -242,12 +242,10 @@ static size_t write(void *ip, const uint8_t *bp, size_t n) {
lastpage = (((EepromFileStream *)ip)->cfg->barrier_low +
eepfs_getposition(ip) + n - 1) / pagesize;
- written = 0;
- /* data fitted in single page */
+ /* data fits in single page */
if (firstpage == lastpage) {
len = n;
__fitted_write(ip, bp, len, &written);
- bp += len;
return written;
}
@@ -255,17 +253,19 @@ static size_t write(void *ip, const uint8_t *bp, size_t n) {
/* write first piece of data to first page boundary */
len = ((firstpage + 1) * pagesize) - eepfs_getposition(ip);
len -= ((EepromFileStream *)ip)->cfg->barrier_low;
- __fitted_write(ip, bp, len, &written);
+ if (__fitted_write(ip, bp, len, &written) != MSG_OK)
+ return written;
bp += len;
- /* now writes blocks at a size of pages (may be no one) */
+ /* now write page sized blocks (zero or more) */
while ((n - written) > pagesize) {
len = pagesize;
- __fitted_write(ip, bp, len, &written);
+ if (__fitted_write(ip, bp, len, &written) != MSG_OK)
+ return written;
bp += len;
}
- /* wrtie tail */
+ /* write tail */
len = n - written;
if (len == 0)
return written;
diff --git a/os/hal/src/hal_ee25xx.c b/os/hal/src/hal_ee25xx.c
index 102aef8..8c35976 100644
--- a/os/hal/src/hal_ee25xx.c
+++ b/os/hal/src/hal_ee25xx.c
@@ -277,7 +277,7 @@ static msg_t __fitted_write(void *ip, const uint8_t *data, size_t len, uint32_t
msg_t status = MSG_RESET;
- osalDbgAssert(len != 0, "something broken in hi level part");
+ osalDbgAssert(len > 0, "len must be greater than 0");
status = ll_eeprom_write(((SPIEepromFileStream *)ip)->cfg,
eepfs_getposition(ip), data, len);
@@ -290,15 +290,15 @@ static msg_t __fitted_write(void *ip, const uint8_t *data, size_t len, uint32_t
/**
* @brief Write data to EEPROM.
- * @details Only one EEPROM page can be written at once. So fucntion
+ * @details Only one EEPROM page can be written at once. So function
* splits large data chunks in small EEPROM transactions if needed.
- * @note To achieve the maximum effectivity use write operations
+ * @note To achieve the maximum efficiency use write operations
* aligned to EEPROM page boundaries.
*/
static size_t write(void *ip, const uint8_t *bp, size_t n) {
- size_t len = 0; /* bytes to be written at one trasaction */
- uint32_t written; /* total bytes successfully written */
+ size_t len = 0; /* bytes to be written per transaction */
+ uint32_t written = 0; /* total bytes successfully written */
uint16_t pagesize;
uint32_t firstpage;
uint32_t lastpage;
@@ -318,32 +318,30 @@ static size_t write(void *ip, const uint8_t *bp, size_t n) {
firstpage = (cfg->barrier_low + eepfs_getposition(ip)) / pagesize;
lastpage = ((cfg->barrier_low + eepfs_getposition(ip) + n) - 1) / pagesize;
- written = 0;
- /* data fitted in single page */
+ /* data fits in single page */
if (firstpage == lastpage) {
len = n;
__fitted_write(ip, bp, len, &written);
- bp += len;
return written;
}
+
else {
/* write first piece of data to first page boundary */
len = ((firstpage + 1) * pagesize) - eepfs_getposition(ip);
len -= cfg->barrier_low;
- __fitted_write(ip, bp, len, &written);
+ if (__fitted_write(ip, bp, len, &written) != MSG_OK)
+ return written;
bp += len;
- /* now writes blocks at a size of pages (may be no one) */
+ /* now write page sized blocks (zero or more) */
while ((n - written) > pagesize) {
len = pagesize;
- if (__fitted_write(ip, bp, len, &written) != MSG_OK) // Fixed: Would increase bp forever and crash in case of timeouts...
+ if (__fitted_write(ip, bp, len, &written) != MSG_OK)
return written;
-
bp += len;
}
-
- /* wrtie tail */
+ /* write tail */
len = n - written;
if (len == 0)
return written;