annotate target-utils/c139explore/dac.c @ 465:003e48f8ebe1

rvinterf/etmsync/fsnew.c: cast 0 to (char *) for execl sentinel I generally don't use NULL and use plain 0 instead, based on a "NULL considered harmful" discussion on the classiccmp mailing list many aeons ago (I couldn't find it, and I reason that it must have been 2005 or earlier), but a recent complaint by a packager sent me searching, and I found this: https://ewontfix.com/11/ While I don't give a @#$% about "modern" systems and code-nazi tools, I realized that passing a plain 0 as a pointer sentinel in execl is wrong because it will break on systems where pointers are longer than the plain int type. Again, I don't give a @#$% about the abomination of x86_64 and the like, but if anyone ever manages to port my code to something like a PDP-11 (16-bit int, 32-bit long and pointers), then passing a plain 0 as a function argument where a pointer is expected most definitely won't work: if the most natural stack slot and SP alignment unit is 16 bits, fitting an int, with longs and pointers taking up two such slots, then the call stack will be totally wrong with a plain 0 passed for a pointer. Casting the 0 to (char *) ought to be the most kosher solution for the most retro systems possible.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Feb 2019 00:00:19 +0000
parents ce636b0ffb3d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Code for exercising Motorola's vibrator, which is driven
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * via the Iota auxiliary DAC on this phone.
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include "types.h"
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "abbdefs.h"
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
110
ce636b0ffb3d target-utils/c139explore/dac.c: added missing extern u_long strtoul();
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
10 extern u_long strtoul();
ce636b0ffb3d target-utils/c139explore/dac.c: added missing extern u_long strtoul();
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
11
39
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 void
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 cmd_dacon()
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 {
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 abb_reg_write(TOGBR1, 0x20);
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 }
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 void
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 cmd_dac(argbulk)
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char *argbulk;
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 {
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 char *argv[2];
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 u32 val;
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (parse_args(argbulk, 1, 1, argv, 0) < 0)
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 return;
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 val = strtoul(argv[0], 0, 0);
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (val > 0x3FF) {
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 printf("ERROR: argument out of range\n");
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return;
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 abb_reg_write(AUXDAC, val);
280826b807e3 c139explore: dac and dacon commands added for exercising the vibrator
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
40
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
34
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
35 void
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
36 cmd_vibe(argbulk)
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
37 char *argbulk;
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
38 {
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
39 char *argv[2];
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
40 u32 val;
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
41 int c;
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
42
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
43 if (parse_args(argbulk, 1, 1, argv, 0) < 0)
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
44 return;
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
45 val = strtoul(argv[0], 0, 0);
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
46 if (val > 0x3FF) {
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
47 printf("ERROR: argument out of range\n");
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
48 return;
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
49 }
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
50 abb_reg_write(AUXDAC, val);
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
51 for (;;) {
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
52 c = serial_in_poll();
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
53 if (c >= 0)
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
54 break;
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
55 }
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
56 abb_reg_write(AUXDAC, 0);
7ecb70b0ac36 c139explore: vibe command added that works like buz
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
57 }