Joachim Steiger | b1a81c1 | 2019-07-26 22:13:51 +0200 | [diff] [blame] | 1 | /* SIMtrace with SAM3S specific application code |
| 2 | * |
| 3 | * (C) 2017 by Harald Welte <laforge@gnumonks.org> |
| 4 | * (C) 2018 by sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
| 19 | */ |
Harald Welte | dd5794c | 2021-06-03 13:19:46 +0200 | [diff] [blame^] | 20 | #include <stdbool.h> |
Joachim Steiger | b1a81c1 | 2019-07-26 22:13:51 +0200 | [diff] [blame] | 21 | #include "board.h" |
| 22 | #include "simtrace.h" |
| 23 | #include "utils.h" |
| 24 | #include "sim_switch.h" |
| 25 | #include <osmocom/core/timer.h> |
| 26 | #include "usb_buf.h" |
| 27 | #include "i2c.h" |
| 28 | #include "mcp23017.h" |
Harald Welte | 31d103b | 2021-06-02 15:43:08 +0200 | [diff] [blame] | 29 | #include "mux.h" |
Joachim Steiger | b1a81c1 | 2019-07-26 22:13:51 +0200 | [diff] [blame] | 30 | |
Harald Welte | dd5794c | 2021-06-03 13:19:46 +0200 | [diff] [blame^] | 31 | static bool mcp2317_present = false; |
| 32 | |
Joachim Steiger | b1a81c1 | 2019-07-26 22:13:51 +0200 | [diff] [blame] | 33 | void board_exec_dbg_cmd(int ch) |
| 34 | { |
| 35 | switch (ch) { |
| 36 | case '?': |
| 37 | printf("\t?\thelp\n\r"); |
| 38 | printf("\tR\treset SAM3\n\r"); |
Joachim Steiger | f7f1ea8 | 2019-10-24 18:09:05 +0200 | [diff] [blame] | 39 | printf("\tm\trun mcp23017 test\n\r"); |
| 40 | printf("\tR\ttoggle MSB of gpio on mcp23017\n\r"); |
Harald Welte | 31d103b | 2021-06-02 15:43:08 +0200 | [diff] [blame] | 41 | printf("\t0-8\tselect physical SIM slot\n\r"); |
Joachim Steiger | b1a81c1 | 2019-07-26 22:13:51 +0200 | [diff] [blame] | 42 | break; |
Harald Welte | 31d103b | 2021-06-02 15:43:08 +0200 | [diff] [blame] | 43 | case '0': mux_set_slot(0); break; |
| 44 | case '1': mux_set_slot(1); break; |
| 45 | case '2': mux_set_slot(2); break; |
| 46 | case '3': mux_set_slot(3); break; |
| 47 | case '4': mux_set_slot(4); break; |
| 48 | case '5': mux_set_slot(5); break; |
| 49 | case '6': mux_set_slot(6); break; |
| 50 | case '7': mux_set_slot(7); break; |
Joachim Steiger | b1a81c1 | 2019-07-26 22:13:51 +0200 | [diff] [blame] | 51 | case 'R': |
| 52 | printf("Asking NVIC to reset us\n\r"); |
| 53 | USBD_Disconnect(); |
| 54 | NVIC_SystemReset(); |
| 55 | break; |
Joachim Steiger | f7f1ea8 | 2019-10-24 18:09:05 +0200 | [diff] [blame] | 56 | case 'm': |
| 57 | mcp23017_test(MCP23017_ADDRESS); |
| 58 | break; |
| 59 | case 't': |
| 60 | mcp23017_toggle(MCP23017_ADDRESS); |
| 61 | break; |
Joachim Steiger | b1a81c1 | 2019-07-26 22:13:51 +0200 | [diff] [blame] | 62 | default: |
| 63 | printf("Unknown command '%c'\n\r", ch); |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | void board_main_top(void) |
| 69 | { |
| 70 | #ifndef APPLICATION_dfu |
| 71 | usb_buf_init(); |
| 72 | |
Harald Welte | 31d103b | 2021-06-02 15:43:08 +0200 | [diff] [blame] | 73 | mux_init(); |
Joachim Steiger | b1a81c1 | 2019-07-26 22:13:51 +0200 | [diff] [blame] | 74 | i2c_pin_init(); |
Harald Welte | dd5794c | 2021-06-03 13:19:46 +0200 | [diff] [blame^] | 75 | /* PORT A: all outputs, Port B0 output, B1..B7 unused */ |
| 76 | if (mcp23017_init(MCP23017_ADDRESS, 0x00, 0xfe) == 0) |
| 77 | mcp2317_present = true; |
Joachim Steiger | b1a81c1 | 2019-07-26 22:13:51 +0200 | [diff] [blame] | 78 | /* Initialize checking for card insert/remove events */ |
| 79 | //card_present_init(); |
| 80 | #endif |
| 81 | } |
| 82 | |
| 83 | int board_override_enter_dfu(void) |
| 84 | { |
| 85 | const Pin bl_sw_pin = PIN_BOOTLOADER_SW; |
| 86 | |
| 87 | PIO_Configure(&bl_sw_pin, 1); |
| 88 | |
| 89 | /* Enter DFU bootloader in case the respective button is pressed */ |
| 90 | if (PIO_Get(&bl_sw_pin) == 0) { |
| 91 | /* do not print to early since the console is not initialized yet */ |
| 92 | //printf("BOOTLOADER switch pressed -> Force DFU\n\r"); |
| 93 | return 1; |
| 94 | } else |
| 95 | return 0; |
| 96 | } |