Using the NicheStack TCP/IP Stack - Nios II Edition Tutorial Using the NicheStack TCP/IP Stack - Nios II Edition Tutorial 101 Innovation Drive San Jose, CA 95134 www.altera.com TU-01001-3.
Copyright © 2011 Altera Corporation. All rights reserved. Altera, The Programmable Solutions Company, the stylized Altera logo, and specific device designations are trademarks and/or service marks of Altera Corporation in the U.S. and other countries. All other words and logos identified as trademarks and/or service marks are the property of Altera Corporation or their respective owners. Altera products are protected under numerous U.S.
Contents Chapter 1. Using the NicheStack TCP/IP Stack Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1–1 Hardware and Software Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1–2 Tutorial Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
iv Using the NicheStack TCP/IP Stack - Nios II Edition Tutorial Contents June 2011 Altera Corporation
1. Using the NicheStack TCP/IP Stack This tutorial introduces you to the Nios® II Software Build Tools (SBT) for Eclipse™ using the MicroC/OS-II and NicheStack TCP/IP Stack development flow. It shows you how to use the Nios II SBT for Eclipse to create a new Nios II project that configures, builds, and runs a MicroC/OS-II and NicheStack TCP/IP Stack program on an Altera® development board.
1–2 Chapter 1: Using the NicheStack TCP/IP Stack Hardware and Software Requirements Hardware and Software Requirements This tutorial requires the following hardware and software: ■ Quartus® II software version 11.0 or later ■ Nios II Embedded Design Suite (EDS) version 11.
Chapter 1: Using the NicheStack TCP/IP Stack Software Development Flow 1–3 You can locate the following software files in the \nichestack_tutorial directory. These software files constitute the Nios II Simple Socket Server application for this tutorial: ■ alt_2_wire.c—Contains utilities that provide a low-level interface to the EEPROM devices. ■ alt_2_wire.h—Defines utilities that provide a low-level interface to the EEPROM devices. ■ alt_eeprom.
1–4 Chapter 1: Using the NicheStack TCP/IP Stack Software Development Flow Creating a New Nios II Project In this section, you create a new Nios II SBT for Eclipse project using a project template. To do so, follow these steps: 1. Start the Nios II SBT for Eclipse by performing one of the following actions: ■ ■ On Windows, on the Start menu, point to All Programs > Altera > Nios II EDS , and click Nios II Software Build Tools for Eclipse.
Chapter 1: Using the NicheStack TCP/IP Stack Software Development Flow 1–5 6. Under Project template, select Blank Project. Figure 1–1 shows the state of the Nios II Application and BSP from Template wizard at this point in the tutorial. Figure 1–1. Nios II Application and BSP from Template Wizard 7. Click Next. The second page of the Nios II Application and BSP from Template wizard appears. 8. Select Select an existing BSP project from your workspace. 9. Click Create.
1–6 Chapter 1: Using the NicheStack TCP/IP Stack Software Development Flow 12. Click Finish. The wizard creates a BSP project and closes the Nios II Board Support Package dialog box. 13. Click Finish. The wizard creates an application project. 1 If the wizard prompts you to open the Nios II perspective, click Yes. If the Finish button is grayed out, click Cancel to close the previous GUI. Repeat Step 2 - 8, select niosII_simple_socket_server_0_bsp, and click Finish. 14.
Chapter 1: Using the NicheStack TCP/IP Stack Software Development Flow 1–7 Configuring the BSP After you create a new BSP, you might want to customize its configuration (for example, defining stdin, stdout, stderr, and other parameters). f For more information, refer to the Getting Started with the Graphical User Interface chapter of the Nios II Software Developer’s Handbook. For this tutorial, you must configure the MicroC/OS-II RTOS kernel and NicheStack TCP/IP Stack software components.
1–8 Chapter 1: Using the NicheStack TCP/IP Stack Software Development Flow 3. On the Main tab (Settings tab in v9.1 and earlier), expand Advanced in the left pane, and click ucosii. Settings for the MicroC/OS-II RTOS appear, as shown in Figure 1–4. Figure 1–4. MicroC/OS-II RTOS Options The MicroC/OS-II kernel is highly configurable. The options that you set in this dialog box determine which MicroC/OS-II options are included in the binary image.
Chapter 1: Using the NicheStack TCP/IP Stack Software Development Flow 1–9 f For more information about the various MicroC/OS-II features, refer to the MicroC/OS-II Real-Time Operating System chapter in the Nios II Software Developer's Handbook. 4. On the Software Packages tab, turn on Enable for the altera_iniche software package, as shown in Figure 1–5. Figure 1–5. NicheStack TCP/IP Stack Options 5. If a DHCP server is available on your network, turn on enable_dhcp_client.
1–10 Chapter 1: Using the NicheStack TCP/IP Stack Software Development Flow 6. On the Linker Script tab, verify that the Linker Region Name is sdram for all enabled Linker Section Names in the table under Linker Section Mappings, as shown in Figure 1–6. If not, click each current Linker Region Name and select sdram from the list that appears. Figure 1–6. BSP Editor Linker Script Tab 7. Click Generate. When prompted to save your changes, click Yes, Save. 8.
Chapter 1: Using the NicheStack TCP/IP Stack Software Development Flow 1–11 Examining the Nios II Simple Socket Server Project Files You have finished creating and configuring the niosII_simple_socket_server_0 application and the associated BSP projects. Use the Project Explorer view, as shown in Figure 1–2, to examine the project files in the niosII_simple_socket_server_0 and niosII_simple_socket_server_0_bsp folders to understand more about the projects.
1–12 Chapter 1: Using the NicheStack TCP/IP Stack Software Development Flow 1. Configure the FPGA on the development board by performing the following steps: a. On the Nios II menu, click Quartus II Programmer. b. In the Quartus II Programmer dialog box, on the File menu, click Open. c. Browse to and open the \niosii_ethernet_standard_\ niosii_ethernet_standard_.sof SRAM Object File (.sof). Information for the file appears in the Quartus II Programmer dialog box. d.
Chapter 1: Using the NicheStack TCP/IP Stack Software Development Flow 1 1–13 If the Run Configurations dialog box appears, click the Target Connection tab. Then click Refresh Connections and Apply until a board connection establishes. After the board connection is established, click Run. The build process takes several minutes. After the build process completes, the Nios II SBT for Eclipse downloads the executable program to your development board.
1–14 Chapter 1: Using the NicheStack TCP/IP Stack Software Development Flow If the connection to port 30 on the development board is successful, the menu of available commands displays in a command window. When you enter commands at the command prompt, Ethernet sends the commands over the telnet connection to a task waiting on a socket for commands. The task responds to those commands by sending instructions to another task that manipulates the LED.
Chapter 1: Using the NicheStack TCP/IP Stack Software Development Flow 1–15 Figure 1–9 shows the corresponding output that appears in the Nios II Console view. Figure 1–9. Nios II Console Output During Telnet Session To test the functionality of the Nios II Simple Socket Server, enter the following commands in the telnet session: 1. Type r, where is a number from one through nine, to change the blink rate of the LED on your board. 2.
1–16 Chapter 1: Using the NicheStack TCP/IP Stack Nios II Simple Socket Server Overview Nios II Simple Socket Server Overview The following sections describe the Nios II Simple Socket Server: ■ “Software Naming Conventions” on page 1–16—Identifies the naming convention used in the tutorial files. ■ “Software Architecture” on page 1–17—Describes the architectural model of a Nios II software application and how it fits with the rest of the Nios II system software components.
Chapter 1: Using the NicheStack TCP/IP Stack Nios II Simple Socket Server Overview 1–17 Software Architecture The onion diagram in Figure 1–10 shows the architectural layers of a Nios II MicroC/OS-II software application. Figure 1–10.
1–18 Chapter 1: Using the NicheStack TCP/IP Stack Nios II Simple Socket Server Overview Figure 1–11 shows the structure of the design example described in “Introduction” on page 1–1. The sections following the figure describe the tasks in the figure. Figure 1–11.
Chapter 1: Using the NicheStack TCP/IP Stack Nios II Simple Socket Server Overview 1–19 MicroC-OS/II Resources This section describes the tasks, queue, event flag, and semaphores that implement the Nios II Simple Socket Server application. Tasks Table 1–3 lists the MicroC/OS-II tasks that implement the Nios II Simple Socket Server application. Table 1–3. MicroC/OS-II Tasks for the Nios II Simple Socket Server Task Description SSSInitialTask() Instantiates all the MicroC/OS-II resources.
1–20 Chapter 1: Using the NicheStack TCP/IP Stack Nios II Simple Socket Server Overview Inter-Task Communication Resources The following global handles (or pointers) create and manipulate your MicroC/OS-II inter-task communication resources. All the resources begin with SSS, indicating a public resource provided by the Nios II Simple Socket Server that is shared between software modules.
Chapter 1: Using the NicheStack TCP/IP Stack Nios II Simple Socket Server Overview 1–21 Nios II Simple Socket Server Implementation Details This section provides details about the simple socket server structures, tasks, and functions.
1–22 Chapter 1: Using the NicheStack TCP/IP Stack Important NicheStack TCP/IP Stack Concepts ■ Calls SSS_handle_receive() to serve the TCP/IP connection. If you require multiple TCP/IP connections, you can modify this task to create other tasks that handle each individual TCP/IP connection. ■ Calls SSS_reset_connection(), SSS_send_menu(), and SSS_exec_command().
Chapter 1: Using the NicheStack TCP/IP Stack Important NicheStack TCP/IP Stack Concepts 1–23 In the Nios II Simple Socket Server design example, only the minimum required NicheStack TCP/IP Stack tasks have been configured to run.
1–24 Chapter 1: Using the NicheStack TCP/IP Stack Important NicheStack TCP/IP Stack Concepts 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).
Chapter 1: Using the NicheStack TCP/IP Stack Important NicheStack TCP/IP Stack Concepts 1–25 Be careful not to overutilize job distribution among several tasks at the same time, for the following reasons: ■ Additional tasks require additional CPU execution time to do task context-switching. ■ Limited number of priorities. Each task must have its own unique priority in MicroC/OS-II, and you do not want to run out of task priorities.
1–26 Chapter 1: Using the NicheStack TCP/IP Stack Important NicheStack TCP/IP Stack Concepts TK_NETTICK_TPRIO, defined in ipport.h, sets the priority to a value of 3 for the NicheStack TCP/IP Stack time-keeping task, launched by netmain(). The NicheStack TCP/IP Stack uses this task to keep track of time-based events in the networking stack. Altera recommends that you set the priority of this task to one priority level lower than TK_NETMAIN_TPRIO.
Chapter 1: Using the NicheStack TCP/IP Stack Where to Go Next 1–27 f For more information about the _reent structure, refer to the “The Newlib ANSI C Standard Library” and the “Implementing MicroC/OS-II Projects for the Nios II Processor” sections of the MicroC/OS-II Real-Time Operating System chapter of the Nios II Software Developer’s Handbook. Where to Go Next This example is easily expandable to handle multiple TCP connections on a single port.
1–28 Using the NicheStack TCP/IP Stack - Nios II Edition Tutorial Chapter 1: Using the NicheStack TCP/IP Stack Where to Go Next June 2011 Altera Corporation
A. Hardware Setup Details Introduction To complete this tutorial, you must have the Nios II SBT for Eclipse installed, and your Altera development board must be connected to a host PC on both the Ethernet and USB/JTAG ports. f For information about download cables and drivers, refer to the Download Cables page of the Altera website. The Nios II Ethernet Standard hardware design examples for Altera development boards include the Ethernet device required by this NicheStack tutorial.
A–2 Using the NicheStack TCP/IP Stack - Nios II Edition Tutorial Appendix A: Hardware Setup Details Network Connection June 2011 Altera Corporation
Additional Information This chapter provides additional information about the document and Altera. Document Revision History The following table shows the revision history for this document. Date Version June 2011 3.0 Changes Revised for Quartus II Software 11.0 release. May 2010 2.0 Revised for Nios II Software Build Tools for Eclipse. January 2007 1.0 Initial release. How to Contact Altera For the most up-to-date information about Altera products, refer to the following table.
Info–2 Additional Information Typographic Conventions Visual Cue Meaning Initial Capital Letters Indicate keyboard keys and menu names. For example, the Delete key and the Options menu. “Subheading Title” Quotation marks indicate references to sections within a document and titles of Quartus II Help topics. For example, “Typographic Conventions.” Indicates signal, port, register, bit, block, and primitive names. For example, data1, tdi, and input. The suffix n denotes an active-low signal.