Im writing a recource manager to communicate with a motor control. I need to
detect when IRQ5 fires to read in data from the board.
I have two problems:
- I only read 0 from the register i want (occasionaly 0x100) when i read it
not waiting for the interrupt that signals that data is ready, i can write
to the register fine, but cant read anything sensible. I know i can write
because when i write the robot moves accordingly.
2)i set up an interrupt handler to monitor IRQ5 but the interrupt handler
never does anything just waits in the InterruptWait(NULL,NULL); part. the
hardware is starts at 0x320.
This is a ported driver from linux, interrupts work fine in linux, not
here:( ive tried everything for 2 days and nothing:( anyone have any ideas?
here is my code:
#define WALKER_NR_PORTS 16
#define IOBASE 0x320
#define DMKPC (IOBASE+0x00)
#define DPCMK1 (IOBASE+0x00)
#define DATA_IGNORE 0xFFFF
main (int argc, char **argv)
{
resmgr_attr_t resmgr_attr;
dispatch_t *dpp;
dispatch_context_t *ctp;
int id;
/Initialize dispatch interface/
if((dpp = dispatch_create()) == NULL)
{
fprintf(stderr, “%s: Unable to allocate dispatch
handle.\n”, argv[0]);
return EXIT_FAILURE;
}
/Initialize recource manager attributes/
memset(&resmgr_attr, 0, sizeof resmgr_attr);
resmgr_attr.nparts_max = 1;
resmgr_attr.msg_max_size = 2048;
/Initialize function for handling messages/
iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs,
_RESMGR_IO_NFUNCS, &io_funcs);
io_funcs.read = io_read;
io_funcs.devctl = io_devctl; /* For handling _IO_DEVCTL, sent
by devctl() */
/initialize attribute structure used by the device/
iofunc_attr_init(&attr, S_IFNAM | 0666, 0, 0);
attr.nbytes = strlen(buffer) +1;
/attach the device name/
if((id = resmgr_attach(dpp, &resmgr_attr, DEVNAME, _FTYPE_ANY,
0, &connect_funcs, &io_funcs, &attr)) == -1)
{
fprintf(stderr, “%s: Unable to attach name. \n”,
argv[0]);
return EXIT_FAILURE;
}
/allocate a context structure/
ctp = dispatch_context_alloc(dpp);
/setup Hardware I/O, need to do only once/
ThreadCtl(_NTO_TCTL_IO, NULL);
iobase = mmap_device_io(WALKER_NR_PORTS, IOBASE);
/Start up a thread that is dedicated to interrupt processing/
pthread_create(NULL, NULL, int_thread, NULL);
/Start the recource manager loop/
while(1)
{
if((ctp = dispatch_block(ctp)) == NULL)
{
fprintf(stderr, “block error\n”);
return EXIT_FAILURE;
}
dispatch_handler(ctp);
}
}
void *int_thread(void *arg)
/This thread is dedicated to handling and managing interrupts/
{
printf(“In interrupt thread: Attaching the interrupt\n”);
/Enable I/O privilege/
ThreadCtl(_NTO_TCTL_IO, NULL);
/Attach the ISR to IRQ/
InterruptAttach(5, isr_handler, NULL, 0, 0);
/Now service the hardware when the ISR says to/
while(1)
{
InterruptWait(NULL, NULL);
}
}
const struct sigevent * isr_handler(void *arg, int id)
/This is the ISR/
{
/PROBLEM: NEVER ENTERS THIS FUNCTION/
/Look at the hardware to see if it caused the interrupt, if not
return NULL/
if(!(in16(SMKPC) & 0x000e))
{
return SIGEV_NONE;
}
/This is done when the robot sends an interrupt that its ready
to recieve data/
if(flag == 1)
{
dmkpc = in16(DMKPC);
flag–;
}
/aknowlege we processed the interrupt/
out16(DATA_IGNORE, IRQACK);
/*Return a pointer to an event structure (preinitialized by
main) that
-
contains SIGEV_INTR as its notification type. This causes the
InterruptWait -
in “int_thread” to unblock.*/
return (struct sigevent *)1;
}
\
Thanks!