Changeset 7ca22e5 in mainline


Ignore:
Timestamp:
2012-07-05T19:32:58Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
725d038
Parents:
8de7ef2
Message:

drv/audio/sb16: Accept event session and send USER_METHOD on playback interrupt.

Location:
uspace/drv/audio/sb16
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/sb16/dsp.c

    r8de7ef2 r7ca22e5  
    162162        dsp->dma8_channel = dma8;
    163163        dsp->dma16_channel = dma16;
     164        dsp->event_session = NULL;
     165        dsp->event_exchange = NULL;
    164166        dsp->sb_dev = dev;
    165167        sb_dsp_reset(dsp);
     
    187189void sb_dsp_interrupt(sb_dsp_t *dsp)
    188190{
     191        assert(dsp);
     192        if (dsp->event_exchange) {
     193                async_msg_0(dsp->event_exchange, IPC_FIRST_USER_METHOD);
     194        } else {
     195                ddf_log_warning("Interrupt with no event consumer.");
     196        }
    189197#ifndef AUTO_DMA_MODE
    190         assert(dsp);
    191198        sb_dsp_write(dsp, SINGLE_DMA_16B_DA);
    192199        sb_dsp_write(dsp, dsp->playing.mode);
     
    200207        assert(dsp);
    201208        assert(size);
     209
     210        /* buffer is already setup by for someone, refuse to work until
     211         * it's released */
     212        if (dsp->buffer.data)
     213                return EBUSY;
    202214
    203215        const int ret = sb_setup_buffer(dsp, *size);
     
    213225        return ret;
    214226}
     227
     228int sb_dsp_set_event_session(sb_dsp_t *dsp, unsigned id, async_sess_t *session)
     229{
     230        assert(dsp);
     231        assert(session);
     232        if (id != BUFFER_ID)
     233                return ENOENT;
     234        if (dsp->event_session)
     235                return EBUSY;
     236        dsp->event_session = session;
     237        return EOK;
     238}
    215239/*----------------------------------------------------------------------------*/
    216240int sb_dsp_release_buffer(sb_dsp_t *dsp, unsigned id)
     
    220244                return ENOENT;
    221245        sb_clear_buffer(dsp);
    222         return EOK;
    223 }
    224 /*----------------------------------------------------------------------------*/
    225 int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned id, unsigned sampling_rate,
    226     unsigned sample_size, unsigned channels, bool sign)
    227 {
    228         assert(dsp);
     246        if (dsp->event_exchange)
     247                async_exchange_end(dsp->event_exchange);
     248        dsp->event_exchange = NULL;
     249        if (dsp->event_session)
     250                async_hangup(dsp->event_session);
     251        dsp->event_session = NULL;
     252        return EOK;
     253}
     254/*----------------------------------------------------------------------------*/
     255int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned id, unsigned parts,
     256    unsigned sampling_rate, unsigned sample_size, unsigned channels, bool sign)
     257{
     258        assert(dsp);
     259
     260        if (!dsp->event_session)
     261                return EINVAL;
     262
     263        /* Play block size must be even number (we use DMA 16)*/
     264        if (dsp->buffer.size % (parts * 2))
     265                return EINVAL;
     266
     267        const unsigned play_block_size = dsp->buffer.size / parts;
    229268
    230269        /* Check supported parameters */
     
    241280                return ENOTSUP;
    242281
     282        dsp->event_exchange = async_exchange_begin(dsp->event_session);
     283        if (!dsp->event_exchange)
     284                return ENOMEM;
    243285
    244286        sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT);
     
    259301        sb_dsp_write(dsp, dsp->playing.mode);
    260302
    261         dsp->playing.samples = sample_count(sample_size, PLAY_BLOCK_SIZE);
     303        dsp->playing.samples = sample_count(sample_size, play_block_size);
    262304        sb_dsp_write(dsp, (dsp->playing.samples - 1) & 0xff);
    263305        sb_dsp_write(dsp, (dsp->playing.samples - 1) >> 8);
    264306
    265307        return EOK;
    266         return ENOTSUP;
    267308}
    268309/*----------------------------------------------------------------------------*/
     
    272313        if (id != BUFFER_ID)
    273314                return ENOENT;
     315        async_exchange_end(dsp->event_exchange);
    274316        sb_dsp_write(dsp, DMA_16B_EXIT);
    275317        return EOK;
  • uspace/drv/audio/sb16/dsp.h

    r8de7ef2 r7ca22e5  
    5757                uint16_t samples;
    5858        } playing;
     59        async_sess_t *event_session;
     60        async_exch_t *event_exchange;
    5961        ddf_dev_t *sb_dev;
    6062} sb_dsp_t;
     
    6567
    6668int sb_dsp_get_buffer(sb_dsp_t *dsp, void **buffer, size_t *size, unsigned *id);
     69int sb_dsp_set_event_session(sb_dsp_t *dsp, unsigned id, async_sess_t *session);
    6770int sb_dsp_release_buffer(sb_dsp_t *dsp, unsigned id);
    68 int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned id, unsigned sample_rate,
    69     unsigned sample_size, unsigned channels, bool sign);
     71int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned id, unsigned parts,
     72    unsigned sample_rate, unsigned sample_size, unsigned channels, bool sign);
    7073int sb_dsp_stop_playback(sb_dsp_t *dsp, unsigned id);
    7174int sb_dsp_start_record(sb_dsp_t *dsp, unsigned id, unsigned sample_rate,
  • uspace/drv/audio/sb16/pcm_iface.c

    r8de7ef2 r7ca22e5  
    3333 */
    3434
     35#include <async.h>
    3536#include <errno.h>
    3637#include <audio_pcm_buffer_iface.h>
     
    5354        return sb_dsp_get_buffer(dsp, buffer, size, id);
    5455}
     56static int sb_set_event_session(ddf_fun_t *fun, unsigned id, async_sess_t *sess)
     57{
     58        assert(fun);
     59        assert(fun->driver_data);
     60        sb_dsp_t *dsp = fun->driver_data;
     61        return sb_dsp_set_event_session(dsp, id, sess);
     62}
    5563/*----------------------------------------------------------------------------*/
    5664static int sb_release_buffer(ddf_fun_t *fun, unsigned id)
     
    6270}
    6371/*----------------------------------------------------------------------------*/
    64 static int sb_start_playback(ddf_fun_t *fun, unsigned id,
     72static int sb_start_playback(ddf_fun_t *fun, unsigned id, unsigned parts,
    6573    unsigned sample_rate, unsigned sample_size, unsigned channels, bool sign)
    6674{
     
    6977        sb_dsp_t *dsp = fun->driver_data;
    7078        return sb_dsp_start_playback(
    71             dsp, id, sample_rate, sample_size, channels, sign);
     79            dsp, id, parts, sample_rate, sample_size, channels, sign);
    7280}
    7381/*----------------------------------------------------------------------------*/
     
    104112        .get_buffer = sb_get_buffer,
    105113        .release_buffer = sb_release_buffer,
     114        .set_event_session = sb_set_event_session,
    106115
    107116        .start_playback = sb_start_playback,
Note: See TracChangeset for help on using the changeset viewer.