comparison flash.c @ 83:05ba84c7da97

Add a flash layer for compatibility (in future). Fix SPI flash block writing. White space fixes.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 02 Mar 2015 14:32:08 +1030
parents
children
comparison
equal deleted inserted replaced
82:c0ff52b8e80c 83:05ba84c7da97
1 #include <stdint.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include "spiflash.h"
6
7 void
8 flashcmd(int argc, char **argv) {
9 uint8_t status, tmp, len;
10 uint32_t addr;
11
12 if (argc == 0) {
13 fputs("No command specified\n", stdout);
14 return;
15 }
16
17 if (!strcmp(argv[0], "str")) {
18 status = spiflashreadstatus();
19 fputs("Status = ", stdout);
20 spiflashprintstatus(status, stdout);
21 printf("(0x%02x)\n", status);
22 } else if (!strcmp(argv[0], "stw")) {
23 if (argc != 2) {
24 fputs("Incorrect number of arguments\n", stdout);
25 return;
26 }
27 tmp = atoi(argv[1]);
28 spiflashwritestatus(tmp);
29 status = spiflashreadstatus();
30 printf("Wrote 0x%02x to status, now 0x%02x\n", tmp, status);
31 } else if (!strcmp(argv[0], "er")) {
32 if (argc != 2) {
33 fputs("Incorrect number of arguments\n", stdout);
34 return;
35 }
36 addr = atoi(argv[1]);
37 spiflash4kerase(addr);
38 printf("Erased 0x%x\n", (unsigned int)addr);
39 } else if (!strcmp(argv[0], "rd")) {
40 if (argc < 2) {
41 fputs("Incorrect number of arguments\n", stdout);
42 return;
43 }
44
45 addr = atoi(argv[1]);
46
47 if (argc > 2)
48 len = atoi(argv[2]);
49 else
50 len = 16;
51
52 spiflashstartread(addr);
53
54 for (uint32_t i = 0; i < len; i++)
55 printf("Read 0x%02x from 0x%06x\n", spiflashreadbyte(), (unsigned int)(addr + i));
56 spiflashstopread();
57
58 fputs("\n", stdout);
59 } else if (!strcmp(argv[0], "wr")) {
60 if (argc < 2) {
61 fputs("Incorrect number of arguments\n", stdout);
62 return;
63 }
64
65 addr = atoi(argv[1]);
66
67 if (argc > 2)
68 len = atoi(argv[2]);
69 else
70 len = 16;
71
72 for (int i = 0; i < 16; i += 2) {
73 uint16_t data;
74 data = ((i + 1) << 8) | i;
75 printf("Writing 0x%04x to 0x%06x\n", data, (unsigned int)(addr + i));
76
77 if (i == 0)
78 spiflashstartwrite(addr, data);
79 else
80 spiflashwriteword(data);
81 }
82 spiflashstopwrite();
83 } else if (!strcmp(argv[0], "id")) {
84 printf("Flash ID = 0x%04hx (expect 0xbf41)\n", spiflashreadid());
85 } else {
86 fputs("Unknown sub command\n", stdout);
87 return;
88 }
89 }
90 int
91 flashreadblock(uint32_t addr, uint32_t len, void *_data) {
92 return spiflashreadblock(addr, len, _data);
93 }
94
95
96 int
97 flashwriteblock(uint32_t addr, uint32_t len, void *_data) {
98 return spiflashwriteblock(addr, len, _data);
99 }
100