vbus_api.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef __VBUS_API_H__
  2. #define __VBUS_API_H__
  3. #define RT_VBUS_USING_FLOW_CONTROL
  4. #define RT_VBUS_CHANNEL_NR 32
  5. #define RT_VBUS_BLK_HEAD_SZ 4
  6. #define RT_VBUS_MAX_PKT_SZ (256 - RT_VBUS_BLK_HEAD_SZ)
  7. #define RT_VMM_RB_BLK_NR (_RT_VBUS_RING_SZ / 64 - 1)
  8. #ifndef __ASSEMBLY__
  9. #include <stddef.h> /* For size_t */
  10. struct rt_vbus_blk
  11. {
  12. unsigned char id;
  13. unsigned char qos;
  14. unsigned char len;
  15. unsigned char reserved;
  16. unsigned char data[60];
  17. } __attribute__((packed));
  18. struct rt_vbus_ring
  19. {
  20. volatile size_t put_idx;
  21. volatile size_t get_idx;
  22. /* whether the writer is blocked on this ring. For RTT, it means the
  23. * central writer thread is waiting. For Linux, it means there are some
  24. * threads waiting for space to write.
  25. *
  26. * Note that we don't record whether there are reading thread blocked. When
  27. * there is new data, the other side will always be waked up. */
  28. volatile unsigned int blocked;
  29. struct rt_vbus_blk blks[RT_VMM_RB_BLK_NR];
  30. };
  31. enum
  32. {
  33. RT_VBUS_CHN0_CMD_ENABLE,
  34. RT_VBUS_CHN0_CMD_DISABLE,
  35. RT_VBUS_CHN0_CMD_SET,
  36. RT_VBUS_CHN0_CMD_ACK,
  37. RT_VBUS_CHN0_CMD_NAK,
  38. /* If the recieving side reached high water mark. It has the right to
  39. * suspend the channel. All the server/client should know about this
  40. * command but the one that does not implement flow control could ignore
  41. * this command. */
  42. RT_VBUS_CHN0_CMD_SUSPEND,
  43. RT_VBUS_CHN0_CMD_RESUME,
  44. RT_VBUS_CHN0_CMD_MAX,
  45. };
  46. enum rt_vbus_chn_status
  47. {
  48. /* initial state, available for reuse */
  49. RT_VBUS_CHN_ST_AVAILABLE,
  50. /* ACK DISABLE send(CS) or received(CS), but not ready for reuse.(the
  51. * channel is not closed by this end) */
  52. RT_VBUS_CHN_ST_CLOSED,
  53. /* ENABLE send(client) or received(server) */
  54. RT_VBUS_CHN_ST_ESTABLISHING,
  55. /* ACK SET send(C) or received(S) */
  56. RT_VBUS_CHN_ST_ESTABLISHED,
  57. /* Channel suspended by flow control. */
  58. RT_VBUS_CHN_ST_SUSPEND,
  59. /* DISABLE received(CS) */
  60. RT_VBUS_CHN_ST_CLOSING,
  61. };
  62. #endif
  63. #undef BUILD_ASSERT
  64. /* borrowed from http://lxr.linux.no/linux+v2.6.26.5/include/linux/kernel.h#L494 */
  65. #define BUILD_ASSERT(condition) ((void)sizeof(char[1 - 2*!(condition)]))
  66. /* max length of a channel name, including the \0 */
  67. #define RT_VBUS_CHN_NAME_MAX 16
  68. #endif /* end of include guard: __VBUS_API_H__ */