annotate flash.c @ 86:345a42f6151b

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