RTEMS 6.1-rc5
Loading...
Searching...
No Matches
nand-mlc.h
Go to the documentation of this file.
1
9/*
10 * Copyright (C) 2010, 2011 embedded brains GmbH & Co. KG
11 *
12 * Copyright (c) 2011 Stephan Hoffmann <sho@reLinux.de>
13 *
14 * The license and distribution terms for this file may be
15 * found in the file LICENSE in this distribution or at
16 * http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef LIBBSP_ARM_LPC32XX_NAND_MLC_H
20#define LIBBSP_ARM_LPC32XX_NAND_MLC_H
21
22#include <rtems.h>
23
24#include <bsp/utility.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif /* __cplusplus */
29
68#define MLC_SMALL_PAGE_SIZE 528
69#define MLC_SMALL_DATA_SIZE 512
70#define MLC_SMALL_SPARE_SIZE 16
71#define MLC_SMALL_USER_SPARE_SIZE 6
72#define MLC_SMALL_ECC_SPARE_SIZE 10
73#define MLC_SMALL_DATA_WORD_COUNT (MLC_SMALL_DATA_SIZE / 4)
74#define MLC_SMALL_SPARE_WORD_COUNT (MLC_SMALL_SPARE_SIZE / 4)
75#define MLC_SMALL_PAGES_PER_LARGE_PAGE 4
76#define MLC_LARGE_PAGE_SIZE \
77 (MLC_SMALL_PAGES_PER_LARGE_PAGE * MLC_SMALL_PAGE_SIZE)
78#define MLC_LARGE_DATA_SIZE \
79 (MLC_SMALL_PAGES_PER_LARGE_PAGE * MLC_SMALL_DATA_SIZE)
80#define MLC_LARGE_SPARE_SIZE \
81 (MLC_SMALL_PAGES_PER_LARGE_PAGE * MLC_SMALL_SPARE_SIZE)
82#define MLC_LARGE_DATA_WORD_COUNT (MLC_LARGE_DATA_SIZE / 4)
83#define MLC_LARGE_SPARE_WORD_COUNT (MLC_LARGE_SPARE_SIZE / 4)
84
93#define FLASHCLK_IRQ_MLC BSP_BIT32(5)
94#define FLASHCLK_MLC_DMA_RNB BSP_BIT32(4)
95#define FLASHCLK_MLC_DMA_INT BSP_BIT32(3)
96#define FLASHCLK_SELECT_SLC BSP_BIT32(2)
97#define FLASHCLK_MLC_CLK_ENABLE BSP_BIT32(1)
98#define FLASHCLK_SLC_CLK_ENABLE BSP_BIT32(0)
99
108#define MLC_TIME_WR_LOW(val) BSP_FLD32(val, 0, 3)
109#define MLC_TIME_WR_HIGH(val) BSP_FLD32(val, 4, 7)
110#define MLC_TIME_RD_LOW(val) BSP_FLD32(val, 8, 11)
111#define MLC_TIME_RD_HIGH(val) BSP_FLD32(val, 12, 15)
112#define MLC_TIME_NAND_TA(val) BSP_FLD32(val, 16, 18)
113#define MLC_TIME_BUSY_DELAY(val) BSP_FLD32(val, 19, 23)
114#define MLC_TIME_TCEA_DELAY(val) BSP_FLD32(val, 24, 25)
115
124#define MLC_UNLOCK_PROT 0xa25e
125
134#define MLC_ISR_DECODER_FAILURE BSP_BIT32(6)
135#define MLC_ISR_SYMBOL_ERRORS(reg) BSP_FLD32GET(reg, 4, 5)
136#define MLC_ISR_ERRORS_DETECTED BSP_BIT32(3)
137#define MLC_ISR_ECC_READY BSP_BIT32(2)
138#define MLC_ISR_CONTROLLER_READY BSP_BIT32(1)
139#define MLC_ISR_NAND_READY BSP_BIT32(0)
140
149#define MLC_ICR_SOFT_WRITE_PROT BSP_BIT32(3)
150#define MLC_ICR_LARGE_PAGES BSP_BIT32(2)
151#define MLC_ICR_ADDR_WORD_COUNT_4_5 BSP_BIT32(1)
152#define MLC_ICR_IO_BUS_16 BSP_BIT32(0)
153
162#define MLC_ECC_AUTO_ENC_PROGRAM BSP_BIT32(8)
163
172#define NAND_STATUS_ERROR (1U << 0)
173#define NAND_STATUS_READY (1U << 6)
174#define NAND_STATUS_NOT_PROTECTED (1U << 7)
175
181typedef struct {
182 uint32_t flags;
183
184 uint32_t block_count;
185
189 uint32_t time;
191
196#define MLC_SMALL_PAGES 0x1U
197
202#define MLC_MANY_ADDRESS_CYCLES 0x2U
203
209#define MLC_NORMAL_BLOCKS 0x4U
210
214#define MLC_IO_WIDTH_16_BIT 0x8U
215
219void lpc32xx_mlc_init(const lpc32xx_mlc_config *cfg);
220
221uint32_t lpc32xx_mlc_page_size(void);
222
223uint32_t lpc32xx_mlc_pages_per_block(void);
224
225uint32_t lpc32xx_mlc_block_count(void);
226
227uint32_t lpc32xx_mlc_io_width(void);
228
229void lpc32xx_mlc_write_protection(
230 uint32_t page_index_low,
231 uint32_t page_index_high
232);
233
234void lpc32xx_mlc_read_id(uint8_t *id, size_t n);
235
250 uint32_t page_index,
251 void *data,
252 void *spare,
253 uint32_t *symbol_error_count
254);
255
273
281rtems_status_code lpc32xx_mlc_erase_block(uint32_t block_index);
282
297
307 uint32_t block_index,
308 uint32_t page_begin,
309 uint32_t page_end
310);
311
318void lpc32xx_mlc_zero_pages(uint32_t page_begin, uint32_t page_end);
319
331 uint32_t page_index,
332 const void *data,
333 const void *spare
334);
335
347 uint32_t block_begin,
348 uint32_t block_end,
349 const void *src,
350 size_t src_size,
351 uint32_t page_buffer [MLC_LARGE_DATA_WORD_COUNT]
352);
353
363 void *process_arg,
364 uint32_t page_index,
365 uint32_t page_size,
366 uint32_t page_data [MLC_LARGE_DATA_WORD_COUNT],
367 uint32_t page_spare [MLC_LARGE_SPARE_WORD_COUNT]
368);
369
381 uint32_t block_begin,
382 uint32_t block_end,
384 void *process_arg,
385 uint32_t page_buffer_0 [MLC_LARGE_DATA_WORD_COUNT],
386 uint32_t page_buffer_1 [MLC_LARGE_DATA_WORD_COUNT]
387);
388
401static inline bool lpc32xx_mlc_is_bad_page(const uint32_t *spare)
402{
403 uint32_t first_byte_mask = 0x000000ff;
404 uint32_t sixth_byte_mask = 0x0000ff00;
405
406 return (spare [0] & first_byte_mask) != first_byte_mask
407 || (spare [1] & sixth_byte_mask) != sixth_byte_mask;
408}
409
412#ifdef __cplusplus
413}
414#endif /* __cplusplus */
415
416#endif /* LIBBSP_ARM_LPC32XX_NAND_MLC_H */
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
void lpc32xx_mlc_init(const lpc32xx_mlc_config *cfg)
Initializes the MLC NAND controller according to cfg.
Definition: nand-mlc.c:178
rtems_status_code lpc32xx_mlc_write_page_with_ecc(uint32_t page_index, const void *data, const void *spare)
Writes the page with index page_index.
Definition: nand-mlc.c:352
rtems_status_code lpc32xx_mlc_erase_block(uint32_t block_index)
Erases the block with index block_index.
Definition: nand-mlc.c:332
rtems_status_code lpc32xx_mlc_write_blocks(uint32_t block_begin, uint32_t block_end, const void *src, size_t src_size, uint32_t page_buffer[MLC_LARGE_DATA_WORD_COUNT])
Writes src_size Bytes from src to the flash area specified by block_begin and block_end.
rtems_status_code lpc32xx_mlc_erase_block_safe(uint32_t block_index)
Erases the block with index block_index.
Definition: nand-mlc-erase-block-safe.c:124
rtems_status_code lpc32xx_mlc_erase_block_safe_3(uint32_t block_index, uint32_t page_begin, uint32_t page_end)
Erases the block with index block_index.
Definition: nand-mlc-erase-block-safe.c:105
rtems_status_code lpc32xx_mlc_is_valid_block(uint32_t block_index)
Checks if the block with index block_index is valid.
Definition: nand-mlc-erase-block-safe.c:97
rtems_status_code lpc32xx_mlc_read_page(uint32_t page_index, void *data, void *spare, uint32_t *symbol_error_count)
Reads the page with index page_index.
Definition: nand-mlc.c:224
void lpc32xx_mlc_zero_pages(uint32_t page_begin, uint32_t page_end)
Writes zero values to the pages specified by page_begin and page_end.
Definition: nand-mlc-erase-block-safe.c:43
bool(* lpc32xx_mlc_read_process)(void *process_arg, uint32_t page_index, uint32_t page_size, uint32_t page_data[MLC_LARGE_DATA_WORD_COUNT], uint32_t page_spare[MLC_LARGE_SPARE_WORD_COUNT])
Read blocks process function type.
Definition: nand-mlc.h:362
rtems_status_code lpc32xx_mlc_read_blocks(uint32_t block_begin, uint32_t block_end, lpc32xx_mlc_read_process process, void *process_arg, uint32_t page_buffer_0[MLC_LARGE_DATA_WORD_COUNT], uint32_t page_buffer_1[MLC_LARGE_DATA_WORD_COUNT])
Reads the pages of block block_begin up to and excluding block_end.
Definition: nand-mlc-read-blocks.c:65
This header file provides utility macros for BSPs.
This header file defines the RTEMS Classic API.
MLC NAND controller configuration.
Definition: nand-mlc.h:181
uint32_t time
Value for the MLC NAND Timing Register (MLC_TIME_REG).
Definition: nand-mlc.h:189