Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 将DOS中可用的中断GPIO程序迁移到Linux_C_Linux - Fatal编程技术网

C 将DOS中可用的中断GPIO程序迁移到Linux

C 将DOS中可用的中断GPIO程序迁移到Linux,c,linux,C,Linux,我正在写一个应用程序,它需要对PC104的输入脉冲进行计数 我正在使用。我在DOS中有一个中断示例程序,但现在在Linux中迁移该代码时遇到了一个问题。有人能帮我用这个或其他方法来满足我的要求吗 以下是DOS代码: #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<time.h> #include<dos.h> typedef void interrupt

我正在写一个应用程序,它需要对PC104的输入脉冲进行计数

我正在使用。我在DOS中有一个中断示例程序,但现在在Linux中迁移该代码时遇到了一个问题。有人能帮我用这个或其他方法来满足我的要求吗

以下是DOS代码:

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include<dos.h>

typedef void interrupt (far *FNISR) (...);
FNISR _pfnOldIsr;
unsigned int _nIrqNo;
unsigned int _nIntNo;
unsigned int _nOldImr;
unsigned int _nOldImr2;
static unsigned long _lCnt = 0;

void interrupt NewIsr(...)
{
    cprintf("IRQ %d trigger. (%lu)\r", _nIrqNo, _lCnt++);
    outp(0x9f, 0xff);
    if(_nIrqNo > 7)
       outp(0xa0, 0x20); //**
    outp(0x20, 0x20);
    // send EOI command
}
// Disable warning message "Parameter xxx is never used
#pragma warn –par
// Write south bridge register
void write_sb(unsigned char idx, unsigned long val)
{
    _asm mov dx, 0cf8h
    __emit__(0x66); __emit__(0xb8);
    __emit__(0x00); __emit__(0x38); 
    __emit__(0x00); __emit__(0x80);
    _asm mov al, idx
    __emit__(0x66); __emit__(0xef);
    _asm mov dx, 0cfch
    __emit__(0x66); __emit__(0x8b); __emit__(0x46); __emit__(0x08);
    __emit__(0x66); __emit__(0xef);
}

int main(int nArgCnt, char *pszArg[])
{
    if(nArgCnt != 2)
    {
        printf("\nUsage: %s <IRQ_NUM> \n", pszArg[0]);
        return 1;
    }
    // Install ISR for IRQ
    _disable();
    _nIrqNo = atoi(pszArg[1]);
    _nIntNo = (_nIrqNo <= 7) ? (_nIrqNo + 8) : (_nIrqNo + 0x70 - 0x08);
    _pfnOldIsr = getvect(_nIntNo);
     setvect(_nIntNo, NewIsr);
     unsigned char byMask = 0x00;
     switch(_nIrqNo)
     {
        case 9:byMask = 0x01;break;
        case 3:byMask = 0x02;break;
        case 10:byMask = 0x03;break;
        case 4:byMask = 0x04; break;
        case 5:byMask = 0x05; break;
        case 7:byMask = 0x06; break;
        case 6:byMask = 0x07; break;
        case 1:byMask = 0x08; break;
        case 11: byMask = 0x09; break;
        case 12: byMask = 0x0b; break;
        case 14: byMask = 0x0d; break;
        case 15: byMask = 0x0f; break;
     }
     if(byMask == 0x00)
     {
        printf("\nError IRQ number.\n");
        return 1;
     }
     printf("Using IRQ %d\n", _nIrqNo);
     // set 8259 interrupt controller
     if(_nIrqNo <= 8)
     {
       _nOldImr = inp(0x21);
       outp(0x21, _nOldImr & (~(1 << _nIrqNo)));
     }
     else
     {
       _nOldImr = inp(0x21);
       outp(0x21, _nOldImr & (~(1 << 2)));
       _nOldImr2 = inp(0xa1);
       outp(0xa1, _nOldImr2 & (~(1 << (_nIrqNo - 8))));
     }
     printf("Test Port0: active low, trigger once\r\n");
     unsigned long val = 0xffff0000L | ((0xA0 | byMask) << 8);
     val = ((val << 8) | 0x0000ffffL) & 0x00ffffffL;
     write_sb(0xdc, val);
     _enable();
     getch();
     _disable();
     write_sb(0xdc, 0x0000ff00L);
     if(_nIrqNo <= 8)
     {
        outp(0x21, _nOldImr);
     }
     else
     {
        outp(0x21, _nOldImr);
        outp(0xa1, _nOldImr2);
     }
     setvect(_nIntNo, _pfnOldIsr);
     return 0;
 }

PC104在这种情况下并不重要,很可能IO卡上的PIO芯片是8255或兼容的。你能提供一些关于你正在使用的IO扩展卡的详细信息吗?处理器是来自icop的VDX6354D。你到底想要什么,请告诉我CPU板是什么。您使用的是单独的IO板还是GPIO功能集成在cpu板中?如果不注册,我无法访问他们的文档。。。我的意思是:在许多情况下,x86GPIO使用8255芯片及其衍生产品,很可能你的主板也在使用该芯片,而且已经有相当多的用于该芯片的软件。如图8255所示,我将复制并粘贴以下处理器数据表中给出的信息,通用可编程I/O–支持40个可编程I/O引脚–每个GPIO引脚可单独配置为输入/输出引脚GPIO_P0~GPIO_P3可通过内部8051–GPIO_P0和GPIO_P1进行编程,并支持中断输入/输出