<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>TE@Onghu RSS Feed</title>
    <link>http://t-engine.onghu.com/rss/</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Articles and news from the TE@Onghu website.</description>
    
    
        <item>
          <title>SDI Device Driver Guide - Part 2</title>
          <description>&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
.cpp1-assembler { color: #0000FF; }
.cpp1-character { }
.cpp1-comment { color: #808080; font-size: 0.9em; }
.cpp1-currentline { color: #000000; }
.cpp1-float { }
.cpp1-hexadecimal { }
.cpp1-identifier { color: #000080; }
.cpp1-illegalchar { color: #FF00FF; }
.cpp1-matchedbraces { color: #FF0000; }
.cpp1-number { color: #FF0000; }
.cpp1-octal { }
.cpp1-preprocessor { color: #008080; }
.cpp1-reservedword { color: #0000FF; font-weight: bold; }
.cpp1-rightedge { color: #C0C0C0; }
.cpp1-selection { color: #191919; }
.cpp1-space { color: #000000; }
.cpp1-string { color: #800000; }
.cpp1-symbol { color: #808080; }
--&gt;
&lt;/style&gt;


	&lt;h1&gt;&lt;span class=&quot;caps&quot;&gt;SDI&lt;/span&gt; Device Driver Guide &amp;#8211; Part 2&lt;/h1&gt;


	&lt;p&gt;Written by: Mukul Sharma and Fauzi Abbas, Centre for High Performance Embedded Systems, &lt;span class=&quot;caps&quot;&gt;NTU&lt;/span&gt; Singapore &lt;br&gt;
Edited by: Mohit Sindhwani (TE@Onghu)&lt;/p&gt;


	&lt;p&gt;In &lt;a href=&quot;/en/articles/sdi-device-driver-guide-part-1/&quot;&gt;the first part of this article&lt;/a&gt;, we explained the process for writing a device driver.  In this concluding part, we look at the process for using the device driver &amp;#8211; building, running and accessing the driver from an application.&lt;/p&gt;


	&lt;p&gt;The main thing to remember is that a device driver is not very different from a regular application, and many of the rules regarding applications apply also to device drivers.&lt;/p&gt;


	&lt;h2&gt;Compiling the Device Driver&lt;/h2&gt;


	&lt;p&gt;The Sample Device Driver can be build and compiled similarly as any other T-Kernel Application.  The procedure described in the article, &lt;a href=&quot;/en/articles/building-and-running-a-sample-program/&quot;&gt;&amp;#8220;Building and Running a Sample Program&amp;#8221;&lt;/a&gt;, is applicable to the device driver also.  It compiles like a regular application.&lt;/p&gt;


	&lt;p&gt;However, there is one big difference &amp;#8211; the makefile.&lt;/p&gt;


	&lt;p&gt;The &lt;code&gt;Makerules&lt;/code&gt; files for applications and device drivers are quite different and the &lt;code&gt;Makefile&lt;/code&gt; for the driver should point to the correct &lt;code&gt;Makerules&lt;/code&gt; file which is at &lt;code&gt;/te/etc/Makerules&lt;/code&gt;.  It is a good idea to build the driver from a project folder inside the &lt;code&gt;/te/driver&lt;/code&gt; directory, so that the &lt;code&gt;Makefile&lt;/code&gt; points to the correct &lt;code&gt;Makerules&lt;/code&gt; file.&lt;/p&gt;


	&lt;h2&gt;Running the Device Driver&lt;/h2&gt;


	&lt;p&gt;If you follow the procedure in the above article, you can download the device driver executable to the T-Engine using the serial console.  Assuming that the executable is called &lt;code&gt;sample_driver&lt;/code&gt; run the following command to launch the driver after it has been downloaded.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
lodspg     sample_driver

&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;If you want to automatically launch the device driver when the T-Engine is started, you can follow the steps in &lt;a href=&quot;/en/articles/howto-load-an-application-at-system-startup/&quot;&gt;this &lt;span class=&quot;caps&quot;&gt;HOWTO&lt;/span&gt; article&lt;/a&gt;.&lt;/p&gt;


	&lt;h2&gt;Sample Device Driver &amp;#8211; Include File&lt;/h2&gt;


	&lt;p&gt;As mentioned in the previous part, the device driver can define certain constants that may be needed by the application that uses the device driver.  This can be done by defining the constants in a header file (e.g. &lt;code&gt;sample_drvr.h&lt;/code&gt;) and this header file can be copied to an include folder of the T-Engine environment (somewhere under &lt;code&gt;/te/include&lt;/code&gt;).&lt;/p&gt;


	&lt;h2&gt;Sample Application using the Device Driver&lt;/h2&gt;


	&lt;p&gt;The following source code shows a simple application that uses the device driver.&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;&lt;span style=&quot;font: 9pt Monaco;&quot;&gt;&lt;span class=&quot;cpp1-preprocessor&quot;&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;tk/tkernel.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;sample_drvr.h&amp;gt;

&lt;/span&gt;&lt;span class=&quot;cpp1-reservedword&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-reservedword&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;)
{
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;UB&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;devnm&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;cpp1-number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;];&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* device name */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ID&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;dds&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* device descriptor */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;INT&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;asiz&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;     &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* read/write size */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ER&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ercd&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;     &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* error code */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;INT&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;dvc&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;

&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;strcpy&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;devnm&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-string&quot;&gt;&amp;quot;DRVSAMP&amp;quot;&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* our device name */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    
    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* The next line will result in our openfn function being called */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;dds&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;tk_opn_dev&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;devnm&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;TD_UPDATE&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* open device in update mode */

&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-reservedword&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;dds&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;E_OK&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;)
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;{
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-string&quot;&gt;&amp;quot; Failed to open device. \n&amp;quot;&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;);
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;cpp1-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;}

&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-string&quot;&gt;&amp;quot; Device Descripter - %x \n&amp;quot;&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;dds&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;);

&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* read the device specifications */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ercd&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;tk_srea_dev&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;dds&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;DN_DVCSPEC&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;dvc&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-reservedword&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;INT&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;asiz&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;);
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-reservedword&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ercd&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;E_OK&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-reservedword&quot;&gt;goto&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;

&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* write device specification */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ercd&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;tk_swri_dev&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;dds&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;DN_DVCSPEC&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;dvc&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-reservedword&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;INT&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;asiz&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;);
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-reservedword&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ercd&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;E_OK&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-reservedword&quot;&gt;goto&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;

&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* Use the device for other things */

&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;:
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;tk_cls_dev&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;dds&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* Close device - will call our closefn */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-string&quot;&gt;&amp;quot; Exiting Demo ! \n&amp;quot;&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;);

&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-reservedword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;
}

&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

	&lt;h2&gt;Building and Running the Application&lt;/h2&gt;


	&lt;p&gt;Build the application like a regular T-Kernel application, download it to the T-Engine and if it is called &lt;code&gt;driver_demo&lt;/code&gt;, launch it using:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
lodspg     driver_demo

&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;You should see something like the screen below when it runs.&lt;/p&gt;


&lt;div align=&quot;center&quot;&gt;
&lt;div class=&quot;photo&quot;&gt;&lt;img src=&quot;/page_attachments/0000/0086/terminal.jpg&quot; /&gt;&lt;/div&gt;
&lt;/div&gt;</description>
          <pubDate>Tue, 01 Apr 2008 04:20:00 GMT</pubDate>
          <guid>http://t-engine.onghu.com/en/articles/sdi-device-driver-guide-part-2/</guid>
          <link>http://t-engine.onghu.com/en/articles/sdi-device-driver-guide-part-2/</link>
        </item>
    
        <item>
          <title>HOWTO: Assembly Language Interrupt Service Routines</title>
          <description>&lt;style type=&quot;text/css&quot;&gt;
&amp;lt;!&amp;#8212;
body { color: #000000; background-color: #FFFFFF; }
.cpp1-assembler { color: #0000FF; }
.cpp1-character { }
.cpp1-comment { color: #808080; font-size: 0.9em; }
.cpp1-currentline { color: #000000; }
.cpp1-float { }
.cpp1-hexadecimal { }
.cpp1-identifier { color: #000080; }
.cpp1-illegalchar { color: #FF00FF; }
.cpp1-matchedbraces { color: #FF0000; }
.cpp1-number { color: #FF0000; }
.cpp1-octal { }
.cpp1-preprocessor { color: #008080; }
.cpp1-reservedword { color: #0000FF; font-weight: bold; }
.cpp1-rightedge { color: #C0C0C0; }
.cpp1-selection { color: #191919; }
.cpp1-space { color: #000000; }
.cpp1-string { color: #800000; }
.cpp1-symbol { color: #808080; }
&amp;#8212;&amp;gt;
&lt;/style&gt;

	&lt;h1&gt;&lt;span class=&quot;caps&quot;&gt;HOWTO&lt;/span&gt;: Assembly Language Interrupt Handlers&lt;/h1&gt;


	&lt;p&gt;Written by: Mohit Sindhwani, &lt;a href=&quot;http://www.viometrix.com/&quot;&gt;Viometrix&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;In a previous article, I had written about defining your own high-level interrupt handler from a T-Kernel application/ middleware.  In this brief &amp;#8216;how-to&amp;#8217; article, we look at some of the concepts in creating a low-level interrupt handler for the T-Kernel.&lt;/p&gt;


	&lt;h2&gt;Background&lt;/h2&gt;


	&lt;p&gt;In many embedded systems, interrupts are used to interface with the real world.  When an event happens, the peripheral responsible for dealing with it raises an interrupt to the &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt;.  The &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; then stops doing what it&amp;#8217;s doing, saves some of its essential context and attends to the interrupt.  The routine that deals with the interrupt is called the &lt;ins&gt;interrupt handler&lt;/ins&gt; (or &lt;ins&gt;interrupt service routine&lt;/ins&gt;) and is supposed to quickly do interrupt-related processing.  After this is completed, the &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; restores the context of the previously running program and execution continues as though nothing happened.  The specifics of how to install and use interrupt handlers is usually dependent on the &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; and/ or the &lt;span class=&quot;caps&quot;&gt;RTOS&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;The T-Kernel allows developers to create two types of interrupt handlers: handlers written in assembly or handlers written in a high-level language.  This article focuses primarily on assembly language handlers.  Details for high-level language handlers are available in the T-Kernel specification and in our other article.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Essential Reading:&lt;/strong&gt; As before, the main reference for this is actually &lt;ins&gt;Section 4.8 &amp;#8211; Interrupt Management Function&lt;/ins&gt; of the T-Kernel specification.  Refer to that section for more details.&lt;/p&gt;


	&lt;h2&gt;Coding the Interrupt Handler&lt;/h2&gt;


	&lt;p&gt;Similar to high-level interrupt handlers, a low-level interrupt handler must do at least the same sets of things:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;&lt;strong&gt;Read/ write data from/ to the peripheral:&lt;/strong&gt; This is the main task that needs to be done to respond to the interrupt.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Remove the interrupt request:&lt;/strong&gt; In devices such as the &lt;span class=&quot;caps&quot;&gt;UART&lt;/span&gt;, a read interrupt request is automatically removed when you read from the device.  However, in some devices such as timers, it is necessary to write to a special flag that clears the interrupt request.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Inform the application that the interrupt occurred:&lt;/strong&gt; In many cases, you will need to communicate to the running application that the event has happened.  Typically, this is done by issuing a system call.  To see the system calls that are possible from the &lt;acronym title=&quot;Interrupt Service Routine&quot;&gt;ISR&lt;/acronym&gt;, check &lt;ins&gt;Section 3.2.2&lt;/ins&gt; of the T-Kernel specification.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Return from the exception:&lt;/strong&gt; Finally, you need to return from the service handler.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;The main points of difference between an assembly interrupt handler and high-level interrupt handler are:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Entry into the Handler&lt;/li&gt;
		&lt;li&gt;Return from the exception&lt;/li&gt;
	&lt;/ol&gt;


	&lt;h3&gt;Entry into the Handler&lt;/h3&gt;


	&lt;p&gt;In the case of a high-level &lt;acronym title=&quot;Interrupt Service Routine&quot;&gt;ISR&lt;/acronym&gt;, the T-Kernel carries out a number of processes before the high-level &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt; function is called.  Most importantly, this involves processes related to saving context so that the &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt; can do its processing without causing problems to the running task.&lt;/p&gt;


	&lt;p&gt;A low-level interrupt handler is started either by the &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; directly in response to the interrupt or by a support function in the T-Monitor.  Depending on the &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; architecture, some &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; state may have been saved before the interrupt is invoked.  The remaining state has to be saved by your low-level &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt; when it starts.  The details of this are highly dependent on the &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; architecture and the specific implementation of the T-Monitor for that architecture.  You will need to refer to the Implementation Specification of the T-Monitor for the T-Engine and the Architecture Manual for the &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; to get a better understanding of this aspect.&lt;/p&gt;


	&lt;h3&gt;Return from the Exception&lt;/h3&gt;


	&lt;p&gt;A high-level &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt; can issue a return from the exception/ interrupt simply by executing a C-style return from &lt;strong&gt;function&lt;/strong&gt;.  In the case of an assembly &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt;, the &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt; is responsible for more things &amp;#8211; it must properly return from the exception and also restore the context.  Further, if interrupts are enabled when a low-level &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt; is run, there is a chance that dispatching may be required when returning from a low-level &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt;.  Therefore, returning from a low-level &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt; requires a special process.&lt;/p&gt;


	&lt;p&gt;The T-Kernel requires every port to provide a system call to support a return from interrupt.  This system call is called tk_ret_int and must be called at the end of a low-level interrupt handler.  It ensures that the necessary processing for possible dispatching is carried out when it returns from the &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;Again, these processes are highly dependent on the &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; and the T-Monitor architecture.  The Implementation Specification for the port should outline the specific process for creating a low-level &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt;.&lt;/p&gt;


	&lt;h3&gt;Template for Low-level ISRs&lt;/h3&gt;


	&lt;p&gt;The main flow of a low-level &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt; is as follows:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Save the context of the &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt;&lt;/li&gt;
		&lt;li&gt;Read/ write data from/ to the peripheral&lt;/li&gt;
		&lt;li&gt;Inform the application that the interrupt has occurred&lt;/li&gt;
		&lt;li&gt;Return from the exception by calling tk_ret_int&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;Specifically in this case, the details are system dependent &amp;#8211; so please refer to the following sources:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; Port Implementation Specification&lt;/li&gt;
		&lt;li&gt;T-Kernel Specification Section 4.8&lt;/li&gt;
		&lt;li&gt;&lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; Architecture Manual&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h3&gt;Examples of Low-level ISRs&lt;/h3&gt;


	&lt;p&gt;The main example of a low-level &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt; is the timer service routine that runs at every system tick.  The source code for this function can be found in each of the &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; ports of the T-Kernel.  If you have access to the source (or if you download it from the T-Engine Forum site), you can find the relevant function and use that as a basic template of a low-level &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt; for your &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt;.&lt;/p&gt;


	&lt;h2&gt;Registering/ defining a Low Level &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt;&lt;/h2&gt;


	&lt;p&gt;This step is similar to that for a high-level &lt;span class=&quot;caps&quot;&gt;ISR&lt;/span&gt;.  Once you have written the function for the interrupt handler, you need to register it with the T-Kernel so that it is called when the interrupt happens the next time.  You register an interrupt handler by calling &lt;strong&gt;tk_def_int&lt;/strong&gt;.&lt;/p&gt;


	&lt;p&gt;The C language interface for tk_def_int is as shown below:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;ER ercd = tk_def_int (UINT dintno, T_DINT *pk_dint ) ;&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The first parameter &lt;strong&gt;dintno&lt;/strong&gt; is the interrupt number.  Usually, this is the interrupt vector number &amp;#8211; the specific meaning of this number is implementation dependent and can be found in the Implementation Specifications that came with your T-Kernel port.&lt;/p&gt;


	&lt;p&gt;Other than this, all you need to do is fill out the details of the T_DINT structure to include the following information:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;The type of handler: high level or assembly (specified using TA_HLANG or TA_ASM respectively) &amp;#8211; we specify TA_ASM in this case&lt;/li&gt;
		&lt;li&gt;The address of the handler function&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;The TA_ASM specifies that the interrupt handler being registered is an assembly language interrupt handler.  The code for defining the interrupt handler is shown below.  You need to call tk_def_int and pass it the interrupt number and the address of the T_DINT structure.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;
&lt;span style=&quot;font: 9pt Monaco;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;{
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;T_DINT&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;int_pkt&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ER&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ercd&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;int_pkt&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;intatr&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;TA_ASM&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;int_pkt&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;inthdr&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;tk_my_isr&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ercd&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;tk_def_int&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;SERIAL_RX_ISR&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;int_pkt&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;);
}
&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;That&amp;#8217;s all there is to it!  Once this is done, the T-Kernel will now call your specific function when the interrupt occurs.&lt;/p&gt;


	&lt;p&gt;If you want to remove the definition that you have made, you need to call tk_def_int and pass it the interrupt number (usually the interrupt vector number) and &lt;span class=&quot;caps&quot;&gt;NULL&lt;/span&gt; as the address of the T_DINT structure.&lt;/p&gt;</description>
          <pubDate>Mon, 31 Mar 2008 07:39:00 GMT</pubDate>
          <guid>http://t-engine.onghu.com/en/articles/howto-assembly-language-interrupt-service-routines/</guid>
          <link>http://t-engine.onghu.com/en/articles/howto-assembly-language-interrupt-service-routines/</link>
        </item>
    
        <item>
          <title>HOWTO: Load an Application at System Startup</title>
          <description>&lt;h1&gt;&lt;span class=&quot;caps&quot;&gt;HOWTO&lt;/span&gt;: Load an Application at System Startup&lt;/h1&gt;


	&lt;p&gt;Written by: Mukul Sharma, &lt;a href=&quot;http://www.chipes.ntu.edu.sg/&quot;&gt;Centre for High Performance Embedded Systems&lt;/a&gt; , &lt;span class=&quot;caps&quot;&gt;NTU&lt;/span&gt; Singapore&lt;br&gt;
Edited by: Mohit Sindhwani, &lt;a href=&quot;http://www.onghu.com/te/&quot;&gt;TE@Onghu&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;In a system, it is a common need to load certain types of applications or system modules when the system starts.  The T-Engine allows applications to be loaded using the Command Line Interface (CLI).  In addition, it is possible to request the T-Engine to load certain drivers, middleware or applications when the system starts.  In this how-to article, we show the procedure for getting the system to automatically load your application, driver or middleware when it starts.&lt;/p&gt;


	&lt;h2&gt;Step 1 &amp;#8211; Finding your friends (the files)&lt;/h2&gt;


	&lt;p&gt;The procedure is simple.  When the Initial Monitor System (IMS) starts up, it looks for a file and runs the script found in it.  This file is called &lt;span class=&quot;caps&quot;&gt;STARTUP&lt;/span&gt;.CMD and is usually located in &amp;#8221;/&amp;#8221; (root) directory and can also be found in &amp;#8221;/SYS&amp;#8221; when booting from a Flash Card.  The file is a plain text file that contains a list of commands to be run during startup.&lt;/p&gt;


	&lt;p&gt;The format of this file is shown below:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;
*
*       @(#)STARTUP.CMD (T-Engine/SH7727)
*
*       システム起動用 IMS 初期コマンドスクリプト
*       Copyright (C) 2002-2004 by Personal Media Corporation
*
$chgsys uda rda
lodspg  kbpd            !30
lodspg  lowkbpd         !28
lodspg  rsdrv           !26
lodspg  screen          !35
lodspg  unixemu
$cli    STARTUP.CLI     !224
exit    1

&lt;/code&gt;&lt;/pre&gt;


	&lt;h2&gt;Step 2 &amp;#8211; Adding your Entry&lt;/h2&gt;


	&lt;p&gt;The lines that we need to observe are the lines that look like this:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
lodspg  lowkbpd         !28

&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This line basically tells the system to load the system program called &amp;#8216;lowkbpd&amp;#8217; with a task priority of &amp;#8216;28&amp;#8217;.&lt;/p&gt;


	&lt;p&gt;Similarly, you need to edit &lt;span class=&quot;caps&quot;&gt;STARTUP&lt;/span&gt;.CMD to add an entry for your application, middleware or driver.  We can add any number of commands that we would like to run.  The system will run all of these in the sequence in which they appear in the file.  For example, you could get the system to load your application, program or middleware at piority 76 by adding this to the file:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
lodspg  my_driver_or_app_or_mw         !76

&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;It&amp;#8217;s important to remember that this is the method to load T-Kernel-based programs (not programs that are based on TK/SE), i.e., task-based programs (not process-based programs).&lt;/p&gt;


	&lt;p&gt;Also, note the line called &lt;code&gt;$cli    STARTUP.CLI     !224&lt;/code&gt; &amp;#8211; it starts the command line interface (CLI) as a process and runs commands from the file &lt;span class=&quot;caps&quot;&gt;STARTUP&lt;/span&gt;.CLI.  If we are starting device drivers and middleware, typically, we would add our commands before this line.&lt;/p&gt;


	&lt;p&gt;That&amp;#8217;s all there is to it &amp;#8211; the next time you restart the T-Engine, it will run your application also.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;More Information:&lt;/strong&gt; For further information, refer to the &lt;strong&gt;T-Engine Development Kit Manual&lt;/strong&gt; that comes with your T-Engine.  It explains the commands that can be used in the &lt;span class=&quot;caps&quot;&gt;STARTUP&lt;/span&gt;.CMD and the &lt;span class=&quot;caps&quot;&gt;STARTUP&lt;/span&gt;.CLI files.&lt;/p&gt;</description>
          <pubDate>Sun, 30 Mar 2008 08:59:00 GMT</pubDate>
          <guid>http://t-engine.onghu.com/en/articles/howto-load-an-application-at-system-startup/</guid>
          <link>http://t-engine.onghu.com/en/articles/howto-load-an-application-at-system-startup/</link>
        </item>
    
        <item>
          <title>SDI Device Driver Guide - Part 1</title>
          <description>&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
.cpp1-assembler { color: #0000FF; }
.cpp1-character { }
.cpp1-comment { color: #808080; font-size: 0.9em; }
.cpp1-currentline { color: #000000; }
.cpp1-float { }
.cpp1-hexadecimal { }
.cpp1-identifier { color: #000080; }
.cpp1-illegalchar { color: #FF00FF; }
.cpp1-matchedbraces { color: #FF0000; }
.cpp1-number { color: #FF0000; }
.cpp1-octal { }
.cpp1-preprocessor { color: #008080; }
.cpp1-reservedword { color: #0000FF; font-weight: bold; }
.cpp1-rightedge { color: #C0C0C0; }
.cpp1-selection { color: #191919; }
.cpp1-space { color: #000000; }
.cpp1-string { color: #800000; }
.cpp1-symbol { color: #808080; }
--&gt;
&lt;/style&gt;


	&lt;h1&gt;&lt;span class=&quot;caps&quot;&gt;SDI&lt;/span&gt; Device Driver Guide &amp;#8211; Part 1&lt;/h1&gt;


	&lt;p&gt;Written by: Mukul Sharma and Fauzi Abbas, Centre for High Performance Embedded Systems, &lt;span class=&quot;caps&quot;&gt;NTU&lt;/span&gt; Singapore &lt;br&gt;
Edited by: Mohit Sindhwani (TE@Onghu)&lt;/p&gt;


	&lt;p&gt;The T-Kernel supports a number of models for device drivers.  In order to make it easy for developers to write device drivers, the &lt;a href=&quot;http://www.t-engine.org/&quot;&gt;T-Engine Forum&lt;/a&gt; has released a document called &lt;a href=&quot;http://www.t-engine.org/english/spec.html&quot;&gt;T-Engine Device Driver Interface Library Specification&lt;/a&gt; and &lt;a href=&quot;/en/articles/short-note-source-files-for-t-engine-device-driver-interface-library/&quot;&gt;associated source code&lt;/a&gt;.  One of the device driver models mentioned in the specification is called the Simple Device Driver Interface or &lt;span class=&quot;caps&quot;&gt;SDI&lt;/span&gt;.  In this article, we present the steps that are needed to create an &lt;span class=&quot;caps&quot;&gt;SDI&lt;/span&gt; device driver for the T-Kernel.&lt;/p&gt;


	&lt;p&gt;For this example, we create a dummy device and a device driver to access it.  Although this is a simplistic example, it demonstrates the basic workings of a simple driver and also points out the main steps involved in creating a device driver.&lt;/p&gt;


	&lt;p&gt;Some parts of this article are based on the presentation about device drivers available from &lt;a href=&quot;http://www.t-engine.com.sg&quot;&gt;&lt;span class=&quot;caps&quot;&gt;TEADEC&lt;/span&gt;&lt;/a&gt; and includes other information based on our experience of writing a device driver.&lt;/p&gt;


	&lt;h2&gt;Equipment and Tools&lt;/h2&gt;


	&lt;p&gt;Our developing environment is set up using the following:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Red Hat Linux 9.0 or Ubuntu Linux 5.04 (Intel x86 versions) or Cygwin.&lt;/li&gt;
		&lt;li&gt;T-Engine Development Kit Release 1.11E or later.&lt;/li&gt;
		&lt;li&gt;T-Engine/SH7727 with 128MB Compact Flash&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;In this guide, references are made to the device driver source codes available on the T-Engine Development Kit Release while working on the current sample device drivers. These device drivers include the &lt;span class=&quot;caps&quot;&gt;LCD&lt;/span&gt;, Console, Touch Panel and several other device drivers and they strictly follow the standard specifications provided by T-Engine Forum.  These sample drivers provide a good way to learn how device drivers are written.&lt;/p&gt;


	&lt;h2&gt;Background&lt;/h2&gt;


	&lt;p&gt;The picture below shows the device driver stack that is used for creating a device driver.&lt;/p&gt;


&lt;div align=&quot;center&quot;&gt;
&lt;div class=&quot;photo&quot;&gt;&lt;img src=&quot;/page_attachments/0000/0082/tk_device_driver_stack.png&quot; /&gt;&lt;/div&gt;
&lt;/div&gt;

	&lt;p style=&quot;text-align:center;&quot;&gt;&lt;ins&gt;T-Kernel Device Management Function (from T-Kernel Specification &amp;#8211; &lt;span class=&quot;caps&quot;&gt;TEF020&lt;/span&gt;–S001–01.00.00/en)&lt;/ins&gt;&lt;/p&gt;


	&lt;p&gt;As can be seen, the device driver itself works with 3 main parts:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;The device driver must interface with the physical hardware that it controls&lt;/li&gt;
		&lt;li&gt;It must work with the kernel so that the kernel knows when/ how to call it&lt;/li&gt;
		&lt;li&gt;It must be accessible by applications/ middleware that require to use the device&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;Since Item #3 in the above list is highly hardware dependent, for the sake of this example, we try to create a simple device that does not actually work with physical hardware.  Instead, it simply outputs messages to indicate when the various functions are called.  When creating a real device driver, those lines  should be replaced with the correct processing for controlling/ accessing/ using the device.  The main focus of this article is how to use &lt;acronym title=&quot;Simple Device Driver Interface&quot;&gt;SDI&lt;/acronym&gt; to manage Items #1 and #2.&lt;/p&gt;


	&lt;p&gt;Typically, a simple device driver must provide at least the following functions:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Open Device and Close Device&lt;/li&gt;
		&lt;li&gt;Read from and Write to the device&lt;/li&gt;
		&lt;li&gt;Event Function (used for events like suspend, resume, etc.)&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;&lt;strong&gt;Essential Reading:&lt;/strong&gt; The following references are essential reading for this article:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;T-Kernel Specification: &lt;ins&gt;Section 5.3 &amp;#8211; Device Management Functions&lt;/ins&gt;: This explains the various functions that we use.&lt;/li&gt;
		&lt;li&gt;T-Engine Device Driver Interface Library Specification: This explains &lt;acronym title=&quot;Simple Device Driver Interface&quot;&gt;SDI&lt;/acronym&gt; and related data structures, etc.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;h2&gt;Creating the Device Driver&lt;/h2&gt;


	&lt;p&gt;The main steps in creating a device driver are as follows:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Create functions to open and close the device (if required)&lt;/li&gt;
		&lt;li&gt;Create functions to read from and write to the device (if required)&lt;/li&gt;
		&lt;li&gt;Create the event function to receive events (if required)&lt;/li&gt;
		&lt;li&gt;Create a structure to describe your device&lt;/li&gt;
		&lt;li&gt;Register your device with the T-Kernel&lt;/li&gt;
	&lt;/ol&gt;


	&lt;h3&gt;Step 1 &amp;#8211; Functions to open and close the Device&lt;/h3&gt;


	&lt;p&gt;These functions are called when an application tries to open or close the device.  In the accompanying source code, refer to &lt;strong&gt;sample_device_driver/src/main.c, line 18 &amp;#8211; 35&lt;/strong&gt;.&lt;/p&gt;


	&lt;p&gt;The &lt;strong&gt;open&lt;/strong&gt; function usually initializes the device while the &lt;strong&gt;close&lt;/strong&gt; function handles the necessary cleanup before ‘free’ing the device. The &lt;strong&gt;open&lt;/strong&gt; function is called during the tk_opn_dev() call and &lt;strong&gt;close&lt;/strong&gt; function is called during the tk_cls_dev() call.&lt;/p&gt;


	&lt;p&gt;If a device is opened multiple times, open function is called the first time it is opened and close function the last time it is closed. If &lt;span class=&quot;caps&quot;&gt;TDA&lt;/span&gt;_OPENREQ is designated as driver attribute, then open/close function will be called for all open/close operations even in case of multiple openings.&lt;/p&gt;


	&lt;p&gt;In the code below, the open function and close functions are shown for our sample device.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;
LOCAL ER openfn  ( ID devid, UINT omode, VP exinf)
{
    /* start device use */
    // Content is Device Dependent
    printf(&quot; A call has been made for the Device Open Function.\n&quot;);
    return E_OK;
}

LOCAL ER closefn  ( ID devid, UINT option, VP exinf)
{
    /* terminate device use */
    // Content is Device Dependent
    printf(&quot; A call has been made for the Device Close Function.\n&quot;);
    return E_OK;
}

ID devid    : Device ID of the device to open
UINT omode  : Open mode (same as tk opn dev)
VP exinf    : Extended information set at device registration
Return code : Error

&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;For more information, refer to the following:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;T-Kernel Specifications Chapter 5.3.4 – Device Driver Interface.&lt;/li&gt;
		&lt;li&gt;T-Kernel Specifications Chapter 5.3.3 – Device Registration.&lt;/li&gt;
		&lt;li&gt;T-Kernel Specifications Chapter 5.3.2 – Application Interface.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h3&gt;Step 2 – Functions to read and write&lt;/h3&gt;


	&lt;p&gt;The next step is to declare the Read/Write Functions for the Device. These functions are required to process read or write requests to the device.  Read and Write Functions follow a standard definition to serve the various Read/Write Requests done from the device. The functions will typically use a switch case statement format to serve different read/write requests.&lt;/p&gt;


	&lt;p&gt;In the accompanying source code, refer to &lt;strong&gt;sample_device_driver/src/main.c, line 40 &amp;#8211; 85&lt;/strong&gt; for our read/ write functions.  The read function is shown below and the write function is created in a similar fashion.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;
LOCAL    INT    readfn(ID devid, INT start, INT size, VP buf, SDI sdi)
{
    printf(&quot; A call has been made for the Device Read Function.\n&quot;);

    switch (start)
    {
        case DN_DVCSPEC:    /* Developer defined Device Specifications Read Call */
                            // Content is Device Dependent                        
            printf(&quot; This function gets the Device Specifications and returns them back to the application.\n&quot;);
            break;

        case DN_DVCREAD:    /* Developer defined Device Read Call */
                            // Content is Device Dependent
            printf(&quot; This function gets the Device Specific Data and returns it back to the application.\n&quot;);
            break;

        default:
        printf(&quot; This is default action for the read function call.\n&quot;);
            break;
    }
    return E_OK;
}

&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;In general, &lt;strong&gt;start&lt;/strong&gt; refers to the starting address from which data is to be read/ written.  According to the specification, zero or positive values are used to read/ write device specific data and negative values are used to read/ write attribute information about the device.  Attribute information that can be read/ written is device-dependent and for this, developers should define their own constants referring to the various attributes.  This can be done by defining the constants in a header file (e.g. sample_drvr.h) and this header file should be copied to the include folder of the T-Engine environment (/te/include).&lt;/p&gt;


	&lt;p&gt;Read/ Write Functions are called during tk_rea_dev()/tk_srea_dev() or tk_wri_dev()/tk_swri_dev() calls.&lt;/p&gt;


	&lt;p&gt;Note that the order of arguments received by the Read/ Write Functions differs from the order in which these arguments are passed from application.&lt;/p&gt;


	&lt;p&gt;For more information, refer to the following:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;T-Kernel Specifications Chapter 5.3.4 – Device Driver Interface.&lt;/li&gt;
		&lt;li&gt;T-Kernel Specifications Chapter 5.3.2 – Application Interface.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h3&gt;Step 3 – Event Function&lt;/h3&gt;


	&lt;p&gt;A device driver can receive events from the system and must carry out processing related to these events.  For physical devices, the driver may be issued requests to suspend or resume the devices.  In the accompanying source code, refer to &lt;strong&gt;sample_device_driver/src/main.c, line 90 &amp;#8211; 124&lt;/strong&gt; for our event function.  Event requests are called when processing the tk_evt_dev() call.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;
LOCAL    INT    eventfn  (INT evttyp, VP evtinf, SDI sdi)
{
    INT    er;
    printf(&quot; A call has been made for the Device Event Function.\n&quot;);
    switch (evttyp)
    {
        case    TDV_SUSPEND:    //  Predefined Suspend Call 
            if (suspended == FALSE)
            {
            // Developer defined function to set device in suspended mode
            printf(&quot; This function will set the device in suspended state.\n&quot;);
            suspended = TRUE;
            }
            er = E_OK;
            break;

        case    TDV_RESUME:        //  Predefined Resume Call 
            if (suspended == TRUE)
            {
            // Developer defined function to resume the device from suspended mode
            printf(&quot; This function will resume the device from the suspended state.\n&quot;);
            suspended = FALSE;
            }
            er = E_OK;
            break;
        default:
            er = E_ILUSE;
            break;
    }

    return er;
}

&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;The constants used here (TDV_SUSPEND and &lt;span class=&quot;caps&quot;&gt;TDV&lt;/span&gt;_RESUME) are defined by the Device Manager in the &amp;#8220;tk/devmgr.h&amp;#8221; header file.  For more information, refer to:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;T-Kernel Specifications Chapter 5.3.4 &amp;#8211; Device Driver Interface.&lt;/li&gt;
		&lt;li&gt;T-Kernel Specifications Chapter 5.3.2 &amp;#8211; Application Interface. &lt;/li&gt;
		&lt;li&gt;T-Kernel Specifications Chapter 5.3.6 &amp;#8211; Device Event Notification&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h3&gt;Step 4 – Driver Registration Structure&lt;/h3&gt;


	&lt;p&gt;Once we have decided the functions that the device driver will support, it is necessary to package the functions and inform the kernel about the functions it call when dealing with the device.  In registering the device, the first step is to create and populate the Device Registration Structure.  This structure tells the T-Kernel what the device is called and also specifies the capabilities and attributes of the device. The structure shown below is based on &lt;acronym title=&quot;Simple Device Driver Interface&quot;&gt;SDI&lt;/acronym&gt;.  In the attached source code, refer to &lt;strong&gt;sample_device_driver/src/main.c, line 134 &amp;#8211; 146&lt;/strong&gt; to see where the device is defined.&lt;/p&gt;


	&lt;p&gt;In this structure, it is necessary to specify the functions that the device driver supports.  An &lt;acronym title=&quot;Simple Device Driver Interface&quot;&gt;SDI&lt;/acronym&gt; device driver may support any of the following functions:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Open&lt;/li&gt;
		&lt;li&gt;Close&lt;/li&gt;
		&lt;li&gt;Read&lt;/li&gt;
		&lt;li&gt;Write&lt;/li&gt;
		&lt;li&gt;Event&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Where the function is supported, the corresponding entry in the structure should store the address of the function in the driver.  Where the function is not supported, the entry should be stored as &lt;span class=&quot;caps&quot;&gt;NULL&lt;/span&gt;.  Note that we used the names openfn, closefn, etc. for the functions in our device driver and are assigning these in the structure.  However, these functions may be named to your choosing &amp;#8211; just make sure that the correct names are assigned in the device structure below.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;
&lt;span style=&quot;font: 9pt Monaco;&quot;&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;SDefDev&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ddev&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;{
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;       &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* exinf: extended information */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-string&quot;&gt;&amp;quot;DRVSAMP&amp;quot;&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* devnm: physical device name */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* devnm should be max. 8 char in the format:
                   &amp;quot;format type + unit + subunit&amp;quot; */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* drvatr driver attribute */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;TDK_UNDEF&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* devatr device attribute */&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;//Undefined Device Type
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* nsub: number of subunits */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* blksz : block size for specific data */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;openfn&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* open function*/
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;closefn&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* close function*/
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;readfn&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* read function*/
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;writefn&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* write function*/
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;eventfn&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* event function*/
&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;};

&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;For more details about the device registration structure, refer to:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;T-Kernel Specification Chapter 5.3.3 – Device Registration&lt;/li&gt;
		&lt;li&gt;T-Engine Device Driver Interface Library Specification&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h3&gt;Step 5 – Entry Routine for Device Driver&lt;/h3&gt;


	&lt;p&gt;The final step in creating a device driver is to register the device with the T-Kernel.  The structure above describes the features of the device and the functions that the driver supports.  Finally, we need to create an entry routine for the device driver and register the device.&lt;/p&gt;


	&lt;p&gt;The entry routine of the device driver is called when the device driver is loaded.  The entry routine may be used to perform device-specific initialization, if required.  In addition, it must make a system call to the T-Kernel to define and register the device.  In the attached source code, this is done in &lt;strong&gt;sample_device_driver/src/main.c, line 130 &amp;#8211; 160&lt;/strong&gt;.&lt;/p&gt;


	&lt;p&gt;This is a standard step for the device drivers and is done by a call to SDefDevice().&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;
LOCAL SDI DvcSdi;    /* device driver I/F handle */ (Global Variable)
ER    er;
T_IDEV    idev;

er  =   SDefDevice (&amp;#38;ddev, &amp;#38;idev, &amp;#38;DvcSdi);

ddev    : Pointer to Device Registration Structure (Refer to Step 1)
idev    : Pointer to location of device initialization information (T-Kernel)
DvcSdi  : Pointer to location of driver interface access handler    
er      : Error code returned

&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;For more detail, refer to:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;T-Engine/SH7727 Development Kit Device Driver Manual Chapter 2.4.1 – Define Device.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h2&gt;In Conclusion&lt;/h2&gt;


	&lt;p&gt;This article introduces how to write a device driver for the T-Kernel based on the Simple Device Driver Interface.  The concepts for a General Device Driver Interface (GDI) are similar and the concepts here can be extended to apply to the &lt;span class=&quot;caps&quot;&gt;GDI&lt;/span&gt; model.&lt;/p&gt;


	&lt;p&gt;In Part 2 of this article, we will look at some of the issues in packaging, building and loading the device driver.  We will also look at a simple application to use this device driver.&lt;/p&gt;


	&lt;p&gt;We are currently packaging the source code for this article and it will be made available soon.&lt;/p&gt;</description>
          <pubDate>Sat, 29 Mar 2008 17:04:00 GMT</pubDate>
          <guid>http://t-engine.onghu.com/en/articles/sdi-device-driver-guide-part-1/</guid>
          <link>http://t-engine.onghu.com/en/articles/sdi-device-driver-guide-part-1/</link>
        </item>
    
        <item>
          <title>Ubiquitous ID Technologies 2008</title>
          <description>&lt;h1&gt;Ubiquitous ID Technologies 2008&lt;/h1&gt;


&lt;div class=&quot;photo&quot;&gt;
&lt;div style=&quot;float:right&quot;&gt;&lt;img src=&quot;/page_attachments/0000/0076/uid2008.png&quot; alt=&quot;&quot; /&gt;&lt;/div&gt;
&lt;/div&gt;

	&lt;p&gt;The &lt;a href=&quot;http://www.t-engine.org/&quot;&gt;T-Engine Forum&lt;/a&gt; has just released more information that introduces the T-Engine in detail.  It&amp;#8217;s called &amp;#8220;Ubiquitous ID Technologies 2008 by Ken Sakamura&amp;#8221; and is available as a &lt;span class=&quot;caps&quot;&gt;PDF&lt;/span&gt; from the &lt;a href=&quot;http://www.uidcenter.org/&quot;&gt;Ubiquitous ID Center website&lt;/a&gt; at &lt;a href=&quot;http://www.uidcenter.org/&quot; title=&quot;http://www.uidcenter.org/&quot;&gt;http://www.uidcenter.org/&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;The document itself has 52 pages (all included) and has all the information that you need to understand what the Ubiquitous ID infrastructure provides.  It goes into details about the technology aspects, such as the Ubqiutous ID infrastructure, authorized tags, security technology, sensor network technology and the ubiquitous communicator.&lt;/p&gt;


	&lt;p&gt;Afte this introduction, a significant portion of the document is devoted to applications of the Ubiquitous ID Technology.  It covers experiments such as Ubiquitous Tracing, Food Traceability, Equipment management&amp;#8230; and so on.  This section is complemented by a comprehensive look at the Ubiquitous location information systems being deployed in Japan.&lt;/p&gt;


	&lt;p&gt;Finally, the document wraps up with an introduction to the T-Engine Forum and the &lt;span class=&quot;caps&quot;&gt;TRONSHOW&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;The document seems to be derived mostly from the &lt;a href=&quot;/en/articles/t-engine-uid-explained-panels-from-tronshow-2008/&quot;&gt;panels that were released earlier&lt;/a&gt; and provides good high-level information about the Ubiquitous ID architecture.  It can be got from &lt;a href=&quot;http://www.uidcenter.org/english/documents.html&quot;&gt;http://www.uidcenter.org/english/documents.html&lt;/a&gt;&lt;/p&gt;</description>
          <pubDate>Fri, 28 Mar 2008 09:09:00 GMT</pubDate>
          <guid>http://t-engine.onghu.com/en/articles/ubiquitous-id-technologies-2008/</guid>
          <link>http://t-engine.onghu.com/en/articles/ubiquitous-id-technologies-2008/</link>
        </item>
    
        <item>
          <title>μT-Kernel Patch Spotted</title>
          <description>&lt;h1&gt;μT-Kernel Patch Spotted&lt;/h1&gt;


	&lt;p&gt;While doing a search for μT-Kernel related information, I stumbled across an &amp;#8220;unofficial patch&amp;#8221; for the μT-Kernel to make it run on the H8/3069.  It is developed by &lt;a href=&quot;http://www.bi.a.u-tokyo.ac.jp/~uaa/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;SASANO&lt;/span&gt; Takayoshi&lt;/a&gt; and seems to be based on the &lt;a href=&quot;http://t-engine.org/T-Kernel/tkernel_e.html#utk_src&quot;&gt;&lt;span class=&quot;caps&quot;&gt;H8S&lt;/span&gt;/2212 μT-Kernel port download&lt;/a&gt; available from the T-Engine Forum.&lt;/p&gt;


	&lt;p&gt;From what I can tell, it&amp;#8217;s available in the public domain and can be used.  The only problem you might face is that the documentation (comments, etc.) are all in Japanese.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ve contacted the author to find out more information about the port.  If I find out anything else, I shall post it here.&lt;/p&gt;


	&lt;p&gt;The patch is available at the following &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt;: &lt;a href=&quot;&quot;http://www.bi.a.u-tokyo.ac.jp/~uaa/codes/utkernel/20080320/&quot;&gt;http://www.bi.a.u-tokyo.ac.jp/~uaa/codes/utkernel/20080320/&lt;/a&gt;&lt;/p&gt;</description>
          <pubDate>Thu, 27 Mar 2008 05:18:00 GMT</pubDate>
          <guid>http://t-engine.onghu.com/en/articles/t-kernel-patch-spotted/</guid>
          <link>http://t-engine.onghu.com/en/articles/t-kernel-patch-spotted/</link>
        </item>
    
        <item>
          <title>HOWTO: Define your own Interrupt Handler</title>
          <description>&lt;style type=&quot;text/css&quot;&gt;
&amp;lt;!&amp;#8212;
body { color: #000000; background-color: #FFFFFF; }
.cpp1-assembler { color: #0000FF; }
.cpp1-character { }
.cpp1-comment { color: #808080; font-size: 0.9em; }
.cpp1-currentline { color: #000000; }
.cpp1-float { }
.cpp1-hexadecimal { }
.cpp1-identifier { color: #000080; }
.cpp1-illegalchar { color: #FF00FF; }
.cpp1-matchedbraces { color: #FF0000; }
.cpp1-number { color: #FF0000; }
.cpp1-octal { }
.cpp1-preprocessor { color: #008080; }
.cpp1-reservedword { color: #0000FF; font-weight: bold; }
.cpp1-rightedge { color: #C0C0C0; }
.cpp1-selection { color: #191919; }
.cpp1-space { color: #000000; }
.cpp1-string { color: #800000; }
.cpp1-symbol { color: #808080; }
&amp;#8212;&amp;gt;
&lt;/style&gt;

	&lt;h1&gt;&lt;span class=&quot;caps&quot;&gt;HOWTO&lt;/span&gt;: Define your own Interrupt Handler&lt;/h1&gt;


	&lt;p&gt;Written by: Mohit Sindhwani, &lt;a href=&quot;http://www.viometrix.com/&quot;&gt;Viometrix&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;In this brief &amp;#8216;how-to&amp;#8217; article, we look at the method to be used for defining your own interrupt handler in the T-Kernel environment.&lt;/p&gt;


	&lt;h2&gt;Background&lt;/h2&gt;


	&lt;p&gt;In many embedded systems, interrupts are used to interface with the real world.  When an event happens, the peripheral responsible for dealing with it raises an interrupt to the &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt;.  The &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; then stops doing what it&amp;#8217;s doing, saves some of its essential context and attends to the interrupt.  The routine that deals with the interrupt is called the &lt;ins&gt;interrupt handler&lt;/ins&gt; (or &lt;ins&gt;interrupt service routine&lt;/ins&gt;) and is supposed to quickly do interrupt-related processing.  After this is completed, the &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; restores the context of the previously running program and execution continues as though nothing happened.  The specifics of how to install and use interrupt handlers is usually dependent on the &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; and/ or the &lt;span class=&quot;caps&quot;&gt;RTOS&lt;/span&gt;.  Here, we look at how you can create and use your own interrupt handler in the T-Kernel environment.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Essential Reading:&lt;/strong&gt; The main reference for this is actually &lt;ins&gt;Section 4.8 &amp;#8211; Interrupt Management Function&lt;/ins&gt; of the T-Kernel specification.  Refer to that section for the necessary details.&lt;/p&gt;


	&lt;h2&gt;Coding the Interrupt Handler&lt;/h2&gt;


	&lt;p&gt;The T-Kernel allows developers to create two types of interrupt handlers: handlers written in assembly or handlers written in a high-level language.  This article focuses primarily on high-level language handlers.  Details for assembly language handlers is available in the T-Kernel specification.&lt;/p&gt;


	&lt;p&gt;The C function prototype for a high-level T-Kernel &lt;acronym title=&quot;Interrupt Service Routine&quot;&gt;ISR&lt;/acronym&gt; is shown below:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;EXPORT void tk_serial_isr (UINT dintno);&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Typically, an interrupt handler should do the following:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;&lt;strong&gt;Read/ write data from/ to the peripheral:&lt;/strong&gt; This is the main task that needs to be done to respond to the interrupt.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Remove the interrupt request:&lt;/strong&gt; In devices such as the &lt;span class=&quot;caps&quot;&gt;UART&lt;/span&gt;, a read interrupt request is automatically removed when you read from the device.  However, in some devices such as timers, it is necessary to write to a special flag that clears the interrupt request.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Inform the application that the interrupt occurred:&lt;/strong&gt; In many cases, you will need to communicate to the running application that the event has happened.  Typically, this is done by issuing a system call.  To see the system calls that are possible from the &lt;acronym title=&quot;Interrupt Service Routine&quot;&gt;ISR&lt;/acronym&gt;, check &lt;ins&gt;Section 3.2.2&lt;/ins&gt; of the T-Kernel specification.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Return from the exception:&lt;/strong&gt; Finally, you need to return from the service handler.  In the case of the high-level interrupt handler, you only need to issue a &lt;strong&gt;return;&lt;/strong&gt; just as in a normal function.  The T-Kernel handles the rest for you.&lt;/li&gt;
	&lt;/ol&gt;



&lt;pre&gt;&lt;code&gt;
&lt;span style=&quot;font: 9pt Monaco;&quot;&gt;&lt;span class=&quot;cpp1-reservedword&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;tk_my_isr&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;UINT&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;dintno&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;)
{
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/*
     * Perform hardware-related work
     *
     * This is where you should put code for reading or writing to the
     * specific peripheral.  This part depends on your device
     */

&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;     &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* Sample: */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;     &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ReadDatafromSerialDevice&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;();

&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/*
     * Remove the Interrupt Request
     *
     * If the hardware requires a specific method for removing the
     * interrupt request, you should deal with it.  Devices like
     * UART usually de-assert the interrupt when you read the data
     * but devices like timer require a special write request to
     * de-assert the interrupt.
     */

&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* Inform the application that the interrupt happened */

&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-comment&quot;&gt;/* Sample: */
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;tk_sig_sem&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;sem_id&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;);

&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-reservedword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;
}
&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


	&lt;h2&gt;Registering/ Defining your Interrupt Handler&lt;/h2&gt;


	&lt;p&gt;Once you have written the function for the interrupt handler, you need to register it with the T-Kernel so that it is called when the interrupt happens the next time.  You register an interrupt handler by calling &lt;strong&gt;tk_def_int&lt;/strong&gt;.&lt;/p&gt;


	&lt;p&gt;The C language interface for tk_def_int is as shown below:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;ER ercd = tk_def_int (UINT dintno, T_DINT *pk_dint ) ;&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The first parameter &lt;strong&gt;dintno&lt;/strong&gt; is the interrupt number.  Usually, this is the interrupt vector number &amp;#8211; the specific meaning of this number is implementation dependent and can be found in the Implementation Specifications that came with your T-Kernel port.&lt;/p&gt;


	&lt;p&gt;Other than this, all you need to do is fill out the details of the T_DINT structure to include the following information:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;The type of handler: high level or assembly (specified using TA_HLANG or TA_ASM respectively)&lt;/li&gt;
		&lt;li&gt;The address of the handler function&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;The TA_HLNG specifies that the interrupt handler being registered is a high-level language interrupt handler.  The T-Kernel will do the necessary part to save the context, etc. &lt;strong&gt;before&lt;/strong&gt; this function is called and will automatically &lt;strong&gt;restore&lt;/strong&gt; the context after execution of the handler is completed.&lt;/p&gt;


	&lt;p&gt;The code for defining the interrupt handler is shown below.  You need to call tk_def_int and pass it the interrupt number and the address of the T_DINT structure.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;
&lt;span style=&quot;font: 9pt Monaco;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;{
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;T_DINT&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;int_pkt&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ER&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ercd&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;int_pkt&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;intatr&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;TA_HLNG&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;int_pkt&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;inthdr&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;tk_my_isr&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;;
&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;ercd&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;tk_def_int&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;SERIAL_RX_ISR&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;cpp1-space&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;cpp1-identifier&quot;&gt;int_pkt&lt;/span&gt;&lt;span class=&quot;cpp1-symbol&quot;&gt;);
}
&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;That&amp;#8217;s all there is to it!  Once this is done, the T-Kernel will now call your specific function when the interrupt occurs.&lt;/p&gt;


	&lt;p&gt;If you want to remove the definition that you have made, you need to call tk_def_int and pass it the interrupt number (usually the interrupt vector number) and &lt;span class=&quot;caps&quot;&gt;NULL&lt;/span&gt; as the address of the T_DINT structure.&lt;/p&gt;</description>
          <pubDate>Wed, 26 Mar 2008 01:26:00 GMT</pubDate>
          <guid>http://t-engine.onghu.com/en/articles/howto-define-your-own-interrupt-handler/</guid>
          <link>http://t-engine.onghu.com/en/articles/howto-define-your-own-interrupt-handler/</link>
        </item>
    
        <item>
          <title>What's the difference between ITRON and T-Engine?</title>
          <description>&lt;h1&gt;What&amp;#8217;s the difference between &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; and T-Engine?&lt;/h1&gt;


	&lt;p&gt;Written by: Mohit Sindhwani, &lt;a href=&quot;http://www.viometrix.com/&quot;&gt;Viometrix&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;This question &lt;a href=&quot;http://onghu.com/tebbs/YaBB.pl?num=1205053596/&quot;&gt;came up recently&lt;/a&gt; on the &lt;a href=&quot;http://www.onghu.com/tebbs&quot;&gt;TE@Onghu Developer Forum/ &lt;span class=&quot;caps&quot;&gt;BBS&lt;/span&gt;&lt;/a&gt; and it seemed that this hasn&amp;#8217;t really been adequately answered in any place.  I had posted an answer to the forum and thought that it would be good to copy the ideas here also so that it serves as a reference for people searching exactly that question.&lt;/p&gt;


	&lt;p&gt;In this article, I&amp;#8217;m expanding the question slightly and will try to explain the difference between T-Engine, &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; and T-Kernel.&lt;/p&gt;


	&lt;h2&gt;Software versus Platform&lt;/h2&gt;


	&lt;p&gt;The first thing that one must realize is that both &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; and T-Engine provide a set of specifications for real-time and embedded systems.  The specifications are agreed on by a set of members and are released to members and the public.  So, in its simplest sense, both come with open specifications.&lt;/p&gt;


	&lt;p&gt;However, there is a big difference in &lt;strong&gt;what&lt;/strong&gt; they specify.  In the case of &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt;, the specifications are for a hard real-time operating system (RTOS).  On the other hand, the T-Engine specifications cover a much larger set of items &amp;#8211; in simple terms, it is said that the T-Engine is an &lt;ins&gt;open platform for the development and execution of real-time and embedded systems&lt;/ins&gt;.  While it seems like a simple enough statement, looking at each of the words in that sentence gives a much better understanding of what it means.  I&amp;#8217;m not going to take the words in sequence but look at them in a different order.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;strong&gt;Platform:&lt;/strong&gt; It&amp;#8217;s important to note that the T-Engine is a platform.  In this sense, the specifications for the T-Engine cover not only the software aspects of the system (such as the operating system, boot monitor support and device driver profiles), but they also go further and cover other items such as the hardware platform, the vendor code system, binary formats, development environment and so on.  In that sense, it is a complete set that specifies a platform that can then be used for a variety of purposes.  Naturally, this is a big difference from &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; that specifies just the Operating System kernel (since the &lt;span class=&quot;caps&quot;&gt;TRON&lt;/span&gt; in &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; stands for The Realtime Operating Nucleus).  However, if you really must compare, you should compare &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; with the T-Kernel that is the standard &lt;span class=&quot;caps&quot;&gt;RTOS&lt;/span&gt; in the T-Engine platform.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Open:&lt;/strong&gt; Well, the T-Engine is open in the sense that it is openly specified upon consensus between members who participate in various standardization (or specification?) committees.  The specifications are then made open to the public and can be used by the general public in any way they see fit as long as due credit is attributed.  The &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; specifications are also open and can be obtained by the public.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Open = Open Source?&lt;/strong&gt; There is a common tendency today to consider open to be analogous in meaning to the term &amp;#8216;open source&amp;#8217;.  In terms of open source credentials, the T-Kernel is, in fact, available in source form.  The source code has been prepared and released by the T-Engine Forum and it centrally manages the release of the code.  The source code can be used in any commercial or non-commercial project on a number of processors without any changes being required and without charge.  Although developers are free to make any modifications to the &lt;span class=&quot;caps&quot;&gt;RTOS&lt;/span&gt; as they feel are needed, there are certain restrictions relating to the disclosure of the modified source code.  One must read the license, of course.  On the other hand, &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; was very much, just a specification.  There is an open-source implementation of &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; called &lt;span class=&quot;caps&quot;&gt;TOPPERS&lt;/span&gt;/JSP but most &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; implementations are commercial implementations that are available from a number of vendors, including semiconductor companies.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Realtime and Embedded Systems:&lt;/strong&gt; The T-Engine platform squarely targets the area of realtime and embedded systems.  Therefore, all the specifications are designed with the policy of reducing unnecessary overheads and minimizing or removing items that may affect the hard real-time nature of the system.  In this sense, &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; is the same &amp;#8211; it is also a hard &lt;span class=&quot;caps&quot;&gt;RTOS&lt;/span&gt; targeted at embedded systems.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Development and Execution:&lt;/strong&gt; Finally, the platform is targeted at being a development platform first &amp;#8211; this means that it is specifically created in a manner to allow a large amount of flexibility so that it behaves like a super-development platform (it has most things you need and more!).  This is clearly shown in the amount of expansion support it has &amp;#8211; &lt;span class=&quot;caps&quot;&gt;PCMCIA&lt;/span&gt;, USB host, serial and bus expansion.  Further, you can purchase a number of expansion boards for the bus expansion connector &amp;#8211; most notably, you can get a bare board for any custom chips you may need to integrate or an &lt;span class=&quot;caps&quot;&gt;FPGA&lt;/span&gt; board for prototyping digital modules in hardware (either before creating a special board, or before you create your system on a chip).  That said, the T-Engine is not just a &amp;#8216;development&amp;#8217; platform &amp;#8211; it&amp;#8217;s also a platform for &amp;#8216;execution&amp;#8217;.  If you are going to ship only small quantities of your system to your customers, you could ship the T-Engine board itself.  The T-Engine has been designed to look good and smart in a form factor similar to a slightly large &lt;span class=&quot;caps&quot;&gt;PDA&lt;/span&gt; and not like a sprawled out development platform with a lots of wires running across it and too big to pass off as a product.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;In short, that concludes a first look at the T-Engine itself.  So, it&amp;#8217;s clear that the T-Engine and &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; are not the best entities to compare.  If we wish to make a technical comparison, we need to compare &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; against T-Kernel.&lt;/p&gt;


	&lt;h2&gt;What&amp;#8217;s the difference between &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; and T-Kernel?&lt;/h2&gt;


	&lt;p&gt;Both &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; and T-Kernel are real-time operating systems.  In many sense, T-Kernel is the evolution of &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; and should be seen as such.  Therefore, there are a number of technical enhancements in the T-Kernel.  However, there are a few important differences between &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; and T-Kernel.  The main differences between T-Kernel and &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; are as follows:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;&lt;strong&gt;Specification versus Source:&lt;/strong&gt; In terms of deliverables from the T-Engine Forum, &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; is only a specification.  People who use the specification will build or buy an &lt;span class=&quot;caps&quot;&gt;RTOS&lt;/span&gt; that is compatible with the specification.  In the case of T-Kernel, the T-Engine Forum provides an implementation of the kernel in source form.  This can be used under the conditions of the T-License.&lt;/li&gt;
		&lt;li&gt;As mentioned, T-Kernel (the &lt;span class=&quot;caps&quot;&gt;RTOS&lt;/span&gt; in the T-Engine) is an evolution of &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt;.  However, it has a richer &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; that supports its goal of being a platform for middleware distribution.&lt;/li&gt;
		&lt;li&gt;T-Kernel has a clear well-specified driver and subsystem guidelines to promote middleware distribution.  &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; focuses more on performance.&lt;/li&gt;
		&lt;li&gt;T-Kernel has extensions that cover the use of virtual memory.  &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; does not.&lt;/li&gt;
		&lt;li&gt;The single source of T-Kernel is written mostly in C but most &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; implementations used to be written in C with a substantial amount of it also being written in assembly to support high performance on small-scale CPUs.&lt;/li&gt;
		&lt;li&gt;The T-Kernel &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; is similar to the &lt;span class=&quot;caps&quot;&gt;ITRON API&lt;/span&gt; although it includes more functions.  Also, one big advantage of the T-Kernel &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; is that the &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; is very similar for kernel versions ranging from small-scaled CPUs (like 8-bit or 16-bit microcontrollers) all the way to multi-CPU implementations.  &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; was never designed with such wide scalability in mind.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;This list summarizes the main differences between &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; and T-Kernel.  However, there is one more contender that you should consider when looking at &lt;span class=&quot;caps&quot;&gt;TRON&lt;/span&gt; Project outputs &amp;#8211; this one is called the μT-Kernel.  The μT-Kernel is a version of the T-Kernel that is specifically targeted at small-scale embedded systems.  The picture below shows the evolution of the different kernels in the T-Engine space.  As can be seen, there is a clear intention to move from the &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; family to the T-Kernel family.  The T-Kernel family essentially shares the same &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; across all the processor types &amp;#8211; this allows programs written for the smallest CPUs to be run largely unmodified even on multi-processor CPUs.&lt;/p&gt;


&lt;div align=&quot;center&quot;&gt;
&lt;div class=&quot;photo&quot;&gt;&lt;img src=&quot;/page_attachments/0000/0074/tkernel_evolution.png&quot; /&gt;&lt;/div&gt;
&lt;/div&gt;

	&lt;p style=&quot;text-align:center;&quot;&gt;Picture from: &lt;a href=&quot;http://www.tron.org/tronshow/2008/bookmark/exhibit/00001c0000000000000100000009020c.pdf&quot; title=&quot;http://www.tron.org/tronshow/2008/bookmark/exhibit/00001c0000000000000100000009020c.pdf&quot;&gt;http://www.tron.org/tronshow/2008/bookmark/exhibit/00001c0000000000000100000009020c.pdf&lt;/a&gt;&lt;/p&gt;


	&lt;h2&gt;So, is &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; dead?&lt;/h2&gt;


	&lt;p&gt;I think it&amp;#8217;s wrong to say that &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; is dead.  There is still a lot of work that is ongoing with &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; and many companies have large numbers of products, applications and middleware that currently run on &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; &amp;#8211; and there&amp;#8217;s no immediate reason to change.  To get some idea of the products that are running on &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt;, take a look at the &lt;a href=&quot;http://www.assoc.tron.org/spec/product2007.pdf&quot;&gt;Products Catalogue&lt;/a&gt; [PDF, 18MB] issued by the &lt;a href=&quot;http://www.tron.org/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;TRON&lt;/span&gt; Association&lt;/a&gt; &amp;#8211; it gives a long list of products based on T-Engine, T-Kernel and &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt;.  (In reality, the list is incomplete because the &lt;a href=&quot;http://www.tron.org/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;TRON&lt;/span&gt; Association&lt;/a&gt; did not require users of &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; to specify that they are using the &lt;span class=&quot;caps&quot;&gt;ITRON&lt;/span&gt; specification &amp;#8211; the list is therefore based on voluntary disclosures).&lt;/p&gt;


	&lt;h2&gt;Further Reading&lt;/h2&gt;


	&lt;p&gt;Check out the following to understand this better:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;/en/articles/t-engine-2008/&quot;&gt;T-Engine 2008&lt;/a&gt;: This gives a good introduction to the T-Engine platform.&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;/en/articles/introducing-the-t-kernel/&quot;&gt;Introducing the μT-Kernel&lt;/a&gt;: An introduction to the μT-Kernel that also explains the difference between the T-Kernel and the μT-Kernel.&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;/en/articles/t-engine-uid-explained-panels-from-tronshow-2008/&quot;&gt;Panels from &lt;span class=&quot;caps&quot;&gt;TRON&lt;/span&gt; Show 2008&lt;/a&gt;: These panels from the &lt;span class=&quot;caps&quot;&gt;TRON&lt;/span&gt; Show explain the T-Engine technology.&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;/en/articles/future-directions-with-the-t-kernel/&quot;&gt;Future Directions with the T-Kernel&lt;/a&gt;: This discusses the further evolution of the T-Kernel.&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;/en/articles/timeline-for-t-engine-activities/&quot;&gt;Timeline for T-Engine Activities&lt;/a&gt;: The picture that shows the timeline for the activities that are ongoing at the T-Engine Forum.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;I hope that this article helps clear up some of the concepts.&lt;/p&gt;</description>
          <pubDate>Tue, 25 Mar 2008 12:35:00 GMT</pubDate>
          <guid>http://t-engine.onghu.com/en/articles/whats-the-difference-between-itron-and-t-engine/</guid>
          <link>http://t-engine.onghu.com/en/articles/whats-the-difference-between-itron-and-t-engine/</link>
        </item>
    
        <item>
          <title>Short Note: Source files for T-Engine Device Driver Interface Library</title>
          <description>&lt;h1&gt;Short Note: Source files for T-Engine Device Driver Interface Library&lt;/h1&gt;


	&lt;p&gt;The &lt;a href=&quot;http://www.t-engine.org/&quot;&gt;T-Engine Forum&lt;/a&gt; has a &lt;a href=&quot;http://t-engine.org/english/spec.html&quot;&gt;number of specifications&lt;/a&gt; that can be downloaded from their &lt;a href=&quot;http://www.t-engine.org/&quot;&gt;website&lt;/a&gt;.  One of these specifications is called the &lt;strong&gt;T-Engine Device Driver Interface Library Specification&lt;/strong&gt; and provides the specification and explanation of concepts that can be used for creating device drivers.&lt;/p&gt;


	&lt;p&gt;Specifically, it introduces the concept of Simple Device Driver Interface (SDI) and General Device Driver Interface (GDI).  These can be used to provide a generic interface for creating device drivers.  The specification refers to source code files that are not available from the specifications page.&lt;/p&gt;


	&lt;p&gt;In case you are looking for the source files for the device driver interface library, don&amp;#8217;t worry!  I got in touch with the T-Engine Forum Secretariat and asked them about the source code.  The necessary files are included as part of the &lt;a href=&quot;http://t-engine.org/T-Kernel/tkernel_e.html#tkse_drv_src&quot;&gt;Source Code of Sample Driver for T-Kernel/SE&lt;/a&gt; and can be accessed from the &lt;a href=&quot;http://t-engine.org/T-Kernel/tkernel_e.html&quot;&gt;downloads page&lt;/a&gt; of the T-Engine Forum website.&lt;/p&gt;</description>
          <pubDate>Mon, 24 Mar 2008 11:20:00 GMT</pubDate>
          <guid>http://t-engine.onghu.com/en/articles/short-note-source-files-for-t-engine-device-driver-interface-library/</guid>
          <link>http://t-engine.onghu.com/en/articles/short-note-source-files-for-t-engine-device-driver-interface-library/</link>
        </item>
    
        <item>
          <title>T-News: Updated Specifications &amp; Source Code</title>
          <description>&lt;h1&gt;T-News: Updated Specifications &amp;#38; Source Code&lt;/h1&gt;


	&lt;p&gt;The &lt;a href=&quot;http://www.t-engine.org/&quot;&gt;T-Engine Forum&lt;/a&gt; has updated their release of the source codes for the T-Kernel and the μT-Kernel and has also released a new version of the specification for the μT-Kernel.&lt;/p&gt;


	&lt;p&gt;As always, the specifications can be downloaded from the &lt;a href=&quot;http://www.t-engine.org/english/spec.html&quot;&gt;Specifications Page&lt;/a&gt; and the source code is available from the &lt;a href=&quot;http://www.t-engine.org/T-Kernel/tkernel_e.html&quot;&gt;Downloads page&lt;/a&gt; on the T-Engine Forum&amp;#8217;s &lt;a href=&quot;http://www.t-engine.org/&quot;&gt;website&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;With this release, the T-Kernel Source Code has been updated to Ver.1.02.04 and the µT-Kernel Source Code and specification has been updated to Ver.1.01.00.&lt;/p&gt;


	&lt;h3&gt;&lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; Support&lt;/h3&gt;


	&lt;p&gt;According to the downloads page, the open source T-Kernel works with the following CPUs: &lt;span class=&quot;caps&quot;&gt;SH7727&lt;/span&gt;, SH7751r, &lt;span class=&quot;caps&quot;&gt;SH7760&lt;/span&gt;, ARM926, &lt;span class=&quot;caps&quot;&gt;ARM920&lt;/span&gt;, ARM720, &lt;span class=&quot;caps&quot;&gt;VR5500&lt;/span&gt;, VR4131 and &lt;span class=&quot;caps&quot;&gt;M32104&lt;/span&gt;.  Further, it is compatible with the following CPUs by applying the patches that can be downloaded from their page: &lt;span class=&quot;caps&quot;&gt;SH7145&lt;/span&gt;, M32192 , &lt;span class=&quot;caps&quot;&gt;SH7780&lt;/span&gt;, MB91403, &lt;span class=&quot;caps&quot;&gt;SH7720&lt;/span&gt;, SH7211 and &lt;span class=&quot;caps&quot;&gt;SH7619&lt;/span&gt;.  The version of the µT-Kernel available from their page works with the &lt;acronym title=&quot;ARM7TDMI&quot;&gt;AT91&lt;/acronym&gt; and &lt;span class=&quot;caps&quot;&gt;H8S&lt;/span&gt;/2212.&lt;/p&gt;


	&lt;h3&gt;Links&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;Specifications: &lt;a href=&quot;http://www.t-engine.org/english/spec.html&quot; title=&quot;http://www.t-engine.org/english/spec.html&quot;&gt;http://www.t-engine.org/english/spec.html&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;Downloads: &lt;a href=&quot;http://www.t-engine.org/T-Kernel/tkernel_e.html&quot; title=&quot;http://www.t-engine.org/T-Kernel/tkernel_e.html&quot;&gt;http://www.t-engine.org/T-Kernel/tkernel_e.html&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;</description>
          <pubDate>Thu, 13 Mar 2008 12:18:00 GMT</pubDate>
          <guid>http://t-engine.onghu.com/en/articles/t-news-updated-specifications-source-code/</guid>
          <link>http://t-engine.onghu.com/en/articles/t-news-updated-specifications-source-code/</link>
        </item>
    
    
  </channel>
</rss>
