File: [local] / prex-old / doc / html / doc / sample.html (download) (as text)
Revision 1.1.1.1 (vendor branch), Tue Jun 3 09:38:43 2008 UTC (16 years ago) by nbrk
Branch: MAIN, KOHSUKE
CVS Tags: PREX_0_7_BASE, HEAD Branch point for: PREX_0_8_BASE
Changes since 1.1: +0 -0 lines
Yeah, this is an initial import of Prex, portable real-time microkernel
operating system. I wanna hack it for non-profit but fun, so let it in.
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Prex Sample Codes</title>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<meta name="keywords" content="Prex, embedded, real-time, operating system, RTOS, open source, free">
<meta name="author" content="Kohsuke Ohtani">
<link rel="stylesheet" type="text/css" href="../default.css" media="screen">
<link rel="stylesheet" type="text/css" href="../print.css" media="print">
</head>
<body>
<div id="top">
</div>
<div id="middle">
<table id="content" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td id="header" colspan="2" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td id="logo">
<a href="http://prex.sourceforge.net/">
<img alt="Prex logo" src="../img/logo.gif" border="0"
style="width: 281px; height: 56px;"></a>
</td>
<td id="brief" align="right" valign="bottom">
An Open Source, Royalty-free,<br>
Real-time Operating System
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td id="directory" style="vertical-align: top;">
<a href="http://prex.sourceforge.net/">Prex Home</a> >
<a href="index.html">Document Index</a> >
Sample Codes
</tr>
<tr><td class="pad" colspan="2" style="vertical-align: top;"></td></tr>
<tr>
<td id="main" style="vertical-align: top;">
<h1>Sample Codes</h1>
<i>Version 1.0, 2005/09/01</i>
<h3>Table of Contents</h3>
<ul>
<li><a href="#run">Running a new thread</a></li>
<li><a href="#ptmr">Periodic timer</a></li>
</ul>
<br>
<h2 id="run">Running a new thread</h2>
<p>
This is a sample to create and run a new thread in the same task.
</p>
<pre>
int thread_run(void *start, void *stack, thread_t *th)
{
thread_t t;
int err;
err = thread_create(task_self(), &t);
if (err)
return err;
err = thread_load(t, start, stack);
if (err)
return err;
err = thread_resume(t);
if (err)
return err;
*th = t;
return 0;
}
</pre>
<h2 id="ptmr">Periodic timer</h2>
<p>
This is a sample to show a message per 100msec starting after 5sec.
</p>
<pre>
int main()
{
int count = 0;
sys_log("periodic timer test program\n");
/* Setup timer */
timer_periodic(thread_self(), 5000, 100);
while (count++ < 5) {
timer_waitperiod();
sys_log("Hello!\n");
}
/* Cancel timer */
timer_periodic(thread_self(), 0, 0);
return 0;
}
</pre>
</td>
</tr>
<tr>
<td id="footer" colspan="2" style="vertical-align: top;">
<a href="http://sourceforge.net">
<img src="http://sourceforge.net/sflogo.php?group_id=132028&type=1"
alt="SourceForge.net Logo" border="0" height="31" width="88"></a><br>
Copyright© 2005-2007 Kohsuke Ohtani
</td>
</tr>
</tbody>
</table>
</div>
<div id="bottom"></div>
</body>
</html>