comparison flash.c @ 26:74efdb21ae5d

Use a 32 bit var to hold address from atoi().
author Daniel O'Connor <darius@dons.net.au>
date Sat, 17 Nov 2012 18:03:48 +1030
parents a9cc07caa801
children 5c9d2e3d6591
comparison
equal deleted inserted replaced
25:a9cc07caa801 26:74efdb21ae5d
30 static int readstate = RW_IDLE; 30 static int readstate = RW_IDLE;
31 31
32 void 32 void
33 flashcmd(char **argv, int argc) { 33 flashcmd(char **argv, int argc) {
34 uint8_t status, tmp; 34 uint8_t status, tmp;
35 35 uint32_t addr;
36
36 if (argc == 0) { 37 if (argc == 0) {
37 fputs("No command specified\r\n", stdout); 38 fputs("No command specified\r\n", stdout);
38 return; 39 return;
39 } 40 }
40 41
59 } else if (!strcmp(argv[0], "er")) { 60 } else if (!strcmp(argv[0], "er")) {
60 if (argc != 2) { 61 if (argc != 2) {
61 fputs("Incorrect number of arguments\r\n", stdout); 62 fputs("Incorrect number of arguments\r\n", stdout);
62 return; 63 return;
63 } 64 }
64 tmp = atoi(argv[1]); 65 addr = atoi(argv[1]);
65 flash4kerase(tmp); 66 flash4kerase(addr);
66 printf("Erased 0x%x\r\n", tmp); 67 printf("Erased 0x%x\r\n", (unsigned int)addr);
67 } else if (!strcmp(argv[0], "rd")) { 68 } else if (!strcmp(argv[0], "rd")) {
68 if (argc != 2) { 69 if (argc != 2) {
69 fputs("Incorrect number of arguments\r\n", stdout); 70 fputs("Incorrect number of arguments\r\n", stdout);
70 return; 71 return;
71 } 72 }
72 tmp = atoi(argv[1]); 73
73 74 addr = atoi(argv[1]);
74 flashstartread(tmp); 75
76 flashstartread(addr);
75 77
76 for (int i = 0; i < 16; i++) 78 for (int i = 0; i < 16; i++)
77 printf("Read 0x%02x from 0x%06x\r\n", flashreadbyte(), tmp + i); 79 printf("Read 0x%02x from 0x%06x\r\n", flashreadbyte(), (unsigned int)(addr + i));
78 flashstopread(); 80 flashstopread();
79 81
80 fputs("\r\n", stdout); 82 fputs("\r\n", stdout);
81 } else if (!strcmp(argv[0], "wr")) { 83 } else if (!strcmp(argv[0], "wr")) {
82 if (argc != 2) { 84 if (argc != 2) {
83 fputs("Incorrect number of arguments\r\n", stdout); 85 fputs("Incorrect number of arguments\r\n", stdout);
84 return; 86 return;
85 } 87 }
86 88
87 tmp = atoi(argv[1]); 89 addr = atoi(argv[1]);
88 90
89 for (int i = 0; i < 16; i += 2) { 91 for (int i = 0; i < 16; i += 2) {
90 uint16_t data; 92 uint16_t data;
91 data = ((i + 1) << 8) | i; 93 data = ((i + 1) << 8) | i;
92 printf("Writing 0x%04x to 0x%06x\r\n", data, tmp + i); 94 printf("Writing 0x%04x to 0x%06x\r\n", data, (unsigned int)(addr + i));
93 95
94 if (i == 0) 96 if (i == 0)
95 flashstartwrite(tmp, data); 97 flashstartwrite(addr, data);
96 else 98 else
97 flashwriteword(data); 99 flashwriteword(data);
98 } 100 }
99 flashstopwrite(); 101 flashstopwrite();
100 } else if (!strcmp(argv[0], "id")) { 102 } else if (!strcmp(argv[0], "id")) {