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