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

4.11
Last change on this file since 03d2108 was 03d2108, checked in by Sebastian Huber <sebastian.huber@…>, on Jul 1, 2011 at 1:05:06 PM

2011-07-01 Stephan Hoffmann <sho@…>

Sebastian Huber <sebastian.huber@…>

  • misc/nand-mlc-erase-block-safe.c: New file
  • Makefile.am: Reflect change from above.
  • misc/nand-mlc-write-blocks.c: Use lpc32xx_mlc_erase_block_safe_3().
  • include/nand-mlc.h: Bad block handling.
  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup lpc32xx_nand_mlc
5 *
6 * @brief lpc32xx_mlc_erase_block_safe() and lpc32xx_mlc_erase_block_safe_3()
7 * 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
30static void zero_block(uint32_t first_page_of_block, uint32_t pages_per_block)
31{
32  uint32_t page = 0;
33
34  for (page = 0; page < pages_per_block; ++page) {
35    lpc32xx_mlc_write_page_with_ecc(
36      first_page_of_block + page,
37      lpc32xx_magic_zero_begin,
38      lpc32xx_magic_zero_begin
39    );
40  }
41}
42
43static bool is_bad_page(
44  uint32_t first_page_of_block,
45  uint32_t page
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    first_page_of_block + page,
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 first_page_of_block,
62  uint32_t pages_per_block
63)
64{
65  rtems_status_code sc = RTEMS_SUCCESSFUL;
66
67  if (is_bad_page(first_page_of_block, 0)) {
68    return RTEMS_INCORRECT_STATE;
69  }
70
71  if (is_bad_page(first_page_of_block, 1)) {
72    return RTEMS_INCORRECT_STATE;
73  }
74
75  sc = lpc32xx_mlc_erase_block(block_index);
76  if (sc != RTEMS_SUCCESSFUL) {
77    zero_block(first_page_of_block, pages_per_block);
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
89  return lpc32xx_mlc_erase_block_safe_3(
90    block_index,
91    block_index * pages_per_block,
92    pages_per_block
93  );
94}
Note: See TracBrowser for help on using the repository browser.