switch.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Copyright 2018 SiFive, Inc */
  2. /* SPDX-License-Identifier: Apache-2.0 */
  3. #ifndef METAL__SWITCH_H
  4. #define METAL__SWITCH_H
  5. /*!
  6. * @file switch.h
  7. * @brief API for reading toggle switches
  8. */
  9. #include <metal/interrupt.h>
  10. struct metal_switch;
  11. struct metal_switch_vtable {
  12. int (*switch_exist)(struct metal_switch *sw, char *label);
  13. struct metal_interrupt* (*interrupt_controller)(struct metal_switch *sw);
  14. int (*get_interrupt_id)(struct metal_switch *sw);
  15. };
  16. /*!
  17. * @brief A handle for a switch
  18. */
  19. struct metal_switch {
  20. const struct metal_switch_vtable *vtable;
  21. };
  22. /*!
  23. * @brief Get a handle for a switch
  24. * @param label The DeviceTree label for the desired switch
  25. * @return A handle to the switch, or NULL if none is found for the requested label
  26. */
  27. struct metal_switch* metal_switch_get(char *label);
  28. /*!
  29. * @brief Get the interrupt controller for a switch
  30. * @param sw The handle for the switch
  31. * @return The interrupt controller handle
  32. */
  33. __inline__ struct metal_interrupt*
  34. metal_switch_interrupt_controller(struct metal_switch *sw) { return sw->vtable->interrupt_controller(sw); }
  35. /*!
  36. * @brief Get the interrupt id for a switch
  37. * @param sw The handle for the switch
  38. * @return The interrupt ID for the switch
  39. */
  40. __inline__ int metal_switch_get_interrupt_id(struct metal_switch *sw) { return sw->vtable->get_interrupt_id(sw); }
  41. #endif