esplink.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Common header file for ESP ("upstream") and FPGA ("downstream")
  3. * sides of link. This MUST contain only data structures!
  4. */
  5. #ifndef ESPLINK_H
  6. #define ESPLINK_H 1
  7. #include <stdlib.h>
  8. #include <stdbool.h>
  9. #include <inttypes.h>
  10. #define ESPLINK_HDR_ADDR ((const uint32_t *)0x40000000)
  11. /*
  12. * Ring buffer descriptor structure; this should be setup time only
  13. * and is statically cached on the upstream side.
  14. */
  15. struct esplink_ringbuf_desc {
  16. struct esplink_ringbuf {
  17. void *start;
  18. size_t size; /* Power of 2 */
  19. } dstr, ustr;
  20. };
  21. /*
  22. * Upstream and downstream pointer blocks, with the pointers encoded as
  23. * offsets into the buffer.
  24. *
  25. * Note that the head and tail pointers are reversed between the two
  26. * directions to allow one to be copied to the other.
  27. */
  28. struct esplink_ptrs_ustr {
  29. size_t head;
  30. size_t tail;
  31. };
  32. struct esplink_ptrs_dstr {
  33. size_t tail;
  34. size_t head;
  35. };
  36. struct esplink_timesync {
  37. struct esplink_timesync_buf {
  38. uint16_t update;
  39. uint16_t tick;
  40. union {
  41. struct {
  42. unsigned int sec2 : 5;
  43. unsigned int min : 6;
  44. unsigned int hour : 5;
  45. unsigned int mday : 5;
  46. unsigned int mon : 4;
  47. unsigned int year : 7;
  48. } tm;
  49. uint32_t td;
  50. };
  51. } get, set;
  52. };
  53. struct esplink_ota {
  54. const void *data;
  55. uint32_t len;
  56. };
  57. #define ESPLINK_CONFIG_BUFSIZE 16384
  58. struct esplink_configbuf {
  59. volatile void *buf; /* Buffer for configuration and data */
  60. size_t buflen; /* Size of buffer */
  61. };
  62. #define ESPLINK_HEAD_MAGIC 0x3648dec4
  63. #define MAX_SIGNATURE_LEN 64
  64. struct esplink_head {
  65. volatile uint32_t magic;
  66. uint32_t hlen;
  67. struct {
  68. union {
  69. uint32_t cfg;
  70. struct {
  71. uint8_t fixes;
  72. uint8_t minor;
  73. uint8_t major;
  74. uint8_t fpga;
  75. };
  76. };
  77. } board;
  78. volatile struct esplink_timesync *tsync;
  79. volatile struct esplink_ota *ota;
  80. struct esplink_configbuf cfg;
  81. struct esplink_ringbuf_head {
  82. uint32_t count;
  83. struct esplink_ringbuf_desc *desc;
  84. struct esplink_ptrs_dstr *dstr; /* Downstream (FPGA) side */
  85. struct esplink_ptrs_ustr *ustr; /* Upstream (ESP32) side */
  86. } rb;
  87. char signature[MAX_SIGNATURE_LEN]; /* Human-readable signature string */
  88. const void *board_info; /* board_info structure pointer */
  89. };
  90. #define EL_DIRQ_UNDERRUN 0 /* Local interrupt/status bit */
  91. #define EL_DIRQ_HELLO 1
  92. #define EL_DIRQ_RINGBUF 2
  93. #define EL_DIRQ_TIME 3
  94. #define EL_DIRQ_DONE 4 /* Some operation completed */
  95. #define EL_DIRQ_BOARDINFO 5 /* board_info structure updated */
  96. #define EL_DIRQ_CONFIG 6 /* config_buf updated */
  97. #define EL_UIRQ_WREN 0 /* Remote write enable bit, not IRQ */
  98. #define EL_UIRQ_READY 1
  99. #define EL_UIRQ_RINGBUF 2
  100. #define EL_UIRQ_TIME 3
  101. #define EL_UIRQ_OTA 4
  102. /*
  103. * Well known ring buffer indicies; must match for both sides.
  104. * Currently assuming one link in each direction; if only a unidirectional
  105. * link is needed, leave the descriptor for the unused direction blank.
  106. */
  107. enum esplink_ringbuf_user {
  108. EL_RB_CONFIG,
  109. EL_RB_COUNT
  110. };
  111. #endif /* ESPLINK_H */