Changeset 7257eea6 in mainline


Ignore:
Timestamp:
2011-10-21T19:01:15Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f14e6ea
Parents:
9f351c8
Message:

sb16: Setup both channels (8/16 bit) to the same buffer and set channel mode.

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

Legend:

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

    r9f351c8 r7257eea6  
    6767#define DMA_MODE_CHAN_SELECT_MASK (0x3)
    6868#define DMA_MODE_CHAN_SELECT_SHIFT (0)
     69#define DMA_MODE_CHAN_TO_REG(x) \
     70    (((x % 4) & DMA_MODE_CHAN_SELECT_MASK) << DMA_MODE_CHAN_SELECT_SHIFT)
    6971#define DMA_MODE_CHAN_TRA_MASK (0x3)
    7072#define DMA_MODE_CHAN_TRA_SHIFT (2)
    7173#define DMA_MODE_CHAN_TRA_SELF_TEST (0)
    72 #define DMA_MODE_CHAN_TRA_WRITE (1)
    73 #define DMA_MODE_CHAN_TRA_READ (2)
     74#define DMA_MODE_CHAN_TRA_WRITE (0x1)
     75#define DMA_MODE_CHAN_TRA_READ (0x2)
    7476#define DMA_MODE_CHAN_AUTO_FLAG (1 << 4)
    7577#define DMA_MODE_CHAN_DOWN_FLAG (1 << 5)
     
    216218        if (channel == 0 || channel == 4)
    217219                return ENOTSUP;
    218 
    219220        if (channel > 7)
    220221                return ENOENT;
     
    267268}
    268269/*----------------------------------------------------------------------------*/
    269 int dma_prepare_channel(unsigned channel, bool write, transfer_mode_t mode)
     270int dma_prepare_channel(
     271    unsigned channel, bool write, bool auto_mode, transfer_mode_t mode)
    270272{
     273        if (channel == 0 || channel == 4)
     274                return ENOTSUP;
     275        if (channel > 7)
     276                return ENOENT;
     277
    271278        if (!controller_8237.initialized)
    272279                return EIO;
    273280
    274         return ENOTSUP;
     281        dma_channel_t dma_channel = controller_8237.channels[channel];
     282
     283        /* Mask DMA request */
     284        uint8_t value = DMA_SINGLE_MASK_CHAN_TO_REG(channel)
     285            | DMA_SINGLE_MASK_MASKED_FLAG;
     286        pio_write_8(dma_channel.single_mask_address, value);
     287
     288        /* Set DMA mode */
     289        value = DMA_MODE_CHAN_TO_REG(channel)
     290            | ((write ? DMA_MODE_CHAN_TRA_WRITE : DMA_MODE_CHAN_TRA_READ)
     291                << DMA_MODE_CHAN_TRA_SHIFT)
     292            | (auto_mode ? DMA_MODE_CHAN_AUTO_FLAG : 0)
     293            | (mode << DMA_MODE_CHAN_MOD_SHIFT);
     294        pio_write_8(dma_channel.mode_address, value);
     295
     296        /* Unmask DMA request */
     297        value = DMA_SINGLE_MASK_CHAN_TO_REG(channel);
     298        pio_write_8(dma_channel.single_mask_address, value);
     299
     300        return EOK;
    275301}
    276302/**
  • uspace/drv/audio/sb16/dma_controller.h

    r9f351c8 r7257eea6  
    4545int dma_setup_channel(unsigned channel, uintptr_t pa, size_t size);
    4646
    47 int dma_prepare_channel(unsigned channel, bool write, transfer_mode_t mode);
     47int dma_prepare_channel(
     48    unsigned channel, bool write, bool auto_mode, transfer_mode_t mode);
    4849
    4950#endif
  • uspace/drv/audio/sb16/dsp.c

    r9f351c8 r7257eea6  
    9999
    100100        const uintptr_t pa = addr_to_phys(buffer);
     101        /* Set 16 bit channel */
    101102        const int ret = dma_setup_channel(SB_DMA_CHAN_16, pa, PAGE_SIZE);
    102103        if (ret == EOK) {
     
    104105                dsp->buffer.buffer_position = buffer;
    105106                dsp->buffer.buffer_size = PAGE_SIZE;
     107                dma_prepare_channel(SB_DMA_CHAN_16, false, true, BLOCK_DMA);
     108                /* Set 8bit channel */
     109                const int ret = dma_setup_channel(SB_DMA_CHAN_8, pa, PAGE_SIZE);
     110                if (ret == EOK) {
     111                        dma_prepare_channel(
     112                            SB_DMA_CHAN_8, false, true, BLOCK_DMA);
     113                }
    106114        } else {
    107115                ddf_log_error("Failed to setup DMA buffer %s.\n",
     
    110118        }
    111119        return ret;
     120}
     121/*----------------------------------------------------------------------------*/
     122static inline void sb_clear_buffer(sb_dsp_t *dsp)
     123{
     124        free24(dsp->buffer.buffer_data);
     125        dsp->buffer.buffer_data = NULL;
     126        dsp->buffer.buffer_position = NULL;
     127        dsp->buffer.buffer_size = 0;
    112128}
    113129/*----------------------------------------------------------------------------*/
     
    155171/*----------------------------------------------------------------------------*/
    156172int sb_dsp_play(sb_dsp_t *dsp, const uint8_t *data, size_t size,
    157     unsigned sampling_rate, unsigned channels, unsigned bit_depth)
     173    uint16_t sampling_rate, unsigned channels, unsigned bit_depth)
    158174{
    159175        assert(dsp);
  • uspace/drv/audio/sb16/dsp.h

    r9f351c8 r7257eea6  
    5757    unsigned sample_rate, unsigned channels, unsigned bit_depth);
    5858int sb_dsp_play(sb_dsp_t *dsp, const uint8_t *data, size_t size,
    59     unsigned sample_rate, unsigned channels, unsigned bit_depth);
     59    uint16_t sample_rate, unsigned channels, unsigned bit_depth);
    6060
    6161#endif
Note: See TracChangeset for help on using the changeset viewer.