esplink.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #define ESPLINK_HEAD_MAGIC 0x3648dec4
  37. struct esplink_head {
  38. volatile uint32_t magic;
  39. uint32_t hlen;
  40. struct {
  41. union {
  42. uint32_t cfg;
  43. struct {
  44. uint8_t fixes;
  45. uint8_t minor;
  46. uint8_t major;
  47. uint8_t fpga;
  48. };
  49. };
  50. } board;
  51. const char *signature;
  52. uint32_t signature_len;
  53. struct esplink_ringbuf_head {
  54. uint32_t count;
  55. struct esplink_ringbuf_desc *desc;
  56. struct esplink_ptrs_dstr *dstr; /* Downstream (FPGA) side */
  57. struct esplink_ptrs_ustr *ustr; /* Upstream (ESP32) side */
  58. } rb;
  59. };
  60. #define EL_DIRQ_UNDERRUN 0 /* Local interrupt/status bit */
  61. #define EL_DIRQ_HELLO 1
  62. #define EL_DIRQ_RINGBUF 2
  63. #define EL_UIRQ_WREN 0 /* Remote write enable bit, not IRQ */
  64. #define EL_UIRQ_READY 1
  65. #define EL_UIRQ_RINGBUF 2
  66. /*
  67. * Well known ring buffer indicies; must match for both sides.
  68. * Currently assuming one link in each direction; if only a unidirectional
  69. * link is needed, leave the descriptor for the unused direction blank.
  70. */
  71. enum esplink_ringbuf_user {
  72. EL_RB_CONFIG,
  73. EL_RB_COUNT
  74. };
  75. #endif /* ESPLINK_H */