繁体   English   中英

在QNX中断服务程序?

[英]interrupt service routine in qnx?

场景:客户端正在发送数据,服务器正在通过以太网层(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函数,用于三个不同的处理程序。

这是一种不好的方法:中断(IRQ)处理程序不可中断。 这意味着:1.当您在其中进行大量工作时,您的计算机将锁定;并且2.您无法调用所有方法。

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

这样,IRQ处理程序将小而快速。 您的后台线程可以任意复杂。 如果线程有错误,则可能发生的最坏情况是它会中断(使IRQ处理程序在队列已满时抛出事件)。

请注意,队列必须以这样的方式实现:添加元素绝不阻塞。 查看文档,应该已经有一些东西可以允许多个线程交换数据。 相同的可用于IRQ处理程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM