Cédric Schaffter
10/22/2008 8:41 AM
post15391
|
Hi list!
I read the page http://www.qnx.co.jp/developers/docs/6.3.2/neutrino/prog/inthandler.html about interrupts.
Then I adapted the given example to handle keyboard irq.
But my system freezes.
//**********************************************************
#include <stdio.h>
#include <sys/neutrino.h>
#include <sys/syspage.h>
#include <semaphore.h>
#include <pthread.h>
#define IRQ1 1
struct sigevent event;
volatile unsigned counter;
sem_t end;
const struct sigevent *handler(void *area, int id) {
printf("ID : %d\n", id);
return(&event);
}
void * int_thread(void * cookie){
int i;
int id;
// Request I/O privity
ThreadCtl(_NTO_TCTL_IO, 0);
// Initialize event structure
printf("setting notification mode\n");
event.sigev_notify = SIGEV_INTR;
id=InterruptAttach(IRQ1, &handler, NULL, 0, 0 );
for( i = 0; i < 10; ++i ) {
InterruptWait( 0, NULL );
printf( "key hit\n" );
InterruptUnmask(IRQ1, id);
}
// Disconnect the ISR handler
InterruptDetach(id);
sem_post(&end);
return NULL;
}
int main() {
printf("application using irq1\n");
sem_init(&end, NULL, 0);
pthread_create(NULL, NULL, int_thread, NULL);
/*
....
*/
sem_wait(&end);
printf("normal termination...\n");
return 0;
}
//*******************************************************
I also have a few questions.
1. If I need to manage with multiples interrupts source. Should I create one thread and one ISR per source. Or can I use
one thread which will wait on many interrupts and then call the right ISR? If yes, how can I implement that?
2. In the handler function, the second parameter is "id", can someone explain me how the kernel informs this parameter?
Thanks,
Cédirc
|
|
|