vbus_api.h 2.2 KB

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