blob: 516d5923761a7e0c8be2537259cd1ea8ae4ca48f [file] [log] [blame]
Kévin Redon9a12d682018-07-08 13:21:16 +02001/* Card simulator specific functions
Harald Welte390760a2016-02-27 16:23:46 +01002 *
Kévin Redon9a12d682018-07-08 13:21:16 +02003 * (C) 2015-2017 by Harald Welte <hwelte@hmw-consulting.de>
Kévin Redon389a4042019-11-18 20:23:20 +01004 * (C) 2018-2019, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
Harald Welte390760a2016-02-27 16:23:46 +01005 *
Kévin Redon9a12d682018-07-08 13:21:16 +02006 * 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 Welte390760a2016-02-27 16:23:46 +010010 *
Kévin Redon9a12d682018-07-08 13:21:16 +020011 * 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 Welte390760a2016-02-27 16:23:46 +010015 *
Kévin Redon9a12d682018-07-08 13:21:16 +020016 * 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 Welte390760a2016-02-27 16:23:46 +010019 */
20
21#include "chip.h"
22#include "board.h"
Harald Welted8a003d2017-02-27 20:31:09 +010023#include "utils.h"
Kévin Redon64f69fc2018-09-06 22:52:42 +020024#include "usb_buf.h"
Harald Welte390760a2016-02-27 16:23:46 +010025
26static const Pin pins_cardsim[] = PINS_CARDSIM;
27
Kévin Redon6303c392018-09-06 22:51:27 +020028void 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 Redon64f69fc2018-09-06 22:52:42 +020046void board_main_top(void)
47{
48#ifndef APPLICATION_dfu
49 usb_buf_init();
50#endif
51}
52
Harald Welte390760a2016-02-27 16:23:46 +010053void 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
64void cardsim_gpio_init(void)
65{
Harald Weltec17bf772018-08-26 09:56:42 +020066 PIO_Configure(pins_cardsim, ARRAY_SIZE(pins_cardsim));
Harald Welte390760a2016-02-27 16:23:46 +010067}
Kévin Redon389a4042019-11-18 20:23:20 +010068
69int 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}