blob: 404bef6e8523c7166bfc15ebc975f05e30e40018 [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 */
Harald Weltedd5794c2021-06-03 13:19:46 +020020#include <stdbool.h>
Joachim Steigerb1a81c12019-07-26 22:13:51 +020021#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 Welte31d103b2021-06-02 15:43:08 +020029#include "mux.h"
Joachim Steigerb1a81c12019-07-26 22:13:51 +020030
Harald Weltedd5794c2021-06-03 13:19:46 +020031static bool mcp2317_present = false;
32
Joachim Steigerb1a81c12019-07-26 22:13:51 +020033void 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 Steigerf7f1ea82019-10-24 18:09:05 +020039 printf("\tm\trun mcp23017 test\n\r");
40 printf("\tR\ttoggle MSB of gpio on mcp23017\n\r");
Harald Welte31d103b2021-06-02 15:43:08 +020041 printf("\t0-8\tselect physical SIM slot\n\r");
Joachim Steigerb1a81c12019-07-26 22:13:51 +020042 break;
Harald Welte31d103b2021-06-02 15:43:08 +020043 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 Steigerb1a81c12019-07-26 22:13:51 +020051 case 'R':
52 printf("Asking NVIC to reset us\n\r");
53 USBD_Disconnect();
54 NVIC_SystemReset();
55 break;
Joachim Steigerf7f1ea82019-10-24 18:09:05 +020056 case 'm':
57 mcp23017_test(MCP23017_ADDRESS);
58 break;
59 case 't':
60 mcp23017_toggle(MCP23017_ADDRESS);
61 break;
Joachim Steigerb1a81c12019-07-26 22:13:51 +020062 default:
63 printf("Unknown command '%c'\n\r", ch);
64 break;
65 }
66}
67
68void board_main_top(void)
69{
70#ifndef APPLICATION_dfu
71 usb_buf_init();
72
Harald Welte31d103b2021-06-02 15:43:08 +020073 mux_init();
Joachim Steigerb1a81c12019-07-26 22:13:51 +020074 i2c_pin_init();
Harald Weltedd5794c2021-06-03 13:19:46 +020075 /* PORT A: all outputs, Port B0 output, B1..B7 unused */
76 if (mcp23017_init(MCP23017_ADDRESS, 0x00, 0xfe) == 0)
77 mcp2317_present = true;
Joachim Steigerb1a81c12019-07-26 22:13:51 +020078 /* Initialize checking for card insert/remove events */
79 //card_present_init();
80#endif
81}
82
83int 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}