view src/g23m-aci/aci/ati_fcmisc.c @ 304:58c7961bd0b0 default tip

TCH tap: extend DL sniffing feature to support CSD modes Our debug feature for TCH DL sniffing reads the content of the DSP's a_dd_0 buffer (or a_dd_1 for TCH/H subchannel 1) at appropriate times and forwards captured bits to the host. This feature was originally implemented for TCH/FS, TCH/EFS and TCH/HS - now extend it to cover TCH/F data modes too.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 25 Nov 2024 23:33:27 +0000
parents d32ac4edb634
children
line wrap: on
line source

/*
 * This module implements miscellaneous FreeCalypso-added AT commands.
 */

#ifndef ATI_FCMISC_C
#define ATI_FCMISC_C

#include "aci_all.h"

#include <ctype.h>
#include <string.h>

#include "aci_cmh.h"
#include "ati_cmd.h"
#include "aci_cmd.h"
#include "aci_io.h"
#include "aci_cmd.h"
#include "l4_tim.h"
#include "line_edit.h"
#include "aci_lst.h"

#include "pcm.h"
#include "audio.h"
#include "aci.h"
#include "rx.h"
#include "pwr.h"
#include "l4_tim.h"

#ifdef GPRS
#ifdef DTI
#include "dti.h"
#include "dti_conn_mng.h"
#include "dti_cntrl_mng.h"
#endif /* DTI */
#include "gaci.h"
#include "gaci_cmh.h"
#include "gaci_cmd.h"
#endif  /* GPRS */

#include "aci_mem.h"
#include "aci_prs.h"

#include "ati_int.h"

#ifndef _SIMULATION_
#include "ffs/ffs.h"
#endif

#ifdef FF_ATI_BAT

#include "typedefs.h"
#include "gdd.h"
#include "bat.h"

#include "ati_bat.h"

#endif /*FF_ATI_BAT*/

#include "cl_user_spver.h"

#include "rv/rv_defined_swe.h"     /* for RVM_BUZM_SWE and RVM_VIBR_SWE */
#include "main/sys_types.h"
#include "fc-target.h"
#include "armio.h"

#ifdef RVM_BUZM_SWE
#include "buzm/buzm_api.h"
#endif

#ifdef RVM_VIBR_SWE
#include "vibr/vibr_api.h"
#endif

extern SYS_UWORD8 SIM_allow_speed_enhancement;

/* AT@SPENH - enable or disable SIM speed enhancement */
GLOBAL T_ATI_RSLT atAtSPENH ( char *cl, UBYTE srcId )
{
	int state, nonvol = 0;

	TRACE_FUNCTION("atAtSPENH()");

	cl = parse(cl, "Dd", &state, &nonvol);
	if (!cl)
		return (ATI_FAIL);
	if (state != 0 && state != 1)
		return (ATI_FAIL);
	SIM_allow_speed_enhancement = state;
	if (!nonvol)
		return (ATI_CMPL);
	ffs_mkdir("/etc");
	if (ffs_file_write("/etc/SIM_spenh", &SIM_allow_speed_enhancement, 1,
			   FFS_O_CREATE | FFS_O_TRUNC) == EFFS_OK)
		return (ATI_CMPL);
	else
		return (ATI_FAIL);
}

GLOBAL T_ATI_RSLT queatAtSPENH (char *cl, UBYTE srcId)
{
	char *me="@SPENH: ";

	TRACE_FUNCTION("queatAtSPENH()");

	sprintf(g_sa, "%s%u", me, SIM_allow_speed_enhancement);
	io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT);
	return (ATI_CMPL);
}

/* AT%MSCAP - tinker with /pcm/MSCAP settings */
GLOBAL T_ATI_RSLT atPercentMSCAP (char *cl, UBYTE srcId)
{
	EF_MSCAP mscap;

	TRACE_FUNCTION("atPercentMSCAP()");

	mscap.featLst1 = 0;
	mscap.featLst2 = 0;
	mscap.featLst3 = 0;
	cl = parse(cl, "XXXxxx", &mscap.chnMode, &mscap.datCap1, &mscap.datCap2,
		   &mscap.featLst1, &mscap.featLst2, &mscap.featLst3);
	if (!cl)
		return (ATI_FAIL);
	pcm_WriteFile((UBYTE *) EF_MSCAP_ID, SIZE_EF_MSCAP, (UBYTE *) &mscap);
	return (ATI_CMPL);
}

GLOBAL T_ATI_RSLT queatPercentMSCAP (char *cl, UBYTE srcId)
{
	EF_MSCAP mscap;
	UBYTE version;
	char *me="%MSCAP: ";

	pcm_ReadFile((UBYTE *) EF_MSCAP_ID, SIZE_EF_MSCAP, (UBYTE *) &mscap,
			&version);
	sprintf(g_sa, "%s%02X,%02X,%02X,%02X,%02X,%02X", me, mscap.chnMode,
		mscap.datCap1, mscap.datCap2, mscap.featLst1, mscap.featLst2,
		mscap.featLst3);
	io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT);
	return (ATI_CMPL);
}

/* AT%SPVER - set custom speech version list */
GLOBAL T_ATI_RSLT atPercentSPVER (char *cl, UBYTE srcId)
{
	UBYTE spver_set;
	UBYTE spver_list[5] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
	UBYTE spver_rc;

	TRACE_FUNCTION("atPercentSPVER()");

	cl = parse(cl, "Xxxxxx", &spver_set, &spver_list[0], &spver_list[1],
		   &spver_list[2], &spver_list[3], &spver_list[4]);
	if (!cl)
		return (ATI_FAIL);
	switch (spver_set) {
	case CL_USER_SPVER_IS_NOT_SET:
		cl_user_spver_reset();
		return (ATI_CMPL);
	case CL_USER_SPVER_IS_SET:
		spver_rc = cl_user_spver_set(spver_list);
		if (spver_rc == CL_USER_SPVER_SET_OK)
			return (ATI_CMPL);
		else
			return (ATI_FAIL);
	default:
		return (ATI_FAIL);
	}
}

GLOBAL T_ATI_RSLT queatPercentSPVER (char *cl, UBYTE srcId)
{
	UBYTE spver_set, rad_chan_req;
	UBYTE spver_list[5], n, sv;
	char *me="%SPVER: ";
	char add[5];

	spver_set = cl_user_spver_get(spver_list, &rad_chan_req);
	sprintf(g_sa, "%s%u", me, spver_set);
	if (spver_set == CL_USER_SPVER_IS_SET) {
		for (n = 0; n < 5; n++) {
			sv = spver_list[n];
			if (sv == NOT_PRESENT_8BIT)
				break;
			sprintf(add, ",%u", sv);
			strcat(g_sa, add);
		}
	}
	io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT);
	return (ATI_CMPL);
}

#ifdef TARGET_HAS_LPG
/* AT@LPG - program LPG output */
GLOBAL T_ATI_RSLT atAtLPG ( char *cl, UBYTE srcId )
{
	unsigned glob, period = 0, ontime = 0;

	TRACE_FUNCTION("atAtLPG()");

	cl = parse(cl, "Ddd", &glob, &period, &ontime);
	if (!cl)
		return (ATI_FAIL);
	if (glob > 3 || period > 7 || ontime > 7)
		return (ATI_FAIL);
	*(volatile SYS_UWORD8 *)0xFFFE7801 = 0x01;
	*(volatile SYS_UWORD8 *)0xFFFE7800 =
					(glob << 6) | (ontime << 3) | period;
	return (ATI_CMPL);
}

GLOBAL T_ATI_RSLT queatAtLPG (char *cl, UBYTE srcId)
{
	char *me="@LPG: ";
	SYS_UWORD8 regval;
	unsigned glob, period, ontime;

	TRACE_FUNCTION("queatAtLPG()");

	regval = *(volatile SYS_UWORD8 *)0xFFFE7800;
	glob = (regval >> 6) & 3;
	ontime = (regval >> 3) & 7;
	period = regval & 7;
	sprintf(g_sa, "%s%u,%u,%u", me, glob, period, ontime);
	io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT);
	return (ATI_CMPL);
}
#endif	/* TARGET_HAS_LPG */

#ifdef TARGET_HAS_PWL
/* AT@PWL - program PWL output */
GLOBAL T_ATI_RSLT atAtPWL ( char *cl, UBYTE srcId )
{
	unsigned level;

	TRACE_FUNCTION("atAtPWL()");

	cl = parse(cl, "D", &level);
	if (!cl)
		return (ATI_FAIL);
	if (level > 255)
		return (ATI_FAIL);
	*(volatile SYS_UWORD8 *)0xFFFE8000 = level;
	*(volatile SYS_UWORD8 *)0xFFFE8001 = 0x01;
	return (ATI_CMPL);
}

GLOBAL T_ATI_RSLT queatAtPWL (char *cl, UBYTE srcId)
{
	char *me="@PWL: ";
	SYS_UWORD8 regval;

	TRACE_FUNCTION("queatAtPWL()");

	regval = *(volatile SYS_UWORD8 *)0xFFFE8000;
	sprintf(g_sa, "%s%u", me, regval);
	io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT);
	return (ATI_CMPL);
}
#endif	/* TARGET_HAS_PWL */

/* AT+IOR - read GPIO pin */
GLOBAL T_ATI_RSLT atPlusIOR (char *cl, UBYTE srcId)
{
	char *me="+IOR: ";
	unsigned ionum;
	int state;

	TRACE_FUNCTION("atPlusIOR()");

	cl = parse(cl, "D", &ionum);
	if (!cl)
		return (ATI_FAIL);
	if (ionum > 13)
		return (ATI_FAIL);
	state = AI_ReadBit(ionum);
	sprintf(g_sa, "%s%u,%d", me, ionum, state);
	io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT);
	return (ATI_CMPL);
}

/* AT+IOW - set GPIO pin */
GLOBAL T_ATI_RSLT atPlusIOW (char *cl, UBYTE srcId)
{
	unsigned ionum;
	int state;

	TRACE_FUNCTION("atPlusIOW()");

	cl = parse(cl, "DD", &ionum, &state);
	if (!cl)
		return (ATI_FAIL);
	if (ionum > 13)
		return (ATI_FAIL);
	if (state)
		AI_SetBit(ionum);
	else
		AI_ResetBit(ionum);
	return (ATI_CMPL);
}

#ifdef RVM_BUZM_SWE
/* AT@BUZ - play a buzzer melody */
GLOBAL T_ATI_RSLT atAtBUZ ( char *cl, UBYTE srcId )
{
	char melody_name[20];
	int play_volume = BUZM_VOLUME_MAX;
	int loopback = 0;

	cl = parse(cl, "Sdd", (LONG)(sizeof(melody_name)), melody_name,
		   &play_volume, &loopback);
	if (!cl || !melody_name[0])
		return (ATI_FAIL);
	if (buzm_play_melody(melody_name, play_volume, loopback) == RV_OK)
		return (ATI_CMPL);
	else
		return (ATI_FAIL);
}

/* AT@BZSTOP - stop melody started with AT@BUZ */
GLOBAL T_ATI_RSLT atAtBZSTOP ( char *cl, UBYTE srcId )
{
	if (buzm_stop_melody() == RV_OK)
		return (ATI_CMPL);
	else
		return (ATI_FAIL);
}
#endif

#ifdef RVM_VIBR_SWE
/* AT@VIBR - run the vibrator by way of VIBR SWE */
GLOBAL T_ATI_RSLT atAtVIBR ( char *cl, UBYTE srcId )
{
	int num_pulses = VIBR_INFINITE;
	int vibr_level = VIBR_LEVEL_MAX;

	cl = parse(cl, "dd", &num_pulses, &vibr_level);
	if (!cl)
		return (ATI_FAIL);
	if (vibr_pulse_train_start(num_pulses, vibr_level) == RV_OK)
		return (ATI_CMPL);
	else
		return (ATI_FAIL);
}

/* AT@VIBS - stop vibration that was started with AT@VIBR */
GLOBAL T_ATI_RSLT atAtVIBS ( char *cl, UBYTE srcId )
{
	if (vibr_pulse_train_stop() == RV_OK)
		return (ATI_CMPL);
	else
		return (ATI_FAIL);
}
#endif

#endif /* ATI_FCMISC_C */