Skip navigation.
Home
The QNX Community Portal

View topic - Interruption

Interruption

For discussion of realtime and/or embedded programming.

Interruption

Postby diogo_angnalo » Tue Feb 17, 2009 4:59 pm

I'm trying to use the interruption and I would liko to know how do it using the edge. That's my code:


struct sigevent event;
void* int_thread (void *arg);
const struct sigevent * isr_handler (void *arg, int id);
int var=0;

int main(int argc, char *argv[]) {

event.sigev_notify = SIGEV_INTR;

while(1){

pthread_create (NULL, NULL, int_thread, NULL);

delay(1000);
}
}

const struct sigevent * isr_handler (void *arg, int id) {
var ++;
return (&event);
}

void* int_thread (void *arg)
{
int errvalue, erroWait, valor;

ThreadCtl (_NTO_TCTL_IO, NULL); // enable I/O privilege

InterruptAttach(0xE,isr_handler,NULL,0,_NTO_INTR_FLAGS_TRK_MSK);
//InterruptAttachEvent(0xE,&event,_NTO_INTR_FLAGS_TRK_MSK);

//errvalue = errno;
//printf("Erro: %s\n", strerror(errvalue));

while (1)
{
InterruptWait (NULL, NULL);

erroWait=errno;
printf("erroWait=%s %d\n", strerror(erroWait),var);

}
}


I'm doing the interruption on IRQ15, but when I run this code, it interrupts alone, without doing anything.
Thanks.


(Sorry about my english.)
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

Postby Tim » Tue Feb 17, 2009 6:55 pm

Diogo,

I'm not sure what you mean when you say 'it interrupts alone, without doing anything'.

Are you saying your ISR never gets trriggered or are you saying your var variable isn't being incremented?

If the problem is the var variable not being incremented then you should know that variables modified inside ISR's must be declared volatile.

Tim
Tim
Senior Member
 
Posts: 1388
Joined: Wed Mar 10, 2004 12:28 am

Postby diogo_angnalo » Tue Feb 17, 2009 7:10 pm

The var is increasing when it have to be 0, because isn't happenning a interruption. I declared as volatile, but I didn't see any change.

In other forum, a guy sad it to me:
" The fact that you have strange value for "var" is probably because there are more than one instance of the interrupt thread. "
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

Postby mario » Tue Feb 17, 2009 7:41 pm

diogo_angnalo wrote:The var is increasing when it have to be 0, because isn't happenning a interruption. I declared as volatile, but I didn't see any change.

In other forum, a guy sad it to me:
" The fact that you have strange value for "var" is probably because there are more than one instance of the interrupt thread. "


I'm that other guy ;-) Seems like the language barrier is causing a problem.

In your post on foundry you reported var was changing? Is it increasing or not?

You did not comment on my first reply: Your program is starting int_thread() many times. This can create strange results.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby diogo_angnalo » Tue Feb 17, 2009 8:07 pm

Yeah.... hehe

yes.. it's changing... it's increasing...

if I don't start int_thread() many times, the program run a little and stops... and there's a infinite while inside int_thread()... it's weird...
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

Postby mario » Tue Feb 17, 2009 8:24 pm

It's not weird, you are starting a thread with pthread_create() that means int_thread will run on it's own, just as if you started another program. The call to pthread_create() will return right away, that's why the program stop almost right away.

Basically every second the program is starting a new thread. After 10 seconds there is 10 copy of int_thread running at the same time... That means that after 10 seconds the 10 copy of int_thread will wake up and print the value of var...

To solve that you can get rid of the while loop in main and call int_thread directly. Or use pthread_create but after do a sleep (100000);

Is the interrupt coming from PCI or ISA?
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby micro » Wed Feb 18, 2009 8:48 am

in thread:

while(1){
//Whatever you like to do
errorthingythere=......;
printf(.......); // <-- this will take a lot of time, really quite a lot
}

and in main:

do not call endless count of threads.
just create ONE other thread, the way you do it you will have a lot of threads running all doing the same thing.
As mario said, in your actual configuration i also would just call your int_thread() directly, but i guess you would like to get into threads.
Therefore just try it with one thread ;P
micro
Senior Member
 
Posts: 458
Joined: Thu Jul 22, 2004 8:41 pm

Postby diogo_angnalo » Wed Feb 18, 2009 3:53 pm

I'm using this processor: VIA Mark CoreFusion
Can use "edge"?
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

Postby diogo_angnalo » Wed Feb 18, 2009 7:16 pm

I found this information about that processor:

Offering full legacy support through ISA (Industry Standard Architecture), the VIA Mark CoreFusion processor platform provides usability of up to five PCI masters, USB 1.1 and up to two communication ports.

ISA Support - Yes with VIA 686B SouthBridge solution


Can use the interruption by edge?

Thanks.
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

Postby diogo_angnalo » Wed Feb 18, 2009 7:29 pm

Now, my code is like this:

int main(int argc, char *argv[]) {

//event.sigev_notify = SIGEV_INTR;
SIGEV_INTR_INIT( &event );

int_thread(*argv);
}

volatile int var=0;

const struct sigevent * isr_handler (void *arg, int id) {
var ++;
return (&event);
}

void* int_thread (void *arg)
{
int errvalue, erroWait, valor, irq;

ThreadCtl (_NTO_TCTL_IO, NULL);

InterruptAttach(0x0E,isr_handler,NULL,0,_NTO_INTR_FLAGS_TRK_MSK);
//InterruptAttachEvent(0x0E,&event,_NTO_INTR_FLAGS_TRK_MSK);

while (1)
{
if( InterruptWait (NULL, NULL) == -1 )
{
erroWait=errno;
printf("erroWait=%s ", strerror(erroWait));
}
else
{
printf("Var %d\n", var );
}

//irq=in8(0x0E);
//printf("irq=%d \n",irq); --> it returns 0 always.
}
}

And returns it:
Var 1
Var 2
Var 3
Var 4
Var 5
Var 6
Var 7
Var 8
Var 9
Var 10
Var 11
Var 12
Var 13
Var 14
Var 16
.
.
.

I don't understand because the IRQ15 is in 0... and the var is increasing, so the interruption is happenning... i don't know why...
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

Postby mario » Thu Feb 19, 2009 2:20 am

Not sure what you mean by "IRQ15 is in 0". Are you talking about the in8(0x0e) returning 0. Reading port 15 will NOT give you the status of the interrupt line.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby diogo_angnalo » Thu Feb 19, 2009 4:26 pm

Yes, it's... and irq15 is connected to GND... but, why is "interrupting"? the interruption has to happens just when I change the irq, like connect it to vcc for example, isn't??

and about edge-sensitive? Can I use a edge interruption?
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

Postby diogo_angnalo » Thu Feb 19, 2009 5:01 pm

ops...
IRQ15 address is 0x0F and not 0x0E.... hehehe
now, I'm testing...
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

Postby mario » Thu Feb 19, 2009 5:32 pm

About edge-sensitive, as I told you before on ISA it`s edge-sensitive on PCI it`s level sensitive.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby diogo_angnalo » Fri Feb 20, 2009 11:43 am

And using my processor? Can the interruption be edge-sensitive?


Ah, my code is working... thanks!
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm


Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 4 guests