]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_FreedomStudio/freedom-metal/metal/switch.h
Update RISCC-V-RV32-SiFive_HiFive1_FreedomStudio project to latest tools and metal...
[freertos] / FreeRTOS / Demo / RISC-V_RV32_SiFive_HiFive1_FreedomStudio / freedom-metal / metal / switch.h
1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
3
4 #ifndef METAL__SWITCH_H
5 #define METAL__SWITCH_H
6
7 /*!
8  * @file switch.h
9  * @brief API for reading toggle switches
10  */
11
12 #include <metal/interrupt.h>
13
14 struct metal_switch;
15
16 struct metal_switch_vtable {
17     int (*switch_exist)(struct metal_switch *sw, char *label);
18     struct metal_interrupt* (*interrupt_controller)(struct metal_switch *sw);
19     int (*get_interrupt_id)(struct metal_switch *sw);
20 };
21
22 /*!
23  * @brief A handle for a switch
24  */
25 struct metal_switch {
26     const struct metal_switch_vtable *vtable;
27 };
28
29 /*!
30  * @brief Get a handle for a switch
31  * @param label The DeviceTree label for the desired switch
32  * @return A handle to the switch, or NULL if none is found for the requested label
33  */
34 struct metal_switch* metal_switch_get(char *label);
35
36 /*!
37  * @brief Get the interrupt controller for a switch
38  * @param sw The handle for the switch
39  * @return The interrupt controller handle
40  */
41 __inline__ struct metal_interrupt*
42     metal_switch_interrupt_controller(struct metal_switch *sw) { return sw->vtable->interrupt_controller(sw); }
43
44 /*!
45  * @brief Get the interrupt id for a switch
46  * @param sw The handle for the switch
47  * @return The interrupt ID for the switch
48  */
49 __inline__ int metal_switch_get_interrupt_id(struct metal_switch *sw) { return sw->vtable->get_interrupt_id(sw); }
50
51 #endif