<< >>

API

Configuration defines

The files multi_uart_tx_conf.h and multi_uart_rx_conf.h must be copied from app_multi_uart_demo\src folder to app_serial_to_ethernet_demo\src folder

UART_RX_CHAN_COUNT

Default value = 8

Define the number of channels that are to be supported, must fit in the port. Also, must be a power of 2 (i.e. 1,2,4,8) - not all channels have to be utilised

UART_TX_CHAN_COUNT

Default value = 8

Define the number of channels that are to be supported, must fit in the port. Also, must be a power of 2 (i.e. 1,2,4,8) - not all channels have to be utilised

UART_RX_MAX_BAUD

Default value = 115200

Define maximum baud rate to be supprted for any of the UART channel

UART_TX_BUF_SIZE

Default value = 8

Define the buffer size in UART word entries - needs to be a power of 2 (i.e. 1,2,4,8,16,32 etc)

The file xtcp_client_conf.h defines configuration fexibility required for XTCP clients in order to use XTCP server functions

UIP_CONF_RECEIVE_WINDOW

Default value = 128

Define window length of TCP packets that the application will receive and process for each TCP packets received from XTCP clients. Note this value will be set as default length of application buffers that will be used to hold UART data collected from XTCP clients.

XTCP_CLIENT_BUF_SIZE

Default value = 650

Define MTU size used for XTCP device packet transmissions

The file udp_discovery.h defines ports used for UDP discovery. This file can set the following defines:

UDP_RECV_BUF_SIZE

Default value = 80

Define length of UDP message buffer which holds the incoming UDP test server request or its corresponding S2E response

INCOMING_UDP_PORT

Default value = 15534

Define incoming UDP port to listen to device discovery requests from UDP test server

OUTGOING_UDP_PORT

Default value = 15533

Define outgoing UDP port in order to send device response to UDP test server

S2E_FIRMWARE_VER

Current value = 1.1.2

Define to specify S2E firmware version. This shall be updated for every release

UART_RX_FLUSH_DELAY

Default value = 20000000

If UART data received is lesser than minimum configured packet size, this defines a minimum wait time to send this data to telnet handler

The file telnet_config.h defines ports used for Telnet socket used for UART configuration.

S2E_TELNET_CONFIG_PORT

Default value = 23

Define to specify telnet port to use for UART configuration

Constants

The file srcs2e_flash.h has some constants defined which may be used by other files while accessing flash.

S2E_FLASH_ERROR

Default value = -1

Any errors (like flash not present, wrong flash, unable to write, etc...) while accessing the flash fitted on the board, are represented using this constant.

S2E_FLASH_OK

Default value = 0

All successfull flash operations are represented using this constant.

UART_CONFIG

Default value = 0

To be used as a data type parameter while calling flash routines. This also represents the sector index (relative to webpage image) in the flash where UART configuration must be stored.

IPVER

Default value = 1

To be used as a data type parameter while calling flash routines. This also represents the sector index (relative to webpage image) in the flash where IP configuration must be stored.

FLASH_CMD_SAVE

Default value = 1

Flash command to ‘save’ configuration to flash.

FLASH_CMD_RESTORE

Default value = 2

Flash command to ‘restore’ configuration from flash.

FLASH_DATA_PRESENT

Default value = $

While ‘saving’ settings to flash, this value is written as the first byte. So, on a ‘restore’ command, by reading for this sybol, we would know that some data is present in that sector of flash.

Data structures

uart_config_data_t

Structure to hold UART configuration details.

Structure Members:

int channel_id

UART Id.

e_uart_config_parity parity

One of valid parity: Odd, Even, Mark, Space, None.

e_uart_config_stop_bits stop_bits

Stop bits configuration: Single or Two.

e_uart_config_polarity polarity

Polarity setting: Start bit as 1 or 0.

int baud

Baud rate of UART channel.

int char_len

Number of bits each UART character contain.

Configuration functions

void uart_config_init(chanend c_uart_config, chanend ?c_flash_data, chanend ?c_xtcp, int &telnet_port_address)

This function retrieves configuration of each UARTs from flash, and applies it to the base configuration structure of type uart_config_data_t.

Telnet port applicable for corresponding UART is also fetched from flash and applied to repective UART configuration structure. If there is no valid flash configuration, default in-program configuration with following values EvenParity-1StopBit-115200Baud-Start0Polarity-8UARTCharLen is used

Parameters:
  • c_uart_config – Channel-end to communicate UART configuration details between TCP handler and UART handler thread
  • c_flash_data – Channel-end to communicate UART configuration data stored in flash to TCP handler thread
  • c_xtcp – Channel-end between XTCP and TCP handler thread
  • telnet_port_address – Reference to structure holding Telnet port addresses mapped for UARTs
Returns:

None

void s2e_webserver_init(chanend c_xtcp, chanend ?c_flash, chanend c_uart_config, chanend ?c_flash_data)

s2e_webserver_init The S2E webserver initialization routine.

Registers all channels used by it.

Parameters:
  • c_xtcp – channel connecting to the xtcp module
  • c_flash – channel for web page data
  • c_uart_config – channel for UART configuration
  • c_flash_data – channel for s2e flash data
Returns:

none

void telnet_to_uart_init(chanend c_xtcp, chanend c_uart_data, int telnet_port_address[])

This function initializes UART state structure, assigns configured/default telnet ports and listens on these ports, shares UART buffer references to UART handler thread.

Parameters:
  • c_xtcp – Channel-end between XTCP and TCP handler thread
  • c_uart_data – Channel-end to communicate UART data between TCP handler and UART handler thread
  • telnet_port_address – Array contining telnet ports mapped for configured UARTs
Returns:

None

void udp_discovery_init(chanend c_xtcp, chanend c_flash_data, xtcp_ipconfig_t &ipconfig)

This function initializes UDP discovery state, fetches S2E IP address stored in flash and references to ETH thread in order to configure device IP.

If valid IP is not present in flash, default configured IP defined from ipconfig is used

Parameters:
  • c_xtcp – Channel between XTCP and TCP handler thread
  • c_flash_data – Channel between Flash and TCP handler thread
  • ipconfig – Reference to structure holding IP configuration info
Returns:

None

Interface functions

void uart_handler(chanend c_uart_data, chanend c_uart_config, streaming chanend c_uart_rx, streaming chanend c_uart_tx)

This function configures UARTs, initializes application buffers states.

As a part of event handling, this function does the following: (i) handles incoming data from UARTs and stores into appropirate buffers (ii) in case of data transfer transaction, either notifies or acknowledges TCP handler about UART data; otherwise, listens from TCP handler to (a) collect telnet received data to UART (b) share appropriate UART buffer holding UART recived data (iii) in case of UART configuration requests, collects appropriate UART configuration and reconfigures UART for received configuration (iv) sends a data byte from telnet UART buffers in a round robin basis, and notifies current transmit and receive transactions

Parameters:
  • c_uart_data – Channel-end to communicate UART data between TCP handler and UART handler thread
  • c_uart_config – Channel-end to communicate UART configuration details between TCP handler and UART handler thread
  • c_uart_rx – Channel primarily to send UART data from application to MultiUART RX server thread
  • c_uart_tx – Channel primarily to collect UART data from MultiUART TX server thread into UART handler thread
Returns:

None

void tcp_handler(chanend c_xtcp, chanend c_uart_data, chanend c_uart_config, chanend ?c_flash_web, chanend ?c_flash_data)

This function handles TCP handler thread.

During initialization, IP configuration details stored in flash are retrieved from UDP discovery function and passed on to ETH thread This thread mainly handles (a) all XTCP events and invokes respective sub-function handlers (b) notification messages from UART handler thread for UART data transactions

Parameters:
  • c_xtcp – Channel-end between XTCP and TCP handler thread
  • c_uart_data – Channel-end to communicate UART data between TCP handler and UART handler thread
  • c_uart_config – Channel-end to communicate UART configuration data TCP handler and UART handler thread
  • c_flash_web – Channel-end to communicate Web page data stored in flash to TCP handler thread
  • c_flash_data – Channel-end to communicate UART configuration data stored in flash to TCP handler thread
Returns:

None

void telnet_config_event_handler(chanend c_xtcp, chanend c_uart_config, chanend c_flash_data, xtcp_connection_t &conn)

This function handles UART configuration requests from telnet configuration client.

It initializes cofnig parse state machine, receives configuration request events, sends response back to the client

Parameters:
  • c_xtcp – Channel-end between XTCP and TCP handler thread
  • c_uart_configChannel-end – to communicate UART configuration data TCP handler and UART handler thread
  • c_flash_data – Channel-end to communicate UART configuration data stored in flash to TCP handler thread
  • conn – Reference to structure holding IP configuration info
Returns:

None

void s2e_webserver_event_handler(chanend c_xtcp, chanend ?c_flash, chanend c_uart_config, xtcp_connection_t &conn)

s2e_webserver_event_handler Handles webserver event.

Parameters:
  • c_xtcp – channel connecting to the xtcp module
  • c_flash – channel for web page data
  • c_uart_config – channel for UART configuration
  • c_flash_data – channel for s2e flash data
Returns:

none

void telnet_to_uart_event_handler(chanend c_xtcp, chanend c_uart_data, xtcp_connection_t &conn)

This function handles XTCP events related to Telnet data communication.

For any event, a correponding UART is mapped from XTCP connection As a part of event handling, this function does the following: (i) for new connections, TCP connection details are stored and telnet parse state machine and TCP ack mode is initialized (ii) for recieve events, data from TCP stack is collected into appropriate UART buffers. Received data is sent to telnet parser server in order to separate application data from telnet protocol. Initiates UART data transaction on c_uart_data channel in order to send data to UART (iii) for send requests initiated by telnet handler, this handler performs either of the following functionality (a) welcome messages are sent to respective telnet clients at the start of each session (b) collect outstanding data from appropriate UART RX active buffer and sends on XTCP connection

Parameters:
  • c_xtcp – Channel-end between XTCP and TCP handler thread
  • c_uart_data – Channel-end to communicate UART data between TCP handler and UART handler thread
  • conn – Reference to structure holding IP configuration info
Returns:

None

void udp_discovery_event_handler(chanend c_xtcp, chanend c_flash_data, xtcp_connection_t &conn)

Handles events related to UDP discovery functionality.

Receives S2E identification and IP configuration requests from UDP test server, frames and sends S2E response messages

Parameters:
  • c_xtcp – Channel between XTCP and TCP handler thread
  • c_flash_data – Channel between Flash and TCP handler thread
  • conn – Reference to UDP connection state
Returns:

None

void s2e_flash(chanend c_flash_web, chanend c_flash_data, fl_SPIPorts &flash_ports)

s2e_flash The S2E flash thread will keep looking for data (or commands) on the c_flash_data channel.

Parameters:
  • c_flash_web – channel for webpage data
  • c_flash_data – channel for s2e data
  • flash_ports – reference to flash ports used by the device
Returns:

none

void send_data_to_flash_thread(chanend c_flash_data, uart_config_data_t &data)

send_data_to_flash_thread Send UART configuration data to flash.

Send one configuration at a time. In order to send configuration for all the channels, this routine must be called in a loop; each time sending the current channels config.

Parameters:
  • c_flash_data – channel for s2e data
  • data – reference to the current channel’s config
Returns:

none

void get_data_from_flash_thread(chanend c_flash_data, uart_config_data_t &data, int &telnet_port)

get_data_from_flash_thread Get UART configuration data from flash.

Get one configuration at a time. In order to get configuration for all the channels, this routine must be called in a loop; each time updating the current channels config. Telnet ports for each channel are also updated.

Parameters:
  • c_flash_data – channel for s2e data
  • data – reference to the current channel’s config to update
  • telnet_port – reference to current channel’s telnet port to update
Returns:

none

void send_ipconfig_to_flash_thread(chanend c_flash_data, xtcp_ipconfig_t &ip)

send_ipconfig_to_flash_thread Send IP configuration data to flash.

Parameters:
  • c_flash_data – channel for s2e data
  • ip – reference to the current IP config
Returns:

none

void get_ipconfig_from_flash_thread(chanend c_flash_data, xtcp_ipconfig_t &ip)

get_ipconfig_from_flash_thread Get IP configuration data from flash.

Parameters:
  • c_flash_data – channel for s2e data
  • ip – reference to the current IP config
Returns:

none

void send_cmd_to_flash_thread(chanend c_flash_data, int data_type, int command)

send_cmd_to_flash_thread Send command to flash thread.

Parameters:
  • c_flash_data – channel for s2e data
  • data_type – UART_CONFIG (or) IPVER
  • command – FLASH_CMD_SAVE (or) FLASH_CMD_RESTORE
Returns:

none

int get_flash_access_result(chanend c_flash_data)

get_flash_access_result Get the flash access result after performing certain command.

Parameters:
  • c_flash_data – channel for s2e data
Returns:

int S2E_FLASH_ERROR (or) S2E_FLASH_OK

Module functions

int parse_telnet_buffer(char data[], int len, int &parse_state, int &close_request)

This function implements Telnet server functionality.

Mainly extracts application data from XTCP data packets in telnet protocol format.

Parameters:
  • data – Buffer to store application data filtered from telnet server
  • len – Number of bytes of received data
  • parse_state – Current state of telnet parser state machine
  • close_request – Flag to set when telnet client is suspended
Returns:

Length of application buffer