source: rtems/bsps/arm/lpc32xx/nand/nand-mlc-read-blocks.c @ 43250167

Last change on this file since 43250167 was 43250167, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 25, 2018 at 8:36:52 AM

bsp/lpc32xx: Move source files to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup lpc32xx_nand_mlc
5 *
6 * @brief lpc32xx_mlc_read_blocks() implementation.
7 */
8
9/*
10 * Copyright (c) 2010
11 * embedded brains GmbH
12 * Obere Lagerstr. 30
13 * D-82178 Puchheim
14 * Germany
15 * <rtems@embedded-brains.de>
16 *
17 * The license and distribution terms for this file may be
18 * found in the file LICENSE in this distribution or at
19 * http://www.rtems.org/license/LICENSE.
20 */
21
22#include <bsp/nand-mlc.h>
23
24#include <string.h>
25
26static rtems_status_code read_page(
27  uint32_t first_page_of_block,
28  uint32_t page,
29  uint32_t page_data [MLC_LARGE_DATA_WORD_COUNT],
30  uint32_t page_spare [MLC_LARGE_SPARE_WORD_COUNT]
31)
32{
33  rtems_status_code sc = RTEMS_SUCCESSFUL;
34  uint32_t page_index = first_page_of_block + page;
35  bool possible_bad_page = page == 0 || page == 1;
36
37  if (possible_bad_page) {
38    memset(page_spare, 0, MLC_LARGE_SPARE_SIZE);
39  }
40
41  sc = lpc32xx_mlc_read_page(page_index, page_data, page_spare, NULL);
42  if (possible_bad_page && lpc32xx_mlc_is_bad_page(page_spare)) {
43    return RTEMS_UNSATISFIED;
44  } else if (sc == RTEMS_SUCCESSFUL) {
45    return RTEMS_SUCCESSFUL;
46  } else {
47    return sc;
48  }
49}
50
51rtems_status_code lpc32xx_mlc_read_blocks(
52  uint32_t block_begin,
53  uint32_t block_end,
54  lpc32xx_mlc_read_process process,
55  void *process_arg,
56  uint32_t page_buffer_0 [MLC_LARGE_DATA_WORD_COUNT],
57  uint32_t page_buffer_1 [MLC_LARGE_DATA_WORD_COUNT]
58)
59{
60  rtems_status_code sc = RTEMS_SUCCESSFUL;
61  uint32_t page_spare_0 [MLC_LARGE_SPARE_WORD_COUNT];
62  uint32_t page_spare_1 [MLC_LARGE_SPARE_WORD_COUNT];
63  uint32_t pages_per_block = lpc32xx_mlc_pages_per_block();
64  uint32_t page_size = lpc32xx_mlc_page_size();
65  uint32_t block = 0;
66  uint32_t first_page_of_block = block_begin * pages_per_block;
67
68  for (
69    block = block_begin;
70    block != block_end;
71    ++block, first_page_of_block += pages_per_block
72  ) {
73    uint32_t page = 0;
74    bool done = false;
75
76    sc = read_page(first_page_of_block, 0, page_buffer_0, page_spare_0);
77    if (sc == RTEMS_UNSATISFIED) {
78      continue;
79    } else if (sc != RTEMS_SUCCESSFUL) {
80      goto done;
81    }
82
83    sc = read_page(first_page_of_block, 1, page_buffer_1, page_spare_1);
84    if (sc == RTEMS_UNSATISFIED) {
85      continue;
86    } else if (sc != RTEMS_SUCCESSFUL) {
87      goto done;
88    }
89
90    done = (*process)(
91      process_arg,
92      first_page_of_block + 0,
93      page_size,
94      page_buffer_0,
95      page_spare_0
96    );
97    if (done) {
98      goto done;
99    }
100
101    done = (*process)(
102      process_arg,
103      first_page_of_block + 1,
104      page_size,
105      page_buffer_1,
106      page_spare_1
107    );
108    if (done) {
109      goto done;
110    }
111
112    for (page = 2; page < pages_per_block; ++page) {
113      sc = read_page(first_page_of_block, page, page_buffer_1, page_spare_1);
114      if (sc != RTEMS_SUCCESSFUL) {
115        goto done;
116      }
117
118      done = (*process)(
119        process_arg,
120        first_page_of_block + page,
121        page_size,
122        page_buffer_1,
123        page_spare_1
124      );
125      if (done) {
126        goto done;
127      }
128    }
129  }
130
131done:
132
133  return sc;
134}
Note: See TracBrowser for help on using the repository browser.