MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / _read

Function _read

components/vbus/vbus_chnx.c:65–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65static rt_ssize_t _read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
66{
67 rt_size_t outsz = 0;
68 struct rt_vbus_dev *vdev = dev->user_data;
69
70 RT_ASSERT(vdev->chnr != 0);
71
72 if (vdev->act == RT_NULL)
73 {
74 vdev->act = rt_vbus_data_pop(vdev->chnr);
75 vdev->pos = 0;
76 }
77
78 while (1)
79 {
80 rt_err_t err;
81
82 while (vdev->act)
83 {
84 rt_size_t cpysz;
85
86 if (size - outsz > vdev->act->size - vdev->pos)
87 cpysz = vdev->act->size - vdev->pos;
88 else
89 cpysz = size - outsz;
90
91 rt_memcpy((char*)buffer + outsz, ((char*)(vdev->act+1)) + vdev->pos, cpysz);
92 vdev->pos += cpysz;
93
94 outsz += cpysz;
95 if (outsz == size)
96 {
97 return outsz;
98 }
99 else if (outsz > size)
100 RT_ASSERT(0);
101
102 /* free old and get new */
103 rt_free(vdev->act);
104 vdev->act = rt_vbus_data_pop(vdev->chnr);
105 vdev->pos = 0;
106 }
107
108 /* TODO: We don't want to touch the rx_indicate here. But this lead to
109 * some duplication. Maybe we should find a better way to handle this.
110 */
111 if (rt_interrupt_get_nest() == 0)
112 {
113 err = rt_vbus_listen_on(vdev->chnr, RT_WAITING_FOREVER);
114 }
115 else
116 {
117 err = rt_vbus_listen_on(vdev->chnr, 0);
118 }
119 if (err != RT_EOK)
120 {
121 rt_set_errno(err);
122 return outsz;

Callers

nothing calls this directly

Calls 6

rt_vbus_data_popFunction · 0.85
rt_memcpyFunction · 0.85
rt_freeFunction · 0.85
rt_interrupt_get_nestFunction · 0.85
rt_vbus_listen_onFunction · 0.85
rt_set_errnoFunction · 0.85

Tested by

no test coverage detected