diff options
author | walkerstop <walkerstop@gmail.com> | 2018-05-01 01:00:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-01 01:00:33 -0700 |
commit | 40db44f540436398e0840544044154d13eee63b6 (patch) | |
tree | dad3f1f3b6ac3927484ee22002a947662a8a0173 /os/hal/src/hal_ee24xx.c | |
parent | 4e9f077fb10255dced1da4d5d2ad9f8ae41442a2 (diff) | |
parent | d4d384557df0e8e7a8071553448b0c42849f98c0 (diff) | |
download | ChibiOS-Contrib-40db44f540436398e0840544044154d13eee63b6.tar.gz ChibiOS-Contrib-40db44f540436398e0840544044154d13eee63b6.tar.bz2 ChibiOS-Contrib-40db44f540436398e0840544044154d13eee63b6.zip |
Merge branch 'master' into master
Diffstat (limited to 'os/hal/src/hal_ee24xx.c')
-rw-r--r-- | os/hal/src/hal_ee24xx.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/os/hal/src/hal_ee24xx.c b/os/hal/src/hal_ee24xx.c index 632ffbb..725258c 100644 --- a/os/hal/src/hal_ee24xx.c +++ b/os/hal/src/hal_ee24xx.c @@ -105,7 +105,7 @@ static systime_t calc_timeout(I2CDriver *i2cp, size_t txbytes, size_t rxbytes) { tmo = ((txbytes + rxbytes + 1) * bitsinbyte * 1000); tmo /= EEPROM_I2C_CLOCK; tmo += 10; /* some additional milliseconds to be safer */ - return MS2ST(tmo); + return TIME_MS2I(tmo); } /** @@ -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; |