FreeCalypso > hg > freecalypso-tools
annotate target-utils/pln-ppb-test/program.c @ 990:f34261bb3355
pln-ppb-test: implement PPB erase
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Dec 2023 00:20:14 +0000 |
parents | a5bff8104b45 |
children |
rev | line source |
---|---|
989
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * program command for special modes |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include "types.h" |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 void |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 cmd_program(argbulk) |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 char *argbulk; |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 { |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 char *argv[3]; |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 u_long addr, pdata; |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 u16 buf[256]; |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int i; |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 if (parse_args(argbulk, 2, 2, argv, 0) < 0) |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 return; |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 if (parse_hexarg(argv[0], 8, &addr) < 0) { |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 printf("ERROR: arg1 must be a valid 32-bit hex address\n"); |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 return; |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 } |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (addr & 1) { |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 printf("ERROR: unaligned address\n"); |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 return; |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (parse_hexarg(argv[1], 4, &pdata) < 0) { |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 printf("ERROR: arg2 must be a valid 16-bit hex value\n"); |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 return; |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 *(volatile u16 *)addr = 0xA0; |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 *(volatile u16 *)addr = pdata; |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 for (i = 0; i < 256; i++) |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 buf[i] = *(volatile u16 *)addr; |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 for (i = 0; i < 256; i++) |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 printf("%04X%c", buf[i], (i & 15) == 15 ? '\n' : ' '); |
a5bff8104b45
pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |