支持GPIO中断(外部中断)
This commit is contained in:
parent
d1bb7c61f4
commit
358612c8a2
|
@ -204,4 +204,63 @@ unsigned int gpio_get(unsigned int gpio)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置中断类型
|
||||
* @gpio gpio引脚
|
||||
* @type 触发中断的条件。高电平触发、低电平触发、上升沿触发 or 下降沿触发
|
||||
*/
|
||||
void gpio_set_irq_type(unsigned int gpio, gpio_irq_type_t type)
|
||||
{
|
||||
volatile unsigned int *int_pol; // 中断极性选择寄存器
|
||||
volatile unsigned int *int_edge; // 中断边沿选择寄存器
|
||||
unsigned int port = GPIO_GET_PORT(gpio);
|
||||
unsigned int pin = GPIO_GET_PIN(gpio);
|
||||
|
||||
// 获取寄存器地址
|
||||
switch (port)
|
||||
{
|
||||
case 0: // GPIO[31:0]
|
||||
int_pol = (volatile unsigned int *)LS1C_INT2_POL;
|
||||
int_edge = (volatile unsigned int *)LS1C_INT2_EDGE;
|
||||
break;
|
||||
|
||||
case 1: // GPIO[63:32]
|
||||
int_pol = (volatile unsigned int *)LS1C_INT3_POL;
|
||||
int_edge = (volatile unsigned int *)LS1C_INT3_EDGE;
|
||||
break;
|
||||
|
||||
case 2: // GPIO[95:64]
|
||||
int_pol = (volatile unsigned int *)LS1C_INT4_POL;
|
||||
int_edge = (volatile unsigned int *)LS1C_INT4_EDGE;
|
||||
break;
|
||||
}
|
||||
|
||||
// 设置中断类型
|
||||
switch (type)
|
||||
{
|
||||
case IRQ_TYPE_EDGE_RISING:
|
||||
*int_pol |= (1 << pin);
|
||||
*int_edge |= (1 << pin);
|
||||
break;
|
||||
|
||||
case IRQ_TYPE_EDGE_FALLING:
|
||||
*int_pol &= ~(1 << pin);
|
||||
*int_edge |= (1 << pin);
|
||||
break;
|
||||
|
||||
case IRQ_TYPE_LEVEL_HIGH:
|
||||
*int_pol |= (1 << pin);
|
||||
*int_edge &= ~(1 << pin);
|
||||
break;
|
||||
|
||||
case IRQ_TYPE_LEVEL_LOW:
|
||||
*int_pol &= ~(1 << pin);
|
||||
*int_edge &= ~(1 << pin);
|
||||
break;
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,19 @@ typedef enum{
|
|||
}gpio_level_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
// 上升沿触发
|
||||
IRQ_TYPE_EDGE_RISING = 0x00000001,
|
||||
// 下降沿触发
|
||||
IRQ_TYPE_EDGE_FALLING = 0x00000002,
|
||||
IRQ_TYPE_EDGE_BOTH = (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING),
|
||||
// 高电平触发
|
||||
IRQ_TYPE_LEVEL_HIGH = 0x00000004,
|
||||
// 低电平触发
|
||||
IRQ_TYPE_LEVEL_LOW = 0x00000008,
|
||||
IRQ_TYPE_LEVEL_MASK = (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH),
|
||||
}gpio_irq_type_t;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
@ -73,6 +86,13 @@ unsigned int gpio_get(unsigned int gpio);
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* 设置中断类型
|
||||
* @gpio gpio引脚
|
||||
* @type 触发中断的条件。高电平触发、低电平触发、上升沿触发 or 下降沿触发
|
||||
*/
|
||||
void gpio_set_irq_type(unsigned int gpio, gpio_irq_type_t type);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -74,13 +74,41 @@
|
|||
|
||||
|
||||
|
||||
// ÖжÏÅäÖüĴæÆ÷
|
||||
#define LS1C_INT0_SR (0xbfd01040)
|
||||
#define LS1C_INT0_EN (0xbfd01044)
|
||||
#define LS1C_INT0_SET (0xbfd01048)
|
||||
#define LS1C_INT0_CLR (0xbfd0104c)
|
||||
#define LS1C_INT0_POL (0xbfd01050)
|
||||
#define LS1C_INT0_EDGE (0xbfd01054)
|
||||
|
||||
#define LS1c_INT1_SR (0xbfd01058)
|
||||
#define LS1C_INT1_EN (0xbfd0105c)
|
||||
#define LS1C_INT1_SET (0xbfd01060)
|
||||
#define LS1C_INT1_CLR (0xbfd01064)
|
||||
#define LS1C_INT1_POL (0xbfd01068)
|
||||
#define LS1C_INT1_EDGE (0xbfd0106c)
|
||||
|
||||
#define LS1C_INT2_SR (0xbfd01070)
|
||||
#define LS1C_INT2_EN (0xbfd01074)
|
||||
#define LS1C_INT2_SET (0xbfd01078)
|
||||
#define LS1C_INT2_CLR (0xbfd0107c)
|
||||
#define LS1C_INT2_POL (0xbfd01080)
|
||||
#define LS1C_INT2_EDGE (0xbfd01084)
|
||||
|
||||
#define LS1C_INT3_SR (0xbfd01088)
|
||||
#define LS1C_INT3_EN (0xbfd0108c)
|
||||
#define LS1C_INT3_SET (0xbfd01090)
|
||||
#define LS1C_INT3_CLR (0xbfd01094)
|
||||
#define LS1C_INT3_POL (0xbfd01098)
|
||||
#define LS1C_INT3_EDGE (0xbfd0109c)
|
||||
|
||||
|
||||
|
||||
|
||||
#define LS1C_INT4_SR (0xbfd010a0)
|
||||
#define LS1C_INT4_EN (0xbfd010a4)
|
||||
#define LS1C_INT4_SET (0xbfd010a8)
|
||||
#define LS1C_INT4_CLR (0xbfd010ac)
|
||||
#define LS1C_INT4_POL (0xbfd010b0)
|
||||
#define LS1C_INT4_EDGE (0xbfd010b4)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -77,6 +77,11 @@
|
|||
#define LS1C_NR_IRQS (32*5)
|
||||
|
||||
|
||||
// GPIO编号和中断号之间的互相转换
|
||||
#define LS1C_GPIO_TO_IRQ(GPIOn) (LS1C_GPIO_FIRST_IRQ + (GPIOn))
|
||||
#define LS1C_IRQ_TO_GPIO(IRQn) ((IRQn) - LS1C_GPIO_FIRST_IRQ)
|
||||
|
||||
|
||||
struct ls1c_intc_regs
|
||||
{
|
||||
volatile unsigned int int_isr;
|
||||
|
|
Loading…
Reference in New Issue