Skip navigation.
Home
The QNX Community Portal

View topic - how to handle the interrupt in the QNX microkernel ?

how to handle the interrupt in the QNX microkernel ?

anything that doesn't fit to other groups.

how to handle the interrupt in the QNX microkernel ?

Postby hemanth » Thu May 08, 2014 10:55 am

int id1; //variables used in the isr should be volatile
struct sigevent event;

int chid;


/* this function is your code */

const struct sigevent *ISR(void *area, int id1)
{


StartInterruptTime = ClockCycles();


return (&event);

}



/* this function is your code */

void *ConfigureISR(void) //void *ISR (void *arg)
{
/* the software must tell the OS that it wishes to associate the ISR with a particular source of interrupts
* / * On x86 platforms, there are generally 16 hardware Interrupt Request lines (IRQs) */


StartInterruptTime = GetTimeStamp(); //startTime of the interrupt

// volatile int irq = 11; //0 : A clock that runs at the resolution set by ClockPeriod()



ThreadCtl (_NTO_TCTL_IO, NULL); // enables the hardware interrupt

// Initialize event structure
//
// Setup COID and event
//

/* Tell the kernel to attach an interrupt signal event to this thread */
chid = ChannelCreate( 0 );
SIGEV_INTR_INIT( &event);


// ISR is the interrupt service routine
id1 = InterruptAttachEvent(irq, ISR, NULL);


if (id1 == -1)
{
fprintf(stderr, "can't attach to IRQ\n");
perror (NULL);
exit (EXIT_FAILURE);
}
InterruptWait(0, NULL);
InterruptLatency = (double) (EndInterruptTime - StartInterruptTime)/(double)(SYSPAGE_ENTRY(qtime)->cycles_per_sec);


//I am storing the difference between the time in array.
measurements[17] = InterruptLatency;


return (EXIT_SUCCESS);
}



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

pthread_t thread_id;

// I am creating the socket to receive data from client

if ((sock = CreateSocket()) < 0) {
perror ("Create_socket");
exit (1);
}


// this is my timer which is calling the task in the background for every2 milliseconds, 10ms and 100ms
if (pthread_create(&thread_id, NULL, &rastertask, NULL)) {
perror ("pthread_create");
exit (1);
}

do
{
socklen_t len;
len = sizeof(client);

printf("NEW DATA ARRIVED\n");
//non blocking mode : MSG_DONTWAIT


// API to receive data from the client.
rc=recvfrom(sock, buf, 256, 0, (struct sockaddr*) &client, &len);


if(rc==0)
{
printf("Server has no connection..\n");
break;
}
if(rc==-1)
{
if (errno == SIGINT)
continue;
printf("Oh dear, something went wrong with read()! %s\n", strerror(errno));
break;
}


// I AM CALLING THE API FOR INTERRUPT HERE
ConfigureISR ();

}

} while (1);



close(sock);

return 0;
}

There is a client and server : Client is sending data to the server . Server is receiving the data and sending a response back to the client. Ethernet interface for communication between client and server. Client is a tool (intecrio tool) for sending data. Server is an embedded PC target (fit pc2) with qnx rtos. Server wi be executing some other process. When server receives the data along the Ethernet interface then the kernel as to stop what it is doing. And start executing the newly arrived data.

My task - I want to take the timestamp when the kernel is interrupted and time at which the kernel starts handling it. In QNX microkernel- I am not able to take the timestamp at which the kernel is interrupted . So I am planning to take the timestamp at which the interrupt handler is called by the kernel . Later I will store this timestamp in a memory and server will send this back to the client.

my problem in the above code : ConfigureISR (); //when this function is called : It will stop executing further and later it will show an error : Execution is suspended because of error.
hemanth
Active Member
 
Posts: 20
Joined: Mon Dec 23, 2013 11:14 pm

Re: how to handle the interrupt in the QNX microkernel ?

Postby Tim » Thu May 08, 2014 7:52 pm

Didn't you already start another thread on this topic? Why aren't you posting there?

This call:
id1 = InterruptAttachEvent(irq, ISR, NULL);

is expecting ISR to be a a structure. You are attempting to pass it a function meant for InterruptAttach. It's no surprise it's not working.

You should really look at this documentation

http://www.qnx.com/developers/docs/6.3. ... ndler.html

then figure out if you want to use InterruptAttach or InterruptAttachEvent. It's easier to use InterruptAttachEvent (and safer too since you can't hang the OS) but it has some costs http://www.qnx.com/developers/docs/660/ ... Event.html

Here is some sample code for InterruptAttachEvent

http://www.qnx.com/developers/docs/660/ ... Event.html

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

Re: how to handle the interrupt in the QNX microkernel ?

Postby hemanth » Thu May 08, 2014 7:57 pm

Could you please give me a small example ??
hemanth
Active Member
 
Posts: 20
Joined: Mon Dec 23, 2013 11:14 pm

Re: how to handle the interrupt in the QNX microkernel ?

Postby Tim » Thu May 08, 2014 8:01 pm

I think I just gave you some links to sample code.

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

Re: how to handle the interrupt in the QNX microkernel ?

Postby hemanth » Thu May 08, 2014 8:02 pm

const struct sigevent *ISR(void *area, int id1)
{


StartInterruptTime = ClockCycles();


return (&event);

}

you said that expecting ISR to be a a structure:

the above code is a structure in the my example.
hemanth
Active Member
 
Posts: 20
Joined: Mon Dec 23, 2013 11:14 pm

Re: how to handle the interrupt in the QNX microkernel ?

Postby Tim » Fri May 09, 2014 5:18 pm

No.

You have declared ISR as a function that returns a pointer to a sigevent structure.

A structure is something like

struct sigevent {
int a;
float b;
};

It does not have executable statements in it like StartInterruptTime = ClockCycles(); and return (&event);

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

Re: how to handle the interrupt in the QNX microkernel ?

Postby hemanth » Tue May 13, 2014 6:54 am

Could you please give me a small example ??
I did not understand that completely and still it is not working !! so please help me.
hemanth
Active Member
 
Posts: 20
Joined: Mon Dec 23, 2013 11:14 pm


Return to General Programming

Who is online

Users browsing this forum: No registered users and 3 guests

cron