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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d15797d was d15797d, checked in by Jiri Svoboda <jiri@…>, 8 years ago

Remove unnecessary references to devman.

  • 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
165 const int ret = hw_res_dma_channel_setup(sess,
166 dsp->dma16_channel, pa, size,
167 DMA_MODE_READ | DMA_MODE_AUTO | DMA_MODE_ON_DEMAND);
[c5cbc1b7]168
[c885a21]169 async_hangup(sess);
170 return ret;
171}
[e941bf8]172
[5eed99d]173static inline int setup_buffer(sb_dsp_t *dsp, size_t size)
[01aef43]174{
175 assert(dsp);
[8442d10]176
177 if ((size > MAX_BUFFER_SIZE) || (size == 0) || ((size % 2) == 1))
[9b3d999]178 size = MAX_BUFFER_SIZE;
[8442d10]179
180 uintptr_t pa = 0;
[bf9cb2f]181 void *buffer = AS_AREA_ANY;
[8442d10]182
[4a90582]183 int ret = dmamem_map_anonymous(size, DMAMEM_16MiB | 0x0000ffff,
[8442d10]184 AS_AREA_WRITE | AS_AREA_READ, 0, &pa, &buffer);
[c5cbc1b7]185 if (ret != EOK) {
[124f9bd]186 ddf_log_error("Failed to allocate DMA buffer.");
[f14e6ea]187 return ENOMEM;
188 }
[8442d10]189
190 ddf_log_verbose("Setup DMA buffer at %p (%zu) %zu.", buffer, pa, size);
191 assert(pa < (1 << 24));
192
[c5cbc1b7]193 /* Setup 16 bit channel */
[8442d10]194 ret = setup_dma(dsp, pa, size);
[01aef43]195 if (ret == EOK) {
[dce7e41]196 dsp->buffer.data = buffer;
[00006e0]197 dsp->buffer.size = size;
[01aef43]198 } else {
[124f9bd]199 ddf_log_error("Failed to setup DMA16 channel: %s.",
[01aef43]200 str_error(ret));
[c5cbc1b7]201 dmamem_unmap_anonymous(buffer);
[01aef43]202 }
[8442d10]203
[01aef43]204 return ret;
205}
[e941bf8]206
[c885a21]207int sb_dsp_init(sb_dsp_t *dsp, sb16_regs_t *regs, ddf_dev_t *dev,
208 int dma8, int dma16)
[bf38143]209{
210 assert(dsp);
211 dsp->regs = regs;
[c885a21]212 dsp->dma8_channel = dma8;
213 dsp->dma16_channel = dma16;
[7ca22e5]214 dsp->event_session = NULL;
215 dsp->event_exchange = NULL;
[c885a21]216 dsp->sb_dev = dev;
[fb6c98f]217 dsp->state = DSP_NO_BUFFER;
[5eed99d]218 dsp_reset(dsp);
[bf38143]219 uint8_t response;
[5eed99d]220 const int ret = dsp_read(dsp, &response);
[bf38143]221 if (ret != EOK) {
[124f9bd]222 ddf_log_error("Failed to read DSP reset response value.");
[bf38143]223 return ret;
224 }
225 if (response != DSP_RESET_RESPONSE) {
[124f9bd]226 ddf_log_error("Invalid DSP reset response: %x.", response);
[bf38143]227 return EIO;
228 }
229
230 /* Get DSP version number */
[5eed99d]231 dsp_write(dsp, DSP_VERSION);
232 dsp_read(dsp, &dsp->version.major);
233 dsp_read(dsp, &dsp->version.minor);
[01aef43]234
235 return ret;
[bf38143]236}
[e941bf8]237
[f14e6ea]238void sb_dsp_interrupt(sb_dsp_t *dsp)
239{
[bf38143]240 assert(dsp);
[ff396ea]241
[57e8b3b]242 dsp->active.frame_count +=
243 dsp->active.samples / ((dsp->active.mode & DSP_MODE_STEREO) ? 2 : 1);
244
[fb6c98f]245 switch (dsp->state)
246 {
247 case DSP_PLAYBACK_ACTIVE_EVENTS:
[0387b92]248 dsp_report_event(dsp, PCM_EVENT_FRAMES_PLAYED);
[fb6c98f]249 case DSP_PLAYBACK_NOEVENTS:
250#ifndef AUTO_DMA_MODE
[d337f74]251 dsp_start_current_active(dsp, SINGLE_DMA_16B_DA);
[fb6c98f]252#endif
253 break;
254 case DSP_CAPTURE_ACTIVE_EVENTS:
[0387b92]255 dsp_report_event(dsp, PCM_EVENT_FRAMES_CAPTURED);
[fb6c98f]256 case DSP_CAPTURE_NOEVENTS:
257#ifndef AUTO_DMA_MODE
[d337f74]258 dsp_start_current_active(dsp, SINGLE_DMA_16B_DA);
[fb6c98f]259#endif
260 break;
[daed689]261 case DSP_CAPTURE_TERMINATE:
[d337f74]262 dsp_change_state(dsp, DSP_READY);
[daed689]263 dsp_report_event(dsp, PCM_EVENT_CAPTURE_TERMINATED);
264 async_exchange_end(dsp->event_exchange);
265 dsp->event_exchange = NULL;
266 break;
267 case DSP_PLAYBACK_TERMINATE:
[d337f74]268 dsp_change_state(dsp, DSP_READY);
[daed689]269 dsp_report_event(dsp, PCM_EVENT_PLAYBACK_TERMINATED);
270 async_exchange_end(dsp->event_exchange);
271 dsp->event_exchange = NULL;
272 break;
[fb6c98f]273 default:
[5b8e08e]274 ddf_log_warning("Interrupt while DSP not active (%s)",
275 dsp_state_to_str(dsp->state));
[7ca22e5]276 }
[01aef43]277}
[e941bf8]278
[f0241bda]279unsigned sb_dsp_query_cap(sb_dsp_t *dsp, audio_cap_t cap)
280{
[37367f7]281 ddf_log_verbose("Querying cap %s", audio_pcm_cap_str(cap));
[f0241bda]282 switch(cap) {
[d86c9736]283 case AUDIO_CAP_CAPTURE:
[f0241bda]284 case AUDIO_CAP_PLAYBACK:
285 case AUDIO_CAP_INTERRUPT:
[1ba95ba]286 case AUDIO_CAP_BUFFER_POS:
[f0241bda]287 return 1;
288 case AUDIO_CAP_MAX_BUFFER:
289 return MAX_BUFFER_SIZE;
290 case AUDIO_CAP_INTERRUPT_MIN_FRAMES:
291 return 1;
292 case AUDIO_CAP_INTERRUPT_MAX_FRAMES:
293 return 16535;
294 default:
[37367f7]295 return ENOTSUP;
[f0241bda]296 }
297}
298
[1ba95ba]299int sb_dsp_get_buffer_position(sb_dsp_t *dsp, size_t *pos)
300{
[fb6c98f]301 if (dsp->state == DSP_NO_BUFFER)
[1ba95ba]302 return ENOENT;
303
[fb6c98f]304 assert(dsp->buffer.data);
[d15797d]305 async_sess_t *sess = ddf_dev_parent_sess_get(dsp->sb_dev);
[1ba95ba]306
307 // TODO: Assumes DMA 16
308 const int remain = hw_res_dma_channel_remain(sess, dsp->dma16_channel);
309 async_hangup(sess);
310 if (remain >= 0) {
311 *pos = dsp->buffer.size - remain;
312 return EOK;
313 }
314 return remain;
315}
316
[b7c080c]317int sb_dsp_test_format(sb_dsp_t *dsp, unsigned *channels, unsigned *rate,
318 pcm_sample_format_t *format)
319{
320 int ret = EOK;
321 if (*channels == 0 || *channels > 2) {
322 *channels = 2;
323 ret = ELIMIT;
324 }
325 //TODO 8bit DMA supports 8bit formats
326 if (*format != PCM_SAMPLE_SINT16_LE && *format != PCM_SAMPLE_UINT16_LE) {
327 *format = pcm_sample_format_is_signed(*format) ?
328 PCM_SAMPLE_SINT16_LE : PCM_SAMPLE_UINT16_LE;
329 ret = ELIMIT;
330 }
[018ab50]331 if (*rate > DSP_RATE_UPPER_LIMIT) {
332 *rate = DSP_RATE_UPPER_LIMIT;
333 ret = ELIMIT;
334 }
335 if (*rate < DSP_RATE_LOWER_LIMIT) {
336 *rate = DSP_RATE_LOWER_LIMIT;
337 ret = ELIMIT;
338 }
[b7c080c]339 return ret;
340}
341
[fb6c98f]342int sb_dsp_set_event_session(sb_dsp_t *dsp, async_sess_t *session)
343{
344 assert(dsp);
[6f57933]345 if (dsp->event_session && session)
[fb6c98f]346 return EBUSY;
347 dsp->event_session = session;
348 ddf_log_debug("Set event session to %p.", session);
349 return EOK;
350}
351
352async_sess_t * sb_dsp_get_event_session(sb_dsp_t *dsp)
353{
354 assert(dsp);
355 ddf_log_debug("Get event session: %p.", dsp->event_session);
356 return dsp->event_session;
357}
358
[b497018]359int sb_dsp_get_buffer(sb_dsp_t *dsp, void **buffer, size_t *size)
[43dec08]360{
361 assert(dsp);
[00006e0]362 assert(size);
363
[7ca22e5]364 /* buffer is already setup by for someone, refuse to work until
365 * it's released */
[fb6c98f]366 if (dsp->state != DSP_NO_BUFFER)
[7ca22e5]367 return EBUSY;
[fb6c98f]368 assert(dsp->buffer.data == NULL);
[7ca22e5]369
[5eed99d]370 const int ret = setup_buffer(dsp, *size);
[124f9bd]371 if (ret == EOK) {
[b497018]372 ddf_log_debug("Providing buffer: %p, %zu B.",
373 dsp->buffer.data, dsp->buffer.size);
[00006e0]374
[124f9bd]375 if (buffer)
376 *buffer = dsp->buffer.data;
377 if (size)
378 *size = dsp->buffer.size;
[5eed99d]379 dsp_change_state(dsp, DSP_READY);
[124f9bd]380 }
[43dec08]381 return ret;
382}
[7ca22e5]383
[b497018]384int sb_dsp_release_buffer(sb_dsp_t *dsp)
[43dec08]385{
386 assert(dsp);
[f2a92b0]387 if (dsp->state != DSP_READY)
[fb6c98f]388 return EINVAL;
389 assert(dsp->buffer.data);
390 dmamem_unmap_anonymous(dsp->buffer.data);
391 dsp->buffer.data = NULL;
392 dsp->buffer.size = 0;
[124f9bd]393 ddf_log_debug("DSP buffer released.");
[5eed99d]394 dsp_change_state(dsp, DSP_NO_BUFFER);
[43dec08]395 return EOK;
396}
[e941bf8]397
[57e8b3b]398int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned frames,
[346643c]399 unsigned channels, unsigned sampling_rate, pcm_sample_format_t format)
[43dec08]400{
401 assert(dsp);
402
[f2a92b0]403 if (!dsp->buffer.data || dsp->state != DSP_READY)
[92b638c]404 return EINVAL;
405
[43dec08]406 /* Check supported parameters */
[57e8b3b]407 ddf_log_debug("Requested playback: %u frames, %uHz, %s, %u channel(s).",
408 frames, sampling_rate, pcm_sample_format_str(format), channels);
[d2765ab3]409 if (sb_dsp_test_format(dsp, &channels, &sampling_rate, &format) != EOK)
[346643c]410 return ENOTSUP;
[43dec08]411
[f3fb83a]412 /* Client requested regular events */
[fda3bd9]413 if (frames && !dsp->event_session)
414 return EINVAL;
415
416 if (dsp->event_session) {
[ff396ea]417 dsp->event_exchange = async_exchange_begin(dsp->event_session);
418 if (!dsp->event_exchange)
419 return ENOMEM;
420 }
[43dec08]421
[57e8b3b]422 dsp->active.mode = 0
[ad42844]423 | (pcm_sample_format_is_signed(format) ? DSP_MODE_SIGNED : 0)
[57e8b3b]424 | (channels == 2 ? DSP_MODE_STEREO : 0);
425 dsp->active.samples = frames * channels;
426 dsp->active.frame_count = 0;
[43dec08]427
[5eed99d]428 dsp_set_sampling_rate(dsp, sampling_rate);
[ad42844]429
430#ifdef AUTO_DMA_MODE
[5eed99d]431 dsp_start_current_active(dsp, AUTO_DMA_16B_DA_FIFO);
[ad42844]432#else
[5eed99d]433 dsp_start_current_active(dsp, SINGLE_DMA_16B_DA);
[ad42844]434#endif
[43dec08]435
[f3fb83a]436 ddf_log_verbose("Playback started, event every %u samples",
437 dsp->active.samples);
[a3ab774]438
[5eed99d]439 dsp_change_state(dsp,
[fb6c98f]440 frames ? DSP_PLAYBACK_ACTIVE_EVENTS : DSP_PLAYBACK_NOEVENTS);
[0387b92]441 if (dsp->state == DSP_PLAYBACK_ACTIVE_EVENTS)
442 dsp_report_event(dsp, PCM_EVENT_PLAYBACK_STARTED);
[9b3d999]443
[43dec08]444 return EOK;
445}
[e941bf8]446
[92b638c]447int sb_dsp_stop_playback(sb_dsp_t *dsp, bool immediate)
[43dec08]448{
449 assert(dsp);
[92b638c]450 if ((dsp->state == DSP_PLAYBACK_NOEVENTS ||
451 dsp->state == DSP_PLAYBACK_ACTIVE_EVENTS) &&
452 immediate)
453 {
[5eed99d]454 dsp_write(dsp, DMA_16B_PAUSE);
455 dsp_reset(dsp);
[92b638c]456 ddf_log_debug("Stopped playback");
[f2a92b0]457 dsp_change_state(dsp, DSP_READY);
[f7b36bc]458 if (dsp->event_exchange) {
459 dsp_report_event(dsp, PCM_EVENT_PLAYBACK_TERMINATED);
460 async_exchange_end(dsp->event_exchange);
461 dsp->event_exchange = NULL;
462 }
[92b638c]463 return EOK;
464 }
465 if (dsp->state == DSP_PLAYBACK_ACTIVE_EVENTS)
466 {
467 /* Stop after current fragment */
468 assert(!immediate);
[5eed99d]469 dsp_write(dsp, DMA_16B_EXIT);
[92b638c]470 ddf_log_debug("Last playback fragment");
[5eed99d]471 dsp_change_state(dsp, DSP_PLAYBACK_TERMINATE);
[92b638c]472 return EOK;
473 }
474 return EINVAL;
[43dec08]475}
[e941bf8]476
[d86c9736]477int sb_dsp_start_capture(sb_dsp_t *dsp, unsigned frames,
[346643c]478 unsigned channels, unsigned sampling_rate, pcm_sample_format_t format)
[43dec08]479{
[a3ab774]480 assert(dsp);
[f2a92b0]481 if (!dsp->buffer.data || dsp->state != DSP_READY)
[92b638c]482 return EINVAL;
[a3ab774]483
484 /* Check supported parameters */
[d86c9736]485 ddf_log_debug("Requested capture: %u frames, %uHz, %s, %u channel(s).",
[57e8b3b]486 frames, sampling_rate, pcm_sample_format_str(format), channels);
[d2765ab3]487 if (sb_dsp_test_format(dsp, &channels, &sampling_rate, &format) != EOK)
[346643c]488 return ENOTSUP;
[a3ab774]489
[f3fb83a]490 /* Client requested regular events */
[fda3bd9]491 if (frames && !dsp->event_session)
492 return EINVAL;
493
494 if (dsp->event_session) {
[ff396ea]495 dsp->event_exchange = async_exchange_begin(dsp->event_session);
496 if (!dsp->event_exchange)
497 return ENOMEM;
498 }
[a3ab774]499
[ad42844]500 dsp->active.mode = 0
501 | (pcm_sample_format_is_signed(format) ? DSP_MODE_SIGNED : 0)
502 | (channels == 2 ? DSP_MODE_STEREO : 0);
503 dsp->active.samples = frames * channels;
504 dsp->active.frame_count = 0;
[a3ab774]505
[5eed99d]506 dsp_set_sampling_rate(dsp, sampling_rate);
[a3ab774]507
508#ifdef AUTO_DMA_MODE
[5eed99d]509 dsp_start_current_active(dsp, AUTO_DMA_16B_AD_FIFO);
[a3ab774]510#else
[5eed99d]511 dsp_start_current_active(dsp, SINGLE_DMA_16B_AD);
[a3ab774]512#endif
513
[f3fb83a]514 ddf_log_verbose("Capture started started, event every %u samples",
515 dsp->active.samples);
[5eed99d]516 dsp_change_state(dsp,
[fb6c98f]517 frames ? DSP_CAPTURE_ACTIVE_EVENTS : DSP_CAPTURE_NOEVENTS);
[0387b92]518 if (dsp->state == DSP_CAPTURE_ACTIVE_EVENTS)
519 dsp_report_event(dsp, PCM_EVENT_CAPTURE_STARTED);
[a3ab774]520 return EOK;
[43dec08]521}
[e941bf8]522
[92b638c]523int sb_dsp_stop_capture(sb_dsp_t *dsp, bool immediate)
[43dec08]524{
[a3ab774]525 assert(dsp);
[92b638c]526 if ((dsp->state == DSP_CAPTURE_NOEVENTS ||
527 dsp->state == DSP_CAPTURE_ACTIVE_EVENTS) &&
528 immediate)
529 {
[5eed99d]530 dsp_write(dsp, DMA_16B_PAUSE);
531 dsp_reset(dsp);
[92b638c]532 ddf_log_debug("Stopped capture fragment");
[f2a92b0]533 dsp_change_state(dsp, DSP_READY);
[f7b36bc]534 if (dsp->event_exchange) {
535 dsp_report_event(dsp, PCM_EVENT_CAPTURE_TERMINATED);
536 async_exchange_end(dsp->event_exchange);
537 dsp->event_exchange = NULL;
538 }
[92b638c]539 return EOK;
540 }
541 if (dsp->state == DSP_CAPTURE_ACTIVE_EVENTS)
542 {
543 /* Stop after current fragment */
544 assert(!immediate);
[5eed99d]545 dsp_write(dsp, DMA_16B_EXIT);
[92b638c]546 ddf_log_debug("Last capture fragment");
[5eed99d]547 dsp_change_state(dsp, DSP_CAPTURE_TERMINATE);
[92b638c]548 return EOK;
549 }
550 return EINVAL;
[43dec08]551}
[763444e]552/**
553 * @}
554 */
Note: See TracBrowser for help on using the repository browser.