blob: d74153d2378298bf10be900f018b8796edaec7f6 [file] [log] [blame]
Kévin Redon69b92d92019-01-24 16:39:20 +01001/*
Kévin Redon78d2f442019-01-24 18:45:59 +01002 * Copyright (C) 2019 sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17*/
Kévin Redon69b92d92019-01-24 16:39:20 +010018
19#include "atmel_start.h"
20#include "atmel_start_pins.h"
21
Kévin Redon8e538002019-01-30 11:19:19 +010022volatile static bool data_arrived = false;
Kévin Redon78d2f442019-01-24 18:45:59 +010023
24static void tx_cb_UART_debug(const struct usart_async_descriptor *const io_descr)
25{
26 /* Transfer completed */
Kévin Redon8e538002019-01-30 11:19:19 +010027 //gpio_toggle_pin_level(LED_system);
Kévin Redon78d2f442019-01-24 18:45:59 +010028}
29
30static void rx_cb_UART_debug(const struct usart_async_descriptor *const io_descr)
31{
32 /* Receive completed */
Kévin Redon6a8295c2019-01-30 18:58:44 +010033 gpio_toggle_pin_level(USER_LED);
Kévin Redon8e538002019-01-30 11:19:19 +010034 data_arrived = true;
Kévin Redon78d2f442019-01-24 18:45:59 +010035}
36
Kévin Redon69b92d92019-01-24 16:39:20 +010037int main(void)
38{
39 atmel_start_init();
Kévin Redon78d2f442019-01-24 18:45:59 +010040
41 usart_async_register_callback(&UART_debug, USART_ASYNC_TXC_CB, tx_cb_UART_debug);
42 usart_async_register_callback(&UART_debug, USART_ASYNC_RXC_CB, rx_cb_UART_debug);
43 usart_async_enable(&UART_debug);
44
Kévin Redon8e538002019-01-30 11:19:19 +010045 usb_start();
46
Kévin Redond7dfb6e2019-02-03 14:09:29 +010047 const char* welcome = "\r\n\r\nsysmocom sysmoOCTSIM\r\n";
48 while (io_write(&UART_debug.io, (const uint8_t*)welcome, strlen(welcome)) != strlen(welcome)); // print welcome message
Kévin Redon8e538002019-01-30 11:19:19 +010049 while (true) { // main loop
50 if (data_arrived) { // input on UART debug
51 data_arrived = false; // clear flag
52 uint8_t recv_char; // to store the input
53 while (io_read(&UART_debug.io, &recv_char, 1) == 1) { // read input
54 while (io_write(&UART_debug.io, &recv_char, 1) != 1); // echo back to output
55 }
56 }
57 }
Kévin Redon69b92d92019-01-24 16:39:20 +010058}