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