46#include "isr_compat.h"
56#define RELEASE_POLL_INTERVAL (CLOCK_SECOND / 16)
59static volatile uint8_t release_poll_mask[5];
61PROCESS(gpio_hal_release_poll_process,
"GPIO HAL release poll");
73 uint8_t m = (uint8_t)1 << pin;
74 uint8_t nm = (uint8_t)~m;
75 uint8_t pull = cfg & GPIO_HAL_PIN_CFG_PULL_MASK;
76 uint8_t edge = cfg & GPIO_HAL_PIN_CFG_EDGE_BOTH;
77 uint8_t int_en = (cfg & GPIO_HAL_PIN_CFG_INT_MASK) ==
78 GPIO_HAL_PIN_CFG_INT_ENABLE;
83 if(pull == GPIO_HAL_PIN_CFG_PULL_NONE) {
87 if(pull == GPIO_HAL_PIN_CFG_PULL_UP) { P1OUT |= m; }
93 if(edge == GPIO_HAL_PIN_CFG_EDGE_RISING) { P1IES &= nm; }
96 if(int_en) { P1IE |= m; }
else { P1IE &= nm; }
99 if(pull == GPIO_HAL_PIN_CFG_PULL_NONE) {
103 if(pull == GPIO_HAL_PIN_CFG_PULL_UP) { P2OUT |= m; }
104 else { P2OUT &= nm; }
106 if(edge == GPIO_HAL_PIN_CFG_EDGE_RISING) { P2IES &= nm; }
109 if(int_en) { P2IE |= m; }
else { P2IE &= nm; }
112 if(pull == GPIO_HAL_PIN_CFG_PULL_NONE) {
116 if(pull == GPIO_HAL_PIN_CFG_PULL_UP) { P3OUT |= m; }
117 else { P3OUT &= nm; }
119 if(edge == GPIO_HAL_PIN_CFG_EDGE_RISING) { P3IES &= nm; }
122 if(int_en) { P3IE |= m; }
else { P3IE &= nm; }
125 if(pull == GPIO_HAL_PIN_CFG_PULL_NONE) {
129 if(pull == GPIO_HAL_PIN_CFG_PULL_UP) { P4OUT |= m; }
130 else { P4OUT &= nm; }
132 if(edge == GPIO_HAL_PIN_CFG_EDGE_RISING) { P4IES &= nm; }
135 if(int_en) { P4IE |= m; }
else { P4IE &= nm; }
143 uint8_t m = (uint8_t)1 << pin;
144 uint8_t ren = 0, out = 0, ies = 0, ie = 0;
148 case 1: ren = P1REN; out = P1OUT; ies = P1IES; ie = P1IE;
break;
149 case 2: ren = P2REN; out = P2OUT; ies = P2IES; ie = P2IE;
break;
150 case 3: ren = P3REN; out = P3OUT; ies = P3IES; ie = P3IE;
break;
151 case 4: ren = P4REN; out = P4OUT; ies = P4IES; ie = P4IE;
break;
156 cfg |= (out & m) ? GPIO_HAL_PIN_CFG_PULL_UP : GPIO_HAL_PIN_CFG_PULL_DOWN;
158 cfg |= GPIO_HAL_PIN_CFG_PULL_NONE;
160 cfg |= (ies & m) ? GPIO_HAL_PIN_CFG_EDGE_FALLING : GPIO_HAL_PIN_CFG_EDGE_RISING;
161 cfg |= (ie & m) ? GPIO_HAL_PIN_CFG_INT_ENABLE : GPIO_HAL_PIN_CFG_INT_DISABLE;
168 uint8_t m = (uint8_t)1 << pin;
170 case 1: P1IFG &= (uint8_t)~m; P1IE |= m;
break;
171 case 2: P2IFG &= (uint8_t)~m; P2IE |= m;
break;
172 case 3: P3IFG &= (uint8_t)~m; P3IE |= m;
break;
173 case 4: P4IFG &= (uint8_t)~m; P4IE |= m;
break;
180 uint8_t nm = (uint8_t)~((uint8_t)1 << pin);
182 case 1: P1IE &= nm;
break;
183 case 2: P2IE &= nm;
break;
184 case 3: P3IE &= nm;
break;
185 case 4: P4IE &= nm;
break;
194piv_to_mask(uint16_t iv)
197 if(iv < 0x02 || iv > 0x10) {
217rearm_press(uint8_t port, uint8_t mask)
220 case 1: P1IFG &= (uint8_t)~mask; P1IE |= mask;
break;
221 case 2: P2IFG &= (uint8_t)~mask; P2IE |= mask;
break;
222 case 3: P3IFG &= (uint8_t)~mask; P3IE |= mask;
break;
223 case 4: P4IFG &= (uint8_t)~mask; P4IE |= mask;
break;
230start_release_poll(uint8_t port, uint8_t mask)
233 case 1: P1IE &= (uint8_t)~mask;
break;
234 case 2: P2IE &= (uint8_t)~mask;
break;
235 case 3: P3IE &= (uint8_t)~mask;
break;
236 case 4: P4IE &= (uint8_t)~mask;
break;
238 release_poll_mask[port] |= mask;
245 uint8_t port, released, active;
253 for(port = 1; port <= 4; port++) {
254 if(release_poll_mask[port] == 0) {
258 released = (uint8_t)(release_poll_mask[port] & port_in(port));
261 release_poll_mask[port] &= (uint8_t)~released;
263 rearm_press(port, released);
264 gpio_hal_event_handler(port, released);
266 if(release_poll_mask[port]) {
282 while((iv = P1IV) != 0) {
283 pins |= piv_to_mask(iv);
286 start_release_poll(1, (uint8_t)pins);
287 gpio_hal_event_handler(1, pins);
298 while((iv = P2IV) != 0) {
299 pins |= piv_to_mask(iv);
302 start_release_poll(2, (uint8_t)pins);
303 gpio_hal_event_handler(2, pins);
312 while((iv = P3IV) != 0) {
313 pins |= piv_to_mask(iv);
316 start_release_poll(3, (uint8_t)pins);
317 gpio_hal_event_handler(3, pins);
326 while((iv = P4IV) != 0) {
327 pins |= piv_to_mask(iv);
330 start_release_poll(4, (uint8_t)pins);
331 gpio_hal_event_handler(4, pins);
Header file for the GPIO HAL.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
void gpio_hal_arch_port_interrupt_enable(gpio_hal_port_t port, gpio_hal_pin_t pin)
Enable interrupts for a gpio pin.
gpio_hal_pin_cfg_t gpio_hal_arch_port_pin_cfg_get(gpio_hal_port_t port, gpio_hal_pin_t pin)
Read the configuration of a GPIO pin.
void gpio_hal_arch_port_interrupt_disable(gpio_hal_port_t port, gpio_hal_pin_t pin)
Disable interrupts for a gpio pin.
void gpio_hal_arch_init(void)
Perform architecture specific gpio initaliaztion.
void gpio_hal_arch_port_pin_cfg_set(gpio_hal_port_t port, gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
Configure a gpio pin.
uint32_t gpio_hal_pin_mask_t
GPIO pin mask representation.
uint32_t gpio_hal_pin_cfg_t
GPIO pin configuration.
uint8_t gpio_hal_port_t
A data structure that represents ports.
uint8_t gpio_hal_pin_t
GPIO pin number representation.
#define PROCESS(name, strname)
Declare a process.
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_END()
Define the end of a process.
void process_start(struct process *p, process_data_t data)
Start a process.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
void process_poll(struct process *p)
Request a process to be polled.
Header file for the Contiki process interface.