請先看『使用說明』
IO Device:SI852DIO
From LEXWiKi
(Difference between revisions)
(→The Sample code introduction) |
(→The Sample code introduction) |
||
Line 7: | Line 7: | ||
== The Sample code introduction == | == The Sample code introduction == | ||
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] | 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 連結標題] | ||
== The Sample code Demo == | == The Sample code Demo == |
Revision as of 18:17, 3 June 2008
The Sample code source you can download form
The Sample code introduction
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 Linux-IO Programming
The Sample code Demo
/* 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 */