lpc177x_8x_eeprom.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #ifndef _LPC177X_8X_EEPROM_H_
  2. #define _LPC177X_8X_EEPROM_H_
  3. /*
  4. * Copyright (C) 2012 by Ole Reinhardt (ole.reinhardt@embedded-it.de)
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the copyright holders nor the names of
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  31. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * For additional information see http://www.ethernut.de/
  35. *
  36. *
  37. * Parts taken from lpc177x_8x_eeprom.h 2011-06-02
  38. * file lpc177x_8x_eeprom.h
  39. * brief Contains all macro definitions and function prototypes
  40. * support for EEPROM firmware library on LPC177x_8x
  41. * version 1.0
  42. * date 02. June. 2011
  43. * author NXP MCU SW Application Team
  44. *
  45. * Copyright(C) 2011, NXP Semiconductor
  46. * All rights reserved.
  47. *
  48. ***********************************************************************
  49. * Software that is described herein is for illustrative purposes only
  50. * which provides customers with programming information regarding the
  51. * products. This software is supplied "AS IS" without any warranties.
  52. * NXP Semiconductors assumes no responsibility or liability for the
  53. * use of the software, conveys no license or title under any patent,
  54. * copyright, or mask work right to the product. NXP Semiconductors
  55. * reserves the right to make changes in the software without
  56. * notification. NXP Semiconductors also make no representation or
  57. * warranty that such application will be suitable for the specified
  58. * use without further testing or modification.
  59. **********************************************************************/
  60. #include <inttypes.h>
  61. /* We can not use the last page, as writing to it will result in a bus fault!!! */
  62. #define EEPROM_SIZE (4096 - 64)
  63. /*----------------------------------------------------------------------------*
  64. Macro defines for EEPROM command register
  65. *----------------------------------------------------------------------------*/
  66. #define EEPROM_CMD_8_BIT_READ 0
  67. #define EEPROM_CMD_16_BIT_READ 1
  68. #define EEPROM_CMD_32_BIT_READ 2
  69. #define EEPROM_CMD_8_BIT_WRITE 3
  70. #define EEPROM_CMD_16_BIT_WRITE 4
  71. #define EEPROM_CMD_32_BIT_WRITE 5
  72. #define EEPROM_CMD_ERASE_PRG_PAGE 6
  73. #define EEPROM_CMD_RDPREFETCH _BV(3)
  74. #define EEPROM_PAGE_SIZE 64
  75. #define EEPROM_PAGE_NUM 64
  76. /*----------------------------------------------------------------------------*
  77. Macro defines for EEPROM address register
  78. *----------------------------------------------------------------------------*/
  79. #define EEPROM_PAGE_OFFSET_MASK 0x3F
  80. #define EEPROM_PAGE_NUM_MASK (0x3F << 6)
  81. #define EEPROM_PAGE_OFFSET(n) ((n) & 0x3F)
  82. #define EEPROM_PAGE_ADRESS(n) (((n) & 0x3F) << 6)
  83. /*----------------------------------------------------------------------------*
  84. Macro defines for EEPROM write data register
  85. *----------------------------------------------------------------------------*/
  86. #define EEPROM_WDATA_8_BIT(n) ((n) & 0x000000FF)
  87. #define EEPROM_WDATA_16_BIT(n) ((n) & 0x0000FFFF)
  88. #define EEPROM_WDATA_32_BIT(n) ((n) & 0xFFFFFFFF)
  89. /*----------------------------------------------------------------------------*
  90. Macro defines for EEPROM read data register
  91. *----------------------------------------------------------------------------*/
  92. #define EEPROM_RDATA_8_BIT(n) ((n) & 0x000000FF)
  93. #define EEPROM_RDATA_16_BIT(n) ((n) & 0x0000FFFF)
  94. #define EEPROM_RDATA_32_BIT(n) ((n) & 0xFFFFFFFF)
  95. /*----------------------------------------------------------------------------*
  96. Macro defines for EEPROM power down register
  97. *----------------------------------------------------------------------------*/
  98. #define EEPROM_PWRDWN _BV(0)
  99. #define EEPROM_ENDOF_RW 26
  100. #define EEPROM_ENDOF_PROG 28
  101. /*----------------------------------------------------------------------------*
  102. Public functions
  103. *----------------------------------------------------------------------------*/
  104. void Lpc177x_8x_EepromInit(void);
  105. int Lpc177x_8x_EepromRead(uint16_t addr, void* buff, size_t size);
  106. int Lpc177x_8x_EepromWrite(uint16_t addr, const void* buff, size_t size);
  107. #endif /* _LPC177X_8X_EEPROM_H_ */