IO Device:SI852DIO

From LEXWiKi

(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
[[Category:AllowPages]]
[[Category:AllowPages]]
 +
 +
== Introduction ==
 +
=== Define Pin Address ===
 +
#define WDT_ENABLE 0x600
 +
#define WDT_DISABLE 0x604
 +
#define DO 0x60C
 +
#define DI 0x608
 +
 +
=== Set the I/O privilege level ===
 +
iopl( 3 ); //iopl() changes the I/O privilege level of the current process , level 3 can read/write to i/o port
 +
 +
=== Set DO ===
 +
DO:
 +
outb( 1 , DO ); //write data:1 to DO
 +
 +
=== Read DI/DO ===
 +
DO: inb ( DO ); //read DO data
 +
DI: inb ( DI ); //read DI data
 +
 +
=== Enable/Disable WDT ===
 +
Enable : outb ( 1 , WDT_ENABLE ); //set 1 sec to WDT enable port, system will reboot after 1 second
 +
Disable: outb ( 1 , WDT_DISABLE ); //set 1 sec to WDT disable port , the disable signal will break off WDT enable signle
 +
== The Sample code source you can download from ==
== The Sample code source you can download from ==
-
[ftp://ftp.lex.com.tw//Engineer/SoftSupport/AP_Module/852_DIO_Sample_Linux/si852dio.C si852dio.c]
+
[ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/852_DIO_Sample_Linux/852_dio_wdt_v2.1L_Src.tar.gz 852_dio_wdt_v2.1L_Src.tar.gz]
 +
 
 +
[ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/852_DIO_Sample_Linux/852_dio_wdt_v2.1L_Bin.tar.gz 852_dio_wdt_v2.1L_Bin.tar.gz]
 +
 
 +
== How to use this Demo Application ==
 +
 
 +
1. Press the "Start" button to test DIO function
-
== The Sample code introduction ==
+
2. Press the "Enable" button to test WDT function
-
This sample code just support the our FI/CI/MI/SI 852X Main board DIO/WDT function,about function we used which you can see more detail information in [http://www.faqs.org/docs/Linux-mini/IO-Port-Programming.html Linux-IO Programming]
+
-
[http://www.faqs.org/docs/Linux-mini/IO-Port-Programming.html 連結標題]
+
3. Press the "Disable" button when WDT enable to disable WDT
-
== The Sample code Demo ==
+
[[Image:852_dio.jpg]]
-
<pre>
+
-
/* si852dio.c:example of CI852X DI/O
+
-
* Compile with `gcc -O2 -o example si852dio.c',
+
-
* and run as root with `./example'.
+
-
* more information in http://www.pluto.it/files/ildp/HOWTO/IO-Port-Programming/IO-Port-Programming.html*/
+
-
+
-
#include <stdio.h>
+
-
#include <unistd.h>
+
-
#include <asm/io.h>
+
-
+
-
#define SI852X_WDTE 0x600 //SI852X,WatcherDog Enable IO space port ,Support Hex value 0x00~0xff
+
-
#define SI852X_WDTD 0x604 //SI852X,WatcherDog Disable IO space port.
+
-
#define SI852X_DI 0x608 //SI852X,DI Function IO space port.
+
-
#define SI852X_DO 0x60C //SI852X,DO Function IO space port.
+
-
+
-
int main()
+
-
{
+
-
// Access to the ports
+
-
iopl(3);
+
-
if (ioperm(SI852X_WDTE, 1, 1)) {perror("ioperm"); exit(1);}
+
-
if (ioperm(SI852X_WDTD, 1, 1)) {perror("ioperm"); exit(1);}
+
-
if (ioperm(SI852X_DI , 1, 1)) {perror("ioperm"); exit(1);}
+
-
if (ioperm(SI852X_DO , 1, 1)) {perror("ioperm"); exit(1);}
+
-
+
-
//The DO Function which set the data value (D0-7) for the SI852X_DO port all to low (0)
+
-
outb(0, CI852X_DO);
+
-
+
-
// Sleep for a while (100 ms)
+
-
usleep(100000);
+
-
+
-
//The DI function which read from SI852X_DI port status then display a result
+
-
printf("status: %d\n", inb(SI852X_DI));
+
-
+
-
// Enable the WatchDog timer of the SI852X_WDTE
+
-
outb(10, CI852X_WDTE); // the Action will reboot after 10 secord
+
-
+
-
// Disable the WatchDog timer of the CI852X_WDTD
+
-
// inb(CI852X_WDTD);
+
-
+
-
exit(0);
+
-
}
+
-
+
-
/* end of si852dio.c */
+
-
</pre>
+

Revision as of 18:14, 18 June 2009


Contents

Introduction

Define Pin Address

   #define WDT_ENABLE 0x600
   #define WDT_DISABLE 0x604
   #define DO 0x60C
   #define DI 0x608

Set the I/O privilege level

   iopl( 3 ); //iopl() changes the I/O privilege level of the current process , level 3 can read/write to i/o port

Set DO

   DO:  
       outb( 1 , DO );  //write data:1 to DO

Read DI/DO

   DO: inb ( DO );  //read DO data
   DI: inb ( DI );  //read DI data

Enable/Disable WDT

   Enable : outb ( 1 , WDT_ENABLE );  //set 1 sec to WDT enable port, system will reboot after 1 second 
   Disable: outb ( 1 , WDT_DISABLE );  //set 1 sec to WDT disable port , the disable signal will break off WDT enable signle


The Sample code source you can download from

852_dio_wdt_v2.1L_Src.tar.gz

852_dio_wdt_v2.1L_Bin.tar.gz

How to use this Demo Application

1. Press the "Start" button to test DIO function

2. Press the "Enable" button to test WDT function

3. Press the "Disable" button when WDT enable to disable WDT

Image:852_dio.jpg

Personal tools