diff rvinterf/tmsh/etmbasic.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 585f63e5bca6
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/etmbasic.c	Sat Jun 11 00:13:35 2016 +0000
@@ -0,0 +1,107 @@
+/*
+ * Basic ETM interaction
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "pktmux.h"
+#include "limits.h"
+#include "etm.h"
+#include "tm3.h"
+
+extern u_char rvi_msg[];
+extern int rvi_msg_len;
+
+void
+print_etm_pkt_raw(err)
+	char *err;
+{
+	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
+	int i;
+
+	sprintf(buf, "%s:", err);
+	dp = index(buf, '\0');
+	for (i = 2; i < rvi_msg_len; i++) {
+		sprintf(dp, " %02X", rvi_msg[i]);
+		dp += 3;
+	}
+	async_msg_output(buf);
+}
+
+void
+etm_packet_rx()
+{
+	int i, c;
+
+	if (rvi_msg_len < 4) {
+runt:		print_etm_pkt_raw("TM runt");
+		return;
+	}
+	c = 0;
+	for (i = 2; i < rvi_msg_len; i++)
+		c ^= rvi_msg[i];
+	if (c) {
+		print_etm_pkt_raw("BAD CKSUM");
+		return;
+	}
+	switch (rvi_msg[2]) {
+	case ETM_CORE:
+		if (rvi_msg_len < 6)
+			goto runt;
+		tmcore_msg_rx();
+		return;
+	case ETM_FFS1:
+		print_etm_pkt_raw("FFS1");
+		return;
+	case ETM_FFS2:
+		if (rvi_msg_len < 5)
+			goto runt;
+		handle_ffs2_response();
+		return;
+	/* TM3 */
+	case MEM_READ:
+		if (rvi_msg_len < 5)
+			goto runt;
+		handle_omr_response();
+		return;
+	default:
+		print_etm_pkt_raw("TM unknown");
+	}
+}
+
+void
+cmd_etmpkt(argc, argv)
+	char **argv;
+{
+	u_char pkt[MAX_PKT_TO_TARGET];
+	int di, c, b;
+	char **ap;
+
+	pkt[0] = RVT_TM_HEADER;
+	di = 1;
+	c = 0;
+	for (ap = argv + 1; *ap; ap++) {
+		b = strtoul(*ap, 0, 16);
+		pkt[di++] = b;
+		c ^= b;
+	}
+	pkt[di++] = c;
+	send_pkt_to_target(pkt, di);
+}
+
+void
+send_etm_cmd(buf, len)
+	u_char *buf;
+{
+	int i, c;
+
+	buf[0] = RVT_TM_HEADER;
+	c = 0;
+	for (i = 1; i <= len; i++)
+		c ^= buf[i];
+	buf[i] = c;
+	send_pkt_to_target(buf, len + 2);
+}