1 | #include "xgpio.h" |
---|
2 | |
---|
3 | #include "wlan_common_types.h" |
---|
4 | #include "wlan_mac_high.h" |
---|
5 | #include "w3_high_userio.h" |
---|
6 | #include "w3_high.h" |
---|
7 | #include "xparameters.h" |
---|
8 | #include "wlan_platform_common.h" |
---|
9 | #include "wlan_platform_high.h" |
---|
10 | #include "wlan_mac_common.h" |
---|
11 | |
---|
12 | static XGpio Gpio_userio; ///< GPIO driver instance for user IO inputs |
---|
13 | static u32 gl_userio_state; |
---|
14 | |
---|
15 | // Private functions |
---|
16 | void _w3_high_userio_gpio_handler(void *InstancePtr); |
---|
17 | |
---|
18 | int w3_high_userio_init(){ |
---|
19 | int return_value; |
---|
20 | |
---|
21 | gl_userio_state = 0; |
---|
22 | |
---|
23 | // Initialize the GPIO driver instances |
---|
24 | return_value = XGpio_Initialize(&Gpio_userio, PLATFORM_DEV_ID_USRIO_GPIO); |
---|
25 | |
---|
26 | if (return_value != XST_SUCCESS) { |
---|
27 | wlan_printf(PL_ERROR, "ERROR: Could not initialize GPIO\n"); |
---|
28 | return WLAN_FAILURE; |
---|
29 | } |
---|
30 | |
---|
31 | // Set direction of GPIO channels |
---|
32 | // User IO GPIO instance has 1 channel, all inputs |
---|
33 | XGpio_SetDataDirection(&Gpio_userio, GPIO_USERIO_INPUT_CHANNEL, 0xFFFFFFFF); |
---|
34 | |
---|
35 | return return_value; |
---|
36 | } |
---|
37 | int w3_high_userio_setup_interrupt() { |
---|
38 | int return_value; |
---|
39 | // GPIO for User IO inputs |
---|
40 | return_value = wlan_platform_interrupt_connect(PLATFORM_INT_ID_USRIO_GPIO, (wlan_intr_handler_t)_w3_high_userio_gpio_handler, &Gpio_userio); |
---|
41 | if (return_value != XST_SUCCESS) { |
---|
42 | wlan_printf(PL_ERROR, "Failed to set up GPIO interrupt\n"); |
---|
43 | return WLAN_FAILURE; |
---|
44 | } |
---|
45 | |
---|
46 | //Update the initial state of the global tracking variable |
---|
47 | gl_userio_state = wlan_platform_userio_get_state(); |
---|
48 | |
---|
49 | wlan_platform_interrupt_enable(PLATFORM_INT_ID_USRIO_GPIO); |
---|
50 | XGpio_InterruptEnable(&Gpio_userio, GPIO_USERIO_INPUT_IR_CH_MASK); |
---|
51 | XGpio_InterruptGlobalEnable(&Gpio_userio); |
---|
52 | return return_value; |
---|
53 | } |
---|
54 | |
---|
55 | void _w3_high_userio_gpio_handler(void *InstancePtr){ |
---|
56 | XGpio *GpioPtr; |
---|
57 | u32 curr_userio_state, userio_state_xor; |
---|
58 | |
---|
59 | GpioPtr = (XGpio*)InstancePtr; |
---|
60 | |
---|
61 | XGpio_InterruptDisable(GpioPtr, GPIO_USERIO_INPUT_IR_CH_MASK); |
---|
62 | |
---|
63 | curr_userio_state = wlan_platform_userio_get_state(); |
---|
64 | |
---|
65 | userio_state_xor = curr_userio_state ^ gl_userio_state; |
---|
66 | |
---|
67 | if(userio_state_xor & USERIO_INPUT_MASK_PB_0) wlan_mac_high_userio_inputs_callback(curr_userio_state & USERIO_INPUT_MASK_PB_0, USERIO_INPUT_MASK_PB_0); |
---|
68 | if(userio_state_xor & USERIO_INPUT_MASK_PB_1) wlan_mac_high_userio_inputs_callback(curr_userio_state & USERIO_INPUT_MASK_PB_1, USERIO_INPUT_MASK_PB_1); |
---|
69 | if(userio_state_xor & USERIO_INPUT_MASK_PB_2) wlan_mac_high_userio_inputs_callback(curr_userio_state & USERIO_INPUT_MASK_PB_2, USERIO_INPUT_MASK_PB_2); |
---|
70 | if(userio_state_xor & USERIO_INPUT_MASK_PB_3) wlan_mac_high_userio_inputs_callback(curr_userio_state & USERIO_INPUT_MASK_PB_3, USERIO_INPUT_MASK_PB_3); |
---|
71 | if(userio_state_xor & USERIO_INPUT_MASK_SW_0) wlan_mac_high_userio_inputs_callback(curr_userio_state & USERIO_INPUT_MASK_SW_0, USERIO_INPUT_MASK_SW_0); |
---|
72 | if(userio_state_xor & USERIO_INPUT_MASK_SW_1) wlan_mac_high_userio_inputs_callback(curr_userio_state & USERIO_INPUT_MASK_SW_1, USERIO_INPUT_MASK_SW_1); |
---|
73 | if(userio_state_xor & USERIO_INPUT_MASK_SW_2) wlan_mac_high_userio_inputs_callback(curr_userio_state & USERIO_INPUT_MASK_SW_2, USERIO_INPUT_MASK_SW_2); |
---|
74 | if(userio_state_xor & USERIO_INPUT_MASK_SW_3) wlan_mac_high_userio_inputs_callback(curr_userio_state & USERIO_INPUT_MASK_SW_3, USERIO_INPUT_MASK_SW_3); |
---|
75 | |
---|
76 | gl_userio_state = curr_userio_state; |
---|
77 | |
---|
78 | |
---|
79 | (void)XGpio_InterruptClear(GpioPtr, GPIO_USERIO_INPUT_IR_CH_MASK); |
---|
80 | XGpio_InterruptEnable(GpioPtr, GPIO_USERIO_INPUT_IR_CH_MASK); |
---|
81 | return; |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | |
---|