<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- permission is obtained from the copyright holder. -->
|
<!-- permission is obtained from the copyright holder. -->
|
<HTML
|
<HTML
|
><HEAD
|
><HEAD
|
><TITLE
|
><TITLE
|
>Building and Running Sample Applications</TITLE
|
>Building and Running Sample Applications</TITLE
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
<META
|
<META
|
NAME="GENERATOR"
|
NAME="GENERATOR"
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
"><LINK
|
"><LINK
|
REL="HOME"
|
REL="HOME"
|
TITLE="eCos User Guide"
|
TITLE="eCos User Guide"
|
HREF="ecos-user-guide.html"><LINK
|
HREF="ecos-user-guide.html"><LINK
|
REL="UP"
|
REL="UP"
|
TITLE="Programming With eCos"
|
TITLE="Programming With eCos"
|
HREF="user-guide-programming.html"><LINK
|
HREF="user-guide-programming.html"><LINK
|
REL="PREVIOUS"
|
REL="PREVIOUS"
|
TITLE="Testing Filters"
|
TITLE="Testing Filters"
|
HREF="testing-filters.html"><LINK
|
HREF="testing-filters.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="A Sample Program with Two Threads"
|
TITLE="A Sample Program with Two Threads"
|
HREF="sample-twothreads.html"></HEAD
|
HREF="sample-twothreads.html"></HEAD
|
><BODY
|
><BODY
|
CLASS="CHAPTER"
|
CLASS="CHAPTER"
|
BGCOLOR="#FFFFFF"
|
BGCOLOR="#FFFFFF"
|
TEXT="#000000"
|
TEXT="#000000"
|
LINK="#0000FF"
|
LINK="#0000FF"
|
VLINK="#840084"
|
VLINK="#840084"
|
ALINK="#0000FF"
|
ALINK="#0000FF"
|
><DIV
|
><DIV
|
CLASS="NAVHEADER"
|
CLASS="NAVHEADER"
|
><TABLE
|
><TABLE
|
SUMMARY="Header navigation table"
|
SUMMARY="Header navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TH
|
><TH
|
COLSPAN="3"
|
COLSPAN="3"
|
ALIGN="center"
|
ALIGN="center"
|
>eCos User Guide</TH
|
>eCos User Guide</TH
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="testing-filters.html"
|
HREF="testing-filters.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="80%"
|
WIDTH="80%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="sample-twothreads.html"
|
HREF="sample-twothreads.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"></DIV
|
WIDTH="100%"></DIV
|
><DIV
|
><DIV
|
CLASS="CHAPTER"
|
CLASS="CHAPTER"
|
><H1
|
><H1
|
><A
|
><A
|
NAME="BUILDING-AND-RUNNING-SAMPLE-APPLIATIONS">Chapter 13. Building and Running Sample Applications</H1
|
NAME="BUILDING-AND-RUNNING-SAMPLE-APPLIATIONS">Chapter 13. Building and Running Sample Applications</H1
|
><DIV
|
><DIV
|
CLASS="TOC"
|
CLASS="TOC"
|
><DL
|
><DL
|
><DT
|
><DT
|
><B
|
><B
|
>Table of Contents</B
|
>Table of Contents</B
|
></DT
|
></DT
|
><DT
|
><DT
|
><A
|
><A
|
HREF="building-and-running-sample-appliations.html#ECOS-HELLO-WORLD"
|
HREF="building-and-running-sample-appliations.html#ECOS-HELLO-WORLD"
|
><SPAN
|
><SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
> Hello World</A
|
> Hello World</A
|
></DT
|
></DT
|
><DT
|
><DT
|
><A
|
><A
|
HREF="sample-twothreads.html"
|
HREF="sample-twothreads.html"
|
>A Sample Program with Two Threads</A
|
>A Sample Program with Two Threads</A
|
></DT
|
></DT
|
></DL
|
></DL
|
></DIV
|
></DIV
|
><P
|
><P
|
>The example programs in this tutorial are included, along
|
>The example programs in this tutorial are included, along
|
with a <TT
|
with a <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>Makefile</TT
|
>Makefile</TT
|
>, in the <TT
|
>, in the <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>examples</TT
|
>examples</TT
|
> directory
|
> directory
|
of the <SPAN
|
of the <SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
> distribution. The first program you will run is a <SPAN
|
> distribution. The first program you will run is a <SPAN
|
CLASS="emphasis"
|
CLASS="emphasis"
|
><I
|
><I
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>hello
|
>hello
|
world</I
|
world</I
|
></SPAN
|
></SPAN
|
>-style application, then you will run a more complex
|
>-style application, then you will run a more complex
|
application that demonstrates the creation of threads and the use
|
application that demonstrates the creation of threads and the use
|
of cyg_thread_delay(), and finally you will run
|
of cyg_thread_delay(), and finally you will run
|
one that uses clocks and alarm handlers.</P
|
one that uses clocks and alarm handlers.</P
|
><P
|
><P
|
>The <TT
|
>The <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>Makefile</TT
|
>Makefile</TT
|
> depends on an externally
|
> depends on an externally
|
defined variable to find the <SPAN
|
defined variable to find the <SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
> library and header files. This
|
> library and header files. This
|
variable is <TT
|
variable is <TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>INSTALL_DIR</TT
|
>INSTALL_DIR</TT
|
> and must be set to the
|
> and must be set to the
|
pathname of the install directory created in <A
|
pathname of the install directory created in <A
|
HREF="using-configtool-windows-linux.html"
|
HREF="using-configtool-windows-linux.html"
|
>the Section called <I
|
>the Section called <I
|
>Configuration Tool on Windows and Linux Quick Start</I
|
>Configuration Tool on Windows and Linux Quick Start</I
|
> in Chapter 11</A
|
> in Chapter 11</A
|
>.</P
|
>.</P
|
><P
|
><P
|
><TT
|
><TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>INSTALL_DIR</TT
|
>INSTALL_DIR</TT
|
> may be either be set in the shell
|
> may be either be set in the shell
|
environment or may be supplied on the command line. To set it in the
|
environment or may be supplied on the command line. To set it in the
|
shell do the following in a <B
|
shell do the following in a <B
|
CLASS="COMMAND"
|
CLASS="COMMAND"
|
>bash</B
|
>bash</B
|
> shell:</P
|
> shell:</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="PROGRAMLISTING"
|
CLASS="PROGRAMLISTING"
|
>$ export INSTALL_DIR=BASE_DIR/ecos-work/arm_install</PRE
|
>$ export INSTALL_DIR=BASE_DIR/ecos-work/arm_install</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>You can then run <B
|
>You can then run <B
|
CLASS="COMMAND"
|
CLASS="COMMAND"
|
>make</B
|
>make</B
|
> without any extra parameters
|
> without any extra parameters
|
to build the examples.</P
|
to build the examples.</P
|
><P
|
><P
|
>Alternatively, if you can do the following:</P
|
>Alternatively, if you can do the following:</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="PROGRAMLISTING"
|
CLASS="PROGRAMLISTING"
|
>$ make INSTALL_DIR=BASE_DIR/ecos-work/arm_install</PRE
|
>$ make INSTALL_DIR=BASE_DIR/ecos-work/arm_install</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><DIV
|
><DIV
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><H1
|
><H1
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><A
|
><A
|
NAME="ECOS-HELLO-WORLD"><SPAN
|
NAME="ECOS-HELLO-WORLD"><SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
> Hello World</H1
|
> Hello World</H1
|
><P
|
><P
|
>The following code is found in the file <TT
|
>The following code is found in the file <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>hello.c</TT
|
>hello.c</TT
|
>
|
>
|
in the <TT
|
in the <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>examples</TT
|
>examples</TT
|
> directory: </P
|
> directory: </P
|
><DIV
|
><DIV
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><H2
|
><H2
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><A
|
><A
|
NAME="AEN835"><SPAN
|
NAME="AEN835"><SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
> hello world program listing</H2
|
> hello world program listing</H2
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="PROGRAMLISTING"
|
CLASS="PROGRAMLISTING"
|
>/* this is a simple hello world program */
|
>/* this is a simple hello world program */
|
#include <stdio.h>
|
#include <stdio.h>
|
int main(void)
|
int main(void)
|
{
|
{
|
printf("Hello, eCos world!\n");
|
printf("Hello, eCos world!\n");
|
return 0;
|
return 0;
|
}</PRE
|
}</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>To compile this or any other program that is not part of the
|
>To compile this or any other program that is not part of the
|
<SPAN
|
<SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
> distribution, you can follow the procedures described below. Type
|
> distribution, you can follow the procedures described below. Type
|
this explicit compilation command (assuming your current working
|
this explicit compilation command (assuming your current working
|
directory is also where you built the <SPAN
|
directory is also where you built the <SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
> kernel):</P
|
> kernel):</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="PROGRAMLISTING"
|
CLASS="PROGRAMLISTING"
|
>$ <TT
|
>$ <TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>TARGET-</I
|
>TARGET-</I
|
></TT
|
></TT
|
>gcc -g -I<TT
|
>gcc -g -I<TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>BASE_DIR</I
|
>BASE_DIR</I
|
></TT
|
></TT
|
>/ecos-work/install/include hello.c -L<TT
|
>/ecos-work/install/include hello.c -L<TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>BASE_DIR</I
|
>BASE_DIR</I
|
></TT
|
></TT
|
>/ecos-work/install/lib -Ttarget.ld -nostdlib</PRE
|
>/ecos-work/install/lib -Ttarget.ld -nostdlib</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>The compilation command above contains some standard GCC
|
>The compilation command above contains some standard GCC
|
options (for example, <TT
|
options (for example, <TT
|
CLASS="OPTION"
|
CLASS="OPTION"
|
>-g</TT
|
>-g</TT
|
> enables debugging), as well
|
> enables debugging), as well
|
as some mention of paths
|
as some mention of paths
|
(<TT
|
(<TT
|
CLASS="OPTION"
|
CLASS="OPTION"
|
>-I<TT
|
>-I<TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>BASE_DIR</I
|
>BASE_DIR</I
|
></TT
|
></TT
|
>/ecos-work/install/include</TT
|
>/ecos-work/install/include</TT
|
> allows files
|
> allows files
|
like <TT
|
like <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>cyg/kernel/kapi.h</TT
|
>cyg/kernel/kapi.h</TT
|
> to be found, and
|
> to be found, and
|
<TT
|
<TT
|
CLASS="OPTION"
|
CLASS="OPTION"
|
>-L<TT
|
>-L<TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>BASE_DIR</I
|
>BASE_DIR</I
|
></TT
|
></TT
|
>/ecos-work/install/lib</TT
|
>/ecos-work/install/lib</TT
|
> allows the linker to
|
> allows the linker to
|
find <TT
|
find <TT
|
CLASS="OPTION"
|
CLASS="OPTION"
|
>-Ttarget.ld</TT
|
>-Ttarget.ld</TT
|
>). </P
|
>). </P
|
><P
|
><P
|
>The executable program will be called <TT
|
>The executable program will be called <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>a.out</TT
|
>a.out</TT
|
>. </P
|
>. </P
|
><DIV
|
><DIV
|
CLASS="NOTE"
|
CLASS="NOTE"
|
><BLOCKQUOTE
|
><BLOCKQUOTE
|
CLASS="NOTE"
|
CLASS="NOTE"
|
><P
|
><P
|
><B
|
><B
|
>Note: </B
|
>Note: </B
|
>Some target systems require special options to be passed to
|
>Some target systems require special options to be passed to
|
gcc to compile correctly for that system. Please examine the Makefile
|
gcc to compile correctly for that system. Please examine the Makefile
|
in the examples directory to see if this applies to your target.</P
|
in the examples directory to see if this applies to your target.</P
|
></BLOCKQUOTE
|
></BLOCKQUOTE
|
></DIV
|
></DIV
|
><P
|
><P
|
>You can now run the resulting program using GDB in exactly the
|
>You can now run the resulting program using GDB in exactly the
|
same the way you ran the test case before. The procedure will be the
|
same the way you ran the test case before. The procedure will be the
|
same, but this time run
|
same, but this time run
|
<B
|
<B
|
CLASS="COMMAND"
|
CLASS="COMMAND"
|
><TT
|
><TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>TARGET-</I
|
>TARGET-</I
|
></TT
|
></TT
|
>gdb</B
|
>gdb</B
|
> specifying
|
> specifying
|
<TT
|
<TT
|
CLASS="OPTION"
|
CLASS="OPTION"
|
>-nw a.out</TT
|
>-nw a.out</TT
|
> on the command line:</P
|
> on the command line:</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="PROGRAMLISTING"
|
CLASS="PROGRAMLISTING"
|
>$ <TT
|
>$ <TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>TARGET-</I
|
>TARGET-</I
|
></TT
|
></TT
|
>gdb -nw a.out</PRE
|
>gdb -nw a.out</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>For targets other than the synthetic linux target, you should
|
>For targets other than the synthetic linux target, you should
|
now run the usual GDB commands described earlier. Once this is done,
|
now run the usual GDB commands described earlier. Once this is done,
|
typing the command "continue" at the (gdb) prompt ("run" for
|
typing the command "continue" at the (gdb) prompt ("run" for
|
simulators) will allow the program to execute and print the string
|
simulators) will allow the program to execute and print the string
|
"Hello, eCos world!" on your screen.</P
|
"Hello, eCos world!" on your screen.</P
|
><P
|
><P
|
>On the synthetic linux target, you may use the "run" command
|
>On the synthetic linux target, you may use the "run" command
|
immediately - you do not need to connect to the target, nor use the
|
immediately - you do not need to connect to the target, nor use the
|
"load" command.</P
|
"load" command.</P
|
></DIV
|
></DIV
|
></DIV
|
></DIV
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="NAVFOOTER"
|
CLASS="NAVFOOTER"
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"><TABLE
|
WIDTH="100%"><TABLE
|
SUMMARY="Footer navigation table"
|
SUMMARY="Footer navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="testing-filters.html"
|
HREF="testing-filters.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="ecos-user-guide.html"
|
HREF="ecos-user-guide.html"
|
ACCESSKEY="H"
|
ACCESSKEY="H"
|
>Home</A
|
>Home</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="sample-twothreads.html"
|
HREF="sample-twothreads.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
>Testing Filters</TD
|
>Testing Filters</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="user-guide-programming.html"
|
HREF="user-guide-programming.html"
|
ACCESSKEY="U"
|
ACCESSKEY="U"
|
>Up</A
|
>Up</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
>A Sample Program with Two Threads</TD
|
>A Sample Program with Two Threads</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|