X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=drv%2Feeprom.c;h=0f301effa709c41d463398d9f45d5033ed69e849;hb=8ff088ff4cf0ddbff09c6630e36370bf25f33535;hp=718a52deed541506eabe4a2740083ec5acde8a1a;hpb=283ff66de6da462b9c7f03e58d259951b05de863;p=bertos.git diff --git a/drv/eeprom.c b/drv/eeprom.c index 718a52de..0f301eff 100755 --- a/drv/eeprom.c +++ b/drv/eeprom.c @@ -5,39 +5,65 @@ * All Rights Reserved. * --> * - * \version $Id$ - * - * \author Stefano Fedrigo - * \author Bernardo Innocenti - * * \brief Driver for the 24xx16 and 24xx256 I2C EEPROMS (implementation) * * \note This implementation is AVR specific. - */ - -/* - * $Log$ - * Revision 1.4 2004/08/10 06:57:22 bernie - * eeprom_erase(): New function. - * - * Revision 1.3 2004/07/29 22:57:09 bernie - * Add 24LC16 support. - * - * Revision 1.2 2004/07/22 01:24:43 bernie - * Document AVR dependency. - * - * Revision 1.1 2004/07/20 17:11:18 bernie - * Import into DevLib. * + * \version $Id$ + * \author Stefano Fedrigo + * \author Bernardo Innocenti */ + +/*#* + *#* $Log$ + *#* Revision 1.11 2004/10/26 08:35:31 bernie + *#* Reset watchdog for long operations. + *#* + *#* Revision 1.10 2004/09/20 03:31:22 bernie + *#* Sanitize for C++. + *#* + *#* Revision 1.9 2004/09/14 21:03:46 bernie + *#* Use debug.h instead of kdebug.h. + *#* + *#* Revision 1.8 2004/08/25 14:12:08 rasky + *#* Aggiornato il comment block dei log RCS + *#* + *#* Revision 1.7 2004/08/24 16:48:40 bernie + *#* Note reason for including + *#* + *#* Revision 1.6 2004/08/24 14:27:20 bernie + *#* Doxygen fix. + *#* + *#* Revision 1.5 2004/08/24 13:46:48 bernie + *#* Include . + *#* + *#* Revision 1.4 2004/08/10 06:57:22 bernie + *#* eeprom_erase(): New function. + *#* + *#* Revision 1.3 2004/07/29 22:57:09 bernie + *#* Add 24LC16 support. + *#* + *#* Revision 1.2 2004/07/22 01:24:43 bernie + *#* Document AVR dependency. + *#* + *#* Revision 1.1 2004/07/20 17:11:18 bernie + *#* Import into DevLib. + *#* + *#*/ + #include "eeprom.h" + +#include #include /* cpu_to_be16() */ -#include +#include #include +#include // MIN() + #include // memset() #include + /* Wait for TWINT flag set: bus is ready */ #define WAIT_TWI_READY do {} while (!(TWCR & BV(TWINT))) @@ -140,8 +166,10 @@ static void twi_stop(void) * * \return true on success, false on error. */ -static bool twi_send(const uint8_t *buf, size_t count) +static bool twi_send(const void *_buf, size_t count) { + const uint8_t *buf = (const uint8_t *)_buf; + while (count--) { TWDR = *buf++; @@ -167,8 +195,10 @@ static bool twi_send(const uint8_t *buf, size_t count) * * \return true on success, false on error */ -static bool twi_recv(uint8_t *buf, size_t count) +static bool twi_recv(void *_buf, size_t count) { + uint8_t *buf = (uint8_t *)_buf; + /* * When reading the last byte the TWEA bit is not * set, and the eeprom should answer with NACK @@ -266,6 +296,8 @@ bool eeprom_write(e2addr_t addr, const void *buf, size_t count) /*! * Copy \c count bytes at address \c addr * from eeprom to RAM to buffer \c buf. + * + * \return true on success. */ bool eeprom_read(e2addr_t addr, void *buf, size_t count) { @@ -333,8 +365,8 @@ int eeprom_read_char(e2addr_t addr) /*! * Erase specified part of eeprom, writing 0xFF. * - * \param addr starting address - * \param len length of block to erase + * \param addr starting address + * \param count length of block to erase */ void eeprom_erase(e2addr_t addr, size_t count) { @@ -344,6 +376,9 @@ void eeprom_erase(e2addr_t addr, size_t count) // Clear all but struct hw_info at start of eeprom while (count) { + // Long operation, reset watchdog + wdt_reset(); + size_t size = MIN(count, sizeof buf); eeprom_write(addr, buf, size); addr += size; @@ -391,8 +426,8 @@ void eeprom_init(void) void eeprom_test(void) { - static const char magic[13] = "Humpty Dumpty"; - char buf[sizeof magic + 1]; + static const char magic[14] = "Humpty Dumpty"; + char buf[sizeof magic]; size_t i; // Write something to EEPROM using unaligned sequential writes