I'm new to freescale MQX and I'm trying to set up interrupts on an input pin using MQX functions (just in case we'd like to change MPU). I couldn't find any good tutorials... Can somebody point me to a direction? Thanx
Asked
Active
Viewed 1,504 times
1 Answers
1
Let's setup an interrupt on rising edge for PTA5, ok?
Define a macro to represent your pin. Not really necessary, but helps.
#define MY_GPIO_INT_PIN (GPIO_PORT_A|GPIO_PIN_IRQ_RISING|GPIO_PIN5)
Declare some needed variables
PORT_MemMapPtr pctl;
GPIO_PIN_STRUCT pins[2];
MQX_FILE_PTR pin_fd;
Get the base pointer for your pin port, and set the apropriate mux option (found on your chip reference manual).
//note: this code should be in init_gpio.c, from your bsp folder.
pctl = (PORT_MemMapPtr) PORTA_BASE_PTR;
/* PTA5 as GPIO (Alt.1) */
pctl->PCR[5] = PORT_PCR_MUX(1) ;
Fill an array of pin structs. Note that you can setup more than one pin at once, and the array needs to be terminated with GPIO_LIST_END, so the driver knows where to stop.
pins[0] = MY_GPIO_INT_PIN;
pins[1] = GPIO_LIST_END;
As a semi POSIX compliant os, pretty much anything is treated as a file on MQX. Lets open a file handler for your pin:
pin_fd = fopen("gpio:input", (char*)pins);
Check if all went well
if(NULL == pin_fd){
//something bad happened, check for error with ferror(fd)
}
Now register the callback for your pin
void pin_int_callback(void* data){
//interrupt handle code goes here
}
if(IO_OK != ioctl(pin_fd, GPIO_IOCTL_SET_IRQ_FUNCTION, (void*)pin_int_callback)){
//something bad happened registering your callback
}
Done! Try putting it all together.

Heeryu
- 852
- 10
- 25
-
Than for your comment. I found this tutorial quite helpful.... Hope it can help others as well https://community.freescale.com/thread/302091 – fakr00n Mar 21 '14 at 16:33
-
@user3297145 that's not exactly what you are looking for. This tutorial explains how to register an interrupt on mqx internal interrupt vector. You still need to configure configuration registers for the pin you want to generate interrupts, and that's what my answer is about. – Heeryu Mar 21 '14 at 16:46
-
Ah ok, I guess the prins were aleady configured with codewarrior gui since the tutorial worked fine form me. But thank you for you example :) – fakr00n Mar 22 '14 at 17:05