NuMaker Transfer data UART to Ethernet

Fork of Serial-to-Ethernet by Morgan Du

Committer:
SHLIU1@OANBE02333.nuvoton.com
Date:
Tue Mar 02 10:09:10 2021 +0800
Revision:
6:014b1a469aed
Parent:
0:11bc39d0f367
Child:
7:c03b2ed97d94
Support the both V5.X and V6.X for mbed-os

Who changed what in which revision?

UserRevisionLine numberNew contents of line
morgandu 0:11bc39d0f367 1 /*
morgandu 0:11bc39d0f367 2 * Copyright (c) 2017 Nuvoton Tecnology Corp. All rights reserved.
morgandu 0:11bc39d0f367 3 *
morgandu 0:11bc39d0f367 4 * Header for Serial-To-Ethernet configuration.
morgandu 0:11bc39d0f367 5 *
morgandu 0:11bc39d0f367 6 */
morgandu 0:11bc39d0f367 7
morgandu 0:11bc39d0f367 8 #ifndef _STE_CONFIG_H
morgandu 0:11bc39d0f367 9 #define _STE_CONFIG_H
morgandu 0:11bc39d0f367 10
morgandu 0:11bc39d0f367 11 #include "mbed.h"
morgandu 0:11bc39d0f367 12 #include "EthernetInterface.h"
morgandu 0:11bc39d0f367 13 #include "FATFileSystem.h"
morgandu 0:11bc39d0f367 14 #include "NuSDBlockDevice.h"
morgandu 0:11bc39d0f367 15
morgandu 0:11bc39d0f367 16
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 17 #include "BufferSerial.h"
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 18
morgandu 0:11bc39d0f367 19
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 20 /* A simple web server for network and UART configuration
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 21 0: Disable the web server.
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 22 1: Enable the web server
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 23 */
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 24 #define ENABLE_WEB_CONFIG 1
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 25
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 26 /* Maximum UART ports supported.
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 27 Must define enough tuples of mapping table "port_config[]" in main.c
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 28 */
morgandu 0:11bc39d0f367 29 #define MAX_UART_PORTS 2
morgandu 0:11bc39d0f367 30
morgandu 0:11bc39d0f367 31 /* Default UART baud */
morgandu 0:11bc39d0f367 32 #define DEFAULT_UART_BAUD 115200
morgandu 0:11bc39d0f367 33
morgandu 0:11bc39d0f367 34 /* Network base port number to listen.
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 35 The base port maps to the 1st UART port,
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 36 the (base port + 1) maps to the 2nd UART port, etc.
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 37 */
morgandu 0:11bc39d0f367 38 #define NET_PORT_BASE 10001
morgandu 0:11bc39d0f367 39
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 40 /* Files in SD card to store settings via web configuration */
morgandu 0:11bc39d0f367 41 #define SER_CONFIG_FILE "/fs/STE_SER.TXT" // for serial ports
morgandu 0:11bc39d0f367 42 #define NET_CONFIG_FILE "/fs/STE_NET.TXT" // for network
morgandu 0:11bc39d0f367 43
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 44 /* Maximum size of server domain name or address for web configuration */
morgandu 0:11bc39d0f367 45 #define MAX_SERVER_ADDRESS_SIZE 63
morgandu 0:11bc39d0f367 46
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 47 /* Maximum size of IP address for web configuration */
morgandu 0:11bc39d0f367 48 #define MAX_IPV4_ADDRESS_SIZE 15
morgandu 0:11bc39d0f367 49
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 50
morgandu 0:11bc39d0f367 51 /* Functions and global variables declaration. */
morgandu 0:11bc39d0f367 52
morgandu 0:11bc39d0f367 53 typedef enum {
morgandu 0:11bc39d0f367 54 NET_SERVER_MODE = 0,
morgandu 0:11bc39d0f367 55 NET_CLIENT_MODE
morgandu 0:11bc39d0f367 56 } E_NetMode;
morgandu 0:11bc39d0f367 57
morgandu 0:11bc39d0f367 58 typedef enum {
morgandu 0:11bc39d0f367 59 IP_STATIC_MODE = 0,
morgandu 0:11bc39d0f367 60 IP_DHCP_MODE
morgandu 0:11bc39d0f367 61 } E_IPMode;
morgandu 0:11bc39d0f367 62
morgandu 0:11bc39d0f367 63 typedef struct {
morgandu 0:11bc39d0f367 64 E_IPMode mode;
morgandu 0:11bc39d0f367 65 char ip[MAX_IPV4_ADDRESS_SIZE+1];
morgandu 0:11bc39d0f367 66 char mask[MAX_IPV4_ADDRESS_SIZE+1];
morgandu 0:11bc39d0f367 67 char gateway[MAX_IPV4_ADDRESS_SIZE+1];
morgandu 0:11bc39d0f367 68 } S_NET_CONFIG;
morgandu 0:11bc39d0f367 69
morgandu 0:11bc39d0f367 70 typedef struct {
morgandu 0:11bc39d0f367 71 E_NetMode mode; // Network server or client mode
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 72 int port; // Network port number (Server mode)
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 73 BufferSerial *pserial; // UART number
morgandu 0:11bc39d0f367 74 int baud; // UART baud
morgandu 0:11bc39d0f367 75 int data; // UART data bits
morgandu 0:11bc39d0f367 76 int stop; // UART stop bits
morgandu 0:11bc39d0f367 77 mbed::SerialBase::Parity parity; // UART parity bit
morgandu 0:11bc39d0f367 78 char server_addr[MAX_SERVER_ADDRESS_SIZE+1]; // Server address for TCP client mode
morgandu 0:11bc39d0f367 79 unsigned short server_port; // Server port for TCP client mode
morgandu 0:11bc39d0f367 80 } S_PORT_CONFIG;
morgandu 0:11bc39d0f367 81
SHLIU1@OANBE02333.nuvoton.com 6:014b1a469aed 82 //extern RawSerial output; // for debug output
morgandu 0:11bc39d0f367 83 extern EthernetInterface eth;
morgandu 0:11bc39d0f367 84 extern S_PORT_CONFIG port_config[MAX_UART_PORTS];
morgandu 0:11bc39d0f367 85 extern S_NET_CONFIG net_config;
morgandu 0:11bc39d0f367 86
morgandu 0:11bc39d0f367 87 extern bool SD_Card_Mounted;
morgandu 0:11bc39d0f367 88 void start_httpd(void);
morgandu 0:11bc39d0f367 89
morgandu 0:11bc39d0f367 90 #endif