qnx中的中断服务程序?

时间:2014-03-26 11:55:42

标签: c linux interrupt qnx qnx-neutrino

场景:客户端正在发送数据,服务器正通过以太网层(udp)从客户端接收数据。当服务器从ip层(内核)上的客户端接收数据时。它会中断内核和内核以便客户端执行数据,因此我想创建一个中断服务函数来捕获来自网络服务卡的中断。

我正在使用Interruptattach api来处理来自网络接口卡的中断和sigevent结构来调用特定的功能。 http://www.qnx.com/developers/docs/6.3.0SP3/neutrino/lib_ref/i/interruptattach.html#HandlerFunction

是处理qnx中的中断的正确方法吗?

volatile int id1, id2, id3;
 const struct sigevent *handler1(void *area, int id1)
 {
    volatile double KernelStartExecutionTime;
     KernelStartExecutionTime = GetTimeStamp();   // calculating the time when the kernel starts executing

    TASK1(Task2ms_Raster);
    return (NULL);

 }
 const struct sigevent *handler2(void *area, int id2)
 {
     volatile double KernelStartExecutionTime;
     KernelStartExecutionTime = GetTimeStamp();   // calculating the time when the kernel starts executing

    TASK2(Task10ms_Raster);
    return (NULL);

 }

 const struct sigevent *handler3(void *area, int id3)
 {
     volatile double KernelStartExecutionTime;
     KernelStartExecutionTime = GetTimeStamp();   // calculating the time when the kernel starts executing

    TASK3(Task100ms_Raster);
    return (NULL);

 }


 /*kernel calls attach the interrupt function handler to the hardware interrupt specified by intr(i.e irq) */
 // InterruptAttach() : Attach an interrupt handler to an interrupt source
 // interrupt source is handler1 for this example
void ISR(void)
 {

 volatile int irq = 0;   //0 :  A clock that runs at the resolution set by ClockPeriod()

 ThreadCtl (_NTO_TCTL_IO, NULL);
 id1 = InterruptAttach(irq, &handler1, NULL, 0, 0);
 id2 = InterruptAttach(irq, &handler2, NULL, 0, 0);
 id3 = InterruptAttach(irq, &handler3, NULL, 0, 0);


 }

int main(int argc, char *argv[])
{
     Xcp_Initialize();

     CreateSocket();

     ISR();      //function call for ISR

     return 0;
}

另一个问题:如果我想在sigevent结构中调用另一个函数,那么我应该使用另一个ISR(即如何处理来自中断的多个函数)?

我修改了上面的代码。如果我喜欢上面的话会有效吗?一个带有InterruptAttach API的ISR函数用于三个不同的处理程序。

1 个答案:

答案 0 :(得分:0)

这是一种糟糕的方法:中断(IRQ)处理程序不可中断。这意味着:1。当您在计算机中完成大量工作时,您的计算机将锁定; 2.您无法调用每种方法。

正确的方法是接收IRQ,调用处理程序。处理程序应该创建一个内存结构,用详细信息填写需要完成的内容并添加这个"任务数据"到队列。然后,后台线程可以等待队列中的元素并完成工作。

这样,IRQ处理程序将小而快。你的后台主题可以像你想的那样复杂。如果线程有错误,可能发生的最坏情况是它会中断(当队列已满时,让IRQ处理程序抛弃事件)。

请注意,必须以这样的方式实现队列,即向其中添加元素永远不会阻塞。检查文档,应该已经存在允许多个线程交换数据的东西;同样可以用于IRQ处理程序。