ISR to generate pulses

Hello all,
I wrote a small sample program to generate pulses on a particular
channel whenever a particular hardware interrupt occurs. Here, I have
written my program such that the ISR sends a pulse on my channel before
returning the event.
This is program is slightly modified from that given in the QNX System
Architecture book but it is not working when I add the pulse generating part
to it. I am attching the program below. Can anybody please give me some
pointers as to why it is not working?
Thanks,
Tray.

#include <stdio.h>
#include <sys/neutrino.h>

struct sigevent event;
volatile unsigned counter;
int coid, chid;

const struct sigevent *handler(void *area, int i)
{
if( ++counter == 100)
{
counter = 0;
MsgSendPulse( coid, SIGEV_PULSE_PRIO_INHERIT, 5, 0);
return (&event);
}
else
return(NULL);
}

int main()
{
int i, num, rcid;
struct _pulse pulse;
chid = ChannelCreate(0);
if(chid == -1)
printf(“Unable to create a channel \n”);
else
printf(“Channel is %d\n”, chid);
coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANNEL, 0);
if(coid == -1)
printf(“Unable to connect to channel\n”);
else
printf(“Connection is %d\n”, coid);

event.sigev_notify = SIGEV_INTR;
ThreadCtl(_NTO_TCTL_IO, 0);
num = InterruptAttach( 0, &handler, NULL, 0, 0);
if(num == -1)
printf(“Handler not attached\n”);

for(i = 0; i < 10; ++i)
{
InterruptWait(0,NULL);
rcid = MsgReceivePulse( chid, &pulse, sizeof(pulse), 0);
if(rcid != -1)
if( pulse.code == 5)
printf(“100 events \n”);
else
printf(“No pulse received\n”);
}

InterruptDetach(num);
return 0;
}

“Tray Karra” <tkarra@ces.clemson.edu> wrote in message
news:apc4gi$2gg$1@inn.qnx.com

Hello all,
I wrote a small sample program to generate pulses on a particular
channel whenever a particular hardware interrupt occurs. Here, I have
written my program such that the ISR sends a pulse on my channel before
returning the event.
This is program is slightly modified from that given in the QNX System
Architecture book but it is not working when I add the pulse generating
part
to it. I am attching the program below. Can anybody please give me some
pointers as to why it is not working?
Thanks,
Tray.

#include <stdio.h
#include <sys/neutrino.h

struct sigevent event;
volatile unsigned counter;
int coid, chid;

const struct sigevent *handler(void *area, int i)
{
if( ++counter == 100)
{
counter = 0;

I’m surprise it doesn’t crash. This function isn’t interrupt safe, that
means you cannot use it from inside an interrupt handler

MsgSendPulse( coid, SIGEV_PULSE_PRIO_INHERIT, 5, 0);
return (&event);
}
else
return(NULL);
}

int main()
{
int i, num, rcid;
struct _pulse pulse;
chid = ChannelCreate(0);
if(chid == -1)
printf(“Unable to create a channel \n”);
else
printf(“Channel is %d\n”, chid);
coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANNEL, 0);
if(coid == -1)
printf(“Unable to connect to channel\n”);
else
printf(“Connection is %d\n”, coid);

Better use SIGEV_INTR_INIT macro to initialize event structure

event.sigev_notify = SIGEV_INTR;
ThreadCtl(_NTO_TCTL_IO, 0);
num = InterruptAttach( 0, &handler, NULL, 0, 0);
if(num == -1)
printf(“Handler not attached\n”);

for(i = 0; i < 10; ++i)
{

This will unblock because the ISR is returning an interrupt event. But
you’ll never get the pulse

InterruptWait(0,NULL); //thi
rcid = MsgReceivePulse( chid, &pulse, sizeof(pulse), 0);
if(rcid != -1)
if( pulse.code == 5)
printf(“100 events \n”);
else
printf(“No pulse received\n”);
}

InterruptDetach(num);
return 0;
}

Hello,
Thanks for the suggestions. I have made the necessary changes but it
still doesant work. I have read the “Writing an Interrupt Handler” from the
programmers guide and also the library reference for InterruptAttach(). It
has been mentioned that “Message driven processes that block in a receive
loop using MsgReceive() should consider using SIGEV_PULSE to trigger a
channel”.
In order to acheive that I have written the program as follows but it
still doesnt work i.e it is not at all receiving the pulses on the channel I
am waiting. The kernel is supposed to deliver the pulse depending on what I
filled in the event structure. But i guess its not happening so in my
program.
What is it that I am missing?
Thanks,
Tray.
#include <stdio.h>
#include <sys/neutrino.h>
#include <sys/siginfo.h>

struct sigevent event;
volatile unsigned counter;
int coid, chid;

const struct sigevent *handler(void *area, int i)
{
if( ++counter == 100)
{
counter = 0;
return (&event);
}
else
return(NULL);
}

int main()
{
int i, num, rcid;
struct _pulse pulse;

chid = ChannelCreate(0);
if(chid == -1)
printf(“Unable to create a channel \n”);
else
printf(“Channel is %d\n”, chid);

coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANNEL, 0);
if(coid == -1)
printf(“Unable to connect to channel\n”);
else
printf(“Connection is %d\n”, coid);

SIGEV_PULSE_INIT(&event, coid, SIGEV_PULSE_PRIO_INHERIT, 5, 0);
ThreadCtl(_NTO_TCTL_IO, 0);
num = InterruptAttach( 0, &handler, 0, 0, 0);
if(num == -1)
printf(“Handler not attached\n”);

for(i = 0; i < 10; ++i)
{
// My program gets stuck here
rcid = MsgReceive( chid, &pulse, sizeof(pulse), 0);
if(rcid != -1)
if( pulse.code == 5)
printf(“100 events \n”);
else
printf(“No pulse received\n”);
}

InterruptDetach(num);
return 0;
}


“Mario Charest” postmaster@127.0.0.1 wrote in message
news:apclta$jqf$1@inn.qnx.com

“Tray Karra” <> tkarra@ces.clemson.edu> > wrote in message
news:apc4gi$2gg$> 1@inn.qnx.com> …
Hello all,
I wrote a small sample program to generate pulses on a particular
channel whenever a particular hardware interrupt occurs. Here, I have
written my program such that the ISR sends a pulse on my channel before
returning the event.
This is program is slightly modified from that given in the QNX
System
Architecture book but it is not working when I add the pulse generating
part
to it. I am attching the program below. Can anybody please give me some
pointers as to why it is not working?
Thanks,
Tray.

#include <stdio.h
#include <sys/neutrino.h

struct sigevent event;
volatile unsigned counter;
int coid, chid;

const struct sigevent *handler(void *area, int i)
{
if( ++counter == 100)
{
counter = 0;

I’m surprise it doesn’t crash. This function isn’t interrupt safe, that
means you cannot use it from inside an interrupt handler

MsgSendPulse( coid, SIGEV_PULSE_PRIO_INHERIT, 5, 0);
return (&event);
}
else
return(NULL);
}

int main()
{
int i, num, rcid;
struct _pulse pulse;
chid = ChannelCreate(0);
if(chid == -1)
printf(“Unable to create a channel \n”);
else
printf(“Channel is %d\n”, chid);
coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANNEL, 0);
if(coid == -1)
printf(“Unable to connect to channel\n”);
else
printf(“Connection is %d\n”, coid);


Better use SIGEV_INTR_INIT macro to initialize event structure

event.sigev_notify = SIGEV_INTR;
ThreadCtl(_NTO_TCTL_IO, 0);
num = InterruptAttach( 0, &handler, NULL, 0, 0);
if(num == -1)
printf(“Handler not attached\n”);

for(i = 0; i < 10; ++i)
{

This will unblock because the ISR is returning an interrupt event. But
you’ll never get the pulse

InterruptWait(0,NULL); file://thi
rcid = MsgReceivePulse( chid, &pulse, sizeof(pulse), 0);
if(rcid != -1)
if( pulse.code == 5)
printf(“100 events \n”);
else
printf(“No pulse received\n”);
}

InterruptDetach(num);
return 0;
}

\

Hello all,
This program is now working. The system is malfunctioning for some
reason and now that I have rebooted, my program is working fine.
I am once again sorry for the inconvenience caused.
Thanks Mario for your help.
Tray.
“Tray Karra” <tkarra@ces.clemson.edu> wrote in message
news:apflhv$stg$1@inn.qnx.com

Hello,
Thanks for the suggestions. I have made the necessary changes but it
still doesant work. I have read the “Writing an Interrupt Handler” from
the
programmers guide and also the library reference for InterruptAttach(). It
has been mentioned that “Message driven processes that block in a receive
loop using MsgReceive() should consider using SIGEV_PULSE to trigger a
channel”.
In order to acheive that I have written the program as follows but it
still doesnt work i.e it is not at all receiving the pulses on the channel
I
am waiting. The kernel is supposed to deliver the pulse depending on what
I
filled in the event structure. But i guess its not happening so in my
program.
What is it that I am missing?
Thanks,
Tray.
#include <stdio.h
#include <sys/neutrino.h
#include <sys/siginfo.h

struct sigevent event;
volatile unsigned counter;
int coid, chid;

const struct sigevent *handler(void *area, int i)
{
if( ++counter == 100)
{
counter = 0;
return (&event);
}
else
return(NULL);
}

int main()
{
int i, num, rcid;
struct _pulse pulse;

chid = ChannelCreate(0);
if(chid == -1)
printf(“Unable to create a channel \n”);
else
printf(“Channel is %d\n”, chid);

coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANNEL, 0);
if(coid == -1)
printf(“Unable to connect to channel\n”);
else
printf(“Connection is %d\n”, coid);

SIGEV_PULSE_INIT(&event, coid, SIGEV_PULSE_PRIO_INHERIT, 5, 0);
ThreadCtl(_NTO_TCTL_IO, 0);
num = InterruptAttach( 0, &handler, 0, 0, 0);
if(num == -1)
printf(“Handler not attached\n”);

for(i = 0; i < 10; ++i)
{
// My program gets stuck here
rcid = MsgReceive( chid, &pulse, sizeof(pulse), 0);
if(rcid != -1)
if( pulse.code == 5)
printf(“100 events \n”);
else
printf(“No pulse received\n”);
}

InterruptDetach(num);
return 0;
}


“Mario Charest” postmaster@127.0.0.1 wrote in message
news:apclta$jqf$> 1@inn.qnx.com> …

“Tray Karra” <> tkarra@ces.clemson.edu> > wrote in message
news:apc4gi$2gg$> 1@inn.qnx.com> …
Hello all,
I wrote a small sample program to generate pulses on a particular
channel whenever a particular hardware interrupt occurs. Here, I have
written my program such that the ISR sends a pulse on my channel
before
returning the event.
This is program is slightly modified from that given in the QNX
System
Architecture book but it is not working when I add the pulse
generating
part
to it. I am attching the program below. Can anybody please give me
some
pointers as to why it is not working?
Thanks,
Tray.

#include <stdio.h
#include <sys/neutrino.h

struct sigevent event;
volatile unsigned counter;
int coid, chid;

const struct sigevent *handler(void *area, int i)
{
if( ++counter == 100)
{
counter = 0;

I’m surprise it doesn’t crash. This function isn’t interrupt safe, that
means you cannot use it from inside an interrupt handler

MsgSendPulse( coid, SIGEV_PULSE_PRIO_INHERIT, 5, 0);
return (&event);
}
else
return(NULL);
}

int main()
{
int i, num, rcid;
struct _pulse pulse;
chid = ChannelCreate(0);
if(chid == -1)
printf(“Unable to create a channel \n”);
else
printf(“Channel is %d\n”, chid);
coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANNEL, 0);
if(coid == -1)
printf(“Unable to connect to channel\n”);
else
printf(“Connection is %d\n”, coid);


Better use SIGEV_INTR_INIT macro to initialize event structure

event.sigev_notify = SIGEV_INTR;
ThreadCtl(_NTO_TCTL_IO, 0);
num = InterruptAttach( 0, &handler, NULL, 0, 0);
if(num == -1)
printf(“Handler not attached\n”);

for(i = 0; i < 10; ++i)
{

This will unblock because the ISR is returning an interrupt event. But
you’ll never get the pulse

InterruptWait(0,NULL); file://thi
rcid = MsgReceivePulse( chid, &pulse, sizeof(pulse), 0);
if(rcid != -1)
if( pulse.code == 5)
printf(“100 events \n”);
else
printf(“No pulse received\n”);
}

InterruptDetach(num);
return 0;
}



\