Changes between Version 3 and Version 4 of jazz/09-05-08


Ignore:
Timestamp:
May 8, 2009, 1:54:47 AM (15 years ago)
Author:
jazz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • jazz/09-05-08

    v3 v4  
    33 * [午餐] [http://www.ipeen.com.tw/shop/shop.php?id=15102 聯合泰國小吃店]
    44
    5  * [專案] 在 Windows 底下常用的 inportb() 跟 outportb(),在 Linux 底下可以用 port I/O (有很多種 outb(),  outw(),  outl(),  outsb(),  outsw(),  outsl(), inb(), inw(), inl(), insb(), insw(), insl() ) 來實現。而在 VxWorks 則用 sysInByte() 跟 sysOutByte() 來實現
     5 * [專案] 在 Windows 底下常用的 inportb() 跟 outportb(),在 Linux 底下可以用 port I/O (有很多種 outb(),  outw(),  outl(),  outsb(),  outsw(),  outsl(), inb(), inw(), inl(), insb(), insw(), insl() ) 來實現。而在 !VxWorks 則用 sysInByte() 跟 sysOutByte() 來實現
     6{{{
     7#!C
     8static int outportb(unsigned int port, unsigned int val, int size)
     9{
     10    static int iopldone = 0;
     11
     12#ifdef DEBUG
     13    printf("outportb(0x%04x)<=0x%02x\n", port, val);
     14#endif
     15
     16    if (port > 1024) {
     17        if (!iopldone && iopl(3)) {
     18            fprintf(stderr, "iopl(): %s\n", strerror(errno));
     19            return 1;
     20        }
     21        iopldone++;
     22    } else if (ioperm(port,size,1)) {
     23        fprintf(stderr, "ioperm(%x): %s\n", port, strerror(errno));
     24        return 1;
     25    }
     26
     27    if (size == 4)
     28        outl(val, port);
     29    else if (size == 2)
     30        outw(val&0xffff, port);
     31    else
     32        outb(val&0xff, port);
     33    return 0;
     34}
     35
     36static int inportb(unsigned int port, int size)
     37{
     38    static int iopldone = 0;
     39
     40#ifdef DEBUG
     41    printf("inportb(0x%04x)\n", port);
     42#endif
     43
     44    if (port > 1024) {
     45        if (!iopldone && iopl(3)) {
     46            fprintf(stderr, "iopl(): %s\n", strerror(errno));
     47            return 1;
     48        }
     49        iopldone++;
     50    } else if (ioperm(port,size,1)) {
     51        fprintf(stderr, "ioperm(%x): %s\n", port, strerror(errno));
     52        return 1;
     53    }
     54
     55    if (size == 4)
     56        return inl(port);
     57    else if (size == 2)
     58        return inw(port) & 0xffff;
     59    else
     60        return inb(port) & 0xff;
     61}
     62}}}