eeprom.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2009 by Rittal GmbH & Co. KG. All rights reserved.
  3. * Copyright (C) 2010 by Ulrich Prinz (uprinz2@netscape.net)
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the copyright holders nor the names of
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY EMBEDDED IT AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EMBEDDED IT
  22. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  25. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  27. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  28. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. * For additional information see http://www.ethernut.de/
  31. *
  32. */
  33. /*!
  34. * \verbatim
  35. * $Id$
  36. *\endverbatim
  37. */
  38. #ifndef _DEV_EEPROM_H_
  39. #define _DEV_EEPROM_H_
  40. #include <cfg/os.h>
  41. #include <cfg/eeprom.h>
  42. #include <sys/timer.h>
  43. #include <sys/event.h>
  44. #include <stdint.h>
  45. #include <dev/twif.h>
  46. #include <dev/at24c.h>
  47. #include <dev/eeprom.h>
  48. static struct at24c at24c32s;
  49. /****************************************************************************/
  50. int EEInit( void )
  51. /****************************************************************************/
  52. {
  53. uint8_t dummy;
  54. at24c32s.PageSize = AT24C_ROW_SIZE;
  55. at24c32s.EepromSize = AT24C_CHIP_SIZE;
  56. at24c32s.SlaveAddress = NUT_CONFIG_AT24_ADR;
  57. at24c32s.IAddrW = AT24C_ADR_SIZE;
  58. #ifdef AT24C_BLOCK_ADDR
  59. at24c32s.BlInSla = 1;
  60. #endif
  61. at24c32s.Timeout = 20;
  62. NutEventPost( &at24c32s.ee_mutex);
  63. if( TwInit(0))
  64. return -1;
  65. /* Do a dummy read for communication test */
  66. return At24cRead( &at24c32s, &dummy, 1, 0);
  67. }
  68. /****************************************************************************/
  69. int EEWriteData( uint16_t addr, const void *data, uint16_t len )
  70. /****************************************************************************/
  71. {
  72. return At24cWrite( &at24c32s, (uint8_t *)data, len, addr );
  73. }
  74. /****************************************************************************/
  75. int EEReadData( uint16_t addr, void *data, uint16_t len )
  76. /****************************************************************************/
  77. {
  78. return At24cRead( &at24c32s, (uint8_t *)data, len, addr );
  79. }
  80. #endif /* _DEV_EEPROM_H_ */