]> git.sur5r.net Git - freertos/blob
59f6fbe483fb6009fef478488a1de37ee2f1a054
[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_GLOBAL_EXTERNAL_INTERRUPTS0
7
8 #include <metal/io.h>
9 #include <metal/shutdown.h>
10 #include <metal/drivers/sifive_global-external-interrupts0.h>
11 #include <metal/machine.h>
12
13 void __metal_driver_sifive_global_external_interrupt_init(struct metal_interrupt *controller)
14 {
15     struct __metal_driver_sifive_global_external_interrupts0 *global0;
16
17     global0 = (struct __metal_driver_sifive_global_external_interrupts0 *)(controller);
18     if ( !global0->init_done ) {
19         struct metal_interrupt *intc =
20             __metal_driver_sifive_global_external_interrupts0_interrupt_parent(controller);
21
22         if (intc) {
23             intc->vtable->interrupt_init(intc);
24             /* Register its interrupts with with parent controller */
25             for (int i = 0;
26                  i < __metal_driver_sifive_global_external_interrupts0_num_interrupts(controller);
27                  i++) {
28                 intc->vtable->interrupt_register(intc,
29                     __metal_driver_sifive_global_external_interrupts0_interrupt_lines(controller, i),
30                                                  NULL, controller);
31             }
32             global0->init_done = 1;
33         }
34     }
35 }
36
37 int __metal_driver_sifive_global_external_interrupt_register(struct metal_interrupt *controller,
38                                                            int id, metal_interrupt_handler_t isr,
39                                                            void *priv)
40 {
41     int rc = -1;
42
43     if (id != 0) {
44         struct metal_interrupt *intc =
45             __metal_driver_sifive_global_external_interrupts0_interrupt_parent(controller);
46
47         /* Enable its interrupts with parent controller */
48         if (intc) {
49             rc = intc->vtable->interrupt_register(intc, id, isr, priv);
50         }
51     }
52     return rc;
53 }
54
55 int __metal_driver_sifive_global_external_interrupt_enable(struct metal_interrupt *controller, int id)
56 {
57     int rc = -1;
58
59     if (id != 0) {
60         struct metal_interrupt *intc =
61             __metal_driver_sifive_global_external_interrupts0_interrupt_parent(controller);
62
63         /* Enable its interrupts with parent controller */
64         if (intc) {
65             rc = intc->vtable->interrupt_enable(intc, id);
66         }
67     }
68     return rc;
69 }
70
71 int __metal_driver_sifive_global_external_interrupt_disable(struct metal_interrupt *controller, int id)
72 {
73     int rc = -1;
74
75     if (id != 0) {
76         struct metal_interrupt *intc =
77             __metal_driver_sifive_global_external_interrupts0_interrupt_parent(controller);
78
79         /* Enable its interrupts with parent controller */
80         if (intc) {
81             rc = intc->vtable->interrupt_disable(intc, id);
82         }
83     }
84     return rc;
85 }
86
87 int __metal_driver_sifive_global_external_command_request (struct metal_interrupt *controller,
88                                                          int command, void *data)
89 {
90     int idx;
91     int rc = -1;
92
93     switch (command) {
94     case METAL_MAX_INTERRUPT_GET:
95         rc = __metal_driver_sifive_global_external_interrupts0_num_interrupts(controller);
96         break;
97     case METAL_INDEX_INTERRUPT_GET:
98         rc = 0;
99         if (data) {
100             idx = *(int *)data;
101             rc = __metal_driver_sifive_global_external_interrupts0_interrupt_lines(controller, idx);
102         }
103         break;
104     default:
105         break;
106     }
107
108     return rc;
109 }
110
111 __METAL_DEFINE_VTABLE(__metal_driver_vtable_sifive_global_external_interrupts0) = {
112     .global0_vtable.interrupt_init     = __metal_driver_sifive_global_external_interrupt_init,
113     .global0_vtable.interrupt_register = __metal_driver_sifive_global_external_interrupt_register,
114     .global0_vtable.interrupt_enable   = __metal_driver_sifive_global_external_interrupt_enable,
115     .global0_vtable.interrupt_disable  = __metal_driver_sifive_global_external_interrupt_disable,
116     .global0_vtable.command_request    = __metal_driver_sifive_global_external_command_request,
117 };
118
119 #endif
120