view target-utils/buzplayer/pwt.c @ 1011:6d9b10633f10 default tip

etmsync Pirelli IMEI retrieval: fix poor use of printf() Bug reported by Vadim Yanitskiy <fixeria@osmocom.org>: the construct where a static-allocated string was passed to printf() without any format arguments causes newer compilers to report a security problem. Given that formatted output is not needed here, just fixed string output, change printf() to fputs(), and direct the error message to stderr while at it.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 23 May 2024 17:29:57 +0000
parents 7c02cc7f28df
children
line wrap: on
line source

/*
 * 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
pwt_on()
{
	ASIC_CONF_REG |= PWT_MODE_MASK;
	PWT_GCR_REG = 0x01;
}

void
pwt_off()
{
	ASIC_CONF_REG &= ~PWT_MODE_MASK;
	PWT_GCR_REG = 0;
}

void
cmd_pwt(argbulk)
	char *argbulk;
{
	char *argv[2];

	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
		return;
	if (!strcmp(argv[0], "on"))
		pwt_on();
	else if (!strcmp(argv[0], "off"))
		pwt_off();
	else
		printf("ERROR: \"on\" or \"off\" argument expected\n");
}

void
cmd_bzt(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_on();
	PWT_FRC_REG = note;
	PWT_VCR_REG = (vol << 1) | 1;
	for (;;) {
		c = serial_in_poll();
		if (c >= 0)
			break;
	}
	PWT_VCR_REG = 0;
}