Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/memswitch Add special methods for hw.serial and hw....
details: https://anonhg.NetBSD.org/src/rev/6c838f6ce846
branches: trunk
changeset: 474112:6c838f6ce846
user: minoura <minoura%NetBSD.org@localhost>
date: Mon Jun 28 08:49:15 1999 +0000
description:
Add special methods for hw.serial and hw.srammode.
diffstat:
usr.sbin/memswitch/methods.c | 188 +++++++++++++++++++++++++++++++++++++++-
usr.sbin/memswitch/methods.h | 6 +-
usr.sbin/memswitch/properties.c | 21 ++-
3 files changed, 201 insertions(+), 14 deletions(-)
diffs (truncated from 309 to 300 lines):
diff -r 8fcff087c689 -r 6c838f6ce846 usr.sbin/memswitch/methods.c
--- a/usr.sbin/memswitch/methods.c Mon Jun 28 08:48:35 1999 +0000
+++ b/usr.sbin/memswitch/methods.c Mon Jun 28 08:49:15 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: methods.c,v 1.2 1999/06/25 14:27:55 minoura Exp $ */
+/* $NetBSD: methods.c,v 1.3 1999/06/28 08:49:15 minoura Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
return 0;
}
- while (*p1 == ' ' || *p1 == '\t');
+ while (*p1 == ' ' || *p1 == '\t') p1++;
*p = p1;
return v;
}
@@ -346,7 +346,7 @@
const char *p = value;
int v;
- while (*p == ' ' || *p == '\t');
+ while (*p == ' ' || *p == '\t') p++;
if (*p == '-') {
p++;
v = -atoi_ (&p);
@@ -391,7 +391,7 @@
const char *p = value;
int v;
- while (*p == ' ' || *p == '\t');
+ while (*p == ' ' || *p == '\t') p++;
if (strcasecmp ("STD", p) == 0)
v = 0;
@@ -429,6 +429,130 @@
}
int
+parse_serial (prop, value)
+ struct property *prop;
+ const char *value;
+#define NEXTSPEC while (*p == ' ' || *p == '\t') p++; \
+ if (*p++ != ',') { \
+ warnx ("%s: Invalid value", value); \
+ return -1; \
+ } \
+ while (*p == ' ' || *p == '\t') p++;
+{
+ const char *p = value;
+ const char *q;
+ int baud, bit, parity, stop, flow;
+ int bauds[] = {75, 150, 300, 600, 1200, 2400, 4800, 9600, 17361, 0};
+ const char parities[] = "noe";
+ int i;
+
+ while (*p == ' ' || *p == '\t') p++;
+
+ /* speed */
+ baud = atoi_ (&p);
+ if (p == 0) {
+ warnx ("%s: Invalid value", value);
+ return -1;
+ }
+ for (i = 0; bauds[i]; i++)
+ if (baud == bauds[i])
+ break;
+ if (bauds[i] == 0) {
+ warnx ("%d: Invalid speed", baud);
+ return -1;
+ }
+ baud = i;
+
+ NEXTSPEC;
+
+ /* bit size */
+ if (*p < '5' || *p > '8') {
+ warnx ("%c: Invalid bit size", *p);
+ return -1;
+ }
+ bit = *p++ - '5';
+
+ NEXTSPEC;
+
+ /* parity */
+ q = strchr(parities, *p++);
+ if (q == 0) {
+ warnx ("%c: Invalid parity spec", *p);
+ return -1;
+ }
+ parity = q - parities;
+
+ NEXTSPEC;
+
+ /* stop bit */
+ if (strncmp (p, "1.5", 3) == 0) {
+ stop = 2;
+ p += 3;
+ } else if (strncmp (p, "2", 1) == 0) {
+ stop = 0;
+ p++;
+ } else if (strncmp (p, "1", 1) == 0) {
+ stop = 1;
+ p++;
+ } else {
+ warnx ("%s: Invalid value", value);
+ return -1;
+ }
+
+ NEXTSPEC;
+
+ /* flow */
+ if (*p == '-')
+ flow = 0;
+ else if (*p == 's')
+ flow = 1;
+ else {
+ warnx ("%s: Invalid value", value);
+ return -1;
+ }
+
+ p++;
+ while (*p == ' ' || *p == '\t') p++;
+ if (*p != 0) {
+ warnx ("%s: Invalid value", value);
+ return -1;
+ }
+
+ prop->modified = 1;
+ prop->modified_value.word[0] = ((stop << 14) +
+ (parity << 12) +
+ (bit << 10) +
+ (flow << 9) +
+ baud);
+
+ return 0;
+}
+#undef NEXTSPEC
+
+int
+parse_srammode (prop, value)
+ struct property *prop;
+ const char *value;
+{
+ const char *sramstrs[] = {"unused", "SRAMDISK", "program"};
+ int i;
+
+ for (i = 0; i <= 2; i++) {
+ if (strcasecmp (value, sramstrs[i]) == 0)
+ break;
+ }
+ if (i > 2) {
+ warnx ("%s: Invalid value", value);
+ return -1;
+ }
+
+ prop->modified = 1;
+ prop->modified_value.byte[0] = i;
+
+ return 0;
+}
+
+int
print_uchar (prop, str)
struct property *prop;
char *str;
@@ -582,3 +706,59 @@
return 0;
}
+
+int
+print_serial (prop, str)
+ struct property *prop;
+ char *str;
+{
+ unsigned int v;
+ char *baud, bit, parity, *stop, flow;
+ char *bauds[] = {"75", "150", "300", "600", "1200",
+ "2400", "4800", "9600", "17361"};
+ const char bits[] = "5678";
+ const char parities[] = "noen";
+ char *stops[] = {"2", "1", "1.5", "2"};
+ const char flows[] = "-s";
+
+ if (prop->modified)
+ v = prop->modified_value.word[0];
+ else {
+ if (!prop->value_valid)
+ prop->fill (prop);
+ v = prop->current_value.word[0];
+ }
+
+ baud = bauds[v & 0x000f];
+ bit = bits[(v & 0x0c00) >> 10];
+ parity = parities[(v & 0x3000) >> 12];
+ stop = stops[(v & 0xe000) >> 14];
+ flow = flows[(v & 0x0200) >> 9];
+ sprintf (str, "%s,%c,%c,%s,%c", baud, bit, parity, stop, flow);
+
+ return 0;
+}
+
+int
+print_srammode (prop, str)
+ struct property *prop;
+ char *str;
+{
+ int v;
+ const char *sramstrs[] = {"unused", "SRAMDISK", "program"};
+
+ if (prop->modified)
+ v = prop->modified_value.byte[0];
+ else {
+ if (!prop->value_valid)
+ prop->fill (prop);
+ v = prop->current_value.byte[0];
+ }
+
+ if (v < 0 || v > 2)
+ strcpy (str, "INVALID");
+ else
+ strcpy (str, sramstrs[v]);
+
+ return 0;
+}
diff -r 8fcff087c689 -r 6c838f6ce846 usr.sbin/memswitch/methods.h
--- a/usr.sbin/memswitch/methods.h Mon Jun 28 08:48:35 1999 +0000
+++ b/usr.sbin/memswitch/methods.h Mon Jun 28 08:49:15 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: methods.h,v 1.2 1999/06/25 14:27:55 minoura Exp $ */
+/* $NetBSD: methods.h,v 1.3 1999/06/28 08:49:15 minoura Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -55,6 +55,8 @@
int parse_byte __P((struct property*, const char*));
int parse_time __P((struct property*, const char*));
int parse_bootdev __P((struct property*, const char*));
+int parse_serial __P((struct property*, const char*));
+int parse_srammode __P((struct property*, const char*));
int print_uchar __P((struct property*, char*));
int print_ucharh __P((struct property*, char*));
@@ -64,3 +66,5 @@
int print_magic __P((struct property*, char*));
int print_timesec __P((struct property*, char*));
int print_bootdev __P((struct property*, char*));
+int print_serial __P((struct property*, char*));
+int print_srammode __P((struct property*, char*));
diff -r 8fcff087c689 -r 6c838f6ce846 usr.sbin/memswitch/properties.c
--- a/usr.sbin/memswitch/properties.c Mon Jun 28 08:48:35 1999 +0000
+++ b/usr.sbin/memswitch/properties.c Mon Jun 28 08:49:15 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: properties.c,v 1.1.1.1 1999/06/21 15:56:03 minoura Exp $ */
+/* $NetBSD: properties.c,v 1.2 1999/06/28 08:49:15 minoura Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -52,15 +52,15 @@
0, 4, 0, {longword:0}, 0, {longword:0}, {longword:MAGIC1},
parse_dummy, 0, 0,
print_magic,
- fill_ulong, flush_dummy,
- " Magic. Must be 0xa3d83638\n"
+ fill_ulong, flush_ulong,
+ " Magic. Must be 0x82773638\n"
},
{
"special", "magic2",
4, 4, 0, {longword:0}, 0, {longword:0}, {longword:MAGIC2},
parse_dummy, 0, 0,
print_magic,
- fill_ulong, flush_dummy,
+ fill_ulong, flush_ulong,
" Magic. Must be 0x30303057\n"
},
{
@@ -230,21 +230,24 @@
" Memory size in byte.\n"
" Can be specified by Kilobyte and Megabyte with suffix KB and MB respectively.\n"
},
-#ifdef notyet
{
"hw", "serial",
26, 2, 0, {word:{[0] 0}}, 0, {word:{[0] 0}}, {word:{[0] 0x4e07}},
parse_serial, 0, 0,
print_serial,
fill_ushort, flush_ushort,
- " Serial mode."
+ " Serial mode.\n"
+ " Consist of comma-separated 5 specs. The first value means speed in bps,\n"
+ " second means the bit width (5-8), third means parity (n for non parity,\n"
+ " o for odd parity, e for even parity), fourth means stop bit (2, 1 or 1.5),\n"
+ " fifth for software flow control (`-' or `s').\n"
+ " Note that the value is ignored on NetBSD.\n"
},
-#endif
{
Home |
Main Index |
Thread Index |
Old Index