]> git.sur5r.net Git - freertos/blob
923fe27116c543c86f1161b334f19e9f91dc8545
[freertos] /
1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
3
4 #include <metal/machine/platform.h>
5
6 #ifdef METAL_SIFIVE_GPIO_BUTTONS
7
8 #include <string.h>
9 #include <metal/drivers/riscv_cpu.h>
10 #include <metal/drivers/sifive_gpio-buttons.h>
11 #include <metal/machine.h>
12
13 int  __metal_driver_button_exist (struct metal_button *button, char *label)
14 {
15     if (strcmp(__metal_driver_sifive_gpio_button_label(button), label) == 0) {
16         return 1;
17     }
18     return 0;
19 }
20
21 struct metal_interrupt *
22 __metal_driver_button_interrupt_controller(struct metal_button *button)
23 {
24     return __metal_driver_sifive_gpio_button_interrupt_controller(button);
25 }
26
27 int __metal_driver_button_get_interrupt_id(struct metal_button *button)
28 {
29     int irq, max_irq;
30     struct metal_interrupt *irc;
31
32     irq = __metal_driver_sifive_gpio_button_interrupt_line(button);
33     irc =  __metal_driver_sifive_gpio_button_interrupt_controller(button);
34
35     if (irc != NULL) {
36         max_irq = _metal_interrupt_command_request(irc,
37                                                    METAL_MAX_INTERRUPT_GET,
38                                                    NULL);
39
40         if (irq < max_irq) {
41             return _metal_interrupt_command_request(irc,
42                                                  METAL_INDEX_INTERRUPT_GET,
43                                                  (void *)&irq);
44         }
45     }
46     return METAL_INTERRUPT_ID_LCMX;
47 }
48
49 __METAL_DEFINE_VTABLE(__metal_driver_vtable_sifive_button) = {
50     .button_vtable.button_exist   = __metal_driver_button_exist,
51     .button_vtable.interrupt_controller = __metal_driver_button_interrupt_controller,
52     .button_vtable.get_interrupt_id = __metal_driver_button_get_interrupt_id,
53 };
54
55 #endif
56
57 typedef int no_empty_translation_units;