Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 1 | /* Card simulator specific functions |
Harald Welte | 390760a | 2016-02-27 16:23:46 +0100 | [diff] [blame] | 2 | * |
Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 3 | * (C) 2015-2017 by Harald Welte <hwelte@hmw-consulting.de> |
Kévin Redon | 389a404 | 2019-11-18 20:23:20 +0100 | [diff] [blame] | 4 | * (C) 2018-2019, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de> |
Harald Welte | 390760a | 2016-02-27 16:23:46 +0100 | [diff] [blame] | 5 | * |
Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 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. |
Harald Welte | 390760a | 2016-02-27 16:23:46 +0100 | [diff] [blame] | 10 | * |
Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 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. |
Harald Welte | 390760a | 2016-02-27 16:23:46 +0100 | [diff] [blame] | 15 | * |
Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 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 |
Harald Welte | 390760a | 2016-02-27 16:23:46 +0100 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "chip.h" |
| 22 | #include "board.h" |
Harald Welte | d8a003d | 2017-02-27 20:31:09 +0100 | [diff] [blame] | 23 | #include "utils.h" |
Kévin Redon | 64f69fc | 2018-09-06 22:52:42 +0200 | [diff] [blame] | 24 | #include "usb_buf.h" |
Harald Welte | 390760a | 2016-02-27 16:23:46 +0100 | [diff] [blame] | 25 | |
| 26 | static const Pin pins_cardsim[] = PINS_CARDSIM; |
| 27 | |
Kévin Redon | 6303c39 | 2018-09-06 22:51:27 +0200 | [diff] [blame] | 28 | void board_exec_dbg_cmd(int ch) |
| 29 | { |
| 30 | switch (ch) { |
| 31 | case '?': |
| 32 | printf("\t?\thelp\n\r"); |
| 33 | printf("\tR\treset SAM3\n\r"); |
| 34 | break; |
| 35 | case 'R': |
| 36 | printf("Asking NVIC to reset us\n\r"); |
| 37 | USBD_Disconnect(); |
| 38 | NVIC_SystemReset(); |
| 39 | break; |
| 40 | default: |
| 41 | printf("Unknown command '%c'\n\r", ch); |
| 42 | break; |
| 43 | } |
| 44 | } |
| 45 | |
Kévin Redon | 64f69fc | 2018-09-06 22:52:42 +0200 | [diff] [blame] | 46 | void board_main_top(void) |
| 47 | { |
| 48 | #ifndef APPLICATION_dfu |
| 49 | usb_buf_init(); |
| 50 | #endif |
| 51 | } |
| 52 | |
Harald Welte | 390760a | 2016-02-27 16:23:46 +0100 | [diff] [blame] | 53 | void cardsim_set_simpres(uint8_t slot, int present) |
| 54 | { |
| 55 | if (slot > 1) |
| 56 | return; |
| 57 | |
| 58 | if (present) |
| 59 | PIO_Set(&pins_cardsim[slot]); |
| 60 | else |
| 61 | PIO_Clear(&pins_cardsim[slot]); |
| 62 | } |
| 63 | |
| 64 | void cardsim_gpio_init(void) |
| 65 | { |
Harald Welte | c17bf77 | 2018-08-26 09:56:42 +0200 | [diff] [blame] | 66 | PIO_Configure(pins_cardsim, ARRAY_SIZE(pins_cardsim)); |
Harald Welte | 390760a | 2016-02-27 16:23:46 +0100 | [diff] [blame] | 67 | } |
Kévin Redon | 389a404 | 2019-11-18 20:23:20 +0100 | [diff] [blame] | 68 | |
| 69 | int board_override_enter_dfu(void) |
| 70 | { |
| 71 | const Pin bl_pin = PIN_BOOTLOADER; |
| 72 | |
| 73 | PIO_Configure(&bl_pin, 1); |
| 74 | |
| 75 | if (PIO_Get(&bl_pin) == 0) { // signal low |
| 76 | return 0; // do not override enter DFU |
| 77 | } else { |
| 78 | return 1; // override enter DFU |
| 79 | } |
| 80 | } |