Dear all ,
i also write an interrupt handle for SH (not x86).
and i have also a problem the same …
int main(int argc, char *argv[]) {
int pathID;
int errvalue;
char *name;
struct sigaction sa;
if (-1 == ThreadCtl(_NTO_TCTL_IO, 0))
{
if (verbose)
{
printf("%s: main: ThreadCtl failed\n", argv[0]);
}
return 0;
}
dev=(hcan2_dev_t *) malloc(sizeof(hcan2_dev_t ));
dev->regbase = (uintptr_t)MAP_FAILED;
// parse the command-line options
options(argc, argv);
// make sure the driver isn’t already running
if ((name = malloc(sizeof(DEV_NAME) + 1)) == NULL)
{
fprintf(stderr, “%s: malloc failed\n”, progname);
exit(-1);
}
// sprintf(name, “%s%d”, RESMGR_NAME, adc_channel);
sprintf(name, “%s”, RESMGR_NAME);
single_instance(name);
// allocate and initialize a dispatch structure for use by our main
loop
dev->dpp = dispatch_create();
if (dev->dpp == NULL)
{
fprintf(stderr, “%s: couldn’t dispatch_create: %s\n”,
progname, strerror (errno));
exit(-1);
}
//
// Set up the resource manager attributes structure, we’ll
// use this as a way of passing information to resmgr_attach().
// For now, we just use defaults.
//
memset(&rattr, 0, sizeof (rattr));
rattr.nparts_max = MAX_IOV_SIZE; // max ctp->iov[] size
rattr.msg_max_size = MAX_MSG_SIZE; // max size of a message
//
// Intialize the connect functions and I/O functions tables to
// their defaults and then override the defaults with the
// functions that we are providing.
//
iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs,
_RESMGR_IO_NFUNCS, &io_funcs);
// use our own: open, read, write, and devctl
connect_funcs.open = io_open;
io_funcs.read = io_read;
io_funcs.write = io_write;
io_funcs.devctl = io_devctl;
// set the mode to 0666 (R/W)
// Note leading 0 for octal -------v
iofunc_attr_init(&dev->hdr, S_IFCHR | 0666, NULL, NULL);
//
// Call resmgr_attach to register our prefix with the
// process manager, and also to let it know about our connect
// and I/O functions.
//
// On error, returns -1 and errno is set.
//
sprintf(name, “%s”, DEV_NAME);
dev->id= resmgr_attach(dev->dpp, &rattr, name, _FTYPE_ANY,
0,
&connect_funcs, &io_funcs, &dev->hdr);
if (dev->id == -1)
{
fprintf(stderr, “%s: couldn’t attach pathname: %s\n”,
progname, strerror(errno));
exit(1);
}
free(name);
/allocate a context structure/
dev->ctp = resmgr_context_alloc(dev->dpp);
//
// initialize the HW, map the registers and create driver structures
//
if (!hcan2_hw_init())
{
// HW init failed
fprintf(stderr, “%s: hcan_hw_init failed\n”, progname);
return 0;
}
//Start up a thread that is dedicated to interrupt processing
pthread_create(NULL, NULL, int_thread, NULL);
/Start the recource manager loop/
while (!done) {
if (dev->ctp == resmgr_block(dev->ctp))
resmgr_handler(dev->ctp);
else if (errno != EFAULT)
atomic_set(&done, 1);
}
free(dev);
return 0;
}
void *int_thread(void *arg)
{
int errvalue;
struct sigaction sa;
printf(“In interrupt thread: Attaching the interrupt\n”);
//Enable I/O privilege
ThreadCtl(_NTO_TCTL_IO, NULL);
memset(&dev->intr_event, 0, sizeof(&dev->intr_event));
// Initialize event structure
dev->intr_event.sigev_notify = SIGEV_INTR;
SIGEV_INTR_INIT(&dev->intr_event);
errno = EOK;
fprintf(stderr,“event =0x%04x
\n”,&dev->intr_event);
fprintf(stderr,“before interrupt dev->status=%d
\n”,&dev->status);
//Attach the ISR to IRQ
//interrupt attatch
dev->iid = InterruptAttach(dev->irq, (void*) _hcan2_irq_ser,
&dev,0, 0);
if(dev->iid==-1)
{
printf( “Couldn’t attach dev->irq %d\n”, dev->irq );
exit(-1);
}
fprintf(stderr,“after interrupt dev->status=%d
\n”,&dev->status);
errvalue = errno;
printf( “The error generated was %d\n”, errvalue );
printf( “That means: %s\n”, strerror( errvalue ) );
printf(“wait\n”);
while(!(dev->status & HCAN_STATUS_DONE))
{
InterruptWait(0, NULL);
printf(“received interrupt \n”);
}
InterruptUnmask(dev->irq,dev->iid);
InterruptDetach(dev->iid);
}
const struct sigevent *
_hcan2_irq_ser(void *arg, int iid)
{
hcan2_dev_t *dev=(hcan2_dev_t *)arg;
struct sigevent *event = NULL;
int icntr;
uint16_t whatReg = 0;
event = &dev->intr_event;
InterruptMask(dev->irq,dev->iid);
return (event);
}
when i run . the terminal announce like as:
“out of interrupt event!”
i don’t know why?
please help me
thanks,
tuyndie