Skkynet Embedded Toolkit  1.7.0
 All Functions Modules Pages
mainline.c

Skkynet ETK mainline. More...

Macros

#define SERVER_IP_ADDRESS   STATIC_SERVER_IP_ADDRESS
 
#define SERVER_NETMASK   STATIC_SERVER_NETMASK
 
#define DNS_SERVER_ADDRESS   STATIC_DNS_SERVER_ADDRESS
 
#define IP_GATEWAY_ADDRESS   STATIC_IP_GATEWAY_ADDRESS
 
#define TICK_STACK_SIZE   512
 
#define MAIN_STACK_SIZE   4096
 
#define MAX_PACKETS   50
 
#define PACKET_PAYLOAD_SIZE   (1536 + 32)
 
#define PACKET_POOL_SIZE   ((PACKET_PAYLOAD_SIZE + sizeof(NX_PACKET)) * MAX_PACKETS)
 
#define NETX_DRIVER_STACK_SIZE   1024
 
#define DNS_THREAD_STACK_SIZE   1024
 
#define DHCP_THREAD_STACK_SIZE   1024
 
#define BSD_THREAD_STACK_SIZE   1024
 

Functions

VOID SYNERGY_ETHERNET_DRIVER (NX_IP_DRIVER *)
 
void mainThreadEntry (ULONG thread_input)
 
void * init_malloc_memory (void *first_unused_memory, int heapSize)
 
INT bsd_initialize (NX_IP *default_ip, NX_PACKET_POOL *default_pool, CHAR *bsd_thread_stack_area, ULONG bsd_thread_stack_size, UINT bsd_thread_priority)
 
VOID hook_nx_ether_driver (NX_IP_DRIVER *driver)
 
void tx_application_define_user (void *first_unused_memory)
 
void my_postConnectHook (CTCPClient *thisptr)
 
void APP_ConfigurePoints (CAppConfig *config)
 
void APP_ConfigureTimers (CAppConfig *config)
 
void APP_ConfigureModbus (CAppConfig *config)
 
void APP_PointChangeHandler (CAppConfig *config, CTCPConnection *writer, CDataHubPoint *point)
 
void APP_ConfigureUserThreads (CAppConfig *config)
 
void APP_InitializeConfig (CAppConfig *config)
 
void mainline_onPointChange (CTCPConnectionContainer *thisptr, CTCPConnection *writer, CDataHubPoint *point)
 

Variables

TX_THREAD tick_thread
 
TX_THREAD main_thread
 
NX_PACKET_POOL pool_0
 
NX_IP ip_0
 
ULONG error_counter
 

Detailed Description

Skkynet ETK mainline.

This is the main entry point for a typical application using the Skkynet Embedded Toolkit. It provides the following:

Assignment of IP address using DHCP:

Configuration of DNS server address:

Initiate a mainline procedure that sets up the ETK and calls your functions to define timer handlers, data points and Modbus I/O mappings.

Macro Definition Documentation

#define BSD_THREAD_STACK_SIZE   1024

The NetX BSD layer uses a separate thread to handle select and poll calls. The default stack for this thread is 1024 bytes.

#define DHCP_THREAD_STACK_SIZE   1024

The DHCP set-up uses a separate thread to obtain DHCP information. The default stack for this thread is 1024 bytes.

#define DNS_THREAD_STACK_SIZE   1024

The DNS set-up uses a separate thread to configure the DNS. The default stack for this thread is 1024 bytes.

#define MAIN_STACK_SIZE   4096

The Skkynet ETK uses its main thread to run an event loop that services all of the connections to the application, and to service any user threads that are using the ETK. The default stack size is 4096 bytes.

#define MAX_PACKETS   50

Sets the number of packets in the NetX packet pool

#define NETX_DRIVER_STACK_SIZE   1024

The NetX driver uses a separate thread to manage IP traffic. The default stack for this thread is 1024 bytes.

#define PACKET_POOL_SIZE   ((PACKET_PAYLOAD_SIZE + sizeof(NX_PACKET)) * MAX_PACKETS)

NetX uses a fixed-size packet pool to maintain IP packets in-flight. This is allocated explicitly and provided when NetX is initialized. The default size is 50 packets, with each packet being 1624 bytes, for a total of 80 KB.

#define SERVER_IP_ADDRESS   STATIC_SERVER_IP_ADDRESS

If you are using DHCP to assign an IP address to this device then the IP address and netmask should be set to zero here. If you are not using DHCP then you need to provide the information in config_app.h

#define TICK_STACK_SIZE   512

The Skkynet ETK uses a thread to count clock ticks to use as a time base for its timers. The default size of the tick stack is 512 bytes.

Function Documentation

void APP_InitializeConfig ( CAppConfig *  config)

Initialize the application configuration object. This object must be allocated before entry to this function, and is typically created as a global static variable in the mainline.c mainline. You can modify this structure to suit your application requirements.

In the example code the contents of this object are hard-coded. In a production system you may prefer to store this information in persistent storage and then read it into the CAppConfig object here.

Parameters
config
void mainThreadEntry ( ULONG  thread_input)

This is the Skkynet ETK main thread function. It creates a container to hold data points, TCP connections, Modbus connections, timers and user thread information. It then triggers the connection process for TCP connections and enters an infinite loop where is continuously monitors sockets for data, handles asynchronous messages coming from user thread and manages timers.

Parameters
thread_input- ignored
void my_postConnectHook ( CTCPClient *  thisptr)

Override the onConnect event. This event is called when an outbound connection is successfully made. At thisptr point we may declare data points to the DataHub and register any data points that we want to receive from it.

Parameters
thisptr- Pointer to the TCP client structure that has just connected to its server.
VOID SYNERGY_ETHERNET_DRIVER ( NX_IP_DRIVER *  )

The Ethernet driver that your application uses will depend on the hardware. If there are multiple Ethernet interfaces then you must choose which one will be used for this application. This is set through a definition in config_app.h, and will typically be nx_ether_driver_eth0 or eth1.

void tx_application_define_user ( void *  first_unused_memory)

This is the entry point from the Synergy start-up code. This is the first call that we should modify. The code that runs up to this point is auto-generated by the Synergy project generator.

Here we set up networking and start the DNS and DHCP configuration threads, then start the mainline thread that configures the Skkynet ETK and implements the event loop.

Parameters
first_unused_memory- passed by the system. We can create stack space and heap after this point.