IO Device:SI852DIO

From LEXWiKi

(Difference between revisions)
Jump to: navigation, search
(The Sample code introduction)
Current revision (12:37, 25 February 2022) (edit) (undo)
(The Sample code source you can download from)
 
(7 intermediate revisions not shown.)
Line 1: Line 1:
[[Category:AllowPages]]
[[Category:AllowPages]]
-
== The Sample code source you can download form ==
+
== Introduction ==
 +
=== Define Pin Address ===
 +
#define WDT_ENABLE 0x600
 +
#define WDT_DISABLE 0x604
 +
#define DO 0x60C
 +
#define DI 0x608
-
[ftp://ftp.lex.com.tw//Engineer/SoftSupport/AP_Module/852_DIO_Sample_Linux/si852dio.C si852dio.c]
+
=== 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
-
== The Sample code introduction ==
+
=== Set DO ===
-
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.pluto.it/files/ildp/HOWTO/IO-Port-Programming/IO-Port-Programming.html Linux-IO Programming]
+
DO:
 +
outb( 1 , DO ); //write data:1 to DO
-
== The Sample code Demo ==
+
=== Read DI/DO ===
-
<pre>
+
DO: inb ( DO ); //read DO data
-
/* si852dio.c:example of CI852X DI/O
+
DI: inb ( DI ); //read DI data
-
* Compile with `gcc -O2 -o example si852dio.c',
+
 
-
* and run as root with `./example'.
+
=== Enable/Disable WDT ===
-
* more information in http://www.pluto.it/files/ildp/HOWTO/IO-Port-Programming/IO-Port-Programming.html*/
+
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
-
#include <stdio.h>
+
 
-
#include <unistd.h>
+
 
-
#include <asm/io.h>
+
== The Sample code source you can download from ==
-
+
 
-
#define SI852X_WDTE 0x600 //SI852X,WatcherDog Enable IO space port ,Support Hex value 0x00~0xff
+
<Google Drive>
-
#define SI852X_WDTD 0x604 //SI852X,WatcherDog Disable IO space port.
+
 
-
#define SI852X_DI 0x608 //SI852X,DI Function IO space port.
+
Source file: [https://drive.google.com/file/d/1Hod5GN6grnyVUfTEtK4HO9ll0p1aTInq/view?usp=sharing 852_DIO_WDT_v2.1L_Src]
-
#define SI852X_DO 0x60C //SI852X,DO Function IO space port.
+
 
-
+
Binary file: [https://drive.google.com/file/d/1gGLGNJ3bXMEme9QECqL7wyCCBOZqQ0TY/view?usp=sharing 852_DIO_WDT_v2.1L_Bin]
-
int main()
+
 
-
{
+
<FTP>
-
// Access to the ports
+
 
-
iopl(3);
+
Source file: [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]
-
if (ioperm(SI852X_WDTE, 1, 1)) {perror("ioperm"); exit(1);}
+
 
-
if (ioperm(SI852X_WDTD, 1, 1)) {perror("ioperm"); exit(1);}
+
Binary file: [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]
-
if (ioperm(SI852X_DI , 1, 1)) {perror("ioperm"); exit(1);}
+
 
-
if (ioperm(SI852X_DO , 1, 1)) {perror("ioperm"); exit(1);}
+
== How to use this Demo Application ==
-
+
 
-
//The DO Function which set the data value (D0-7) for the SI852X_DO port all to low (0)
+
1. Press the "Start" button to test DIO function
-
outb(0, CI852X_DO);
+
 
-
+
2. Press the "Enable" button to test WDT function
-
// Sleep for a while (100 ms)
+
 
-
usleep(100000);
+
3. Press the "Disable" button when WDT enable to disable WDT
-
+
 
-
//The DI function which read from SI852X_DI port status then display a result
+
[[Image:852_dio.jpg]]
-
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>
+

Current revision


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

<Google Drive>

Source file: 852_DIO_WDT_v2.1L_Src

Binary file: 852_DIO_WDT_v2.1L_Bin

<FTP>

Source file: 852_DIO_WDT_v2.1L_Src

Binary file: 852_DIO_WDT_v2.1L_Bin

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