source: rtems/c/src/lib/libbsp/arm/lpc32xx/misc/nand-mlc-erase-block-safe.c @ c499856

4.11
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup lpc32xx_nand_mlc
5 *
6 * @brief lpc32xx_mlc_erase_block_safe(), lpc32xx_mlc_erase_block_safe_3(), and
7 * lpc32xx_mlc_zero_block() implementation.
8 */
9
10/*
11 * Copyright (c) 2011 embedded brains GmbH.  All rights reserved.
12 *
13 *  embedded brains GmbH
14 *  Obere Lagerstr. 30
15 *  82178 Puchheim
16 *  Germany
17 *  <rtems@embedded-brains.de>
18 *
19 * The license and distribution terms for this file may be
20 * found in the file LICENSE in this distribution or at
21 * http://www.rtems.org/license/LICENSE.
22 */
23
24#include <bsp/nand-mlc.h>
25
26#include <string.h>
27
28#include <bsp.h>
29
30void lpc32xx_mlc_zero_pages(uint32_t page_begin, uint32_t page_end)
31{
32  uint32_t page = 0;
33
34  for (page = page_begin; page < page_end; ++page) {
35    lpc32xx_mlc_write_page_with_ecc(
36      page,
37      lpc32xx_magic_zero_begin,
38      lpc32xx_magic_zero_begin
39    );
40  }
41}
42
43static rtems_status_code is_valid_page(
44  uint32_t page_begin,
45  uint32_t page_offset
46)
47{
48  rtems_status_code sc = RTEMS_SUCCESSFUL;
49  uint32_t spare [MLC_LARGE_SPARE_WORD_COUNT];
50
51  memset(spare, 0, MLC_LARGE_SPARE_SIZE);
52
53  sc = lpc32xx_mlc_read_page(
54    page_begin + page_offset,
55    lpc32xx_magic_zero_begin,
56    spare,
57    NULL
58  );
59  if (sc == RTEMS_SUCCESSFUL) {
60    if (lpc32xx_mlc_is_bad_page(spare)) {
61      sc = RTEMS_INCORRECT_STATE;
62    }
63  }
64
65  return sc;
66}
67
68static rtems_status_code is_valid_block(uint32_t page_begin)
69{
70  rtems_status_code sc = RTEMS_SUCCESSFUL;
71
72  if (lpc32xx_mlc_page_size() == 512 && lpc32xx_mlc_io_width() == 8) {
73    sc = is_valid_page(page_begin, 0);
74    if (sc == RTEMS_SUCCESSFUL) {
75      sc = is_valid_page(page_begin, 1);
76    }
77  } else {
78    sc = RTEMS_NOT_IMPLEMENTED;
79  }
80
81  return sc;
82}
83
84rtems_status_code lpc32xx_mlc_is_valid_block(uint32_t block_index)
85{
86  uint32_t pages_per_block = lpc32xx_mlc_pages_per_block();
87  uint32_t page_begin = block_index * pages_per_block;
88
89  return is_valid_block(page_begin);
90}
91
92rtems_status_code lpc32xx_mlc_erase_block_safe_3(
93  uint32_t block_index,
94  uint32_t page_begin,
95  uint32_t page_end
96)
97{
98  rtems_status_code sc = RTEMS_SUCCESSFUL;
99
100  sc = is_valid_block(page_begin);
101  if (sc == RTEMS_SUCCESSFUL) {
102    sc = lpc32xx_mlc_erase_block(block_index);
103    if (sc == RTEMS_UNSATISFIED) {
104      lpc32xx_mlc_zero_pages(page_begin, page_end);
105    }
106  }
107
108  return sc;
109}
110
111rtems_status_code lpc32xx_mlc_erase_block_safe(uint32_t block_index)
112{
113  uint32_t pages_per_block = lpc32xx_mlc_pages_per_block();
114  uint32_t page_begin = block_index * pages_per_block;
115  uint32_t page_end = page_begin + pages_per_block;
116
117  return lpc32xx_mlc_erase_block_safe_3(
118    block_index,
119    page_begin,
120    page_end
121  );
122}
Note: See TracBrowser for help on using the repository browser.