Specifications

1–24 Chapter 1: Using the NicheStack TCP/IP Stack
Important NicheStack TCP/IP Stack Concepts
Using the NicheStack TCP/IP Stack - Nios II Edition Tutorial June 2011 Altera Corporation
In addition to declaring the
struct inet_taskinfo
structure, you must invoke two
macro definitions:
TK_OBJECT
and
TK_ENTRY
. These macros have the following uses:
TK_OBJECT(name)
—Creates the static task object named
name
, which is used by
NicheStack during operation. The static task object is also set in
TK_OBJECT_PTR(tk_ptr)
. A NicheStack naming convention for the
name
parameter
is to set it to the string “
to_
”, followed by the declared name of the
struct
inet_taskinfo
instance.
TK_ENTRY(name)
—Used to create a declaration of the task’s entry point, or function
name. The
name
parameter is identical to the function name you specified for the
task that you want to create, which must have the form
void name (void)
. The
name
parameter sets the
TK_ENTRY_PTR(entry)
macro.
To create your own application tasks that use the services offered by the NicheStack
TCP/IP Stack, follow these steps:
1. Invoke Task Macros—Include the
TK_OBJECT
and
TK_ENTRY
macros, with
information about your task.
2. Define Task Parameters—Define your task application by filling in a local
inet_taskinfo
structure in your code.
3. Wait for Stack Initialization—Before launching your task, wait until the external
variable
iniche_net_ready
is set to TRUE. This variable sets to FALSE at run time
and changes to TRUE when the NicheStack TCP/IP Networking Stack is
operational.
4. Launch Task—Call
TK_NEWTASK
while passing in a pointer to the
inet_taskinfo
structure for your task.
Following is a code sample for creating your own application task:
// Declaration of SSSNiosIISimpleSocketServerTask
void SSSNiosIISimpleSocketServerTask(void){
// task specific code
}
// Creation of NicheStack networking task
TK_OBJECT(to_ssstask);
TK_ENTRY(SSSNiosIISimpleSocketServerTask);
struct inet_taskinfo ssstask = {
&to_ssstask,
"simple socket server",
SSSNiosIISimpleSocketServerTask,
TASK_PRIORITY,
APP_STACK_SIZE,
};
while (!iniche_net_ready)
TK_SLEEP(1);
/* Create the main simple socket server task. */
TK_NEWTASK(&ssstask);
Networking tasks can hand off large processing jobs that are independent of
networking to other tasks. This task load segmentation has the advantage of
increasing control over memory usage for task stacks, as well as greater control over
prioritization of jobs.