spi_at45d2.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (C) 2008-2009 by egnite GmbH
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*!
  35. * \file dev/spi_at45d2.c
  36. * \brief Third AT45D DataFlash device.
  37. *
  38. * \verbatim
  39. * $Id: spi_at45d2.c 5472 2013-12-06 00:16:28Z olereinhardt $
  40. * \endverbatim
  41. */
  42. #include <cfg/memory.h>
  43. #include <dev/blockdev.h>
  44. #include <dev/spi_at45d.h>
  45. #ifndef SPI_RATE_AT45D2
  46. #define SPI_RATE_AT45D2 1000000
  47. #endif
  48. #ifndef SPI_MODE_AT45D2
  49. #ifndef SPI_CSHIGH_AT45D2
  50. #define SPI_MODE_AT45D2 (SPI_MODE_3 | SPI_MODE_CSHIGH)
  51. #else
  52. #define SPI_MODE_AT45D2 SPI_MODE_3
  53. #endif
  54. #endif
  55. #ifndef MOUNT_OFFSET_AT45D2
  56. #define MOUNT_OFFSET_AT45D2 0
  57. #endif
  58. #ifndef MOUNT_TOP_RESERVE_AT45D2
  59. #define MOUNT_TOP_RESERVE_AT45D2 0
  60. #endif
  61. /*!
  62. * \brief AT45D DataFlash SPI node implementation structure.
  63. */
  64. NUTSPINODE nodeSpiAt45d2 = {
  65. NULL, /*!< \brief Pointer to the bus controller driver, node_bus. */
  66. NULL, /*!< \brief Pointer to device driver specific settings, node_stat. */
  67. SPI_RATE_AT45D2, /*!< \brief Initial clock rate, node_rate. */
  68. SPI_MODE_AT45D2, /*!< \brief Initial mode, node_mode. */
  69. 8, /*!< \brief Initial data bits, node_bits. */
  70. 0 /*!< \brief Chip select, node_cs. */
  71. };
  72. /*!
  73. * \brief AT45D DataFlash block I/O implementation structure.
  74. */
  75. static NUTBLOCKIO blkIoAt45d2 = {
  76. NULL, /*!< \brief Device specific parameters, blkio_info. */
  77. 0, /*!< \brief Total number of pages, blkio_blk_cnt. */
  78. 0, /*!< \brief Number of bytes per page, blkio_blk_siz. */
  79. MOUNT_OFFSET_AT45D2, /*!< \brief Number of sectors reserved at bottom, blkio_vol_bot. */
  80. MOUNT_TOP_RESERVE_AT45D2, /*!< \brief Number of sectors reserved at top, blkio_vol_top. */
  81. SpiAt45dPageRead, /*!< \brief Read from node, blkio_read. */
  82. SpiAt45dPageWrite, /*!< \brief Write to node, blkio_write. */
  83. #ifdef __HARVARD_ARCH__
  84. SpiAt45dPageWrite_P, /*!< \brief Write program memory to node, blkio_write_P. */
  85. #endif
  86. SpiAt45dIOCtl /*!< \brief Control functions, blkio_ioctl. */
  87. };
  88. /*!
  89. * \brief AT45D DataFlash device implementation structure.
  90. */
  91. NUTDEVICE devSpiAt45d2 = {
  92. NULL, /* Pointer to next device, dev_next. */
  93. {'A', 'T', '4', '5', 'D', '2', 0, 0, 0}, /* Unique device name, dev_name. */
  94. IFTYP_BLKIO, /* Type of device, dev_type. */
  95. 0, /* Base address, dev_base (not used). */
  96. 0, /* First interrupt number, dev_irq (not used). */
  97. &nodeSpiAt45d2, /* Interface control block, dev_icb. */
  98. &blkIoAt45d2, /* Driver control block, dev_dcb. */
  99. SpiAt45dInit, /* Driver initialization routine, dev_init. */
  100. NutBlockDeviceIOCtl, /* Driver specific control function, dev_ioctl. */
  101. NutBlockDeviceRead, /* Read from device, dev_read. */
  102. NutBlockDeviceWrite, /* Write to device, dev_write. */
  103. #ifdef __HARVARD_ARCH__
  104. NutBlockDeviceWrite_P, /* Write data from program space to device, dev_write_P. */
  105. #endif
  106. NutBlockDeviceOpen, /* Open a device or file, dev_open. */
  107. NutBlockDeviceClose, /* Close a device or file, dev_close. */
  108. NutBlockDeviceSize, /* Request file size, dev_size. */
  109. NULL, /* Select function, optional, not yet implemented */
  110. };