gd_spieeprom.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*!
  2. *****************************************************************************
  3. ** \file gd_lib/GK7101/inc/gd_spieeprom.h
  4. **
  5. ** \version $Id$
  6. **
  7. ** \brief
  8. **
  9. ** \attention THIS SAMPLE CODE IS PROVIDED AS IS. GOKE MICROELECTRONICS
  10. ** ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR
  11. ** OMMISSIONS
  12. **
  13. ** (C) Copyright 2012-2013 by GOKE MICROELECTRONICS CO.,LTD
  14. **
  15. *****************************************************************************
  16. */
  17. #ifndef _GD_SPIEEPROM_H_
  18. #define _GD_SPIEEPROM_H_
  19. #include <gtypes.h>
  20. #include <gmodids.h>
  21. #include "gd_gpio.h"
  22. #include "gd_spi.h"
  23. //*****************************************************************************
  24. //*****************************************************************************
  25. //** Defines and Macros
  26. //*****************************************************************************
  27. //*****************************************************************************
  28. //*****************************************************************************
  29. //*****************************************************************************
  30. //** Enumerated types
  31. //*****************************************************************************
  32. //*****************************************************************************
  33. typedef enum
  34. {
  35. GD_SPI_EEPROM_AT25320B = 0,
  36. GD_SPI_EEPROM_AT25640B,
  37. GD_SPI_EEPROM_NUM
  38. }GD_SPI_EEPROM_E;
  39. /*!
  40. *******************************************************************************
  41. **
  42. ** \anchor
  43. ** \brief he base error code for the serial spi eeprom device driver.
  44. **
  45. *******************************************************************************
  46. */
  47. #define GD_SPI_EEPROM_ERR_BASE (GD_SPI_EEPROM_MODULE_ID<<16)
  48. /*!
  49. *******************************************************************************
  50. **
  51. ** \brief Flash driver error codes.
  52. **
  53. *******************************************************************************
  54. */
  55. enum
  56. {
  57. GD_ERR_SPI_EEPROM_TYPE_NOT_SUPPORTED = GD_SPI_EEPROM_ERR_BASE, //!< Device not supported.
  58. GD_ERR_SPI_EEPROM_IN_USE, //!< Read error.
  59. GD_ERR_SPI_EEPROM_READ, //!< Read error.
  60. GD_ERR_SPI_EEPROM_WRITE, //!< Write error.
  61. };
  62. //*****************************************************************************
  63. //*****************************************************************************
  64. //** Data Structures
  65. //*****************************************************************************
  66. //*****************************************************************************
  67. /*
  68. *******************************************************************************
  69. **
  70. ** serial spi eeprom specific commands and statis register bit definitions
  71. **
  72. *******************************************************************************
  73. */
  74. typedef struct
  75. {
  76. U8 writeEnable; // command to WREN Set Write Enable Latch
  77. U8 writeDisable; // command to WRDI Reset Write Enable Latch
  78. U8 readStatus; // command to RDSR Read Status Register
  79. U8 writeStatus; // command to WRSR Write Status Register
  80. U8 readData; // command to READ Read Data from Memory Array
  81. U8 WriteData; // command to WRITE Write Data to Memory Array
  82. }GD_SPI_EEPROM_CMD_S;
  83. /*
  84. *******************************************************************************
  85. **
  86. ** serial spi eeprom specific geometry and information data structure
  87. **
  88. *******************************************************************************
  89. */
  90. typedef struct
  91. {
  92. char* manufactureName; // Pointer to manufacture name
  93. char* deviceName; // Pointer to device name
  94. U32 deviceBytes; // Size of spi eeprom device in bytes
  95. U32 sectorCount; // Number of sectors
  96. U32 sectorBytes; // Size of a single sector in bytes
  97. GD_SPI_EEPROM_CMD_S* commands; // Device specific access commands
  98. GBOOL wptoporbottom;
  99. GD_SPI_EEPROM_E device;
  100. GD_HANDLE spi;
  101. GD_HANDLE wp;
  102. GD_HANDLE hold;
  103. }GD_SPI_EEPROM_DEV_S;
  104. typedef struct
  105. {
  106. GD_SPI_EEPROM_E device;
  107. GD_SPI_CHANNEL_E channel;
  108. GD_SPI_SLAVE_E slave;
  109. GD_SPI_SPEED_MODE speed;
  110. GD_SPI_POLARITY_MODE polarity;
  111. GBOOL used_irq;
  112. GD_GPIO_PIN_E csgpiopin;
  113. GD_GPIO_TYPE_E csgpiotype;
  114. GD_GPIO_PIN_E wpgpiopin;
  115. GD_GPIO_TYPE_E wpgpiotype;
  116. GD_GPIO_PIN_E holdgpiopin;
  117. GD_GPIO_TYPE_E holdgpiotype;
  118. } GD_SPI_EEPROM_OPEN_PARAMS_S;
  119. //*****************************************************************************
  120. //*****************************************************************************
  121. //** Global Data
  122. //*****************************************************************************
  123. //*****************************************************************************
  124. //*****************************************************************************
  125. //*****************************************************************************
  126. //** API Functions
  127. //*****************************************************************************
  128. //*****************************************************************************
  129. #ifdef __cplusplus
  130. extern "C" {
  131. #endif
  132. GERR GD_SPI_EEPROM_Init(void);
  133. GERR GD_SPI_EEPROM_Exit(void);
  134. GERR GD_SPI_EEPROM_Open(GD_SPI_EEPROM_OPEN_PARAMS_S *openParamsP, GD_HANDLE* pHandle);
  135. GERR GD_SPI_EEPROM_Close(GD_HANDLE* pHandle);
  136. GERR GD_SPI_EEPROM_Read(GD_HANDLE handle, U32 address, U8* buffer, U32 bytes);
  137. GERR GD_SPI_EEPROM_Write(GD_HANDLE handle, U32 address, U8* buffer, U32 bytes);
  138. GERR GD_SPI_EEPROM_GetNames(GD_HANDLE handle, char** manufactureName, char** deviceName);
  139. GERR GD_SPI_EEPROM_GetNumberOfSectors(GD_HANDLE handle, U16* numberOfSectors);
  140. GERR GD_SPI_EEPROM_GetSectorAddress(GD_HANDLE handle, U16 sector, U32* address);
  141. GERR GD_SPI_EEPROM_GetSize(GD_HANDLE handle, U32* deviceBytes);
  142. GERR GD_SPI_EEPROM_GetSectorSize(GD_HANDLE handle, U16 sector, U32* deviceBytes);
  143. GERR GD_SPI_EEPROM_GetSector(GD_HANDLE handle, U32 address, U16* sector);
  144. GERR GD_SPI_EEPROM_Unlock(GD_HANDLE handle);
  145. GERR GD_SPI_EEPROM_Lock(GD_HANDLE handle);
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. #endif /* _GD_SPIEEPROM_H_ */