esplink.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #define ESPLINK_HEAD_MAGIC 0x3648dec4
  54. #define MAX_SIGNATURE_LEN 64
  55. struct esplink_head {
  56. volatile uint32_t magic;
  57. uint32_t hlen;
  58. struct {
  59. union {
  60. uint32_t cfg;
  61. struct {
  62. uint8_t fixes;
  63. uint8_t minor;
  64. uint8_t major;
  65. uint8_t fpga;
  66. };
  67. };
  68. } board;
  69. volatile struct esplink_timesync *tsync;
  70. struct esplink_ringbuf_head {
  71. uint32_t count;
  72. struct esplink_ringbuf_desc *desc;
  73. struct esplink_ptrs_dstr *dstr; /* Downstream (FPGA) side */
  74. struct esplink_ptrs_ustr *ustr; /* Upstream (ESP32) side */
  75. } rb;
  76. char signature[MAX_SIGNATURE_LEN]; /* Human-readable signature string */
  77. };
  78. #define EL_DIRQ_UNDERRUN 0 /* Local interrupt/status bit */
  79. #define EL_DIRQ_HELLO 1
  80. #define EL_DIRQ_RINGBUF 2
  81. #define EL_DIRQ_TIME 3
  82. #define EL_UIRQ_WREN 0 /* Remote write enable bit, not IRQ */
  83. #define EL_UIRQ_READY 1
  84. #define EL_UIRQ_RINGBUF 2
  85. #define EL_UIRQ_TIME 3
  86. /*
  87. * Well known ring buffer indicies; must match for both sides.
  88. * Currently assuming one link in each direction; if only a unidirectional
  89. * link is needed, leave the descriptor for the unused direction blank.
  90. */
  91. enum esplink_ringbuf_user {
  92. EL_RB_CONFIG,
  93. EL_RB_COUNT
  94. };
  95. #endif /* ESPLINK_H */