fix - KL46Z cmsis header (v2.2), shared interrupt PORTCD

- Ports C and D sharing same interrupt vectors
	- KL46Z CMSIS header update
	- InterruptIn methods irq_disable/enable comment update
pull/136/head
0xc0170 2013-12-30 12:19:24 +01:00
parent fba199a9c4
commit dc19dcbb94
3 changed files with 188 additions and 162 deletions

View File

@ -108,11 +108,13 @@ public:
*/
void mode(PinMode pull);
/** Enable IRQ
/** Enable IRQ. This method depends on hw implementation, might enable one
* port interrupts. For further information, check gpio_irq_enable().
*/
void enable_irq();
/** Disable IRQ
/** Disable IRQ. This method depends on hw implementation, might disable one
* port interrupts. For further information, check gpio_irq_disable().
*/
void disable_irq();

View File

@ -19,7 +19,7 @@
#include "gpio_irq_api.h"
#include "error.h"
#define CHANNEL_NUM 64
#define CHANNEL_NUM 96
static uint32_t channel_ids[CHANNEL_NUM] = {0};
static gpio_irq_handler irq_handler;
@ -37,7 +37,8 @@ static void handle_interrupt_in(PORT_Type *port, int ch_base) {
if (port->ISFR & pmask) {
mask |= pmask;
uint32_t id = channel_ids[ch_base + i];
if (id == 0) continue;
if (id == 0)
continue;
FGPIO_Type *gpio;
gpio_irq_event event = IRQ_NONE;
@ -51,7 +52,13 @@ static void handle_interrupt_in(PORT_Type *port, int ch_base) {
break;
case IRQ_EITHER_EDGE:
gpio = (port == PORTA) ? (FPTA) : (FPTD);
if (port == PORTA) {
gpio = FPTA;
} else if (port == PORTC) {
gpio = FPTC;
} else {
gpio = FPTD;
}
event = (gpio->PDIR & pmask) ? (IRQ_RISE) : (IRQ_FALL);
break;
}
@ -62,11 +69,19 @@ static void handle_interrupt_in(PORT_Type *port, int ch_base) {
port->ISFR = mask;
}
void gpio_irqA(void) {handle_interrupt_in(PORTA, 0);}
void gpio_irqD(void) {handle_interrupt_in(PORTD, 32);}
void gpio_irqA(void) {
handle_interrupt_in(PORTA, 0);
}
void gpio_irqCD(void) {
/* PORTC and PORTD share same vector */
handle_interrupt_in(PORTC, 32);
handle_interrupt_in(PORTD, 64);
}
int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) {
if (pin == NC) return -1;
if (pin == NC)
return -1;
irq_handler = handler;
@ -80,12 +95,16 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
ch_base = 0; irq_n = PORTA_IRQn; vector = (uint32_t)gpio_irqA;
break;
case PortC:
ch_base = 32; irq_n = PORTC_PORTD_IRQn; vector = (uint32_t)gpio_irqCD;
break;
case PortD:
ch_base = 32; irq_n = PORTD_IRQn; vector = (uint32_t)gpio_irqD;
ch_base = 64; irq_n = PORTC_PORTD_IRQn; vector = (uint32_t)gpio_irqCD;
break;
default:
error("gpio_irq only supported on port A and D\n");
error("gpio_irq only supported on port A,C and D\n");
break;
}
NVIC_SetVector(irq_n, vector);
@ -147,15 +166,15 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) {
void gpio_irq_enable(gpio_irq_t *obj) {
if (obj->port == PortA) {
NVIC_EnableIRQ(PORTA_IRQn);
} else if (obj->port == PortD) {
NVIC_EnableIRQ(PORTD_IRQn);
} else {
NVIC_EnableIRQ(PORTC_PORTD_IRQn);
}
}
void gpio_irq_disable(gpio_irq_t *obj) {
if (obj->port == PortA) {
NVIC_DisableIRQ(PORTA_IRQn);
} else if (obj->port == PortD) {
NVIC_DisableIRQ(PORTD_IRQn);
} else {
NVIC_DisableIRQ(PORTC_PORTD_IRQn);
}
}