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

Function rt_audio_pipe_read

components/drivers/audio/dev_audio_pipe.c:50–106  ·  view source on GitHub ↗

* @brief Read audio pipe * * @param[in] dev pointer to audio device will be read * * @param[in] pos useless param * * @param[in] buffer pointer to ringbuffer of audio pipe to be read * * @param[in] size number of bytes will be read * * @return number of read bytes * * @note This function will execute time-consuming or affecting the * system operations like memcpy and disable int

Source from the content-addressed store, hash-verified

48 * system operations like memcpy and disable interrupt.
49 */
50static rt_ssize_t rt_audio_pipe_read(rt_device_t dev,
51 rt_off_t pos,
52 void *buffer,
53 rt_size_t size)
54{
55 rt_base_t level;
56 rt_thread_t thread;
57 struct rt_audio_pipe *pipe;
58 rt_size_t read_nbytes;
59
60 pipe = (struct rt_audio_pipe *)dev;
61 RT_ASSERT(pipe != RT_NULL);
62
63 if (!(pipe->flag & RT_PIPE_FLAG_BLOCK_RD))
64 {
65 level = rt_hw_interrupt_disable();
66 read_nbytes = rt_ringbuffer_get(&(pipe->ringbuffer), (rt_uint8_t *)buffer, size);
67
68 /* if the ringbuffer is empty, there won't be any writer waiting */
69 if (read_nbytes)
70 _rt_audio_pipe_resume_writer(pipe);
71
72 rt_hw_interrupt_enable(level);
73
74 return read_nbytes;
75 }
76
77 thread = rt_thread_self();
78
79 /* current context checking */
80 RT_DEBUG_NOT_IN_INTERRUPT;
81
82 do
83 {
84 level = rt_hw_interrupt_disable();
85 read_nbytes = rt_ringbuffer_get(&(pipe->ringbuffer), (rt_uint8_t *)buffer, size);
86 if (read_nbytes == 0)
87 {
88 rt_thread_suspend(thread);
89 /* waiting on suspended read list */
90 rt_list_insert_before(&(pipe->suspended_read_list),
91 &RT_THREAD_LIST_NODE(thread));
92 rt_hw_interrupt_enable(level);
93
94 rt_schedule();
95 }
96 else
97 {
98 _rt_audio_pipe_resume_writer(pipe);
99 rt_hw_interrupt_enable(level);
100 break;
101 }
102 }
103 while (read_nbytes == 0);
104
105 return read_nbytes;
106}
107

Callers

nothing calls this directly

Calls 8

rt_ringbuffer_getFunction · 0.85
rt_thread_selfFunction · 0.85
rt_thread_suspendFunction · 0.85
rt_list_insert_beforeFunction · 0.85
rt_hw_interrupt_disableFunction · 0.50
rt_hw_interrupt_enableFunction · 0.50
rt_scheduleFunction · 0.50

Tested by

no test coverage detected