简体   繁体   English

在QNX中断服务程序?

[英]interrupt service routine in qnx?

Scenario : Client is sending a data and the server is receving the data from client via ethernet layer (udp). 场景:客户端正在发送数据,服务器正在通过以太网层(udp)从客户端接收数据。 When the server receives a data from the client on the ip layer (kernel). 服务器在ip层(内核)上从客户端接收数据时。 It interrupts the kernel and kernel as to execute the data by the client, so I want to create a interrupt service function to catch the interrupt from the network service card. 它会中断内核并由客户端执行数据,因此我想创建一个中断服务函数来捕获来自网络服务卡的中断。

I am using Interruptattach api to handle the interrupt from the network interface card and sigevent structure to call the specific function. 我正在使用Interruptattach api处理来自网络接口卡的中断和sigevent结构以调用特定功能。 http://www.qnx.com/developers/docs/6.3.0SP3/neutrino/lib_ref/i/interruptattach.html#HandlerFunction http://www.qnx.com/developers/docs/6.3.0SP3/neutrino/lib_ref/i/interruptattach.html#HandlerFunction

is it the right way to handle interrupts in qnx ?? 这是在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;
}

another question : if I want to call another function in the sigevent structure then should I use another ISR for that (ie how to handle multiple function from the interrupt)? 另一个问题:如果我想在sigevent结构中调用另一个函数,那么我是否应该为此使用另一个ISR(即,如何从中断中处理多个函数)?

I modified my code as above. 我如上所述修改了我的代码。 Will it be efficient if I do like above. 如果我喜欢上面的方法,效率会更高吗? One ISR function with InterruptAttach API for three different handler. 一个带有InterruptAttach API的ISR函数,用于三个不同的处理程序。

This is a bad approach: Interrupt (IRQ) handlers are not interruptable. 这是一种不好的方法:中断(IRQ)处理程序不可中断。 That means: 1. your computer will lock up when you do a lot of work in them and 2. you can't call every method. 这意味着:1.当您在其中进行大量工作时,您的计算机将锁定;并且2.您无法调用所有方法。

The correct approach is to receive the IRQ, call a handler. 正确的方法是接收IRQ,调用处理程序。 The handler should create a memory structure, fill it with the details what needs to be done and adds this "task data" to a queue. 处理程序应创建一个内存结构,在其中填充需要执行的详细信息,并将此“任务数据”添加到队列中。 A background thread can then wait for elements in the queue and do the work. 然后,后台线程可以等待队列中的元素并完成工作。

That way, IRQ handlers will be small and fast. 这样,IRQ处理程序将小而快速。 Your background thread can be as complex as you like. 您的后台线程可以任意复杂。 if the thread has a bug, the worst that can happen is that it breaks (make the IRQ handler throw away events when the queue is full). 如果线程有错误,则可能发生的最坏情况是它会中断(使IRQ处理程序在队列已满时抛出事件)。

Note that the queue must be implemented in such a way that adding elements to it never blocks. 请注意,队列必须以这样的方式实现:添加元素绝不阻塞。 Check the documentation, there should already be something that allows several threads to exchange data; 查看文档,应该已经有一些东西可以允许多个线程交换数据。 the same can be used for IRQ handlers. 相同的可用于IRQ处理程序。

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

相关问题 中断服务程序会发生什么? - What happens in an interrupt service routine? 在内核中添加中断服务程序 - Adding Interrupt service routine in kernel PIC的中断服务程序“不允许使用不完整的类型” - “incomplete type is not allowed” for interrupt service routine for PIC ISR(中断服务程序)中的信号量同步 - semaphore like synchronization in ISR (Interrupt service routine) STM32 Discovery上的看门狗定时器的中断服务程序 - Interrupt service routine for watchdog timer on STM32 Discovery 由中断服务程序触发的对 volatile 变量的更改未反映在 main() 中 - Changes to volatile variable toggled by interrupt service routine not reflected in main() Windows操作系统中C的软件中断服务例程 - software Interrupt Service routine in C for windows operating system 如何在8051中结束外部中断服务程序(ISR) - How to end external Interrupt Service Routine (ISR) in 8051 中断服务例程不会跳回到ARM Cortex M0上的中断处理程序 - Interrupt Service Routine doesn't jump back to Interrupt Handler on an ARM Cortex M0 如何使用中断服务例程来检测此MSP430代码上的按钮事件? - How can I use an interrupt service routine to detect button events on this MSP430 code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM