aboutsummaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-06-02 15:43:08 +0200
committerHarald Welte <laforge@osmocom.org>2021-06-02 22:56:12 +0200
commit31d103b9f6bfdcf6460744df9e3deef3aa6db00e (patch)
treea3d1523b276a1f03c27a0829d228d111e5a827bf /firmware
parent73466e2b89c32774750b278d7f7147a85e806ff4 (diff)
octsimtest: most code for support of this new board
* code for controlling the Card slot + frequencyt divider muxes * put everything in place to build cardem application for it Change-Id: I7e03e0c0f2999a1ce2dad966d98e22033fa58465
Diffstat (limited to 'firmware')
-rw-r--r--firmware/libboard/octsimtest/include/board.h6
-rw-r--r--firmware/libboard/octsimtest/include/mux.h16
-rw-r--r--firmware/libboard/octsimtest/source/board_octsimtest.c11
-rw-r--r--firmware/libboard/octsimtest/source/mux.c99
-rw-r--r--firmware/libboard/octsimtest/source/sim_switch.c37
5 files changed, 167 insertions, 2 deletions
diff --git a/firmware/libboard/octsimtest/include/board.h b/firmware/libboard/octsimtest/include/board.h
index a267f0f..6006796 100644
--- a/firmware/libboard/octsimtest/include/board.h
+++ b/firmware/libboard/octsimtest/include/board.h
@@ -57,7 +57,7 @@
/* Phone USIM slot 1 VCC pin (VCC_PHONE in schematic) */
#define PIN_USIM1_VCC {PIO_PA25, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
/* Phone USIM slot 1 RST pin (active low; RST_PHONE in schematic) */
-#define PIN_USIM1_nRST {PIO_PA24, PIOA, ID_PIOA, PIO_INPUT, PIO_IT_RISE_EDGE | PIO_DEGLITCH }
+#define PIN_USIM1_nRST {PIO_PA24, PIOA, ID_PIOA, PIO_INPUT, PIO_IT_EDGE | PIO_DEGLITCH }
/* Phone I/O data signal input/output (I/O_PHONE in schematic) */
#define PIN_PHONE_IO {PIO_PA22A_TXD1, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
/* Phone CLK clock input (CLK_PHONE in schematic) */
@@ -102,13 +102,15 @@
/* Indicate SIMtrace is bus power in USB attributes */
#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
+#define DETECT_VCC_BY_ADC
+
/** Supported modes */
/* SIMtrace board supports sniffer mode */
//#define HAVE_SNIFFER
/* SIMtrace board supports CCID mode */
//#define HAVE_CCID
/* SIMtrace board supports card emulation mode */
-//#define HAVE_CARDEM
+#define HAVE_CARDEM
/* SIMtrace board supports man-in-the-middle mode */
//#define HAVE_MITM
/* octsimtest board supports gpio_test mode */
diff --git a/firmware/libboard/octsimtest/include/mux.h b/firmware/libboard/octsimtest/include/mux.h
new file mode 100644
index 0000000..ba7ae9f
--- /dev/null
+++ b/firmware/libboard/octsimtest/include/mux.h
@@ -0,0 +1,16 @@
+#pragma once
+
+void mux_init(void);
+void mux_set_slot(uint8_t s);
+void mux_set_freq(uint8_t s);
+
+/* this reflects the wiring between U5 and U4 */
+#define MUX_FREQ_DIV_2 0
+#define MUX_FREQ_DIV_4 1
+#define MUX_FREQ_DIV_16 2
+#define MUX_FREQ_DIV_32 3
+#define MUX_FREQ_DIV_32 3
+#define MUX_FREQ_DIV_128 4
+#define MUX_FREQ_DIV_512 5
+#define MUX_FREQ_DIV_2048 6
+#define MUX_FREQ_DIV_4096 7
diff --git a/firmware/libboard/octsimtest/source/board_octsimtest.c b/firmware/libboard/octsimtest/source/board_octsimtest.c
index b7d7245..85d8aab 100644
--- a/firmware/libboard/octsimtest/source/board_octsimtest.c
+++ b/firmware/libboard/octsimtest/source/board_octsimtest.c
@@ -25,6 +25,7 @@
#include "usb_buf.h"
#include "i2c.h"
#include "mcp23017.h"
+#include "mux.h"
void board_exec_dbg_cmd(int ch)
{
@@ -34,7 +35,16 @@ void board_exec_dbg_cmd(int ch)
printf("\tR\treset SAM3\n\r");
printf("\tm\trun mcp23017 test\n\r");
printf("\tR\ttoggle MSB of gpio on mcp23017\n\r");
+ printf("\t0-8\tselect physical SIM slot\n\r");
break;
+ case '0': mux_set_slot(0); break;
+ case '1': mux_set_slot(1); break;
+ case '2': mux_set_slot(2); break;
+ case '3': mux_set_slot(3); break;
+ case '4': mux_set_slot(4); break;
+ case '5': mux_set_slot(5); break;
+ case '6': mux_set_slot(6); break;
+ case '7': mux_set_slot(7); break;
case 'R':
printf("Asking NVIC to reset us\n\r");
USBD_Disconnect();
@@ -57,6 +67,7 @@ void board_main_top(void)
#ifndef APPLICATION_dfu
usb_buf_init();
+ mux_init();
i2c_pin_init();
if (!mcp23017_init(MCP23017_ADDRESS))
printf("mcp23017 not found!\n\r");
diff --git a/firmware/libboard/octsimtest/source/mux.c b/firmware/libboard/octsimtest/source/mux.c
new file mode 100644
index 0000000..8d9f625
--- /dev/null
+++ b/firmware/libboard/octsimtest/source/mux.c
@@ -0,0 +1,99 @@
+/* sysmoOCTSIMTEST support for multiplexers
+ *
+ * (C) 2021 by Harald Welte <laforge@gnumonks.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include "board.h"
+#include "mux.h"
+#include <stdbool.h>
+
+/* 3-bit S0..S2 signal for slot selection */
+static const Pin pin_in_sel[3] = {
+ { PIO_PA1, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT },
+ { PIO_PA2, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT },
+ { PIO_PA3, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT },
+};
+
+/* 3-bit S0..S2 signal for frequency divider selection */
+static const Pin pin_freq_sel[3] = {
+ { PIO_PA16, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT },
+ { PIO_PA17, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT },
+ { PIO_PA18, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT },
+};
+
+/* low-active output enable for all muxes */
+static const Pin pin_oe = { PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT };
+
+/* initialize the external 1:8 multiplexers */
+void mux_init(void)
+{
+ PIO_Configure(&pin_oe, PIO_LISTSIZE(pin_oe));
+ PIO_Configure(pin_in_sel, PIO_LISTSIZE(pin_in_sel));
+ PIO_Configure(pin_freq_sel, PIO_LISTSIZE(pin_freq_sel));
+
+ mux_set_slot(0);
+}
+
+/* set the slot selection mux */
+void mux_set_slot(uint8_t s)
+{
+ printf("%s(%u)\r\n", __func__, s);
+
+ /* !OE = H: disconnect input and output of muxes */
+ PIO_Set(&pin_oe);
+
+ if (s & 1)
+ PIO_Set(&pin_in_sel[0]);
+ else
+ PIO_Clear(&pin_in_sel[0]);
+ if (s & 2)
+ PIO_Set(&pin_in_sel[1]);
+ else
+ PIO_Clear(&pin_in_sel[1]);
+ if (s & 4)
+ PIO_Set(&pin_in_sel[2]);
+ else
+ PIO_Clear(&pin_in_sel[2]);
+
+ /* !OE = L: (re-)enable the output of muxes */
+ PIO_Clear(&pin_oe);
+}
+
+/* set the frequency divider mux */
+void mux_set_freq(uint8_t s)
+{
+ printf("%s(%u)\r\n", __func__, s);
+
+ /* no need for 'break before make' here, this would also affect
+ * the SIM card I/O signals which we don't want to disturb */
+
+ if (s & 1)
+ PIO_Set(&pin_freq_sel[0]);
+ else
+ PIO_Clear(&pin_freq_sel[0]);
+ if (s & 2)
+ PIO_Set(&pin_freq_sel[1]);
+ else
+ PIO_Clear(&pin_freq_sel[1]);
+ if (s & 4)
+ PIO_Set(&pin_freq_sel[2]);
+ else
+ PIO_Clear(&pin_freq_sel[2]);
+
+ /* !OE = L: ensure enable the output of muxes */
+ PIO_Clear(&pin_oe);
+}
diff --git a/firmware/libboard/octsimtest/source/sim_switch.c b/firmware/libboard/octsimtest/source/sim_switch.c
new file mode 100644
index 0000000..2b60a30
--- /dev/null
+++ b/firmware/libboard/octsimtest/source/sim_switch.c
@@ -0,0 +1,37 @@
+/* Code to switch between local (physical) and remote (emulated) SIM
+ *
+ * (C) 2021 by Harald Welte <hwelte@hmw-consulting.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
+ */
+#include "board.h"
+#include "trace.h"
+#include "sim_switch.h"
+
+int sim_switch_use_physical(unsigned int nr, int physical)
+{
+ if (physical) {
+ TRACE_ERROR("%u: Use local/physical SIM - UNSUPPORTED!\r\n", nr);
+ } else {
+ TRACE_INFO("%u: Use remote/emulated SIM\r\n", nr);
+ }
+
+ return 0;
+}
+
+int sim_switch_init(void)
+{
+ return 1; // SIMtrace hardware has only one switchable interface
+}