]> git.sur5r.net Git - freertos/blob
b9302529d79e141aef5d673047e967b4d248459e
[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_SWITCHES
7
8 #include <string.h>
9 #include <metal/drivers/riscv_cpu.h>
10 #include <metal/drivers/sifive_gpio-switches.h>
11 #include <metal/machine.h>
12
13 int  __metal_driver_switch_exist (struct metal_switch *flip, char *label)
14 {
15     if (strcmp(__metal_driver_sifive_gpio_switch_label(flip), label) == 0) {
16         return 1;
17     }
18     return 0;
19 }
20
21 struct metal_interrupt *
22 __metal_driver_switch_interrupt_controller(struct metal_switch *flip)
23 {
24     return __metal_driver_sifive_gpio_switch_interrupt_controller(flip);
25 }
26
27 int __metal_driver_switch_get_interrupt_id(struct metal_switch *flip)
28 {
29     int irq, max_irq;
30     struct metal_interrupt *irc;
31
32     irq = __metal_driver_sifive_gpio_switch_interrupt_line(flip);
33     irc =  __metal_driver_sifive_gpio_switch_interrupt_controller(flip);
34     if (irc != NULL) {
35         max_irq = _metal_interrupt_command_request(irc,
36                                                    METAL_MAX_INTERRUPT_GET,
37                                                    NULL);
38
39         if (irq < max_irq) {
40             return _metal_interrupt_command_request(irc,
41                                                  METAL_INDEX_INTERRUPT_GET,
42                                                  (void *)&irq);
43         }
44     }
45     return METAL_INTERRUPT_ID_LCMX;
46 }
47
48 __METAL_DEFINE_VTABLE(__metal_driver_vtable_sifive_switch) = {
49     .switch_vtable.switch_exist   = __metal_driver_switch_exist,
50     .switch_vtable.interrupt_controller = __metal_driver_switch_interrupt_controller,
51     .switch_vtable.get_interrupt_id = __metal_driver_switch_get_interrupt_id,
52 };
53
54 #endif