From 2819e9c131258132f4647da2128adcfb11a739b1 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 3 Feb 2017 07:46:01 +0100 Subject: [PATCH] wwan_led: Read + report status changes of WWAN LED inputs --- firmware/Makefile | 2 +- firmware/include_board/qmod/board.h | 5 ++ firmware/src_simtrace/main.c | 3 ++ firmware/src_simtrace/wwan_led.c | 80 +++++++++++++++++++++++++++++ firmware/src_simtrace/wwan_led.h | 4 ++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 firmware/src_simtrace/wwan_led.c create mode 100644 firmware/src_simtrace/wwan_led.h diff --git a/firmware/Makefile b/firmware/Makefile index 13766e98..d7a55866 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -147,7 +147,7 @@ C_CMSIS = core_cm3.o C_LOWLEVEL = board_cstartup_gnu.o board_lowlevel.o syscalls.o exceptions.o C_LIBLEVEL = spi.o pio.o pmc.o usart.o pio_it.o pio_capture.o uart_console.o iso7816_4.o wdt.o led.o tc.o unique_id.o C_CCID = cciddriver.o USBD.o USBDDriver.o USBD_HAL.o USBRequests.o USBDCallbacks.o USBDescriptors.o USBDDriverCallbacks.o -C_SIMTRACE = simtrace_iso7816.o usb.o ccid.o sniffer.o mitm.o ringbuffer.o host_communication.o iso7816_fidi.o tc_etu.o req_ctx.o card_emu.o mode_cardemu.o i2c.o +C_SIMTRACE = simtrace_iso7816.o usb.o ccid.o sniffer.o mitm.o ringbuffer.o host_communication.o iso7816_fidi.o tc_etu.o req_ctx.o card_emu.o mode_cardemu.o i2c.o wwan_led.o C_APPLEVEL = main.o C_OBJECTS = $(C_CMSIS) $(C_LOWLEVEL) $(C_LIBLEVEL) $(C_APPLEVEL) $(C_CCID) $(C_SIMTRACE) diff --git a/firmware/include_board/qmod/board.h b/firmware/include_board/qmod/board.h index 13602024..5b5c751e 100644 --- a/firmware/include_board/qmod/board.h +++ b/firmware/include_board/qmod/board.h @@ -43,6 +43,11 @@ #define PIN_PRTPWR_OVERRIDE {PIO_PA8, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} +/* inputs reading the WWAN LED level */ +#define PIN_WWAN1 {PIO_PA15, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP | PIO_DEGLITCH | PIO_IT_EDGE} +#define PIN_WWAN2 {PIO_PA16, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP | PIO_DEGLITCH | PIO_IT_EDGE} +#define PINS_WWAN_IN { PIN_WWAN1, PIN_WWAN2 } + #define SIMTRACE_VENDOR_ID 0x1d50 #define SIMTRACE_PRODUCT_ID 0x60e3 /* FIXME */ #define USB_VENDOR_ID SIMTRACE_VENDOR_ID diff --git a/firmware/src_simtrace/main.c b/firmware/src_simtrace/main.c index c33cfeaa..412b1ce1 100644 --- a/firmware/src_simtrace/main.c +++ b/firmware/src_simtrace/main.c @@ -7,6 +7,7 @@ #include "simtrace.h" #include "utils.h" #include "req_ctx.h" +#include "wwan_led.h" uint32_t g_unique_id[4]; @@ -278,6 +279,8 @@ extern int main(void) PIO_InitializeInterrupts(0); + wwan_led_init(); + EEFC_ReadUniqueID(g_unique_id); printf("\r\n\r\n" diff --git a/firmware/src_simtrace/wwan_led.c b/firmware/src_simtrace/wwan_led.c new file mode 100644 index 00000000..3bae0ff8 --- /dev/null +++ b/firmware/src_simtrace/wwan_led.c @@ -0,0 +1,80 @@ +/* Code to read/track the status of the WWAN LEDs of attached modems + * + * Depending on the board this is running on, it might be possible + * for the controller to read the status of the WWAN LED output lines of + * the cellular modem. If the board supports this, it sets the + * PIN_WWAN1 and/or PIN_WWAN2 defines in its board.h file. + */ + +#include "board.h" +#include "wwan_led.h" + +#ifdef PIN_WWAN1 +static const Pin pin_wwan1 = PIN_WWAN1; + +static void wwan1_irqhandler(const Pin *pPin) +{ + int active = wwan_led_active(1); + + TRACE_INFO("WWAN1 LED %u\r\n", active); + + /* TODO: notify host via USB */ +} +#endif + +#ifdef PIN_WWAN2 +static const Pin pin_wwan2 = PIN_WWAN2; + +static void wwan2_irqhandler(const Pin *pPin) +{ + int active = wwan_led_active(2); + TRACE_INFO("WWAN2 LED %u\r\n", active); + + /* TODO: notify host via USB */ +} +#endif + +/* determine if a tiven WWAN led is currently active or not */ +int wwan_led_active(int wwan) +{ + const Pin *pin; + int active; + + switch (wwan) { +#ifdef PIN_WWAN1 + case 1: + pin = &pin_wwan1; + break; +#endif +#ifdef PIN_WWAN2 + case 2: + pin = &pin_wwan2; + break; +#endif + default: + return -1; + } + + active = PIO_Get(&pin_wwan1) ? 0 : 1; + return active; +} + +int wwan_led_init(void) +{ + int num_leds = 0; + +#ifdef PIN_WWAN1 + PIO_Configure(&pin_wwan1, 1); + PIO_ConfigureIt(&pin_wwan1, wwan1_irqhandler); + PIO_EnableIt(&pin_wwan1); + num_leds++; +#endif + +#ifdef PIN_WWAN2 + PIO_Configure(&pin_wwan2, 1); + PIO_ConfigureIt(&pin_wwan2, wwan2_irqhandler); + PIO_EnableIt(&pin_wwan2); + num_leds++; +#endif + return num_leds; +} diff --git a/firmware/src_simtrace/wwan_led.h b/firmware/src_simtrace/wwan_led.h new file mode 100644 index 00000000..7ba72ea9 --- /dev/null +++ b/firmware/src_simtrace/wwan_led.h @@ -0,0 +1,4 @@ +#pragma once + +int wwan_led_active(int wwan); +int wwan_led_init(void);