<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.ethernut.de/nutwiki/index.php?action=history&amp;feed=atom&amp;title=Run_Once_Thread</id>
		<title>Run Once Thread - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.ethernut.de/nutwiki/index.php?action=history&amp;feed=atom&amp;title=Run_Once_Thread"/>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Run_Once_Thread&amp;action=history"/>
		<updated>2026-04-29T00:25:36Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://www.ethernut.de/nutwiki/index.php?title=Run_Once_Thread&amp;diff=246&amp;oldid=prev</id>
		<title>Harald: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Run_Once_Thread&amp;diff=246&amp;oldid=prev"/>
				<updated>2016-10-27T16:03:00Z</updated>
		
		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 16:03, 27 October 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;' lang='en'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Harald</name></author>	</entry>

	<entry>
		<id>http://www.ethernut.de/nutwiki/index.php?title=Run_Once_Thread&amp;diff=245&amp;oldid=prev</id>
		<title>AdrianPyka: /* Test Environment */</title>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Run_Once_Thread&amp;diff=245&amp;oldid=prev"/>
				<updated>2010-08-02T11:20:53Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Test Environment&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;smalldiv&amp;quot;&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; |&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | Hardware Comments&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.8.3'''&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.8.7'''&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Ethernut 1.3 H&amp;lt;/span&amp;gt;&lt;br /&gt;
| &lt;br /&gt;
| OK &amp;lt;br&amp;gt; [[Media:Run-once-thread-enut13H-nutos-4.8.3.zip|'''Binaries''']]&amp;lt;br&amp;gt;'''Compiler:''' AVR-GCC 4.3.2&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [[Media:Run-once-thread-enut13H-nutos-4.8.7.zip|'''Binaries''']]&amp;lt;br&amp;gt;'''Compiler:''' AVR-GCC 4.3.2&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Ethernut 2.1 B&amp;lt;/span&amp;gt;&lt;br /&gt;
| &lt;br /&gt;
| OK &amp;lt;br&amp;gt; [[Media:Run-once-thread-enut21B-nutos-4.8.3.zip|'''Binaries''']]&amp;lt;br&amp;gt;'''Compiler:''' AVR-GCC 4.3.2&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [[Media:Run-once-thread-enut21B-nutos-4.8.7.zip|'''Binaries''']]&amp;lt;br&amp;gt;'''Compiler:''' AVR-GCC 4.3.2&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Ethernut 3.0 E&amp;lt;/span&amp;gt;&lt;br /&gt;
| &lt;br /&gt;
| OK &amp;lt;br&amp;gt; [[Media:Run-once-thread-enut30E-nutos-4.8.3.zip|'''Binaries''']]&amp;lt;br&amp;gt;'''Compiler:''' ARM-GCC 4.3.3&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [[Media:Run-once-thread-enut30E-nutos-4.8.7.zip|'''Binaries''']]&amp;lt;br&amp;gt;'''Compiler:''' ARM-GCC 4.3.3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This sample should run on all platforms. I actually used:&lt;br /&gt;
&lt;br /&gt;
Nut/OS: Version 4.1.0&lt;br /&gt;
&lt;br /&gt;
Hardware: Ethernut 2.1B with ATmega2561. &lt;br /&gt;
&lt;br /&gt;
Compiler: avr-gcc (GCC) 4.1.2 (WinAVR 20070525)&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
This sample demonstrates how to terminate a running thread.&lt;br /&gt;
&lt;br /&gt;
When started, the program enters an endless loop, which continuously creates a thread and then sleeps for 1.5 seconds. As soon as the main loop is sleeping, the new thread starts, sleeps for 1 second and then terminates.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;io.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;dev/board.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;sys/thread.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/timer.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Temporary thread.&lt;br /&gt;
 */&lt;br /&gt;
THREAD(RunOnce, arg)&lt;br /&gt;
{&lt;br /&gt;
    puts(&amp;quot;Started&amp;quot;);&lt;br /&gt;
    NutSleep(1000);&lt;br /&gt;
&lt;br /&gt;
    puts(&amp;quot;Terminating\n&amp;quot;);&lt;br /&gt;
    NutThreadExit();&lt;br /&gt;
&lt;br /&gt;
    for(;;); /* Avoids compiler warning. */&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Application entry. &lt;br /&gt;
 */&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
    u_long baud = 115200;&lt;br /&gt;
&lt;br /&gt;
    /* Enable standard output. */&lt;br /&gt;
    NutRegisterDevice(&amp;amp;DEV_UART, 0, 0);&lt;br /&gt;
    freopen(DEV_UART_NAME, &amp;quot;w&amp;quot;, stdout);&lt;br /&gt;
    _ioctl(_fileno(stdout), UART_SETSPEED, &amp;amp;baud);&lt;br /&gt;
&lt;br /&gt;
    puts(&amp;quot;\nRun Once Thread Test&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    /* Endless loop. */&lt;br /&gt;
    for (;;) {&lt;br /&gt;
        puts(&amp;quot;Creating&amp;quot;);&lt;br /&gt;
        NutThreadCreate(&amp;quot;once&amp;quot;, RunOnce, 0, 256);&lt;br /&gt;
        NutSleep(1500);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    return 0;  /* Avoids compiler warning. */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Building the Binaries ==&lt;br /&gt;
&lt;br /&gt;
# If not done, create a sample directory with the Configurator.&lt;br /&gt;
# In the sample directory create a new directory named runonce.&lt;br /&gt;
# In the new directory create a new file named runonce.c. Use a plain text editor.&lt;br /&gt;
# Copy the source above into the new file. Use the clipboard.&lt;br /&gt;
# Save the new file.&lt;br /&gt;
# Create another file named Makefile in the same directory. Again use your text editor.&lt;br /&gt;
# Copy the sample Makefile given below. &lt;br /&gt;
# Replace any leading spaces with a tab character. This is important.&lt;br /&gt;
# Save the Makefile.&lt;br /&gt;
# Open a command line window and navigate to the newly created directory.&lt;br /&gt;
# On Windows PCs, make sure that your environment is properly set (example is given below).&lt;br /&gt;
# On the command line enter ''make''&lt;br /&gt;
&lt;br /&gt;
Among others, the files runonce.bin, runonce.hex and runonce.elf will be created. Use the proper method, depending on your hardware, to upload one of these to the target board.&lt;br /&gt;
&lt;br /&gt;
Contents of the Makefile (spaces in front of ''-rm'' must be replaced by a tab character):&lt;br /&gt;
 PROJ = runonce&lt;br /&gt;
 include ../Makedefs&lt;br /&gt;
 SRCS =  $(PROJ).c&lt;br /&gt;
 OBJS =  $(SRCS:.c=.o)&lt;br /&gt;
 LIBS =  $(LIBDIR)/nutinit.o -lnutcrt -lnutos -lnutdev -lnutarch $(ADDLIBS)&lt;br /&gt;
 TARG =  $(PROJ).hex&lt;br /&gt;
 all: $(OBJS) $(TARG) $(ITARG) $(DTARG)&lt;br /&gt;
 include ../Makerules&lt;br /&gt;
 clean:&lt;br /&gt;
        -rm -f $(OBJS)&lt;br /&gt;
        -rm -f $(TARG) $(ITARG) $(DTARG)&lt;br /&gt;
        -rm -f $(PROJ).eep&lt;br /&gt;
        -rm -f $(PROJ).obj&lt;br /&gt;
        -rm -f $(PROJ).map&lt;br /&gt;
        -rm -f $(SRCS:.c=.lst)&lt;br /&gt;
        -rm -f $(SRCS:.c=.bak)&lt;br /&gt;
        -rm -f $(SRCS:.c=.i)&lt;br /&gt;
&lt;br /&gt;
On Windows use the following command shows how to setup your environment. This is just an example. The actual paths on your computer will be different, if you installed Nut/OS or WinAVR in another location.&lt;br /&gt;
&lt;br /&gt;
 SET PATH=C:\ethernut-4.4.0\nut\tools\win32;C:\WinAVR\bin;C:\WinAVR\utils\bin;%PATH%&lt;br /&gt;
&lt;br /&gt;
The expected output when running ''make'' is similar to&lt;br /&gt;
&lt;br /&gt;
 avr-gcc -c -mmcu=atmega2561 -Os -fno-delete-null-pointer-checks &lt;br /&gt;
  -Wall -Wstrict-prototypes -Wa,-ahlms=runonce.lst -DETHERNUT2&lt;br /&gt;
  -D__HARVARD_ARCH__ -DATMega2561 -I../../nutbld-enut21b-256gcc/include&lt;br /&gt;
  -I../../nut/include  runonce.c -o runonce.o&lt;br /&gt;
 avr-gcc runonce.o -mmcu=atmega2561 -Wl,--defsym=main=0,-Map=runonce.map,&lt;br /&gt;
  --cref -L../../nutbld-enut21b-256gcc/lib -Wl,--start-group&lt;br /&gt;
  ../../nutbld-enut21b-256gcc/lib/nutinit.o -lnutcrt -lnutos -lnutdev &lt;br /&gt;
  -lnutarch  -Wl,--end-group -o runonce.elf&lt;br /&gt;
 avr-objcopy -R .eeprom -O ihex runonce.elf runonce.hex&lt;br /&gt;
 avr-objcopy -O binary runonce.elf runonce.bin&lt;br /&gt;
&lt;br /&gt;
== Expected Program Output ==&lt;br /&gt;
&lt;br /&gt;
On stdout (default UART at 115.2 kBaud, 8n1) the following output should be seen:&lt;br /&gt;
&lt;br /&gt;
 Run Once Thread Test&lt;br /&gt;
 Creating&lt;br /&gt;
 Started&lt;br /&gt;
 Terminating&lt;br /&gt;
 &lt;br /&gt;
 Creating&lt;br /&gt;
 Started&lt;br /&gt;
 Terminating&lt;br /&gt;
 &lt;br /&gt;
 Creating&lt;br /&gt;
 Started&lt;br /&gt;
 Terminating&lt;br /&gt;
 &lt;br /&gt;
 Creating&lt;br /&gt;
 Started&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* More [[Nut/OS Examples]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Code Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Languages}}&lt;/div&gt;</summary>
		<author><name>AdrianPyka</name></author>	</entry>

	</feed>