FreeCalypso > hg > freecalypso-tools
annotate target-utils/libcommon/buzzer.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 | 4be951811791 |
children |
rev | line source |
---|---|
36
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Commands for exercising the Calypso's buzzer output, whatever |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * actual hardware (piezo buzzer or vibrator) it may be driving |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * on a given Calypso device. |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/types.h> |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "types.h" |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
107
4be951811791
target-utils/libcommon: extern u_long strtoul(); added where needed
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
10 extern u_long strtoul(); |
4be951811791
target-utils/libcommon: extern u_long strtoul(); added where needed
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
11 |
36
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #define ARMIO_LOAD_TIM (*(volatile u16 *) 0xFFFE4808) |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #define BUZZ_LIGHT_REG (*(volatile u16 *) 0xFFFE480E) |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #define BUZZ_LEVEL_REG (*(volatile u16 *) 0xFFFE4812) |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 void |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 cmd_buzlev(argbulk) |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 char *argbulk; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 { |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 char *argv[2]; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 u32 arg; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (parse_args(argbulk, 0, 1, argv, 0) < 0) |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 return; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (argv[0]) { |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 arg = strtoul(argv[0], 0, 0); |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (arg > 0xFFFF) { |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 printf("ERROR: argument out of range\n"); |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 return; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 BUZZ_LEVEL_REG = arg; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 } else |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 printf("%04X\n", BUZZ_LEVEL_REG); |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 void |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 cmd_buz(argbulk) |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 char *argbulk; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 { |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 char *argv[2]; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 u32 arg; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 int c; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (parse_args(argbulk, 1, 1, argv, 0) < 0) |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 arg = strtoul(argv[0], 0, 0); |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (arg > 0xFFFF) { |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 printf("ERROR: argument out of range\n"); |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 ARMIO_LOAD_TIM = arg; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 BUZZ_LIGHT_REG = 1; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 for (;;) { |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 c = serial_in_poll(); |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (c >= 0) |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 break; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 BUZZ_LIGHT_REG = 0; |
29d0965ebf86
target-utils: buzzer exercising code written, added to c139explore
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |