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

4.11
Last change on this file since 542d350e was 542d350e, checked in by Sebastian Huber <sebastian.huber@…>, on Jul 4, 2011 at 9:26:19 AM

2011-07-04 Sebastian Huber <sebastian.huber@…>

  • misc/nand-mlc-erase-block-safe.c, misc/nand-mlc-write-blocks.c, include/nand-mlc.h: Fixed write blocks.
  • Property mode set to 100644
File size: 2.0 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.com/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 bool is_bad_page(
44  uint32_t page_begin,
45  uint32_t page_offset
46)
47{
48  uint32_t spare [MLC_LARGE_SPARE_WORD_COUNT];
49
50  memset(spare, 0, MLC_LARGE_SPARE_SIZE);
51  lpc32xx_mlc_read_page(
52    page_begin + page_offset,
53    lpc32xx_magic_zero_begin,
54    spare
55  );
56  return lpc32xx_mlc_is_bad_page(spare);
57}
58
59rtems_status_code lpc32xx_mlc_erase_block_safe_3(
60  uint32_t block_index,
61  uint32_t page_begin,
62  uint32_t page_end
63)
64{
65  rtems_status_code sc = RTEMS_SUCCESSFUL;
66
67  if (is_bad_page(page_begin, 0)) {
68    return RTEMS_INCORRECT_STATE;
69  }
70
71  if (is_bad_page(page_begin, 1)) {
72    return RTEMS_INCORRECT_STATE;
73  }
74
75  sc = lpc32xx_mlc_erase_block(block_index);
76  if (sc != RTEMS_SUCCESSFUL) {
77    lpc32xx_mlc_zero_pages(page_begin, page_end);
78
79    return RTEMS_IO_ERROR;
80  }
81
82  return RTEMS_SUCCESSFUL;
83}
84
85rtems_status_code lpc32xx_mlc_erase_block_safe(uint32_t block_index)
86{
87  uint32_t pages_per_block = lpc32xx_mlc_pages_per_block();
88  uint32_t page_begin = block_index * pages_per_block;
89  uint32_t page_end = page_begin + pages_per_block;
90
91  return lpc32xx_mlc_erase_block_safe_3(
92    block_index,
93    page_begin,
94    page_end
95  );
96}
Note: See TracBrowser for help on using the repository browser.