-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
82 lines (77 loc) · 1.38 KB
/
main.c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* 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.
*/
#include "nand.h"
#include "nand-utils.h"
#include <stdio.h>
#include <stdlib.h>
int erase_write_test(int block, int page)
{
int ret = 0;
int i = 0;
char data[NAND_PAGE_BYTE] = {
0,
};
// read
ret = nand_read(data, block, page);
if (ret) {
printf("read fail (err: %s)\n", nand_get_read_error_msg(ret));
return ret;
}
nand_page_print(data);
nand_status();
// erase
ret = nand_erase(block);
if (ret) {
printf("erase fail\n");
return ret;
}
ret = nand_read(data, block, page);
if (ret) {
printf("read fail (err: %s)\n", nand_get_read_error_msg(ret));
return ret;
}
nand_page_print(data);
nand_status();
// write
srand((unsigned int)time(NULL));
for (i = 0; i < NAND_PAGE_BYTE; i++) {
data[i] = (char)rand();
}
ret = nand_write(data, block, page);
if (ret) {
printf("write fail\n");
return ret;
}
ret = nand_read(data, block, page);
if (ret) {
printf("read fail\n");
return ret;
}
nand_page_print(data);
nand_status();
return 0;
}
int main(void)
{
int ret;
ret = nand_init();
if (ret) {
goto out;
}
ret = nand_info_print();
if (ret) {
goto out;
}
ret = erase_write_test(0, 0);
if (ret) {
goto out;
}
out:
nand_free();
return 0;
}