blob: 277201533d4790a74aeeb6b55d90219d861e57ba [file] [log] [blame]
Joachim Steigerb1a81c12019-07-26 22:13:51 +02001/* 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 */
20#include "board.h"
21#include "simtrace.h"
22#include "utils.h"
23#include "sim_switch.h"
24#include <osmocom/core/timer.h>
25#include "usb_buf.h"
26#include "i2c.h"
27#include "mcp23017.h"
28
29void board_exec_dbg_cmd(int ch)
30{
31 switch (ch) {
32 case '?':
33 printf("\t?\thelp\n\r");
34 printf("\tR\treset SAM3\n\r");
35 break;
36 case 'R':
37 printf("Asking NVIC to reset us\n\r");
38 USBD_Disconnect();
39 NVIC_SystemReset();
40 break;
41 default:
42 printf("Unknown command '%c'\n\r", ch);
43 break;
44 }
45}
46
47void board_main_top(void)
48{
49#ifndef APPLICATION_dfu
50 usb_buf_init();
51
52 i2c_pin_init();
53 mcp23017_init(MCP23017_ADDRESS);
54 /* Initialize checking for card insert/remove events */
55 //card_present_init();
56#endif
57}
58
59int board_override_enter_dfu(void)
60{
61 const Pin bl_sw_pin = PIN_BOOTLOADER_SW;
62
63 PIO_Configure(&bl_sw_pin, 1);
64
65 /* Enter DFU bootloader in case the respective button is pressed */
66 if (PIO_Get(&bl_sw_pin) == 0) {
67 /* do not print to early since the console is not initialized yet */
68 //printf("BOOTLOADER switch pressed -> Force DFU\n\r");
69 return 1;
70 } else
71 return 0;
72}