source: mainline/uspace/drv/audio/sb16/dsp.c@ 071a1ddb

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 071a1ddb was c19a5a59, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

Return value from hw_res_dma_channel_remain separately from error code.

  • Property mode set to 100644
File size: 14.5 KB
RevLine 
[763444e]1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28/** @addtogroup drvaudiosb16
29 * @{
30 */
31/** @file
32 * @brief DSP helper functions implementation
33 */
34
[c5cbc1b7]35#include <as.h>
[03362fbd]36#include <stdbool.h>
[d15797d]37#include <ddf/driver.h>
[c5cbc1b7]38#include <ddi.h>
[c885a21]39#include <device/hw_res.h>
[763444e]40#include <libarch/ddi.h>
[0b4f060]41#include <libarch/barrier.h>
[365f259]42#include <macros.h>
[01aef43]43#include <str_error.h>
[1240bb9]44#include <audio_pcm_iface.h>
[0f2e7c1]45
[bf38143]46#include "ddf_log.h"
47#include "dsp_commands.h"
[763444e]48#include "dsp.h"
49
[c5cbc1b7]50/* Maximum allowed transfer size for ISA DMA transfers is 64kB */
[537620a8]51#define MAX_BUFFER_SIZE (64 * 1024)
[bf38143]52
53#ifndef DSP_RETRY_COUNT
54#define DSP_RETRY_COUNT 100
55#endif
56
57#define DSP_RESET_RESPONSE 0xaa
[018ab50]58
59/* These are only for SB16 (DSP4.00+) */
60#define DSP_RATE_UPPER_LIMIT 44100
61#define DSP_RATE_LOWER_LIMIT 5000
[bf38143]62
[5984107]63#define AUTO_DMA_MODE
64
[fb6c98f]65static inline const char * dsp_state_to_str(dsp_state_t state)
66{
67 static const char* state_names[] = {
68 [DSP_PLAYBACK_ACTIVE_EVENTS] = "PLAYBACK w/ EVENTS",
[f3fb83a]69 [DSP_CAPTURE_ACTIVE_EVENTS] = "CAPTURE w/ EVENTS",
70 [DSP_PLAYBACK_NOEVENTS] = "PLAYBACK w/o EVENTS",
[fb6c98f]71 [DSP_CAPTURE_NOEVENTS] = "CAPTURE w/o EVENTS",
[03d6e0d]72 [DSP_PLAYBACK_TERMINATE] = "PLAYBACK TERMINATE",
73 [DSP_CAPTURE_TERMINATE] = "CAPTURE TERMINATE",
[fb6c98f]74 [DSP_READY] = "READY",
75 [DSP_NO_BUFFER] = "NO BUFFER",
76 };
[05b59393]77 if ((size_t)state < ARRAY_SIZE(state_names))
[fb6c98f]78 return state_names[state];
79 return "UNKNOWN";
80}
81
82
[5eed99d]83static inline void dsp_change_state(sb_dsp_t *dsp, dsp_state_t state)
[fb6c98f]84{
85 assert(dsp);
86 ddf_log_verbose("Changing state from %s to %s",
87 dsp_state_to_str(dsp->state), dsp_state_to_str(state));
88 dsp->state = state;
89}
90
[5eed99d]91static inline int dsp_read(sb_dsp_t *dsp, uint8_t *data)
[bf38143]92{
93 assert(data);
94 assert(dsp);
95 uint8_t status;
96 size_t attempts = DSP_RETRY_COUNT;
97 do {
98 status = pio_read_8(&dsp->regs->dsp_read_status);
99 } while (--attempts && ((status & DSP_READ_READY) == 0));
100
101 if ((status & DSP_READ_READY) == 0)
102 return EIO;
103
104 *data = pio_read_8(&dsp->regs->dsp_data_read);
105 return EOK;
106}
[e941bf8]107
[5eed99d]108static inline int dsp_write(sb_dsp_t *dsp, uint8_t data)
[bf38143]109{
110 assert(dsp);
111 uint8_t status;
112 size_t attempts = DSP_RETRY_COUNT;
113 do {
114 status = pio_read_8(&dsp->regs->dsp_write);
115 } while (--attempts && ((status & DSP_WRITE_BUSY) != 0));
116
117 if ((status & DSP_WRITE_BUSY))
118 return EIO;
119
120 pio_write_8(&dsp->regs->dsp_write, data);
121 return EOK;
122}
[e941bf8]123
[5eed99d]124static inline void dsp_reset(sb_dsp_t *dsp)
[bf38143]125{
126 assert(dsp);
127 /* Reset DSP, see Chapter 2 of Sound Blaster HW programming guide */
128 pio_write_8(&dsp->regs->dsp_reset, 1);
129 udelay(3); /* Keep reset for 3 us */
130 pio_write_8(&dsp->regs->dsp_reset, 0);
[5eed99d]131 /* "DSP takes about 100 microseconds to initialize itself" */
132 udelay(100);
[bf38143]133}
[e941bf8]134
[5eed99d]135static inline void dsp_start_current_active(sb_dsp_t *dsp, uint8_t command)
[ad42844]136{
[5eed99d]137 dsp_write(dsp, command);
138 dsp_write(dsp, dsp->active.mode);
139 dsp_write(dsp, (dsp->active.samples - 1) & 0xff);
140 dsp_write(dsp, (dsp->active.samples - 1) >> 8);
[ad42844]141}
142
[5eed99d]143static inline void dsp_set_sampling_rate(sb_dsp_t *dsp, unsigned rate)
[ad42844]144{
[5eed99d]145 dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT);
[05b59393]146 uint8_t rate_lo = rate & 0xff;
147 uint8_t rate_hi = rate >> 8;
148 dsp_write(dsp, rate_hi);
149 dsp_write(dsp, rate_lo);
150 ddf_log_verbose("Sampling rate: %hhx:%hhx.", rate_hi, rate_lo);
[ad42844]151}
152
[5eed99d]153static inline void dsp_report_event(sb_dsp_t *dsp, pcm_event_t event)
154{
155 assert(dsp);
156 if (!dsp->event_exchange)
157 ddf_log_warning("No one listening for event %u", event);
158 async_msg_1(dsp->event_exchange, event, dsp->active.frame_count);
159}
160
161static inline int setup_dma(sb_dsp_t *dsp, uintptr_t pa, size_t size)
[c885a21]162{
[d15797d]163 async_sess_t *sess = ddf_dev_parent_sess_get(dsp->sb_dev);
[c885a21]164
[53a309e]165 return hw_res_dma_channel_setup(sess,
[c885a21]166 dsp->dma16_channel, pa, size,
167 DMA_MODE_READ | DMA_MODE_AUTO | DMA_MODE_ON_DEMAND);
168}
[e941bf8]169
[5eed99d]170static inline int setup_buffer(sb_dsp_t *dsp, size_t size)
[01aef43]171{
172 assert(dsp);
[8442d10]173
174 if ((size > MAX_BUFFER_SIZE) || (size == 0) || ((size % 2) == 1))
[9b3d999]175 size = MAX_BUFFER_SIZE;
[8442d10]176
177 uintptr_t pa = 0;
[bf9cb2f]178 void *buffer = AS_AREA_ANY;
[8442d10]179
[4a90582]180 int ret = dmamem_map_anonymous(size, DMAMEM_16MiB | 0x0000ffff,
[8442d10]181 AS_AREA_WRITE | AS_AREA_READ, 0, &pa, &buffer);
[c5cbc1b7]182 if (ret != EOK) {
[124f9bd]183 ddf_log_error("Failed to allocate DMA buffer.");
[f14e6ea]184 return ENOMEM;
185 }
[8442d10]186
187 ddf_log_verbose("Setup DMA buffer at %p (%zu) %zu.", buffer, pa, size);
188 assert(pa < (1 << 24));
189
[c5cbc1b7]190 /* Setup 16 bit channel */
[8442d10]191 ret = setup_dma(dsp, pa, size);
[01aef43]192 if (ret == EOK) {
[dce7e41]193 dsp->buffer.data = buffer;
[00006e0]194 dsp->buffer.size = size;
[01aef43]195 } else {
[124f9bd]196 ddf_log_error("Failed to setup DMA16 channel: %s.",
[01aef43]197 str_error(ret));
[c5cbc1b7]198 dmamem_unmap_anonymous(buffer);
[01aef43]199 }
[8442d10]200
[01aef43]201 return ret;
202}
[e941bf8]203
[c885a21]204int sb_dsp_init(sb_dsp_t *dsp, sb16_regs_t *regs, ddf_dev_t *dev,
205 int dma8, int dma16)
[bf38143]206{
207 assert(dsp);
208 dsp->regs = regs;
[c885a21]209 dsp->dma8_channel = dma8;
210 dsp->dma16_channel = dma16;
[7ca22e5]211 dsp->event_session = NULL;
212 dsp->event_exchange = NULL;
[c885a21]213 dsp->sb_dev = dev;
[fb6c98f]214 dsp->state = DSP_NO_BUFFER;
[5eed99d]215 dsp_reset(dsp);
[bf38143]216 uint8_t response;
[5eed99d]217 const int ret = dsp_read(dsp, &response);
[bf38143]218 if (ret != EOK) {
[124f9bd]219 ddf_log_error("Failed to read DSP reset response value.");
[bf38143]220 return ret;
221 }
222 if (response != DSP_RESET_RESPONSE) {
[124f9bd]223 ddf_log_error("Invalid DSP reset response: %x.", response);
[bf38143]224 return EIO;
225 }
226
227 /* Get DSP version number */
[5eed99d]228 dsp_write(dsp, DSP_VERSION);
229 dsp_read(dsp, &dsp->version.major);
230 dsp_read(dsp, &dsp->version.minor);
[01aef43]231
232 return ret;
[bf38143]233}
[e941bf8]234
[f14e6ea]235void sb_dsp_interrupt(sb_dsp_t *dsp)
236{
[bf38143]237 assert(dsp);
[ff396ea]238
[57e8b3b]239 dsp->active.frame_count +=
240 dsp->active.samples / ((dsp->active.mode & DSP_MODE_STEREO) ? 2 : 1);
241
[fb6c98f]242 switch (dsp->state)
243 {
244 case DSP_PLAYBACK_ACTIVE_EVENTS:
[0387b92]245 dsp_report_event(dsp, PCM_EVENT_FRAMES_PLAYED);
[fb6c98f]246 case DSP_PLAYBACK_NOEVENTS:
247#ifndef AUTO_DMA_MODE
[d337f74]248 dsp_start_current_active(dsp, SINGLE_DMA_16B_DA);
[fb6c98f]249#endif
250 break;
251 case DSP_CAPTURE_ACTIVE_EVENTS:
[0387b92]252 dsp_report_event(dsp, PCM_EVENT_FRAMES_CAPTURED);
[fb6c98f]253 case DSP_CAPTURE_NOEVENTS:
254#ifndef AUTO_DMA_MODE
[d337f74]255 dsp_start_current_active(dsp, SINGLE_DMA_16B_DA);
[fb6c98f]256#endif
257 break;
[daed689]258 case DSP_CAPTURE_TERMINATE:
[d337f74]259 dsp_change_state(dsp, DSP_READY);
[daed689]260 dsp_report_event(dsp, PCM_EVENT_CAPTURE_TERMINATED);
261 async_exchange_end(dsp->event_exchange);
262 dsp->event_exchange = NULL;
263 break;
264 case DSP_PLAYBACK_TERMINATE:
[d337f74]265 dsp_change_state(dsp, DSP_READY);
[daed689]266 dsp_report_event(dsp, PCM_EVENT_PLAYBACK_TERMINATED);
267 async_exchange_end(dsp->event_exchange);
268 dsp->event_exchange = NULL;
269 break;
[fb6c98f]270 default:
[5b8e08e]271 ddf_log_warning("Interrupt while DSP not active (%s)",
272 dsp_state_to_str(dsp->state));
[7ca22e5]273 }
[01aef43]274}
[e941bf8]275
[f0241bda]276unsigned sb_dsp_query_cap(sb_dsp_t *dsp, audio_cap_t cap)
277{
[37367f7]278 ddf_log_verbose("Querying cap %s", audio_pcm_cap_str(cap));
[f0241bda]279 switch(cap) {
[d86c9736]280 case AUDIO_CAP_CAPTURE:
[f0241bda]281 case AUDIO_CAP_PLAYBACK:
282 case AUDIO_CAP_INTERRUPT:
[1ba95ba]283 case AUDIO_CAP_BUFFER_POS:
[f0241bda]284 return 1;
285 case AUDIO_CAP_MAX_BUFFER:
286 return MAX_BUFFER_SIZE;
287 case AUDIO_CAP_INTERRUPT_MIN_FRAMES:
288 return 1;
289 case AUDIO_CAP_INTERRUPT_MAX_FRAMES:
290 return 16535;
291 default:
[37367f7]292 return ENOTSUP;
[f0241bda]293 }
294}
295
[1ba95ba]296int sb_dsp_get_buffer_position(sb_dsp_t *dsp, size_t *pos)
297{
[fb6c98f]298 if (dsp->state == DSP_NO_BUFFER)
[1ba95ba]299 return ENOENT;
300
[fb6c98f]301 assert(dsp->buffer.data);
[d15797d]302 async_sess_t *sess = ddf_dev_parent_sess_get(dsp->sb_dev);
[1ba95ba]303
304 // TODO: Assumes DMA 16
[c19a5a59]305 size_t remain;
306 int rc = hw_res_dma_channel_remain(sess, dsp->dma16_channel, &remain);
307 if (rc == EOK) {
[1ba95ba]308 *pos = dsp->buffer.size - remain;
309 }
[c19a5a59]310 return rc;
[1ba95ba]311}
312
[b7c080c]313int sb_dsp_test_format(sb_dsp_t *dsp, unsigned *channels, unsigned *rate,
314 pcm_sample_format_t *format)
315{
316 int ret = EOK;
317 if (*channels == 0 || *channels > 2) {
318 *channels = 2;
319 ret = ELIMIT;
320 }
321 //TODO 8bit DMA supports 8bit formats
322 if (*format != PCM_SAMPLE_SINT16_LE && *format != PCM_SAMPLE_UINT16_LE) {
323 *format = pcm_sample_format_is_signed(*format) ?
324 PCM_SAMPLE_SINT16_LE : PCM_SAMPLE_UINT16_LE;
325 ret = ELIMIT;
326 }
[018ab50]327 if (*rate > DSP_RATE_UPPER_LIMIT) {
328 *rate = DSP_RATE_UPPER_LIMIT;
329 ret = ELIMIT;
330 }
331 if (*rate < DSP_RATE_LOWER_LIMIT) {
332 *rate = DSP_RATE_LOWER_LIMIT;
333 ret = ELIMIT;
334 }
[b7c080c]335 return ret;
336}
337
[fb6c98f]338int sb_dsp_set_event_session(sb_dsp_t *dsp, async_sess_t *session)
339{
340 assert(dsp);
[6f57933]341 if (dsp->event_session && session)
[fb6c98f]342 return EBUSY;
343 dsp->event_session = session;
344 ddf_log_debug("Set event session to %p.", session);
345 return EOK;
346}
347
348async_sess_t * sb_dsp_get_event_session(sb_dsp_t *dsp)
349{
350 assert(dsp);
351 ddf_log_debug("Get event session: %p.", dsp->event_session);
352 return dsp->event_session;
353}
354
[b497018]355int sb_dsp_get_buffer(sb_dsp_t *dsp, void **buffer, size_t *size)
[43dec08]356{
357 assert(dsp);
[00006e0]358 assert(size);
359
[7ca22e5]360 /* buffer is already setup by for someone, refuse to work until
361 * it's released */
[fb6c98f]362 if (dsp->state != DSP_NO_BUFFER)
[7ca22e5]363 return EBUSY;
[fb6c98f]364 assert(dsp->buffer.data == NULL);
[7ca22e5]365
[5eed99d]366 const int ret = setup_buffer(dsp, *size);
[124f9bd]367 if (ret == EOK) {
[b497018]368 ddf_log_debug("Providing buffer: %p, %zu B.",
369 dsp->buffer.data, dsp->buffer.size);
[00006e0]370
[124f9bd]371 if (buffer)
372 *buffer = dsp->buffer.data;
373 if (size)
374 *size = dsp->buffer.size;
[5eed99d]375 dsp_change_state(dsp, DSP_READY);
[124f9bd]376 }
[43dec08]377 return ret;
378}
[7ca22e5]379
[b497018]380int sb_dsp_release_buffer(sb_dsp_t *dsp)
[43dec08]381{
382 assert(dsp);
[f2a92b0]383 if (dsp->state != DSP_READY)
[fb6c98f]384 return EINVAL;
385 assert(dsp->buffer.data);
386 dmamem_unmap_anonymous(dsp->buffer.data);
387 dsp->buffer.data = NULL;
388 dsp->buffer.size = 0;
[124f9bd]389 ddf_log_debug("DSP buffer released.");
[5eed99d]390 dsp_change_state(dsp, DSP_NO_BUFFER);
[43dec08]391 return EOK;
392}
[e941bf8]393
[57e8b3b]394int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned frames,
[346643c]395 unsigned channels, unsigned sampling_rate, pcm_sample_format_t format)
[43dec08]396{
397 assert(dsp);
398
[f2a92b0]399 if (!dsp->buffer.data || dsp->state != DSP_READY)
[92b638c]400 return EINVAL;
401
[43dec08]402 /* Check supported parameters */
[57e8b3b]403 ddf_log_debug("Requested playback: %u frames, %uHz, %s, %u channel(s).",
404 frames, sampling_rate, pcm_sample_format_str(format), channels);
[d2765ab3]405 if (sb_dsp_test_format(dsp, &channels, &sampling_rate, &format) != EOK)
[346643c]406 return ENOTSUP;
[43dec08]407
[f3fb83a]408 /* Client requested regular events */
[fda3bd9]409 if (frames && !dsp->event_session)
410 return EINVAL;
411
412 if (dsp->event_session) {
[ff396ea]413 dsp->event_exchange = async_exchange_begin(dsp->event_session);
414 if (!dsp->event_exchange)
415 return ENOMEM;
416 }
[43dec08]417
[57e8b3b]418 dsp->active.mode = 0
[ad42844]419 | (pcm_sample_format_is_signed(format) ? DSP_MODE_SIGNED : 0)
[57e8b3b]420 | (channels == 2 ? DSP_MODE_STEREO : 0);
421 dsp->active.samples = frames * channels;
422 dsp->active.frame_count = 0;
[43dec08]423
[5eed99d]424 dsp_set_sampling_rate(dsp, sampling_rate);
[ad42844]425
426#ifdef AUTO_DMA_MODE
[5eed99d]427 dsp_start_current_active(dsp, AUTO_DMA_16B_DA_FIFO);
[ad42844]428#else
[5eed99d]429 dsp_start_current_active(dsp, SINGLE_DMA_16B_DA);
[ad42844]430#endif
[43dec08]431
[f3fb83a]432 ddf_log_verbose("Playback started, event every %u samples",
433 dsp->active.samples);
[a3ab774]434
[5eed99d]435 dsp_change_state(dsp,
[fb6c98f]436 frames ? DSP_PLAYBACK_ACTIVE_EVENTS : DSP_PLAYBACK_NOEVENTS);
[0387b92]437 if (dsp->state == DSP_PLAYBACK_ACTIVE_EVENTS)
438 dsp_report_event(dsp, PCM_EVENT_PLAYBACK_STARTED);
[9b3d999]439
[43dec08]440 return EOK;
441}
[e941bf8]442
[92b638c]443int sb_dsp_stop_playback(sb_dsp_t *dsp, bool immediate)
[43dec08]444{
445 assert(dsp);
[92b638c]446 if ((dsp->state == DSP_PLAYBACK_NOEVENTS ||
447 dsp->state == DSP_PLAYBACK_ACTIVE_EVENTS) &&
448 immediate)
449 {
[5eed99d]450 dsp_write(dsp, DMA_16B_PAUSE);
451 dsp_reset(dsp);
[92b638c]452 ddf_log_debug("Stopped playback");
[f2a92b0]453 dsp_change_state(dsp, DSP_READY);
[f7b36bc]454 if (dsp->event_exchange) {
455 dsp_report_event(dsp, PCM_EVENT_PLAYBACK_TERMINATED);
456 async_exchange_end(dsp->event_exchange);
457 dsp->event_exchange = NULL;
458 }
[92b638c]459 return EOK;
460 }
461 if (dsp->state == DSP_PLAYBACK_ACTIVE_EVENTS)
462 {
463 /* Stop after current fragment */
464 assert(!immediate);
[5eed99d]465 dsp_write(dsp, DMA_16B_EXIT);
[92b638c]466 ddf_log_debug("Last playback fragment");
[5eed99d]467 dsp_change_state(dsp, DSP_PLAYBACK_TERMINATE);
[92b638c]468 return EOK;
469 }
470 return EINVAL;
[43dec08]471}
[e941bf8]472
[d86c9736]473int sb_dsp_start_capture(sb_dsp_t *dsp, unsigned frames,
[346643c]474 unsigned channels, unsigned sampling_rate, pcm_sample_format_t format)
[43dec08]475{
[a3ab774]476 assert(dsp);
[f2a92b0]477 if (!dsp->buffer.data || dsp->state != DSP_READY)
[92b638c]478 return EINVAL;
[a3ab774]479
480 /* Check supported parameters */
[d86c9736]481 ddf_log_debug("Requested capture: %u frames, %uHz, %s, %u channel(s).",
[57e8b3b]482 frames, sampling_rate, pcm_sample_format_str(format), channels);
[d2765ab3]483 if (sb_dsp_test_format(dsp, &channels, &sampling_rate, &format) != EOK)
[346643c]484 return ENOTSUP;
[a3ab774]485
[f3fb83a]486 /* Client requested regular events */
[fda3bd9]487 if (frames && !dsp->event_session)
488 return EINVAL;
489
490 if (dsp->event_session) {
[ff396ea]491 dsp->event_exchange = async_exchange_begin(dsp->event_session);
492 if (!dsp->event_exchange)
493 return ENOMEM;
494 }
[a3ab774]495
[ad42844]496 dsp->active.mode = 0
497 | (pcm_sample_format_is_signed(format) ? DSP_MODE_SIGNED : 0)
498 | (channels == 2 ? DSP_MODE_STEREO : 0);
499 dsp->active.samples = frames * channels;
500 dsp->active.frame_count = 0;
[a3ab774]501
[5eed99d]502 dsp_set_sampling_rate(dsp, sampling_rate);
[a3ab774]503
504#ifdef AUTO_DMA_MODE
[5eed99d]505 dsp_start_current_active(dsp, AUTO_DMA_16B_AD_FIFO);
[a3ab774]506#else
[5eed99d]507 dsp_start_current_active(dsp, SINGLE_DMA_16B_AD);
[a3ab774]508#endif
509
[f3fb83a]510 ddf_log_verbose("Capture started started, event every %u samples",
511 dsp->active.samples);
[5eed99d]512 dsp_change_state(dsp,
[fb6c98f]513 frames ? DSP_CAPTURE_ACTIVE_EVENTS : DSP_CAPTURE_NOEVENTS);
[0387b92]514 if (dsp->state == DSP_CAPTURE_ACTIVE_EVENTS)
515 dsp_report_event(dsp, PCM_EVENT_CAPTURE_STARTED);
[a3ab774]516 return EOK;
[43dec08]517}
[e941bf8]518
[92b638c]519int sb_dsp_stop_capture(sb_dsp_t *dsp, bool immediate)
[43dec08]520{
[a3ab774]521 assert(dsp);
[92b638c]522 if ((dsp->state == DSP_CAPTURE_NOEVENTS ||
523 dsp->state == DSP_CAPTURE_ACTIVE_EVENTS) &&
524 immediate)
525 {
[5eed99d]526 dsp_write(dsp, DMA_16B_PAUSE);
527 dsp_reset(dsp);
[92b638c]528 ddf_log_debug("Stopped capture fragment");
[f2a92b0]529 dsp_change_state(dsp, DSP_READY);
[f7b36bc]530 if (dsp->event_exchange) {
531 dsp_report_event(dsp, PCM_EVENT_CAPTURE_TERMINATED);
532 async_exchange_end(dsp->event_exchange);
533 dsp->event_exchange = NULL;
534 }
[92b638c]535 return EOK;
536 }
537 if (dsp->state == DSP_CAPTURE_ACTIVE_EVENTS)
538 {
539 /* Stop after current fragment */
540 assert(!immediate);
[5eed99d]541 dsp_write(dsp, DMA_16B_EXIT);
[92b638c]542 ddf_log_debug("Last capture fragment");
[5eed99d]543 dsp_change_state(dsp, DSP_CAPTURE_TERMINATE);
[92b638c]544 return EOK;
545 }
546 return EINVAL;
[43dec08]547}
[763444e]548/**
549 * @}
550 */
Note: See TracBrowser for help on using the repository browser.