Skip to content

Commit c6f7c5d

Browse files
committed
Create a common handler.
1 parent 5a4ce3c commit c6f7c5d

File tree

1 file changed

+18
-53
lines changed

1 file changed

+18
-53
lines changed

libraries/mbed/targets/hal/TARGET_WIZNET/TARGET_W7500x/gpio_irq_api.c

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@
4141

4242
static gpio_irq_handler irq_handler;
4343

44-
45-
//typedef struct {
46-
// uint32_t port[4];
47-
// uint32_t pin[16];
48-
// uint32_t ids;
49-
//} irq_channel;
50-
5144
static uint32_t channel_ids[4][16];
5245

5346
#ifdef __cplusplus
@@ -57,68 +50,40 @@ extern "C"{
5750

5851
void PORT0_Handler(void)
5952
{
60-
int i = 0;
61-
62-
for(i=0; i<16; i++)
63-
{
64-
if(GPIOA->Interrupt.INTSTATUS & (1 << i))
65-
{
66-
GPIOA->Interrupt.INTCLEAR |= (1 << i);
67-
if(GPIOA->INTPOLSET >> i) //rising
68-
irq_handler(channel_ids[0][i], IRQ_RISE);
69-
else //falling
70-
irq_handler(channel_ids[0][i], IRQ_FALL);
71-
}
72-
}
53+
port_generic_handler(GPIOA, 0);
7354
}
7455

7556
void PORT1_Handler(void)
7657
{
77-
int i = 0;
78-
79-
for(i=0; i<16; i++)
80-
{
81-
if(GPIOB->Interrupt.INTSTATUS & (1 << i))
82-
{
83-
GPIOB->Interrupt.INTCLEAR |= (1 << i);
84-
if(GPIOB->INTPOLSET >> i) //rising
85-
irq_handler(channel_ids[0][i], IRQ_RISE);
86-
else //falling
87-
irq_handler(channel_ids[0][i], IRQ_FALL);
88-
}
89-
}
58+
port_generic_handler(GPIOB, 1);
9059
}
9160

9261
void PORT2_Handler(void)
9362
{
94-
int i = 0;
95-
96-
for(i=0; i<16; i++)
97-
{
98-
if(GPIOC->Interrupt.INTSTATUS & (1 << i))
99-
{
100-
GPIOC->Interrupt.INTCLEAR |= (1 << i);
101-
if(GPIOC->INTPOLSET >> i) //rising
102-
irq_handler(channel_ids[0][i], IRQ_RISE);
103-
else //falling
104-
irq_handler(channel_ids[0][i], IRQ_FALL);
105-
}
106-
}
63+
port_generic_handler(GPIOC, 2);
10764
}
10865

10966
void PORT3_Handler(void)
11067
{
111-
int i;
68+
port_generic_handler(GPIOD, 3);
69+
}
70+
71+
void port_generic_handler(GPIO_TypeDef* GPIOx, uint32_t port_num)
72+
{
73+
int i = 0;
74+
int loop = 16;
75+
76+
if(GPIOx == GPIOD) loop = 5;
11277

113-
for(i=0; i<5; i++)
78+
for(i=0; i<loop; i++)
11479
{
115-
if(GPIOD->Interrupt.INTSTATUS & (1 << i))
80+
if(GPIOx->Interrupt.INTSTATUS & (1 << i))
11681
{
117-
GPIOD->Interrupt.INTCLEAR |= (1 << i);
118-
if(GPIOD->INTPOLSET >> i) //rising
119-
irq_handler(channel_ids[0][i], IRQ_RISE);
82+
GPIOx->Interrupt.INTCLEAR |= (1 << i);
83+
if(GPIOx->INTPOLSET >> i) //rising
84+
irq_handler(channel_ids[port_num][i], IRQ_RISE);
12085
else //falling
121-
irq_handler(channel_ids[0][i], IRQ_FALL);
86+
irq_handler(channel_ids[port_num][i], IRQ_FALL);
12287
}
12388
}
12489
}

0 commit comments

Comments
 (0)