vbus_api.h 2.2 KB

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