TT Nios2 Microc Osii Tutorial
TT Nios2 Microc Osii Tutorial
TT Nios2 Microc Osii Tutorial
Tutorial
11.0
May 2011
Subscribe
2011 Altera Corporation. All rights reserved. ALTERA, ARRIA, CYCLONE, HARDCOPY, MAX, MEGACORE, NIOS, QUARTUS and STRATIX words and logos
are trademarks of Altera Corporation and registered in the U.S. Patent and Trademark Office and in other countries. All other words and logos identified as
trademarks or service marks are the property of their respective holders as described at www.altera.com/common/legal.html. Altera warrants performance of its
semiconductor products to current specifications in accordance with Altera's standard warranty, but reserves the right to make changes to any products and services
at any time without notice. Altera assumes no responsibility or liability arising out of the application or use of any information, product, or service described herein
except as expressly agreed to in writing by Altera. Altera customers are advised to obtain the latest version of device specifications before relying on any published
information and before placing orders for products or services.
May 2011
Altera Corporation
Contents
Additional Information
Document Revision History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Info1
How to Contact Altera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Info1
Typographic Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Info1
May 2011
Altera Corporation
iv
Contents
This tutorial familiarizes you with the Nios II Software Build Tools (SBT) for Eclipse
and the MicroC/OS-II development flow. The Nios II SBT for Eclipse offers designers
a rich development platform for Nios II applications. The Nios II SBT for Eclipse
enables you to integrate the MicroC/OS-II real-time operating system, giving you the
ability to build MicroC/OS-II applications for the Nios II processor quickly. This
tutorial provides step-by-step instructions for building a simple program based on the
MicroC/OS-II RTOS and an Altera hardware design example.
f For complete details about MicroC/OS-II for the Nios II processor, refer to the
MicroC/OS-II Real-Time Operating System chapter in the Nios II Software Developers
Handbook.
One of the Altera development boards listed on the Nios II Ethernet Standard
Design Example page of the Altera website.
1
The page contains information about the design example and includes the
hardware design files for a number of Altera development boards.
The hardware design files for the Nios II Ethernet Standard design example
May 2011
Altera Corporation
12
When you extract the files from uCOS_II_Tutorial.zip, make sure there are
no spaces in your destination path.
receive_task1
nd
e
QP
send_task
OSQPostOpt
OS
OS
QP
en
d
receive_task2
OSSemPost
OSSemPend
OSSemPend
OSSemPost
getsem_task2
getsem_task1
As shown in Figure 11, the design has five active tasks. send_task fills up a message
queue with incrementing data. receive_task1 and receive_task2 periodically pull
messages out of the message queue. getsem_task1 and getsem_task2 compete over a
shared resource that is protected by a semaphore. The design also has two tasks not
shown in Figure 11: one for initialization and one for printing status information.
The process for creating a MicroC/OS-II software image for the Nios II processor
involves the following steps:
1. Create a new Nios II SBT for Eclipse project.
2. Configure the Nios II board support package (BSP).
3. Build and run the Nios II software project.
13
In the Windows operating system, on the Start menu, point to Programs >
Altera > Nios II EDS <version>, and click Nios II <version> Software Build
Tools for Eclipse.
2. If the Workspace Launcher dialog box appears, click OK to accept the default
workspace location.
May 2011
Altera Corporation
14
3. On the File menu, point to New, and click Nios II Application and BSP from
Template. The first page of the Nios II Application and BSP from Template
wizard appears, as shown in Figure 12.
Figure 12. Selecting the Application Project Template
15
9. Ensure that Create a new BSP project based on the application project template
is selected and Use default location is on.
1
In this tutorial, you use the Hello MicroC/OS-II project template to easily
and quickly create a BSP based on MicroC/OS-II. However, if you wish to
use your own BSP, select Select an existing BSP project from your
workspace and use the bottom portion of the Nios II Application and BSP
from Template wizard to select, create, or import your BSP. Make sure that
your BSP is based on the MicroC/OS-II operating system.
May 2011
Altera Corporation
16
11. The Nios II SBT for Eclipse creates two folders, visible in the Project Explorer view:
ucosii_tutorial and ucosii_tutorial_bsp. To view the files created from the Hello
MicroC/OS-II project template, expand the ucosii_tutorial and
ucosii_tutorial_bsp projects, as shown in Figure 14.
Figure 14. Files Created from the Project Template
12. In the application project, delete hello_ucosii.c (right-click the file and click
Delete).
17
ucosii_tutorial.c
alt_ucosii_simple_error_check.c
alt_ucosii_simple_error_check.h
You have created the MicroC/OS-II application. You configure the BSP in the next
section.
May 2011
Altera Corporation
18
1. Right-click ucosii_tutorial_bsp, point to Nios II, and click BSP Editor, as shown
in Figure 16. The Nios II BSP Editor opens.
Figure 16. Launching the Nios II BSP Editor
19
2. In the BSP Editor Main tab, locate the expandable tree of settings, expand
Advanced, and then expand and select ucosii.
You can see that the BSP settings for MicroC/OS-II are highly configurable, as
shown in Figure 17. The settings determine which MicroC/OS-II options are
included in the binary image. The Nios II SBT also saves the setting values to the
system.h file.
Figure 17. BSP Settings for MicroC/OS-II
May 2011
Altera Corporation
110
4. Expand the Common settings, expand and select hal, and ensure that stderr, stdin
and stdout are all set to peripheral_subsystem_jtag_uart.
5. If you make any changes, save the BSP and click Generate to recreate the BSP files.
6. Click Exit to close the BSP Editor.
You have finished configuring the BSP. You are ready to build and run the software
example as described in the next section.
111
2. Make sure power on the development board is on, and the USB cable is properly
attached and detected by the Quartus II Programmer.
3. Click Hardware Setup in the upper left corner of the Quartus II Programmer to
verify your download cable settings. The Hardware Setup dialog box appears.
4. On the Hardware Settings tab, select the appropriate download cable in the
Currently selected hardware list. If the appropriate download cable does not
appear in the list, you must first install drivers for the cable.
f For information about download cables and drivers, refer to the Download
Cables page of the Altera website.
5. Click Close.
6. On the File menu in Quartus II Programmer, click Open.
7. Navigate to <your hardware design directory> and select
niosii_ethernet_standard_<board>.sof.
8. Click Open to select the .sof file and return to the Quartus II Programmer.
9. In the table row for the opened .sof, ensure that Program/Configure is on.
10. Click Start to configure the FPGA. Upon successful completion, the Quartus II
Programmer displays messages similar to the following example:
Info: Configuration succeeded -- 1 device(s) configured
Info: Successfully performed operation(s)
Info: Ended Programmer operation at Tue May 03 10:44:00 2011
11. Exit the Quartus II Programmer. You return to the Nios II SBT for Eclipse.
1
12. Right-click ucosii_tutorial and select Build Project to build the program. Building
the software might take several minutes.
13. Right-click ucosii_tutorial, point to Run As, and click Nios II Hardware to
download the program to the board and run it.
1
May 2011
Altera Corporation
If the Run Configurations dialog box appears, click the Target Connection
tab. Then click Refresh Connections and Apply until a board connection
establishes. Once the board connection is established, click Run.
112
123
If the correct output does not appear on the Nios II Console view, you might need to
turn on Reset the selected target system in the Target Connection tab of the Run
Configurations dialog box. You must relaunch your application after modifying the
run configuration.
Congratulations! You have successfully configured, built, and run a MicroC/OS-II
program.
f For more information about this example, examine the source file ucosii_tutorial.c.
For more information about the MicroC/OS-II operating system, refer to the
MicroC/OS-II Real-Time Operating System chapter in the Nios II Software Developer's
Handbook.
Additional Information
This chapter provides additional information about the document and Altera.
Version
Changes
May 2011
3.0
June 2010
2.0
January 2007
1.2
September 2004
1.1
May 2004
1.0
First publication
Contact Method
Address
Website
www.altera.com/support
Website
www.altera.com/training
Email
Website
custrain@altera.com
www.altera.com/literature
nacomp@altera.com
(Software Licensing)
authorization@altera.com
Note to Table:
(1) You can also contact your local Altera sales office or sales representative.
Typographic Conventions
The following table shows the typographic conventions this document uses.
Visual Cue
Meaning
Indicate command names, dialog box titles, dialog box options, and other GUI
labels. For example, Save As dialog box. For GUI elements, capitalization matches
the GUI.
bold type
Indicates directory names, project names, disk drive names, file names, file name
extensions, software utility names, and GUI labels. For example, \qdesigns
directory, D: drive, and chiptrip.gdf file.
May 2011
Altera Corporation
Info2
Additional Information
Typographic Conventions
Visual Cue
Meaning
Indicates variables. For example, n + 1.
italic type
Variable names are enclosed in angle brackets (< >). For example, <file name> and
<project name>.pof file.
Indicate keyboard keys and menu names. For example, the Delete key and the
Options menu.
Subheading Title
Courier type
Indicates command line commands and anything that must be typed exactly as it
appears. For example, c:\qdesigns\tutorial\chiptrip.gdf.
Also indicates sections of an actual file, such as a Report File, references to parts of
files (for example, the AHDL keyword SUBDESIGN), and logic function names (for
example, TRI).
Numbered steps indicate a list of items when the sequence of the items is important,
such as the steps listed in a procedure.
Bullets indicate a list of items when the sequence of the items is not important.
The question mark directs you to a software help system with related information.
The feet direct you to another document or website with related information.
A warning calls attention to a condition or possible situation that can cause you
injury.
The envelope links to the Email Subscription Management Center page of the Altera
website, where you can sign up to receive update notifications for Altera documents.