Problems with Pulse

I’m working on a driver, basing my code on the IPC sample
from the QNX samples disk. I need to process an interrupt
in an IST and then send a pulse to my resource manager to awaken
a thread that is blocked waiting for input.

I’ve distilled my code down to the following sample (that runs off
the timer interrupt rather than my real hardware) and it still exhibits
the same problem – I get messages claiming my pulses are sent, but
I never get a message saying the pulse was received.

Undoubtedly, I’m missing some initialization or something is out
of sequence. Anyone spot the problem?

Thanks,
Randy Hyde

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>
#include <errno.h>
#include <sys/neutrino.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <hw/inout.h>
#include <unistd.h>

typedef void* pvoid_t;
typedef const struct sigevent* psigevent;

#define ever ;;

int port2IntID; // ID for the port2 IRQ

dispatch_t *dpp;
resmgr_attr_t resmgr_attr;
resmgr_context_t *ctp;
resmgr_connect_funcs_t connect_func;
resmgr_io_funcs_t io_func;
iofunc_attr_t attr;

int writePulseCode;
int coidPulse;

struct sigevent intr_event;

pvoid_t
IRQ5IST( pvoid_t NotInUse )
{
int cntr;


coidPulse = message_connect( dpp, MSG_FLAG_SIDE_CHANNEL );
printf( “coidPulse=0x%x\n”, coidPulse );

// Set up the interrupt:

ThreadCtl( _NTO_TCTL_IO, 0 ); // So we can call InterruptAttach.
intr_event.sigev_notify = SIGEV_INTR;
port2IntID =
InterruptAttachEvent
(
0,
&intr_event,
_NTO_INTR_FLAGS_TRK_MSK
);

for(ever)
{
// Wait for an interrupt from port 2:

InterruptWait( NULL, NULL );
if( ++cntr == 5000 )
{
cntr = 0;

MsgSendPulse
(
coidPulse,
20,
writePulseCode,
NULL
);
printf( “Sent Pulse\n” );

}

// Unmask the interrupts so we can respond to future
// serial port interrupts.

InterruptUnmask( 0, port2IntID);

}// endfor
return NULL; // Just to shut up the compiler…
}






int
port2PulseHandler
(
message_context_t *ctp,
int code,
unsigned flags,
void *handle
)
{

printf( “Pulse arrived, code=%d, handle=%p\n”, code, handle );
if( code == writePulseCode )
{
printf( “Got write pulse\n” );
}
return code;
}




int
main( int argc, char **argv )
{
int id;
uintptr_t serHandle;
uchar_t ch;

// Map in the eight bytes of I/O space associated with this chip:

ThreadCtl( _NTO_TCTL_IO, NULL );




// Okay, now set up the resource manager:
//
// create the dispatch structure

if ((dpp = dispatch_create ()) == NULL)
{
perror (“Unable to dispatch_create\n”);
exit (EXIT_FAILURE);
}

// initialize the various data structures

memset (&resmgr_attr, 0, sizeof (resmgr_attr));
resmgr_attr.nparts_max = 2;
resmgr_attr.msg_max_size = 4096;

// bind default functions into the outcall tables

iofunc_func_init
(
_RESMGR_CONNECT_NFUNCS,
&connect_func,
_RESMGR_IO_NFUNCS,
&io_func
);

iofunc_attr_init (&attr, S_IFNAM | 0666, 0, 0);

// establish a name in the pathname space

if
(
resmgr_attach
(
dpp,
&resmgr_attr,
“/dev/pulser”,
_FTYPE_ANY,
0,
&connect_func,
&io_func,
&attr
) == -1
)
{
perror (“Unable to resmgr_attach\n”);
exit (EXIT_FAILURE);
}


writePulseCode =
pulse_attach( dpp, MSG_FLAG_ALLOC_PULSE, 0, port2PulseHandler, NULL );


printf( “writePulseCode=%d\n”, writePulseCode );


// Complete the initialization of the resource manager:

ctp = resmgr_context_alloc (dpp);


// Start the interrupt service thread:

pthread_create( 0, NULL, IRQ5IST, NULL );


// wait here forever, handling messages

while (1)
{
if ((ctp = resmgr_block (ctp)) == NULL)
{
perror (“Unable to resmgr_block\n”);
exit (EXIT_FAILURE);
}
resmgr_handler (ctp);
}

return 0;
}

Randall Hyde <randall.nospam.hyde@ustraffic.net> wrote:

For pulse_attach() to work and call your pulse handler, you
need to use dispatch_contect_alloc(), dispatch_block(), and
dispatch_handler() instead of the resmgr_*() variants.

-David

ctp = resmgr_context_alloc (dpp);
// Start the interrupt service thread:

// wait here forever, handling messages
while (1)
{
if ((ctp = resmgr_block (ctp)) == NULL)
{
perror (“Unable to resmgr_block\n”);
exit (EXIT_FAILURE);
}
resmgr_handler (ctp);
}
return 0;
}





QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:b42i9p$lgs$4@nntp.qnx.com

Randall Hyde <> randall.nospam.hyde@ustraffic.net> > wrote:

For pulse_attach() to work and call your pulse handler, you
need to use dispatch_contect_alloc(), dispatch_block(), and
dispatch_handler() instead of the resmgr_*() variants.

-David

Thanks, I can’t believe I’ve looked at the code a dozen times
(comparing my code against the ipc example on the QNX
samples disk) and missed that.
Cheers,
Randy Hyde