nand_ecc.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /****************************************************************************
  2. * include/nuttx/mtd/nand_ecc.h
  3. *
  4. * Copyright (C) 2013 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * This logic was based largely on Atmel sample code with modifications for
  8. * better integration with NuttX. The Atmel sample code has a BSD
  9. * compatible license that requires this copyright notice:
  10. *
  11. * Copyright (c) 2012, Atmel Corporation
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions
  15. * are met:
  16. *
  17. * 1. Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in
  21. * the documentation and/or other materials provided with the
  22. * distribution.
  23. * 3. Neither the names NuttX nor Atmel nor the names of its contributors
  24. * may be used to endorse or promote products derived from this software
  25. * without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  30. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  31. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  33. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  34. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  35. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. ****************************************************************************/
  41. #ifndef __INCLUDE_NUTTX_MTD_ECC_H
  42. #define __INCLUDE_NUTTX_MTD_ECC_H
  43. /****************************************************************************
  44. * Included Files
  45. ****************************************************************************/
  46. #include <nuttx/config.h>
  47. #include <nuttx/mtd/nand_config.h>
  48. #include <stdint.h>
  49. /****************************************************************************
  50. * Pre-processor Definitions
  51. ****************************************************************************/
  52. /****************************************************************************
  53. * Public Types
  54. ****************************************************************************/
  55. /****************************************************************************
  56. * Public Data
  57. ****************************************************************************/
  58. #ifndef __ASSEMBLY__
  59. #ifdef __cplusplus
  60. #define EXTERN extern "C"
  61. extern "C"
  62. {
  63. #else
  64. #define EXTERN extern
  65. #endif
  66. /****************************************************************************
  67. * Public Function Prototypes
  68. ****************************************************************************/
  69. /****************************************************************************
  70. * Name: nandecc_readpage
  71. *
  72. * Description:
  73. * Reads the data and/or spare areas of a page of a NAND FLASH chip and
  74. * verifies that the data is valid using the ECC information contained in
  75. * the spare area. If a buffer pointer is NULL, then the corresponding area
  76. * is not saved.
  77. *
  78. * Input Parameters:
  79. * nand - Upper-half, NAND FLASH interface
  80. * block - Number of the block where the page to read resides.
  81. * page - Number of the page to read inside the given block.
  82. * data - Buffer where the data area will be stored.
  83. * spare - Buffer where the spare area will be stored.
  84. *
  85. * Returned Value:
  86. * OK is returned in success; a negated errno value is returned on failure.
  87. *
  88. ****************************************************************************/
  89. int nandecc_readpage(FAR struct nand_dev_s *nand, off_t block,
  90. unsigned int page, FAR void *data, FAR void *spare);
  91. /****************************************************************************
  92. * Name: nandecc_writepage
  93. *
  94. * Description:
  95. * Writes the data and/or spare area of a NAND FLASH page after
  96. * calculating an ECC for the data area and storing it in the spare. If no
  97. * data buffer is provided, the ECC is read from the existing page spare.
  98. * If no spare buffer is provided, the spare area is still written with the
  99. * ECC information calculated on the data buffer.
  100. *
  101. * Input Parameters:
  102. * nand - Upper-half, NAND FLASH interface
  103. * block - Number of the block where the page to write resides.
  104. * page - Number of the page to write inside the given block.
  105. * data - Buffer containing the data to be writing
  106. * spare - Buffer containing the spare data to be written.
  107. *
  108. * Returned Value:
  109. * OK is returned in success; a negated errno value is returned on failure.
  110. *
  111. ****************************************************************************/
  112. int nandecc_writepage(FAR struct nand_dev_s *nand, off_t block,
  113. unsigned int page, FAR const void *data,
  114. FAR void *spare);
  115. #undef EXTERN
  116. #ifdef __cplusplus
  117. }
  118. #endif
  119. #endif /* __ASSEMBLY__ */
  120. #endif /* __INCLUDE_NUTTX_MTD_ECC_H */