vbus_api.h 2.5 KB

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