changeset 820:03457a66d860

buzplayer: add basic support for PWT
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 30 May 2021 03:39:58 +0000
parents 7b24c192a1e1
children 16bee7b6bd6b
files target-utils/buzplayer/Makefile target-utils/buzplayer/cmdtab.c target-utils/buzplayer/pwt.c
diffstat 3 files changed, 72 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/target-utils/buzplayer/Makefile	Sat May 15 03:15:03 2021 +0000
+++ b/target-utils/buzplayer/Makefile	Sun May 30 03:39:58 2021 +0000
@@ -7,7 +7,7 @@
 INSTDIR=/opt/freecalypso/target-bin
 
 PROG=	buzplayer
-OBJS=	crt0.o cmdtab.o main.o melentry.o melplay.o timer.o
+OBJS=	crt0.o cmdtab.o main.o melentry.o melplay.o pwt.o timer.o
 LIBS=	../libcommon/libcommon.a ../libprintf/libprintf.a ../libbase/libbase.a \
 	../libc/libc.a
 LIBGCC=	`${CC} -print-file-name=libgcc.a`
--- a/target-utils/buzplayer/cmdtab.c	Sat May 15 03:15:03 2021 +0000
+++ b/target-utils/buzplayer/cmdtab.c	Sun May 30 03:39:58 2021 +0000
@@ -5,7 +5,9 @@
 extern void cmd_baud_switch();
 extern void cmd_buz();
 extern void cmd_buzlev();
+extern void cmd_buzpwt();
 extern void cmd_jump();
+extern void cmd_pwt();
 extern void cmd_r8();
 extern void cmd_r16();
 extern void cmd_r32();
@@ -32,8 +34,10 @@
 	{"baud", cmd_baud_switch},
 	{"buz", cmd_buz},
 	{"buzlev", cmd_buzlev},
+	{"buzpwt", cmd_buzpwt},
 	{"jump", cmd_jump},
 	{"poweroff", abb_power_off},
+	{"pwt", cmd_pwt},
 	{"r8", cmd_r8},
 	{"r16", cmd_r16},
 	{"r32", cmd_r32},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/buzplayer/pwt.c	Sun May 30 03:39:58 2021 +0000
@@ -0,0 +1,67 @@
+/*
+ * Commands for exercising the Calypso buzzer in PWT mode.
+ */
+
+#include <sys/types.h>
+#include <strings.h>
+#include "types.h"
+
+extern u_long strtoul();
+
+#define	ASIC_CONF_REG	(*(volatile u16 *) 0xFFFEF008)
+#define	PWT_MODE_MASK	0x0020
+
+#define	PWT_FRC_REG	(*(volatile u8 *) 0xFFFE8800)
+#define	PWT_VCR_REG	(*(volatile u8 *) 0xFFFE8801)
+#define	PWT_GCR_REG	(*(volatile u8 *) 0xFFFE8802)
+
+void
+cmd_pwt(argbulk)
+	char *argbulk;
+{
+	char *argv[2];
+
+	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
+		return;
+	if (!strcmp(argv[0], "on")) {
+		ASIC_CONF_REG |= PWT_MODE_MASK;
+		PWT_GCR_REG = 0x01;
+	} else if (!strcmp(argv[0], "off")) {
+		ASIC_CONF_REG &= ~PWT_MODE_MASK;
+		PWT_GCR_REG = 0;
+	} else
+		printf("ERROR: \"on\" or \"off\" argument expected\n");
+}
+
+void
+cmd_buzpwt(argbulk)
+	char *argbulk;
+{
+	char *argv[3];
+	u32 note, vol;
+	int c;
+
+	if (parse_args(argbulk, 1, 2, argv, 0) < 0)
+		return;
+	note = strtoul(argv[0], 0, 0);
+	if (note > 47) {
+		printf("ERROR: note argument out of range\n");
+		return;
+	}
+	if (argv[1]) {
+		vol = strtoul(argv[1], 0, 0);
+		if (vol > 63) {
+			printf("ERROR: volume argument out of range\n");
+			return;
+		}
+	} else
+		vol = 63;
+	PWT_FRC_REG = note;
+	PWT_VCR_REG = (vol << 1) | 1;
+	for (;;) {
+		c = serial_in_poll();
+		if (c >= 0)
+			break;
+	}
+	PWT_VCR_REG = 0;
+}