Hi…
QNX lovers, can you all provide me sample code for
InterruptAttach*() with event notification type of SIGEV_PULSE?
Tq
arms
Hi…
QNX lovers, can you all provide me sample code for
InterruptAttach*() with event notification type of SIGEV_PULSE?
Tq
arms
[code]
#define D_PulseValue_Interrupt 1
struct sInterruptArea
{
unsigned int dIrq;
// hardware specific
/*
struct csr_t *dCsr;
uint8_t dAck;
*/
struct sigevent dEvent;
};
// initialization
int rcvid;
int chid, coid;
struct sigevent event;
struct sched_param param;
struct sInterruptArea *ia;
struct _pulse pulse;
ThreadCtl(_NTO_TCTL_IO, NULL);
if ((ia = (struct sInterruptArea *)malloc(sizeof(struct sInterruptArea))) == NULL)
{
printf("%s: %s\n", "malloc", "failed");
return -1;
}
if (mlock(ia, sizeof(struct sInterruptArea)) == -1)
{
/*
printf("%s: %s\n", “mlock”, “failed”);
return -1;
*/
}
chid = ChannelCreate(_NTO_CHF_DISCONNECT | _NTO_CHF_UNBLOCK);
if (chid == -1)
{
printf("%s: s\n", "ChannelCreate", "failed");
return -1;
}
coid = ConnectAttach(0, 0, chid, _NTO_SIDE_CHANNEL, 0);
if (coid == -1)
{
printf("%s: %s\n", "ConnectAttach", "failed");
return -1;
}
sched_getparam(0, ¶m);
SIGEV_PULSE_INIT(&ia->dEvent, coid, param.sched_priority, _PULSE_CODE_MINAVAIL, D_PulseValue_Interrupt);
if (InterruptAttach(ia->dIrq, interrupt_handler, ia, sizeof(*ia), _NTO_INTR_FLAGS_TRK_MSK) == -1)
{
printf("%s: %s\n", "InterruptAttach", "failed");
return -1;
}
// initialization end
// receiving pulses
for (;
{
memset(&pulse, 0, sizeof(pulse));
rcvid = MsgReceive(chid, &pulse, sizeof(pulse), NULL);
if (rcvid == 0)
{
if (pulse.code == _PULSE_CODE_MINAVAIL)
{
if (pulse.value.sival_int == D_PulseValue_Interrupt)
{
// hardware specific
/*
if (ia->dAck & D_SCB_Ack)
{
...
...
...
csr->intr_mask = INTR_Mask_None;
// tmp = csr->status;
}
*/
}
else
{
printf("%s: %s - %d\n", “pulse.value”, “unknown”, pulse.value.sival_int);
}
}
else
{
printf("%s: %s - %d\n", “pulse.code”, “unknown”, pulse.code);
}
}
else if (rcvid > 0)
{
printf(“message received\n”);
MsgError(rcvid, -1);
}
else if (rcvid == -1)
{
if (errno == EINTR)
{
}
else
{
printf("%s: %s: %d - %s\n", “MsgReceive”, “failed”, errno, strerror(errno));
exit(-1);
}
}
else
{
printf("%s: %s\n", “MsgReceive”, “fatal failure”);
exit(-1);
}
}
// receiving pulses end
// an example of handling function (contains some hardware specific commands)
const struct sigevent * interrupt_handler (void *area, int id)
{
struct sInterruptArea *ia = area;
struct sigevent *event;
uint8_t tmp;
// hardware specific
if (ia->dCsr->ack & D_SCB_Ack) // check if the interrupt was generated by my hardware
{
event = &ia->dEvent;
ia->dCsr->intr_mask = INTR_Mask_All;
ia->dAck = ia->dCsr->ack;
ia->dCsr->ack = D_SCB_Ack; // aknowledging interrupts
// tmp = ia->dCsr->status;
}
else
event = NULL;
InterruptUnmask(ia->dIrq, id);
return event;
} [/code]
Thanks a lot mezek