Changeset 01aef43 in mainline


Ignore:
Timestamp:
2011-10-21T16:48:27Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9f351c8
Parents:
1a11a16
Message:

sb16: Add lazy buffer initialization.

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

Legend:

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

    r1a11a16 r01aef43  
    151151
    152152typedef struct dma_controller {
    153         dma_channel_t channel[8];
     153        dma_channel_t channels[8];
    154154        dma_page_regs_t *page_table;
    155155        dma_controller_regs_first_t *first;
     
    157157} dma_controller_t;
    158158
    159 static const dma_controller_t controller_8237 = {
    160         .channel = {
     159static dma_controller_t controller_8237 = {
     160        .channels = {
    161161            { (uint8_t*)0x00, (uint8_t*)0x01, (uint8_t*)0x87 },
    162162            { (uint8_t*)0x02, (uint8_t*)0x03, (uint8_t*)0x83 },
     
    209209        /* Low byte */
    210210        value = pa & 0xff;
    211         pio_write_8(controller->channel[channel].offset_reg_address, value);
     211        pio_write_8(controller->channels[channel].offset_reg_address, value);
    212212
    213213        /* High byte */
    214214        value = (pa >> 8) & 0xff;
    215         pio_write_8(controller->channel[channel].offset_reg_address, value);
     215        pio_write_8(controller->channels[channel].offset_reg_address, value);
    216216
    217217        /* Page address - third byte */
    218218        value = (pa >> 16) & 0xff;
    219         pio_write_8(controller->channel[channel].offset_reg_address, value);
     219        pio_write_8(controller->channels[channel].offset_reg_address, value);
    220220
    221221        /* Set size -- reset flip-flop */
     
    224224        /* Low byte */
    225225        value = size & 0xff;
    226         pio_write_8(controller->channel[channel].offset_reg_address, value);
     226        pio_write_8(controller->channels[channel].offset_reg_address, value);
    227227
    228228        /* High byte */
    229229        value = (size >> 8) & 0xff;
    230         pio_write_8(controller->channel[channel].offset_reg_address, value);
     230        pio_write_8(controller->channels[channel].offset_reg_address, value);
    231231
    232232        /* Unmask DMA request */
     
    253253        /* Low byte */
    254254        value = pa & 0xff;
    255         pio_write_8(controller->channel[channel].offset_reg_address, value);
     255        pio_write_8(controller->channels[channel].offset_reg_address, value);
    256256
    257257        /* High byte */
    258258        value = (pa >> 8) & 0xff;
    259         pio_write_8(controller->channel[channel].offset_reg_address, value);
     259        pio_write_8(controller->channels[channel].offset_reg_address, value);
    260260
    261261        /* Page address - third byte */
    262262        value = (pa >> 16) & 0xff;
    263         pio_write_8(controller->channel[channel].offset_reg_address, value);
     263        pio_write_8(controller->channels[channel].offset_reg_address, value);
    264264
    265265        /* Set size -- reset flip-flop */
     
    268268        /* Low byte */
    269269        value = size & 0xff;
    270         pio_write_8(controller->channel[channel].offset_reg_address, value);
     270        pio_write_8(controller->channels[channel].offset_reg_address, value);
    271271
    272272        /* High byte */
    273273        value = (size >> 8) & 0xff;
    274         pio_write_8(controller->channel[channel].offset_reg_address, value);
     274        pio_write_8(controller->channels[channel].offset_reg_address, value);
    275275
    276276        /* Unmask DMA request */
  • uspace/drv/audio/sb16/dsp.c

    r1a11a16 r01aef43  
    3434
    3535#include <libarch/ddi.h>
     36#include <str_error.h>
    3637
    3738#include "dma.h"
     
    4748
    4849#define DSP_RESET_RESPONSE 0xaa
     50#define SB_DMA_CHAN_16 5
     51#define SB_DMA_CHAN_8 1
    4952
    5053static inline int sb_dsp_read(sb_dsp_t *dsp, uint8_t *data)
     
    9093}
    9194/*----------------------------------------------------------------------------*/
     95static inline int sb_setup_buffer(sb_dsp_t *dsp)
     96{
     97        assert(dsp);
     98        uint8_t *buffer = malloc24(PAGE_SIZE);
     99
     100        const uintptr_t pa = addr_to_phys(buffer);
     101        const int ret = dma_setup_channel(SB_DMA_CHAN_16, pa, PAGE_SIZE);
     102        if (ret == EOK) {
     103                dsp->buffer.buffer_data = buffer;
     104                dsp->buffer.buffer_position = buffer;
     105                dsp->buffer.buffer_size = PAGE_SIZE;
     106        } else {
     107                ddf_log_error("Failed to setup DMA buffer %s.\n",
     108                    str_error(ret));
     109                free24(buffer);
     110        }
     111        return ret;
     112}
     113/*----------------------------------------------------------------------------*/
    92114int sb_dsp_init(sb_dsp_t *dsp, sb16_regs_t *regs)
    93115{
     
    112134        sb_dsp_read(dsp, &dsp->version.major);
    113135        sb_dsp_read(dsp, &dsp->version.minor);
    114         return EOK;
     136
     137        return ret;
    115138}
    116139/*----------------------------------------------------------------------------*/
     
    130153        return EOK;
    131154}
     155/*----------------------------------------------------------------------------*/
     156int sb_dsp_play(sb_dsp_t *dsp, const uint8_t *data, size_t size,
     157    unsigned sampling_rate, unsigned channels, unsigned bit_depth)
     158{
     159        assert(dsp);
     160        if (!data)
     161                return EOK;
     162
     163        /* Check supported parameters */
     164        if (bit_depth != 8 && bit_depth != 16)
     165                return ENOTSUP;
     166        if (channels != 1 && channels != 2)
     167                return ENOTSUP;
     168
     169        const int ret = sb_setup_buffer(dsp);
     170
     171        return ret;
     172}
    132173/**
    133174 * @}
  • uspace/drv/audio/sb16/dsp.h

    r1a11a16 r01aef43  
    4646                uint8_t minor;
    4747        } version;
    48         uint8_t *data_buffer;
    49         uint8_t *buffer_position;
    50         size_t buffer_size;
     48        struct {
     49                uint8_t *buffer_data;
     50                uint8_t *buffer_position;
     51                size_t buffer_size;
     52        } buffer;
    5153} sb_dsp_t;
    5254
    53 
    54 
    55 /*----------------------------------------------------------------------------*/
    5655int sb_dsp_init(sb_dsp_t *dsp, sb16_regs_t *regs);
    57 /*----------------------------------------------------------------------------*/
    5856int sb_dsp_play_direct(sb_dsp_t *dsp, const uint8_t *data, size_t size,
    5957    unsigned sample_rate, unsigned channels, unsigned bit_depth);
     58int sb_dsp_play(sb_dsp_t *dsp, const uint8_t *data, size_t size,
     59    unsigned sample_rate, unsigned channels, unsigned bit_depth);
     60
    6061#endif
    6162/**
Note: See TracChangeset for help on using the changeset viewer.