Nto pulses.

Hi,

i am currently trying to convert a QNX application to NTO.
I have to replace QNX proxies by NTO pulses but i have some problems
with those. I juste create a channel using ChannelCreate() and use the
channel
id in the functions MsgReceivePulse() and MsgSendPulse() but nothing
happens.
It seems that the pulse is well sent but it is never received. I checked
every return code and function parameters and everything seems to be
correct.

Here is the code : ( i launch a thread that is in charge of sending a pulse
to the
main thread )



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

struct sigevent event;
struct _pulse p;
int ChID;

void *thread( void * attr)
{
printf(“Thread running\n”);

if( MsgSendPulse(ChID, sched_get_priority_min(SCHED_FIFO),
_PULSE_CODE_MINAVAIL + 1, 0) == -1 ){

printf(“Thread() : Error while trying to send the pulse\n”);
}

printf(“Thread() : exiting\n”);

return NULL;
}


int main(void)
{
int recvid;
int thId;

/// creating the channel
ChID = ChannelCreate(_NTO_CHF_UNBLOCK);

assert( ChID != -1);

thId = pthread_create(NULL, NULL, thread, NULL);

switch( thId ){

case EOK:

break;
case EAGAIN:
case EINVAL:
case EFAULT:

printf(“error\n”);
return -1;
break;
}

if( ( recvid = MsgReceivePulse(ChID, &p, sizeof(p), NULL) ) < 0 ){
printf(“Error\n”);
}

if( recvid != 0 )
printf(“Not a pulse … \n”);
else
printf(“Pulse \n”);

ChannelDestroy(ChID);
printf(“exciting \n”);

return 0;
}



Thanks for your help,


Alexandre Abreu

“Alexandre ABREU” <alexandre.abreu@opal-rt.com> wrote in message
news:9kum50$kk8$1@inn.qnx.com

Hi,

i am currently trying to convert a QNX application to NTO.
I have to replace QNX proxies by NTO pulses but i have some problems
with those. I juste create a channel using ChannelCreate() and use the
channel
id in the functions MsgReceivePulse() and MsgSendPulse() but nothing
happens.
It seems that the pulse is well sent but it is never received. I checked
every return code and function parameters and everything seems to be
correct.

Here is the code : ( i launch a thread that is in charge of sending a
pulse
to the
main thread )



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

struct sigevent event;
struct _pulse p;
int ChID;

void *thread( void * attr)
{
printf(“Thread running\n”);

You need to connect to the channel first before sending to it.
You cannot send on a chid (Channel Id) you have to send to a coid
(connection id ) which you get from ConnectAttach()

I think you are not getting any error because the ChID is probably
equal to an already existing coid created to support stdin/stdout/stderr.
So the pulse is going somewhere else.

if( MsgSendPulse(ChID, sched_get_priority_min(SCHED_FIFO),
_PULSE_CODE_MINAVAIL + 1, 0) == -1 ){

printf(“Thread() : Error while trying to send the pulse\n”);
}

printf(“Thread() : exiting\n”);

return NULL;
}


int main(void)
{
int recvid;
int thId;

/// creating the channel
ChID = ChannelCreate(_NTO_CHF_UNBLOCK);

assert( ChID != -1);

thId = pthread_create(NULL, NULL, thread, NULL);

switch( thId ){

case EOK:

break;
case EAGAIN:
case EINVAL:
case EFAULT:

printf(“error\n”);
return -1;
break;
}

if( ( recvid = MsgReceivePulse(ChID, &p, sizeof(p), NULL) ) < 0 ){
printf(“Error\n”);
}

if( recvid != 0 )
printf(“Not a pulse … \n”);
else
printf(“Pulse \n”);

ChannelDestroy(ChID);
printf(“exciting \n”);

return 0;
}



Thanks for your help,


Alexandre Abreu

Thank you for this help,
it works now.

But unfortunaltely i got another question :slight_smile:.

I use the same idea of pulse in an interrupt handler.
In QNX the interrupt handler used to returning a proxy
and the server thread used to block on a Receive()
and check the its return value.

I actually use the same idea since my interrupt handler
init a pulse event ( SIGEV_PULSE_INIT ) and return
it ( return &event ) while the message server just blocks
on a MsgReceivePulse() … but once again nothing happens.

I have tried just to use a simple InterruptWait() for
the message server and a SIGEV_INTR_INIT for
the interrupt handler and it works. My interrupt handler
( tried to attach to the keyboard interrupt as a test )
returns an event which is catched by my message server.

I cannot call a function like ConnectAttach in my
interrupt handler … and this stuff should have worked.

Once again here some code snippet :


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

#define INTR_LINE_KEYBOARD 1

struct sigevent event;
int ChID;

const struct sigevent *isr(void *area, int id)
{
SIGEV_PULSE_INIT(&event, ChID, 10, _PULSE_CODE_MINAVAIL + 1, NULL);

// SIGEV_INTR_INIT(&event);

return &event;
}


int main(void)
{
int j = 0;
int intrId;
int recvid;

struct _pulse p;


// creating the channel
ChID = ChannelCreate(_NTO_CHF_UNBLOCK);

assert( ChID != -1 );

ThreadCtl(_NTO_TCTL_IO, 0);

intrId = InterruptAttach( INTR_LINE_KEYBOARD, isr, NULL, 0, 0);

assert( intrId != -1 );

InterruptEnable();

while(1){

if( ( recvid = MsgReceivePulse(ChID, &p, sizeof(p), NULL) ) < 0 )
break;

/*
if( InterruptWait(0, NULL) == -1 ){

break;
}
*/

printf(“keyboard %d\n”,j++);

if( j==10)
break;
}

InterruptDetach(intrId);

ChannelDestroy(ChID);

return 0;
}



Thank you very much for your patience and help,

Alexandre Abreu


“Mario Charest” <mcharest@zinformatic.com> wrote in message
news:9kumf6$ksj$1@inn.qnx.com

“Alexandre ABREU” <> alexandre.abreu@opal-rt.com> > wrote in message
news:9kum50$kk8$> 1@inn.qnx.com> …
Hi,

i am currently trying to convert a QNX application to NTO.
I have to replace QNX proxies by NTO pulses but i have some problems
with those. I juste create a channel using ChannelCreate() and use the
channel
id in the functions MsgReceivePulse() and MsgSendPulse() but nothing
happens.
It seems that the pulse is well sent but it is never received. I checked
every return code and function parameters and everything seems to be
correct.

Here is the code : ( i launch a thread that is in charge of sending a
pulse
to the
main thread )



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

struct sigevent event;
struct _pulse p;
int ChID;

void *thread( void * attr)
{
printf(“Thread running\n”);


You need to connect to the channel first before sending to it.
You cannot send on a chid (Channel Id) you have to send to a coid
(connection id ) which you get from ConnectAttach()

I think you are not getting any error because the ChID is probably
equal to an already existing coid created to support stdin/stdout/stderr.
So the pulse is going somewhere else.

if( MsgSendPulse(ChID, sched_get_priority_min(SCHED_FIFO),
_PULSE_CODE_MINAVAIL + 1, 0) == -1 ){

printf(“Thread() : Error while trying to send the pulse\n”);
}

printf(“Thread() : exiting\n”);

return NULL;
}


int main(void)
{
int recvid;
int thId;

/// creating the channel
ChID = ChannelCreate(_NTO_CHF_UNBLOCK);

assert( ChID != -1);

thId = pthread_create(NULL, NULL, thread, NULL);

switch( thId ){

case EOK:

break;
case EAGAIN:
case EINVAL:
case EFAULT:

printf(“error\n”);
return -1;
break;
}

if( ( recvid = MsgReceivePulse(ChID, &p, sizeof(p), NULL) ) < 0 ){
printf(“Error\n”);
}

if( recvid != 0 )
printf(“Not a pulse … \n”);
else
printf(“Pulse \n”);

ChannelDestroy(ChID);
printf(“exciting \n”);

return 0;
}



Thanks for your help,


Alexandre Abreu
\

Alexandre ABREU <alexandre.abreu@opal-rt.com> wrote:

But unfortunaltely i got another question > :slight_smile:> .

I use the same idea of pulse in an interrupt handler.
In QNX the interrupt handler used to returning a proxy
and the server thread used to block on a Receive()
and check the its return value.

If you haven’t already, take a look at the documentation
for struct sigevent.

I actually use the same idea since my interrupt handler
init a pulse event ( SIGEV_PULSE_INIT ) and return
it ( return &event ) while the message server just blocks
on a MsgReceivePulse() … but once again nothing happens.

I cannot call a function like ConnectAttach in my
interrupt handler … and this stuff should have worked.

Setup the struct sigevent (including coid) before enterring
your interrupt handler.

Once again here some code snippet :



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

#define INTR_LINE_KEYBOARD 1

struct sigevent event;
int ChID;

const struct sigevent *isr(void *area, int id)
{
return &event;
}



int main(void)
{
int j = 0;
int intrId;
int recvid;

int coid;

struct _pulse p;



// creating the channel
ChID = ChannelCreate(_NTO_CHF_UNBLOCK);
coid = ConnectAttach( 0, 0, ChID, _NTO_SIDE_CHANNEL, 0 );

SIGEV_PULSE_INIT(&event, coid, 10, _PULSE_CODE_MINAVAIL + 1, NULL);

assert( ChID != -1 );

ThreadCtl(_NTO_TCTL_IO, 0);

intrId = InterruptAttach( INTR_LINE_KEYBOARD, isr, NULL, 0, 0);

assert( intrId != -1 );

InterruptEnable();

while(1){

if( ( recvid = MsgReceivePulse(ChID, &p, sizeof(p), NULL) ) < 0 )
break;

/*
if( InterruptWait(0, NULL) == -1 ){

break;
}
*/

printf(“keyboard %d\n”,j++);

if( j==10)
break;
}

InterruptDetach(intrId);

ChannelDestroy(ChID);

return 0;
}



Thank you very much for your patience and help,

Alexandre Abreu



“Mario Charest” <> mcharest@zinformatic.com> > wrote in message
news:9kumf6$ksj$> 1@inn.qnx.com> …

“Alexandre ABREU” <> alexandre.abreu@opal-rt.com> > wrote in message
news:9kum50$kk8$> 1@inn.qnx.com> …
Hi,

i am currently trying to convert a QNX application to NTO.
I have to replace QNX proxies by NTO pulses but i have some problems
with those. I juste create a channel using ChannelCreate() and use the
channel
id in the functions MsgReceivePulse() and MsgSendPulse() but nothing
happens.
It seems that the pulse is well sent but it is never received. I checked
every return code and function parameters and everything seems to be
correct.

Here is the code : ( i launch a thread that is in charge of sending a
pulse
to the
main thread )



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

struct sigevent event;
struct _pulse p;
int ChID;

void *thread( void * attr)
{
printf(“Thread running\n”);


You need to connect to the channel first before sending to it.
You cannot send on a chid (Channel Id) you have to send to a coid
(connection id ) which you get from ConnectAttach()

I think you are not getting any error because the ChID is probably
equal to an already existing coid created to support stdin/stdout/stderr.
So the pulse is going somewhere else.

if( MsgSendPulse(ChID, sched_get_priority_min(SCHED_FIFO),
_PULSE_CODE_MINAVAIL + 1, 0) == -1 ){

printf(“Thread() : Error while trying to send the pulse\n”);
}

printf(“Thread() : exiting\n”);

return NULL;
}


int main(void)
{
int recvid;
int thId;

/// creating the channel
ChID = ChannelCreate(_NTO_CHF_UNBLOCK);

assert( ChID != -1);

thId = pthread_create(NULL, NULL, thread, NULL);

switch( thId ){

case EOK:

break;
case EAGAIN:
case EINVAL:
case EFAULT:

printf(“error\n”);
return -1;
break;
}

if( ( recvid = MsgReceivePulse(ChID, &p, sizeof(p), NULL) ) < 0 ){
printf(“Error\n”);
}

if( recvid != 0 )
printf(“Not a pulse … \n”);
else
printf(“Pulse \n”);

ChannelDestroy(ChID);
printf(“exciting \n”);

return 0;
}



Thanks for your help,


Alexandre Abreu

\


QNX Training Services
dagibbs@qnx.com

It works, that you very much.

Alex


“David Gibbs” <dagibbs@qnx.com> wrote in message
news:9kup96$1if$2@nntp.qnx.com

Alexandre ABREU <> alexandre.abreu@opal-rt.com> > wrote:
But unfortunaltely i got another question > :slight_smile:> .

I use the same idea of pulse in an interrupt handler.
In QNX the interrupt handler used to returning a proxy
and the server thread used to block on a Receive()
and check the its return value.

If you haven’t already, take a look at the documentation
for struct sigevent.