Change in simtrace2[master]: firmware: cardem for ngff

Hoernchen gerrit-no-reply at lists.osmocom.org
Wed Jul 28 13:46:48 UTC 2021


Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/simtrace2/+/25082 )


Change subject: firmware: cardem for ngff
......................................................................

firmware: cardem for ngff

Change-Id: Ia96124fbe8a752c98e7fd4096d542a3b2b9bc255
---
M firmware/apps/cardem/main.c
M firmware/libboard/ngff_cardem/include/board.h
M firmware/libboard/ngff_cardem/source/board_ngff_cardem.c
M firmware/libboard/ngff_cardem/source/card_pres.c
M firmware/libboard/ngff_cardem/source/sim_switch.c
M firmware/libcommon/source/mode_cardemu.c
6 files changed, 86 insertions(+), 41 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/82/25082/1

diff --git a/firmware/apps/cardem/main.c b/firmware/apps/cardem/main.c
index a30a211..95967ba 100644
--- a/firmware/apps/cardem/main.c
+++ b/firmware/apps/cardem/main.c
@@ -71,8 +71,13 @@
 		.init = mode_cardemu_init,
 		.exit = mode_cardemu_exit,
 		.run = mode_cardemu_run,
+#if defined (ngff_cardem)
+		.usart0_irq = mode_cardemu_usart1_irq,
+		.usart1_irq = mode_cardemu_usart0_irq,
+#else
 		.usart0_irq = mode_cardemu_usart0_irq,
 		.usart1_irq = mode_cardemu_usart1_irq,
+#endif
 	},
 #endif
 #ifdef HAVE_MITM
diff --git a/firmware/libboard/ngff_cardem/include/board.h b/firmware/libboard/ngff_cardem/include/board.h
index 8520d6b..bdedcf3 100644
--- a/firmware/libboard/ngff_cardem/include/board.h
+++ b/firmware/libboard/ngff_cardem/include/board.h
@@ -68,7 +68,7 @@
 #define PINS_TC_USIM1		PIN_USIM1_IO_TC, PIN_USIM1_CLK_TC
 
 #define PIN_USIM1_nRST		{PIO_PA24, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
-#define PIN_USIM1_VCC		{PIO_PB2, PIOB, ID_PIOB, PIO_INPUT, PIO_DEFAULT}
+#define PIN_USIM1_VCC		{PIO_PB3, PIOB, ID_PIOB, PIO_INPUT, PIO_DEFAULT}
 
 #define PIN_USIM2_nRST		{PIO_PA7, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
 //#define PIN_USIM2_VCC		{PIO_PB2, PIOB, ID_PIOB, PIO_INPUT, PIO_DEFAULT}
@@ -77,14 +77,17 @@
 #define PINS_USIM2		PINS_TC_USIM2, PINS_ISO7816_USIM2, PIN_USIM2_nRST
 
 /* from v3 and onwards only (!) */
-#define PIN_DET_USIM1_PRES	{PIO_PA8, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP | PIO_DEGLITCH | PIO_IT_EDGE}
+#define PIN_DET_USIM1_PRES	{PIO_PA8, PIOA, ID_PIOA, PIO_INPUT, PIO_DEGLITCH | PIO_IT_EDGE}
 
 /* inputs reading the WWAN LED level */
 #define PIN_WWAN1		{PIO_PA15, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP | PIO_DEGLITCH | PIO_IT_EDGE}
 #define PINS_WWAN_IN		{ PIN_WWAN1 }
 
+#define PIN_MODEM_EN {PIO_PA11, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
+#define PIN_N_MODEM_PWR_ON {PIO_PA26, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
+
 /* outputs controlling RESET input of modems */
-#define PIN_PERST1		{PIO_PA25, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_PULLUP}
+#define PIN_PERST1		{PIO_PA25, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
 #define PINS_PERST		{ PIN_PERST1 }
 
 #define PIN_VERSION_DET		{PIO_PA19, PIOA, ID_PIOA, PIO_PERIPH_D, PIO_DEFAULT}
@@ -102,6 +105,9 @@
 
 #define DETECT_VCC_BY_ADC
 #define VCC_UV_THRESH_1V8	1500000
-#define VCC_UV_THRESH_3V	2500000
+#define VCC_UV_THRESH_3V	VCC_UV_THRESH_1V8
 
 #define HAVE_CARDEM
+#define HAVE_BOARD_CARDINSERT
+struct cardem_inst;
+void board_set_card_insert(struct cardem_inst *ci, bool card_insert);
\ No newline at end of file
diff --git a/firmware/libboard/ngff_cardem/source/board_ngff_cardem.c b/firmware/libboard/ngff_cardem/source/board_ngff_cardem.c
index 742ec55..6bfe997 100644
--- a/firmware/libboard/ngff_cardem/source/board_ngff_cardem.c
+++ b/firmware/libboard/ngff_cardem/source/board_ngff_cardem.c
@@ -101,6 +101,7 @@
 	/* Initialize checking for card insert/remove events */
 	card_present_init();
 #endif
+	wwan_perst_set(0, 0);
 }
 
 static int uart_has_loopback_jumper(void)
@@ -150,3 +151,11 @@
 
 	return 0;
 }
+
+ static const Pin deton = {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
+ static const Pin detoff = {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT};
+
+void board_set_card_insert(struct cardem_inst *ci, bool card_insert)
+{
+	PIO_Configure(card_insert ? &deton : &detoff, 1);
+}
\ No newline at end of file
diff --git a/firmware/libboard/ngff_cardem/source/card_pres.c b/firmware/libboard/ngff_cardem/source/card_pres.c
index 198318f..7d6c483 100644
--- a/firmware/libboard/ngff_cardem/source/card_pres.c
+++ b/firmware/libboard/ngff_cardem/source/card_pres.c
@@ -39,9 +39,9 @@
 		return -1;
 	pin = &pin_cardpres[port];
 
-	/* Card present signals are low-active, as we have a switch
-	 * against GND and an internal-pull-up in the SAM3 */
-	present = PIO_Get(pin) ? 0 : 1;
+
+	/* high active here */
+	present = PIO_Get(pin);
 
 	return present;
 }
diff --git a/firmware/libboard/ngff_cardem/source/sim_switch.c b/firmware/libboard/ngff_cardem/source/sim_switch.c
index 59513ad..3961747 100644
--- a/firmware/libboard/ngff_cardem/source/sim_switch.c
+++ b/firmware/libboard/ngff_cardem/source/sim_switch.c
@@ -21,18 +21,41 @@
 #include "led.h"
 #include "sim_switch.h"
 
-#ifdef PIN_SIM_SWITCH1
-static const Pin pin_conn_usim1 = {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
-#endif
-#ifdef PIN_SIM_SWITCH2
-static const Pin pin_conn_usim2 = {PIO_PA28, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
-#endif
+//uart12bus	2-20e pa20
+//uart22bus	1-20e pa28
+//usim2bus	1-10e pa0  pivot
+//sim det	2-10e pa13
+
+
+//default state: NO uart connected, modem connected to physical sim, NO sim presence override, modem powers sim slot
+#define pin_conn_usim1_default {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
+#define pin_conn_usim2_default {PIO_PA28, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
+#define pin_conn_mdm_sim_default {PIO_PA0, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
+#define pin_conn_set_sim_det_default {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
+#define pin_en_st_sim_vdd_default {PIO_PB2, PIOB, ID_PIOB, PIO_OUTPUT_0, PIO_DEFAULT}
+#define pin_en_mdm_sim_vdd_default {PIO_PA16, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
+
+//default state: uart2 (!) connected, NO modem connected to physical sim, sim presence override, NOTHING powers sim slot
+#define pin_conn_usim1_cem {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
+#define pin_conn_usim2_cem {PIO_PA28, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
+#define pin_conn_mdm_sim_cem {PIO_PA0, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
+#define pin_en_st_sim_vdd_cem {PIO_PB2, PIOB, ID_PIOB, PIO_OUTPUT_0, PIO_DEFAULT}
+#define pin_en_mdm_sim_vdd_cem {PIO_PA16, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
+
+//#define pin_conn_set_sim_det_cem {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
+
+
+#define INIT_SIM_DEFAULT pin_conn_usim1_default, pin_conn_usim2_default, pin_conn_mdm_sim_default, pin_conn_set_sim_det_default, PIN_N_MODEM_PWR_ON, PIN_MODEM_EN, pin_en_st_sim_vdd_default, pin_en_mdm_sim_vdd_default
+#define INIT_SIM_CEM pin_conn_usim1_cem, pin_conn_usim2_cem, pin_conn_mdm_sim_cem, pin_en_mdm_sim_vdd_cem, pin_en_st_sim_vdd_cem// , pin_conn_set_sim_det_cem
+
+static const Pin pins_default[]	= {INIT_SIM_DEFAULT};
+static const Pin pins_cem[]	= {INIT_SIM_CEM};
 
 static int initialized = 0;
 
 int sim_switch_use_physical(unsigned int nr, int physical)
 {
-	const Pin *pin;
+	const Pin pin = PIN_MODEM_EN;// PIN_N_MODEM_PWR_ON;
 	enum led led;
 
 	if (!initialized) {
@@ -44,18 +67,10 @@
 		   physical ? "physical" : "virtual");
 
 	switch (nr) {
-#ifdef PIN_SIM_SWITCH1
 	case 0:
-		pin = &pin_conn_usim1;
 		led = LED_USIM1;
 		break;
-#endif
-#ifdef PIN_SIM_SWITCH2
-	case 1:
-		pin = &pin_conn_usim2;
-		led = LED_USIM2;
-		break;
-#endif
+
 	default:
 		TRACE_ERROR("Invalid SIM%u\n\r", nr);
 		return -1;
@@ -63,28 +78,26 @@
 
 	if (physical) {
 		TRACE_INFO("%u: Use local/physical SIM\r\n", nr);
-		PIO_Clear(pin);
+		PIO_Configure(pins_default, PIO_LISTSIZE(pins_default));
 		led_blink(led, BLINK_ALWAYS_ON);
 	} else {
 		TRACE_INFO("%u: Use remote/emulated SIM\r\n", nr);
-		PIO_Set(pin);
+		PIO_Configure(pins_cem, PIO_LISTSIZE(pins_cem));
 		led_blink(led, BLINK_ALWAYS_OFF);
 	}
 
+	/* just power cycle the modem because this circumvents weird issues with unreliable signals */
+	PIO_Clear(&pin);
+	mdelay(200);
+	PIO_Set(&pin);
+
+
 	return 0;
 }
 
 int sim_switch_init(void)
 {
-	int num_switch = 0;
-#ifdef PIN_SIM_SWITCH1
-	PIO_Configure(&pin_conn_usim1, 1);
-	num_switch++;
-#endif
-#ifdef PIN_SIM_SWITCH2
-	PIO_Configure(&pin_conn_usim2, 1);
-	num_switch++;
-#endif
+	PIO_Configure(pins_default, PIO_LISTSIZE(pins_default));
 	initialized = 1;
-	return num_switch;
+	return 1;
 }
diff --git a/firmware/libcommon/source/mode_cardemu.c b/firmware/libcommon/source/mode_cardemu.c
index 2440ec5..4a0b862 100644
--- a/firmware/libcommon/source/mode_cardemu.c
+++ b/firmware/libcommon/source/mode_cardemu.c
@@ -39,9 +39,21 @@
 #endif
 
 /* UART pins */
+#if defined(ngff_cardem)
+static const Pin pins_usim1[]	= {PINS_USIM2};
+static const Pin pin_usim1_rst	= PIN_USIM2_nRST;
+#define FIRST_USART_BASE USART0
+#define FIRST_USART_ID ID_USART0
+#define FIRST_USART_IRQ USART0_IRQn
+#else
 static const Pin pins_usim1[]	= {PINS_USIM1};
 static const Pin pin_usim1_rst	= PIN_USIM1_nRST;
+#define FIRST_USART_BASE USART1
+#define FIRST_USART_ID ID_USART1
+#define FIRST_USART_IRQ USART1_IRQn
+#endif
 static const Pin pin_usim1_vcc	= PIN_USIM1_VCC;
+
 #ifdef PIN_USIM1_IO_DIR
 static const Pin pin_io_dir 	= PIN_USIM1_IO_DIR;
 #endif
@@ -85,8 +97,8 @@
 	{
 		.num = 0,
 		.usart_info = 	{
-			.base = USART1,
-			.id = ID_USART1,
+			.base = FIRST_USART_BASE,
+			.id = FIRST_USART_ID,
 			.state = USART_RCV
 		},
 		.ep_out = SIMTRACE_CARDEM_USB_EP_USIM1_DATAOUT,
@@ -569,7 +581,7 @@
 
 	/* configure USART as ISO-7816 slave (e.g. card) */
 	ISO7816_Init(&cardem_inst[0].usart_info, CLK_SLAVE);
-	NVIC_EnableIRQ(USART1_IRQn);
+	NVIC_EnableIRQ(FIRST_USART_IRQ);
 	PIO_ConfigureIt(&pin_usim1_rst, usim1_rst_irqhandler);
 	PIO_EnableIt(&pin_usim1_rst);
 
@@ -627,9 +639,9 @@
 	PIO_DisableIt(&pin_usim1_rst);
 	PIO_DisableIt(&pin_usim1_vcc);
 
-	NVIC_DisableIRQ(USART1_IRQn);
-	USART_SetTransmitterEnabled(USART1, 0);
-	USART_SetReceiverEnabled(USART1, 0);
+	NVIC_DisableIRQ(FIRST_USART_IRQ);
+	USART_SetTransmitterEnabled(FIRST_USART_BASE, 0);
+	USART_SetReceiverEnabled(FIRST_USART_BASE, 0);
 
 #ifdef CARDEMU_SECOND_UART
 	PIO_DisableIt(&pin_usim2_rst);

-- 
To view, visit https://gerrit.osmocom.org/c/simtrace2/+/25082
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-Change-Id: Ia96124fbe8a752c98e7fd4096d542a3b2b9bc255
Gerrit-Change-Number: 25082
Gerrit-PatchSet: 1
Gerrit-Owner: Hoernchen <ewild at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210728/e5621579/attachment.htm>


More information about the gerrit-log mailing list