-
Notifications
You must be signed in to change notification settings - Fork 0
/
nand.h
64 lines (52 loc) · 1.34 KB
/
nand.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright (C) 2023 Gijun Oh
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
#ifndef NAND_H
#define NAND_H
#ifdef __cplusplus
extern "C" {
#endif
#include <wiringPi.h>
#include <time.h>
#define NAND_CLE (21)
#define NAME_ALE (22)
#define NAND_R_B (23)
#define NAND_WE (24)
#define NAND_RE (25)
#define NAND_CE (26)
#define NAND_WP (27)
#define NAND_DEFAULT_DELAY_NS (35)
#define NAND_PAGE_BYTE (2048)
#define NAND_PAGE_OOB_BYTE (64)
#define NAND_PAGES_PER_BLOCK (64)
#define NAND_HAMMING_DATA_BYTE (256)
#define NAND_HAMMING_PARITY_BYTE (3)
#define NAND_OOB_ERROR_SINGLEBIT (1)
#define NAND_OOB_ERROR_ECC (2)
#define NAND_OOB_ERROR_MULTIPLEBITS (3)
#define NAND_OOB_INVALID_BLOCK (4)
// #define NAND_ENABLE_RESET
int nand_init(void);
int nand_read(char *data, int block, int page);
int nand_write(char *data, int block, int page);
int nand_erase(int block);
void nand_free(void);
static const char *nand_read_errmsg[] = {
"No Error",
"A single bit is corrupted (automatically fixed by ecc)",
"The ECC is corrupted",
"Multiple bits are corrupted",
"Invalid block is detected",
};
static inline const char *nand_get_read_error_msg(int status_code)
{
return nand_read_errmsg[-status_code];
}
#ifdef __cplusplus
}
#endif
#endif