* GPIO irq files updated.

* updated with modification for KnR Standard.
pull/1243/head
akhilpanayam 2015-07-03 11:23:14 +05:30 committed by Karthik Purushothaman
parent 503c970d98
commit 6a23ca1da4
7 changed files with 364 additions and 207 deletions

View File

@ -45,28 +45,35 @@ typedef enum {
} UARTName;
typedef enum {
ADC0_0 = 0,
ADC0_1,
ADC0_2,
ADC0_3,
ADC0_4,
ADC0_5,
ADC0_6,
ADC0_7/*,
ADC0_8,
ADC0_9,
ADC0_10,
ADC0_11,
ADC0_12,
ADC0_13,
ADC0_14,
ADC0_15,
ADC0_16,
ADC0_17,
ADC0_18,
ADC0_19*/
ADC_0 = 0,
ADC_1,
ADC_2,
ADC_3,
ADC_4,
ADC_5,
ADC_6,
ADC_7
} ADCName;
typedef enum {
EXTINT_0 = 0,
EXTINT_1,
EXTINT_2,
EXTINT_3,
EXTINT_4,
EXTINT_5,
EXTINT_6,
EXTINT_7,
EXTINT_8,
EXTINT_9,
EXTINT_10,
EXTINT_11,
EXTINT_12,
EXTINT_13,
EXTINT_14,
EXTINT_15
} EXTINTName;
/*
typedef enum {
DAC_0 = 0

View File

@ -51,6 +51,8 @@ extern const PinMap PinMap_SERCOM_PADEx[];
/************PWM***************/
//extern const PinMap PinMap_PWM[];
/**********EXTINT*************/
extern const PinMap PinMap_EXTINT[];
#endif

View File

@ -34,14 +34,14 @@ const PinMap PinMap_RTC[] = {
/************ADC***************/
const PinMap PinMap_ADC[] = {
{PA04, ADC0_0, 1},
{PA05, ADC0_1, 1},
{PA06, ADC0_2, 1},
{PA07, ADC0_3, 1},
{PA08, ADC0_4, 1},
{PA09, ADC0_5, 1},
{PB02, ADC0_6, 1},
{PB03, ADC0_7, 1}
{PA04, ADC_0, 1},
{PA05, ADC_1, 1},
{PA06, ADC_2, 1},
{PA07, ADC_3, 1},
{PA08, ADC_4, 1},
{PA09, ADC_5, 1},
{PB02, ADC_6, 1},
{PB03, ADC_7, 1}
};
/************DAC***************/
@ -137,6 +137,64 @@ const PinMap PinMap_SPI_SSEL[] = {
const PinMap PinMap_PWM[] = {
};
/**********EXTINT*************/
const PinMap PinMap_EXTINT[] = {
{PA16, EXTINT_0, 0},
{PB00, EXTINT_0, 0},
{PB16, EXTINT_0, 0},
{PA00, EXTINT_0, 0},
{PA17, EXTINT_1, 0},
{PB17, EXTINT_1, 0},
{PA01, EXTINT_1, 0},
{PA18, EXTINT_2, 0},
{PA02, EXTINT_2, 0},
{PA19, EXTINT_3, 0},
{PB03, EXTINT_3, 0},
{PA04, EXTINT_4, 0},
{PA20, EXTINT_4, 0},
{PA05, EXTINT_5, 0},
{PA06, EXTINT_6, 0},
{PA22, EXTINT_6, 0},
{PB22, EXTINT_6, 0},
{PA07, EXTINT_7, 0},
{PA23, EXTINT_7, 0},
{PB28, EXTINT_7, 0},
{PA28, EXTINT_8, 0},
{PB08, EXTINT_8, 0},
{PA09, EXTINT_9, 0},
{PB09, EXTINT_9, 0},
{PA10, EXTINT_10, 0},
{PA30, EXTINT_10, 0},
{PA11, EXTINT_11, 0},
{PA31, EXTINT_11, 0},
{PA12, EXTINT_12, 0},
{PA24, EXTINT_12, 0},
{PA13, EXTINT_13, 0},
{PA25, EXTINT_13, 0},
{PB14, EXTINT_14, 0},
{PB30, EXTINT_14, 0},
{PA14, EXTINT_14, 0},
{PA15, EXTINT_15, 0},
{PA27, EXTINT_15, 0},
{PB15, EXTINT_15, 0},
{PB31, EXTINT_15, 0}
};
/********SERCOM MAPPING*********/
struct pin_sercom {
uint8_t pad_num; // a pin always mapped to a pad

View File

@ -20,10 +20,17 @@
#include "gpio_api.h"
#include "mbed_error.h"
#include "extint.h"
#include "pinmap.h"
#include "PeripheralPins.h"
#include "port.h"
#define CHANNEL_NUM 15
#define CHANNEL_NUM 16
#define pEXT_CONF(obj) (obj->config_extint_chan)
static uint32_t channel_ids[CHANNEL_NUM] = {0};
static gpio_irq_handler irq_handler;
uint8_t ext_int_pins[EIC_NUMBER_OF_INTERRUPTS] = {0xFF};
uint8_t fallcount = 0;
uint8_t risecount = 0;
int get_extint_channel(PinName pin)
{
@ -104,39 +111,119 @@ int get_extint_channel(PinName pin)
}
}
uint32_t find_peripheral_index (PinName pin, const PinMap* map)
{
uint8_t count = 0;
while (map->pin != NC) {
if (map->pin == pin)
return map[count].peripheral;
map++;
count++;
}
return (uint32_t)NC;
}
uint32_t find_pin_index (PinName pin, const PinMap* map)
{
uint8_t count = 0;
while (map->pin != NC) {
if (map->pin == pin)
return count;
map++;
count++;
}
return (uint32_t)NC;
}
void gpio_irq(void)
{
uint32_t current_channel;
uint32_t config_pos;
uint32_t new_config;
uint32_t mask;
Eic *const EIC_module = EIC;
uint32_t config = 0;
gpio_irq_event event = IRQ_NONE;
PortGroup *port_base;
uint32_t index = 0;
for (current_channel = 0; current_channel < EIC_NUMBER_OF_INTERRUPTS ; current_channel++) {
if (extint_chan_is_detected(current_channel)) {
extint_chan_clear_detected(current_channel);
port_base = (PortGroup*)port_get_group_from_gpio_pin(ext_int_pins[current_channel]);
mask = gpio_set(ext_int_pins[current_channel]);
if ((port_base->IN.reg & mask) != 0) {
event = IRQ_RISE;
risecount++;
} else {
event = IRQ_FALL;
fallcount++;
}
if (event != IRQ_NONE) {
index = find_pin_index(ext_int_pins[current_channel], PinMap_EXTINT);
irq_handler(channel_ids[current_channel], event);
}
}
}
}
int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id)
{
struct extint_chan_conf config_extint_chan;
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector, ab = 0;
irq_handler = handler;
obj->pin = pin;
int int_channel = 0;
if (pin == NC)
return -1;
irq_handler = handler;
extint_chan_get_config_defaults(&config_extint_chan);
config_extint_chan.gpio_pin = (uint32_t)pin;
config_extint_chan.gpio_pin_mux = 0; // mux setting for ext int is 0
config_extint_chan.gpio_pin_pull = EXTINT_PULL_UP;
config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;
extint_chan_get_config_defaults(&pEXT_CONF(obj));
pEXT_CONF(obj).gpio_pin = (uint32_t)pin;
pEXT_CONF(obj).gpio_pin_mux = 0; // mux setting for ext int is 0
pEXT_CONF(obj).gpio_pin_pull = EXTINT_PULL_NONE;
pEXT_CONF(obj).detection_criteria = EXTINT_DETECT_BOTH;
int_channel = get_extint_channel(pin);
if (int_channel != 0xFF) {
extint_chan_set_config(int_channel, &config_extint_chan);
extint_chan_set_config(int_channel, &pEXT_CONF(obj));
}
ext_int_pins[int_channel] = pin;
irq_n = EIC_IRQn;
vector = (uint32_t)gpio_irq;
NVIC_SetVector(irq_n, vector);
NVIC_EnableIRQ(irq_n);
obj->int_ch = find_pin_index(pin, PinMap_EXTINT);
obj->ch = int_channel;
channel_ids[obj->ch] = id;
}
void gpio_irq_free(gpio_irq_t *obj)
{
channel_ids[obj->int_ch] = 0;
}
void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
{
Eic *const eic = _extint_get_eic_from_channel(obj->ch);
if (enable) {
pEXT_CONF(obj).detection_criteria = EXTINT_DETECT_BOTH;
extint_chan_set_config(obj->ch, &pEXT_CONF(obj));
eic->INTENSET.reg = (1UL << obj->ch);
} else {
pEXT_CONF(obj).detection_criteria = EXTINT_DETECT_BOTH;
extint_chan_set_config(obj->ch, &pEXT_CONF(obj));
// channel_ids[obj->ch] = 0;
}
}
void gpio_irq_enable(gpio_irq_t *obj)
{
// NVIC_EnableIRQ(EIC_IRQn);
}
void gpio_irq_disable(gpio_irq_t *obj)
{
// NVIC_DisableIRQ(EIC_IRQn);
}

View File

@ -21,6 +21,7 @@
#include "PeripheralNames.h"
#include "gpio_object.h"
#include "adc.h"
#include "extint.h"
#ifdef __cplusplus
extern "C" {
@ -30,6 +31,8 @@ struct gpio_irq_s {
uint32_t port;
uint32_t pin;
uint32_t ch;
uint32_t int_ch;
struct extint_chan_conf config_extint_chan;
};
struct port_s {

View File

@ -29,38 +29,38 @@ extern uint8_t g_sys_init;
static inline void pinmux_get_current_config(PinName pin, struct system_pinmux_config *const config)
{
MBED_ASSERT(pin != (PinName)NC);
uint32_t pin_index = pin % 32;
uint32_t pin_mask = (uint32_t)(1UL << pin_index);
PortGroup *const port = system_pinmux_get_group_from_gpio_pin(pin);
MBED_ASSERT(port);
config->mux_position = system_pinmux_pin_get_mux_position(pin);
if (port->PINCFG[pin_index].reg & PORT_PINCFG_INEN) {
if (port->DIR.reg & pin_mask) {
config->direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT_WITH_READBACK;
config->input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
} else {
config->direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
if (port->PINCFG[pin_index].reg & PORT_PINCFG_PULLEN) {
if (port->OUT.reg & pin_mask) {
config->input_pull = SYSTEM_PINMUX_PIN_PULL_UP;
} else {
config->input_pull = SYSTEM_PINMUX_PIN_PULL_DOWN;
}
} else {
config->input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
}
}
} else {
config->input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
config->direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT;
}
/* Not relevant for now */
config->powersave = false;
MBED_ASSERT(pin != (PinName)NC);
uint32_t pin_index = pin % 32;
uint32_t pin_mask = (uint32_t)(1UL << pin_index);
PortGroup *const port = system_pinmux_get_group_from_gpio_pin(pin);
MBED_ASSERT(port);
config->mux_position = system_pinmux_pin_get_mux_position(pin);
if (port->PINCFG[pin_index].reg & PORT_PINCFG_INEN) {
if (port->DIR.reg & pin_mask) {
config->direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT_WITH_READBACK;
config->input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
} else {
config->direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
if (port->PINCFG[pin_index].reg & PORT_PINCFG_PULLEN) {
if (port->OUT.reg & pin_mask) {
config->input_pull = SYSTEM_PINMUX_PIN_PULL_UP;
} else {
config->input_pull = SYSTEM_PINMUX_PIN_PULL_DOWN;
}
} else {
config->input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
}
}
} else {
config->input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
config->direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT;
}
/* Not relevant for now */
config->powersave = false;
}
/** Change the MUX padding of input pin
@ -72,14 +72,14 @@ static inline void pinmux_get_current_config(PinName pin, struct system_pinmux_c
*/
void pin_function(PinName pin, int function)
{
MBED_ASSERT(pin != (PinName)NC);
MBED_ASSERT(pin != (PinName)NC);
struct system_pinmux_config pin_conf;
struct system_pinmux_config pin_conf;
pinmux_get_current_config(pin, &pin_conf);
pin_conf.mux_position = function;
pinmux_get_current_config(pin, &pin_conf);
pin_conf.mux_position = function;
system_pinmux_pin_set_config(pin, &pin_conf);
system_pinmux_pin_set_config(pin, &pin_conf);
}
/** Change the pin pull mode
@ -91,18 +91,18 @@ void pin_function(PinName pin, int function)
*/
void pin_mode(PinName pin, PinMode mode)
{
MBED_ASSERT(pin != (PinName)NC);
MBED_ASSERT(pin != (PinName)NC);
struct system_pinmux_config pin_conf;
struct system_pinmux_config pin_conf;
pinmux_get_current_config(pin, &pin_conf);
if (mode == PullUp) {
pin_conf.input_pull = SYSTEM_PINMUX_PIN_PULL_UP;
} else if (mode == PullDown) {
pin_conf.input_pull = SYSTEM_PINMUX_PIN_PULL_DOWN;
} else {
pin_conf.input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
}
pinmux_get_current_config(pin, &pin_conf);
if (mode == PullUp) {
pin_conf.input_pull = SYSTEM_PINMUX_PIN_PULL_UP;
} else if (mode == PullDown) {
pin_conf.input_pull = SYSTEM_PINMUX_PIN_PULL_DOWN;
} else {
pin_conf.input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
}
system_pinmux_pin_set_config(pin, &pin_conf);
system_pinmux_pin_set_config(pin, &pin_conf);
}

View File

@ -33,56 +33,56 @@
*/
uint32_t pinmap_merge_sercom(PinName pin1, PinName pin2)
{
int i, j;
uint32_t pin1_sercom[2];
uint32_t pin2_sercom[2];
uint32_t sercom_index[4];
int i, j;
uint32_t pin1_sercom[2];
uint32_t pin2_sercom[2];
uint32_t sercom_index[4];
uint32_t pin_com = NC;
uint32_t pin_alt = NC;
uint32_t count_com = 0;
uint32_t count_alt = 0;
uint32_t pin_com = NC;
uint32_t pin_alt = NC;
uint32_t count_com = 0;
uint32_t count_alt = 0;
/* Adding a condition check just in case we need a different result when swapping arguments */
if (pin1 >= pin2) {
pin1_sercom[0] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PAD);
pin1_sercom[1] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PADEx);
} else {
pin1_sercom[0] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PADEx);
pin1_sercom[1] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PAD);
}
/* Adding a condition check just in case we need a different result when swapping arguments */
if (pin1 >= pin2) {
pin1_sercom[0] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PAD);
pin1_sercom[1] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PADEx);
} else {
pin1_sercom[0] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PADEx);
pin1_sercom[1] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PAD);
}
pin2_sercom[0] = pinmap_find_peripheral(pin2, PinMap_SERCOM_PAD);
pin2_sercom[1] = pinmap_find_peripheral(pin2, PinMap_SERCOM_PADEx);
pin2_sercom[0] = pinmap_find_peripheral(pin2, PinMap_SERCOM_PAD);
pin2_sercom[1] = pinmap_find_peripheral(pin2, PinMap_SERCOM_PADEx);
for (i=0; i<2; i++) {
if (pin1_sercom[i] != NC) {
pin1_sercom[i] &= 0x0F;
}
for (j=0; j<2; j++) {
if (pin2_sercom[i] != NC) {
pin2_sercom[i] &= 0x0F;
}
sercom_index[(i*2) + j] = pinmap_merge(pin1_sercom[i], pin2_sercom[j]);
}
}
for (i=0; i<2; i++) {
if (pin1_sercom[i] != NC) {
pin1_sercom[i] &= 0x0F;
}
for (j=0; j<2; j++) {
if (pin2_sercom[i] != NC) {
pin2_sercom[i] &= 0x0F;
}
sercom_index[(i*2) + j] = pinmap_merge(pin1_sercom[i], pin2_sercom[j]);
}
}
for (i=0; i<4; i++) {
if (sercom_index[i] != NC) {
if (pin_com == NC) {
pin_com = sercom_index[i];
count_com++;
} else if (pin_com == sercom_index[i]) {
count_com++;
} else if (pin_alt == NC) {
pin_alt = sercom_index[i];
count_alt++;
} else if (pin_alt == sercom_index[i]) {
count_alt++;
} else {}
}
}
return ((count_com >= count_alt) ? pin_com : pin_alt);
for (i=0; i<4; i++) {
if (sercom_index[i] != NC) {
if (pin_com == NC) {
pin_com = sercom_index[i];
count_com++;
} else if (pin_com == sercom_index[i]) {
count_com++;
} else if (pin_alt == NC) {
pin_alt = sercom_index[i];
count_alt++;
} else if (pin_alt == sercom_index[i]) {
count_alt++;
} else {}
}
}
return ((count_com >= count_alt) ? pin_com : pin_alt);
}
/** Find the common SERCOM shared by four pins
@ -97,35 +97,35 @@ uint32_t pinmap_merge_sercom(PinName pin1, PinName pin2)
*/
uint32_t pinmap_find_sercom(PinName pin1, PinName pin2, PinName pin3, PinName pin4)
{
int i;
uint32_t sercom_index[4];
uint32_t pin_com = NC;
uint32_t pin_alt = NC;
uint32_t count_com = 0;
uint32_t count_alt = 0;
sercom_index[0] = pinmap_merge_sercom(pin1, pin2);
sercom_index[1] = pinmap_merge_sercom(pin3, pin3);
sercom_index[2] = pinmap_merge_sercom(pin1, pin3);
sercom_index[3] = pinmap_merge_sercom(pin2, pin4);
int i;
uint32_t sercom_index[4];
uint32_t pin_com = NC;
uint32_t pin_alt = NC;
uint32_t count_com = 0;
uint32_t count_alt = 0;
sercom_index[0] = pinmap_merge_sercom(pin1, pin2);
sercom_index[1] = pinmap_merge_sercom(pin3, pin3);
sercom_index[2] = pinmap_merge_sercom(pin1, pin3);
sercom_index[3] = pinmap_merge_sercom(pin2, pin4);
for (i=0; i<4; i++) {
if (sercom_index[i] != NC) {
if (pin_com == NC) {
pin_com = sercom_index[i];
count_com++;
} else if (pin_com == sercom_index[i]) {
count_com++;
} else if (pin_alt == NC) {
pin_alt = sercom_index[i];
count_alt++;
} else if (pin_alt == sercom_index[i]) {
count_alt++;
} else {}
}
}
return ((count_com >= count_alt) ? pin_com : pin_alt);
for (i=0; i<4; i++) {
if (sercom_index[i] != NC) {
if (pin_com == NC) {
pin_com = sercom_index[i];
count_com++;
} else if (pin_com == sercom_index[i]) {
count_com++;
} else if (pin_alt == NC) {
pin_alt = sercom_index[i];
count_alt++;
} else if (pin_alt == sercom_index[i]) {
count_alt++;
} else {}
}
}
return ((count_com >= count_alt) ? pin_com : pin_alt);
}
/** Find the MUX function of input pin specific to given SERCOM index
@ -136,24 +136,24 @@ uint32_t pinmap_find_sercom(PinName pin1, PinName pin2, PinName pin3, PinName pi
*/
uint32_t pinmap_function_sercom(PinName pin, uint32_t sercom_index)
{
uint32_t func = NC;
uint32_t index;
sercom_index &= 0x0F;
if ((pin == NC) || (sercom_index >= SERCOM_INST_NUM)) {
return NC;
}
index = pinmap_peripheral(pin, PinMap_SERCOM_PAD);
if ((index & 0x0F) == sercom_index) {
func = pinmap_function(pin, PinMap_SERCOM_PAD);
return func;
}
index = pinmap_peripheral(pin, PinMap_SERCOM_PADEx);
if ((index & 0x0F) == sercom_index) {
func = pinmap_function(pin, PinMap_SERCOM_PADEx);
return func;
}
return NC;
uint32_t func = NC;
uint32_t index;
sercom_index &= 0x0F;
if ((pin == NC) || (sercom_index >= SERCOM_INST_NUM)) {
return NC;
}
index = pinmap_peripheral(pin, PinMap_SERCOM_PAD);
if ((index & 0x0F) == sercom_index) {
func = pinmap_function(pin, PinMap_SERCOM_PAD);
return func;
}
index = pinmap_peripheral(pin, PinMap_SERCOM_PADEx);
if ((index & 0x0F) == sercom_index) {
func = pinmap_function(pin, PinMap_SERCOM_PADEx);
return func;
}
return NC;
}
/** Find the MUX pad of input pin specific to given SERCOM index
@ -164,22 +164,22 @@ uint32_t pinmap_function_sercom(PinName pin, uint32_t sercom_index)
*/
uint32_t pinmap_pad_sercom(PinName pin, uint32_t sercom_index)
{
uint32_t func = NC;
uint32_t index;
sercom_index &= 0x0F;
if ((pin == NC) || (sercom_index >= SERCOM_INST_NUM)) {
return NC;
}
index = pinmap_peripheral(pin, PinMap_SERCOM_PAD);
if ((index & 0x0F) == sercom_index) {
return ((index >> 4) & 0x0F);
}
index = pinmap_peripheral(pin, PinMap_SERCOM_PADEx);
if ((index & 0x0F) == sercom_index) {
return ((index >> 4) & 0x0F);
}
return NC;
uint32_t func = NC;
uint32_t index;
sercom_index &= 0x0F;
if ((pin == NC) || (sercom_index >= SERCOM_INST_NUM)) {
return NC;
}
index = pinmap_peripheral(pin, PinMap_SERCOM_PAD);
if ((index & 0x0F) == sercom_index) {
return ((index >> 4) & 0x0F);
}
index = pinmap_peripheral(pin, PinMap_SERCOM_PADEx);
if ((index & 0x0F) == sercom_index) {
return ((index >> 4) & 0x0F);
}
return NC;
}
/** Find the MUX function of input pin specific to given SERCOM index
@ -190,18 +190,18 @@ uint32_t pinmap_pad_sercom(PinName pin, uint32_t sercom_index)
*/
uint32_t pinmap_peripheral_sercom(PinName pin, uint32_t sercom_index)
{
uint32_t sercom_address[6] = {
0x42000800UL, // Base address of SERCOM0
0x42000C00UL, // Base address of SERCOM1
0x42001000UL, // Base address of SERCOM2
0x42001400UL, // Base address of SERCOM3
0x42001800UL, // Base address of SERCOM4
0x42001C00UL // Base address of SERCOM5
};
uint32_t index = sercom_index & 0x0F;
if (index >= SERCOM_INST_NUM) {
return NC;
}
return sercom_address[(sercom_index&0x0F)];
uint32_t sercom_address[6] = {
0x42000800UL, // Base address of SERCOM0
0x42000C00UL, // Base address of SERCOM1
0x42001000UL, // Base address of SERCOM2
0x42001400UL, // Base address of SERCOM3
0x42001800UL, // Base address of SERCOM4
0x42001C00UL // Base address of SERCOM5
};
uint32_t index = sercom_index & 0x0F;
if (index >= SERCOM_INST_NUM) {
return NC;
}
return sercom_address[(sercom_index&0x0F)];
}