changeset 319:9ffdfacfe969

implemented pseudo-modem keepalive for C139 and Pirelli targets
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Dec 2017 03:51:28 +0000
parents 6cea809631d7
children 3f3c98f8b85d
files components/riviera_cust_flash src/cs/riviera/rvt/rvt_keepalive.c src/cs/riviera/rvt/rvt_task.c
diffstat 3 files changed, 131 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/components/riviera_cust_flash	Sun Dec 03 01:24:19 2017 +0000
+++ b/components/riviera_cust_flash	Sun Dec 03 03:51:28 2017 +0000
@@ -3,6 +3,19 @@
 CFLAGS="-mn -mt -me -pw2"
 CPPFLAGS="-DTOOL_CHOICE=0 -D_TMS470"
 
+if [ "$MMI" = 0 ]
+then
+	case "$TARGET" in
+		c139)
+			CPPFLAGS="$CPPFLAGS -DPSEUDO_MODEM_KEEPALIVE"
+			;;
+		pirelli)
+			CPPFLAGS="$CPPFLAGS -DPSEUDO_MODEM_KEEPALIVE"
+			CPPFLAGS="$CPPFLAGS -DPSEUDO_MODEM_USB"
+			;;
+	esac
+fi
+
 # Includes
 
 CPPFLAGS="$CPPFLAGS -I$SRC/cs/os/nucleus"
@@ -40,3 +53,4 @@
 cfile_plain $SRCDIR/rvt/rvt_api.c
 cfile_plain $SRCDIR/rvt/rvt_env.c
 cfile_plain $SRCDIR/rvt/rvt_task.c
+cfile_plain $SRCDIR/rvt/rvt_keepalive.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cs/riviera/rvt/rvt_keepalive.c	Sun Dec 03 03:51:28 2017 +0000
@@ -0,0 +1,105 @@
+/*
+ * This module is a FreeCalypso addition.  Here we implement the special
+ * operation mode that is only used when a device that was originally
+ * meant to be a phone handset is turned into a pseudo-modem with no UI,
+ * requiring connection to a host computer running rvinterf for control.
+ */
+
+#ifdef PSEUDO_MODEM_KEEPALIVE
+
+#include "nucleus.h"
+
+#include "abb.h"
+
+#include "rv/general.h"
+#include "rv/rv_general.h"
+#include "rvf/rvf_api.h"
+#include "rvt/rvt_gen.h"
+#include "rvt/rvt_def_i.h"
+#include "rvt/rvt_env.h"
+#include "rvt/rvt_env_i.h"
+#include "rvm/rvm_use_id_list.h"
+
+#include "uart/serialswitch.h"
+
+#include <string.h>
+
+volatile UINT8 rvt_keepalive_counter;
+
+void rvt_keepalive_input(T_RVT_BUFFER p_msg, UINT16 msg_length)
+{
+	/* Checking for an invalid PDU. */
+	if ((p_msg == NULL) || (msg_length != 1))
+		return;
+
+	/* Check for the correct opcode */
+	if (*p_msg != 'A')
+		return;
+
+	/* good keepalive response from external host */
+	rvt_keepalive_counter = 0;
+}
+
+void rvt_keepalive_register(void)
+{
+	T_RVT_USER_ID rvt_id;
+
+	rvt_register_id("KEEPALIVE", &rvt_id, rvt_keepalive_input);
+}
+
+static void keepalive_send(UINT8 *buf, UINT32 size)
+{
+	UINT32 sent;
+
+	for (sent = 0; sent < size; )
+		sent += SER_tr_WriteNBytes(SER_LAYER_1, buf + sent,
+					   size - sent);
+}
+
+#ifdef PSEUDO_MODEM_USB
+static char poweroff_msg[] = "System: USB unplugged, powering off";
+#else
+static char poweroff_msg[] = "System: no keepalive response, powering off";
+static UINT8 keepalive_msg[2] = {RVT_KEEPALIVE_HEADER, 'Q'};
+#endif
+
+static void keepalive_poweroff(void)
+{
+	UINT8 poweroff_msg_buf[50], *p;
+
+	p = poweroff_msg_buf;
+	*p++ = RVT_RV_HEADER;
+	*p++ = 0;
+	*p++ = 0;
+	*p++ = 0;
+	*p++ = 0;
+	*p++ = RV_TRACE_LEVEL_ERROR;
+	strcpy((char *)p, poweroff_msg);
+	keepalive_send(poweroff_msg_buf, strlen(poweroff_msg) + 6);
+	/* do it */
+	ABB_Power_Off();
+}
+
+void rvt_keepalive_process(void)
+{
+	SYS_UWORD16 abb_status;
+
+	abb_status = ABB_Read_Status();
+	if (abb_status & CHGPRES) {
+		rvt_keepalive_counter = 0;
+		return;
+	}
+
+#ifdef PSEUDO_MODEM_USB
+	keepalive_poweroff();
+#else
+	if (rvt_keepalive_counter >= 3)
+		keepalive_poweroff();
+	else {
+		rvt_keepalive_counter++;
+		keepalive_send(keepalive_msg, sizeof keepalive_msg);
+	}
+#endif
+}
+
+#endif
--- a/src/cs/riviera/rvt/rvt_task.c	Sun Dec 03 01:24:19 2017 +0000
+++ b/src/cs/riviera/rvt/rvt_task.c	Sun Dec 03 03:51:28 2017 +0000
@@ -47,6 +47,10 @@
 #define RVT_WAIT_FOR_HEADER       (1)
 #define RVT_WAIT_FOR_DATA         (2)
 
+#ifdef PSEUDO_MODEM_KEEPALIVE
+extern void rvt_keepalive_register(void);
+extern void rvt_keepalive_process(void);
+#endif
 
 /********************************************************************************/
 /*                                                                              */
@@ -72,6 +76,10 @@
 	UINT16  event         = 0;
 	UINT32  nb_bytes_sent = 0;
 
+#ifdef PSEUDO_MODEM_KEEPALIVE
+	rvt_keepalive_register();
+#endif
+
 	#ifdef FRAMING_PROTOCOL
 
 		// Request for the level of filtering, as well as the 32-bit
@@ -242,6 +250,10 @@
 														 sys_time_length - nb_bytes_sent);
 				}
 
+			#ifdef PSEUDO_MODEM_KEEPALIVE
+				rvt_keepalive_process();
+			#endif
+
 			} // End of if (event & (RVF_TIMER_0_EVT_MASK))
 		}
 	#else