Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Parallel port and irq7: (7 Items)
   
Parallel port and irq7  
Hi there :)

I wrote a test application to work with the parallel port. The following code works, but after around 20k interrupts, 
the programm freezes.

I place an external source with these parameter :
 - period = 100us
 - pulse duration = 20us

I also increase these parameters, but the problem persists.


Can someone help me?




//******************************************************************************


#include <stdio.h>
#include <sys/neutrino.h>
#include <hw/inout.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/mman.h>



#define IRQ7                              0x07
#define BASE_ADDRESS_LPT1      0x378
#define INTR_BIT                        0x10
#define INIT_BIT			 0x04
#define MASK_OVLD                    0x01
#define MASK_RUN                      0x20
#define MASK_ACK                      0x10

struct sigevent event;
volatile int id1;

const struct sigevent *handler(void *area, int id);

int main(void){

	//variables
	int i;
	unsigned char reg;
	unsigned long lpt;


	ThreadCtl(_NTO_TCTL_IO, 0);
	event.sigev_notify = SIGEV_INTR;
	
        id1 = InterruptAttach(IRQ7, &handler, NULL, 0, 0 );
	lpt = mmap_device_io(3, BASE_ADDRESS_LPT1);


	reg = in8(lpt + 2);
	out8(lpt + 2, reg|INTR_BIT|INIT_BIT);

	

	while (in8(lpt + 1) & MASK_RUN){
		InterruptWait(0, NULL);
		i += 1;
		i %= 10000;
		printf("int %d.\n", i);

	}
	printf("end of test\n");
	
        munmap_device_io(lpt, 3);
	InterruptDetach(id1);

	return 0;

}

const struct sigevent *handler(void *area, int id) {
	if (id == id1)
            return &event;
        else
            return NULL;

}

//**********************************************************
Re: Parallel port and irq7  
I am really sorry, but found my error. It was because of the testing printf.

Have a nice day!
Cédric
Re: Parallel port and irq7  
Hi again ;)

Sorry to disturb you... I still have issues with interrupts and parrallel port.

In a few words : 

My program await on a lpt interrupt (IRQ7), its period is 1ms and the pulse duration is half of this period.

An input pin gives the start and stop signal ("MASK_RUN").

Every time the program catch an interrupt, it toggles one output pin.

This pin state is displayed on a oscilloscope and after around fifteen seconds the execution freezes...

Is it a kind of overflow?

I read some internet pages about lpt port, but didn't find anything about particular servicing.




//**********************************************************
#include <stdio.h>
#include <sys/neutrino.h>
#include <hw/inout.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/mman.h>
#include <unistd.h>


#define IRQ7                              0x07
#define BASE_ADDRESS_LPT1      0x378
#define INTR_BIT                        0x10
#define MASK_RUN                      0x20
#define MASK_TOGGLE		 0x02


struct sigevent event;
volatile int id1;

const struct sigevent *handler(void *area, int id);

int main(void){

	unsigned char reg;
	unsigned long lpt;

	ThreadCtl(_NTO_TCTL_IO, 0);
	event.sigev_notify = SIGEV_INTR;

	id1 = InterruptAttach(IRQ7, &handler, NULL, 0, 0 );
	/*access to parallel port bytes... to write, read and configure...*/
	lpt = mmap_device_io(3, BASE_ADDRESS_LPT1);

       /* lpt irq activation */
	reg = in8(lpt + 2);
	out8(lpt + 2, reg|INTR_BIT);


	while(~in8(lpt + 1) & MASK_RUN);
	while(in8(lpt + 1) & MASK_RUN){
		InterruptWait(0, NULL);
		reg = in8(lpt);
		out8(lpt, reg ^ MASK_TOGGLE);
	}

	munmap_device_io(lpt, 3);
	InterruptDetach(id1);

	return 0;

}

/*
  isr
*/
const struct sigevent *handler(void *area, int id) {
	if (id == id1)
		return &event;
	else
		return NULL;
}

//**********************************************************


I also tried to replace InterruptAttach by InterruptAttachEvent without any succes :/.


Thanks for your help and hints!

Cédric




Re: Parallel port and irq7  

Cédric Schaffter wrote:
> 	while(~in8(lpt + 1) & MASK_RUN);
> 	while(in8(lpt + 1) & MASK_RUN){
> 		InterruptWait(0, NULL);
> 		reg = in8(lpt);
> 		out8(lpt, reg ^ MASK_TOGGLE);
		InterruptUnmask(IRQ7, id1);
> 	}
> 
> 	munmap_device_io(lpt, 3);
> 	InterruptDetach(id1);
> 
> 	return 0;
> 
> }
> 
> /*
>   isr
> */
> const struct sigevent *handler(void *area, int id) {
> 	if (id == id1)
{
		InterruptMask(IRQ7, id1);
> 		return &event;

}
> 	else
> 		return NULL;
> }
> 

I would try the above - does it make a difference?
Re: Parallel port and irq7  
Thanks Aleksandar for your help :)

Unfortunately it didn't solve my problem.

Regards,
Cédric
RE: Parallel port and irq7  
This may seem like an obvious thing but is devc-par running? That would be the standard parallel port driver. When I was
 playing with a similar thing I seem to remember strange behaviour until I killed off devc-par.

--
Keith

-----Original Message-----
From: Cédric Schaffter [mailto:community-noreply@qnx.com] 
Sent: November 5, 2008 03:48
To: general-community
Subject: Re: Parallel port and irq7

Thanks Aleksandar for your help :)

Unfortunately it didn't solve my problem.

Regards,
Cédric

_______________________________________________
General
http://community.qnx.com/sf/go/post15948
Re: RE: Parallel port and irq7  
Thanks Keith !

I perform a "slay devc-par" and it solves the problem!

Best regards,
Cédric