Kévin Redon | 69b92d9 | 2019-01-24 16:39:20 +0100 | [diff] [blame] | 1 | /* |
Kévin Redon | 78d2f44 | 2019-01-24 18:45:59 +0100 | [diff] [blame] | 2 | * 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 Redon | 69b92d9 | 2019-01-24 16:39:20 +0100 | [diff] [blame] | 18 | |
| 19 | #include "atmel_start.h" |
| 20 | #include "atmel_start_pins.h" |
| 21 | |
Harald Welte | c3f170d | 2019-02-24 09:06:59 +0100 | [diff] [blame] | 22 | #include "i2c_bitbang.h" |
| 23 | #include "octsim_i2c.h" |
| 24 | #include "ncn8025.h" |
| 25 | |
Kévin Redon | 8e53800 | 2019-01-30 11:19:19 +0100 | [diff] [blame] | 26 | volatile static bool data_arrived = false; |
Kévin Redon | 78d2f44 | 2019-01-24 18:45:59 +0100 | [diff] [blame] | 27 | |
| 28 | static void tx_cb_UART_debug(const struct usart_async_descriptor *const io_descr) |
| 29 | { |
| 30 | /* Transfer completed */ |
Kévin Redon | 8e53800 | 2019-01-30 11:19:19 +0100 | [diff] [blame] | 31 | //gpio_toggle_pin_level(LED_system); |
Kévin Redon | 78d2f44 | 2019-01-24 18:45:59 +0100 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static void rx_cb_UART_debug(const struct usart_async_descriptor *const io_descr) |
| 35 | { |
| 36 | /* Receive completed */ |
Kévin Redon | 6a8295c | 2019-01-30 18:58:44 +0100 | [diff] [blame] | 37 | gpio_toggle_pin_level(USER_LED); |
Kévin Redon | 8e53800 | 2019-01-30 11:19:19 +0100 | [diff] [blame] | 38 | data_arrived = true; |
Kévin Redon | 78d2f44 | 2019-01-24 18:45:59 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Harald Welte | c3f170d | 2019-02-24 09:06:59 +0100 | [diff] [blame] | 41 | static void board_init() |
| 42 | { |
| 43 | int i; |
| 44 | |
| 45 | for (i = 0; i < 4; i++) |
| 46 | i2c_init(&i2c[i]); |
| 47 | |
| 48 | /* only 7 slots, as last slot is debug uart! */ |
| 49 | for (i = 0; i < 7; i++) |
| 50 | ncn8025_init(i); |
| 51 | } |
| 52 | |
Kévin Redon | 69b92d9 | 2019-01-24 16:39:20 +0100 | [diff] [blame] | 53 | int main(void) |
| 54 | { |
| 55 | atmel_start_init(); |
Kévin Redon | 78d2f44 | 2019-01-24 18:45:59 +0100 | [diff] [blame] | 56 | |
| 57 | usart_async_register_callback(&UART_debug, USART_ASYNC_TXC_CB, tx_cb_UART_debug); |
| 58 | usart_async_register_callback(&UART_debug, USART_ASYNC_RXC_CB, rx_cb_UART_debug); |
| 59 | usart_async_enable(&UART_debug); |
| 60 | |
Kévin Redon | 8e53800 | 2019-01-30 11:19:19 +0100 | [diff] [blame] | 61 | usb_start(); |
| 62 | |
Harald Welte | c3f170d | 2019-02-24 09:06:59 +0100 | [diff] [blame] | 63 | board_init(); |
| 64 | |
Kévin Redon | d7dfb6e | 2019-02-03 14:09:29 +0100 | [diff] [blame] | 65 | const char* welcome = "\r\n\r\nsysmocom sysmoOCTSIM\r\n"; |
| 66 | while (io_write(&UART_debug.io, (const uint8_t*)welcome, strlen(welcome)) != strlen(welcome)); // print welcome message |
Kévin Redon | 8e53800 | 2019-01-30 11:19:19 +0100 | [diff] [blame] | 67 | while (true) { // main loop |
| 68 | if (data_arrived) { // input on UART debug |
| 69 | data_arrived = false; // clear flag |
| 70 | uint8_t recv_char; // to store the input |
| 71 | while (io_read(&UART_debug.io, &recv_char, 1) == 1) { // read input |
| 72 | while (io_write(&UART_debug.io, &recv_char, 1) != 1); // echo back to output |
| 73 | } |
| 74 | } |
| 75 | } |
Kévin Redon | 69b92d9 | 2019-01-24 16:39:20 +0100 | [diff] [blame] | 76 | } |