Specifications

Chapter 1: Using the NicheStack TCP/IP Stack 1–21
Nios II Simple Socket Server Overview
June 2011 Altera Corporation Using the NicheStack TCP/IP Stack - Nios II Edition Tutorial
Nios II Simple Socket Server Implementation Details
This section provides details about the simple socket server structures, tasks, and
functions.
The Nios II Simple Socket Server application uses following structure to manage each
single socket connection:
typedef struct SSS_SOCKET {
enum { READY, COMPLETE, CLOSE } state;
int fd;
int close;
INT8U rx_buffer[SSS_RX_BUF_SIZE]; /* circular buffer */
INT8U *rx_rd_pos; /* position we've read up to */
INT8U *rx_wr_pos; /* position we've written up to */
} SSSConn;
The application’s
main()
function (located in iniche_init.c) performs the following
actions:
Calls
OSTimeSet()
Calls
OSTaskCreateExt
which in turn calls
SSSInitialTask()
Calls
alt_uCOSIIErrorHandler()
Calls
OSStart()
to begin multithreading
The Micrium’s MicroC/OS-II examples suggest using a single task to initialize the rest
of the application. This technique ensures that stack checking initializes enabled
features correctly. In this tutorial, the
SSSInitialTask()
task (located in iniche_init.c)
initializes the NicheStack TCP/IP Stack software, initializes the operating system data
structures, and starts any user-defined networking tasks and regular tasks. The
SSSInitialTask()
task performs the following specific actions:
Calls
alt_iniche_init()
to perform pre-initialization of the NicheStack
Networking Stack
Calls
netmain()
to initialize and start the NicheStack Networking Stack
Instantiates
ssstask()
and
sssphytask()
(via
TK_NEWTASK
) to start the Nios II
Simple Socket Server networking task
Calls
SSSCreateOSDataStructs()
to create data structures (
SSSLEDCommandQ
and
SSSLEDFreqMailbox
RTOS resources) for the Nios II Simple Socket Server
application
Calls
SSSCreateTasks()
to create non-NicheStack TCP/IP Stack dependent tasks,
including the LED tasks
Calls
OSTaskDel()
to delete itself as a task
The
SSSNiosIISimpleSocketServerTask()
task (located in
niosII_simple_socket_server.c) performs the following actions:
Creates a socket to serve a TCP/IP connection, binds to the socket, and listens for
TCP/IP connection requests from a client.
Calls
SSS_handle_accept()
for an incoming TCP/IP connection.