2
0

abcio.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef ABCIO_H
  2. #define ABCIO_H
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. #define DEVSEL_NONE 64 /* No device at all selected */
  6. struct abc_dev;
  7. /* Called from an interrupt handler, so hot */
  8. #define ABC_CALLBACK_DECL(func) \
  9. void func(struct abc_dev *dev __unused, \
  10. uint8_t data __unused, \
  11. uint8_t addr __unused)
  12. #define ABC_CALLBACK(func) \
  13. __hot ABC_CALLBACK_DECL(func)
  14. typedef ABC_CALLBACK_DECL((*abc_callback_t));
  15. struct abc_dev {
  16. uint8_t *out_buf;
  17. size_t out_cnt;
  18. const uint8_t *inp_buf;
  19. size_t inp_cnt;
  20. uint16_t callback_mask;
  21. uint16_t event_mask; /* Can be a superset of callback_mask */
  22. uint8_t status_first_out_mask;
  23. uint8_t status_first_inp_mask;
  24. uint8_t out_data[6]; /* [1] is devsel, all 8 bits */
  25. union {
  26. struct {
  27. uint8_t inp_data[2];
  28. uint8_t inp_en;
  29. uint8_t inp_data_def; /* inp_data[0] when no queue active */
  30. };
  31. uint32_t inp_data_w;
  32. };
  33. abc_callback_t callback_out[6];
  34. abc_callback_t callback_inp[2];
  35. abc_callback_t callback_rst;
  36. };
  37. extern struct abc_dev *_abc_selected_dev;
  38. static inline struct abc_dev *abc_selected_dev(void)
  39. {
  40. return _abc_selected_dev;
  41. }
  42. void abc_setup_out_queue(struct abc_dev *dev, void *buf, size_t len,
  43. uint8_t status);
  44. void abc_setup_inp_queue(struct abc_dev *dev, const void *buf, size_t len,
  45. uint8_t status);
  46. void abc_set_inp_default(struct abc_dev *dev, uint8_t val);
  47. void abc_set_inp_status(struct abc_dev *dev, uint8_t val);
  48. /*
  49. * The _ versions can be used from interrupt handlers or when ABC_IRQ
  50. * is known to be masked already; for the _inp_data() functions this ALSO
  51. * requires that dev->inp_cnt is known to be zero (no currently configured
  52. * queue.)
  53. *
  54. * The __ versions can be used when it is *also* known that the device
  55. * in question is already selected (e.g. inside a callback.)
  56. */
  57. static inline void _abc_set_inp_data(struct abc_dev *dev, uint8_t val)
  58. {
  59. dev->inp_data[0] = dev->inp_data_def = val;
  60. if (dev == abc_selected_dev())
  61. ABC_INP0_DATA = val;
  62. }
  63. static inline void _abc_set_inp_status(struct abc_dev *dev, uint8_t val)
  64. {
  65. dev->inp_data[1] = val;
  66. if (dev == abc_selected_dev())
  67. ABC_INP1_DATA = val;
  68. }
  69. static inline void __abc_set_inp_data(struct abc_dev *dev, uint8_t val)
  70. {
  71. ABC_INP0_DATA = dev->inp_data[0] = dev->inp_data_def = val;
  72. }
  73. static inline void __abc_set_inp_status(struct abc_dev *dev, uint8_t val)
  74. {
  75. ABC_INP1_DATA = dev->inp_data[1] = val;
  76. }
  77. void abc_register(struct abc_dev *dev, unsigned int devsel);
  78. void abc_init(void);
  79. void abcdisk_init(void);
  80. void abcdisk_io_poll(void);
  81. void abc_init_memmap(void);
  82. #endif /* ABCIO_H */