Changeset bf38143 in mainline
- Timestamp:
- 2011-09-26T15:26:48Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ce1e5ea
- Parents:
- bde691c
- Location:
- uspace/drv/audio/sb16
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/audio/sb16/dsp.c
rbde691c rbf38143 34 34 35 35 #include <libarch/ddi.h> 36 #include "ddf_log.h" 37 #include "dsp_commands.h" 36 38 #include "dsp.h" 37 39 38 int dsp_play_direct(sb16_regs_t *regs, const uint8_t *data, size_t size, 40 41 #ifndef DSP_RETRY_COUNT 42 #define DSP_RETRY_COUNT 100 43 #endif 44 45 #define DSP_RESET_RESPONSE 0xaa 46 47 static inline int sb_dsp_read(sb_dsp_t *dsp, uint8_t *data) 48 { 49 assert(data); 50 assert(dsp); 51 uint8_t status; 52 size_t attempts = DSP_RETRY_COUNT; 53 do { 54 status = pio_read_8(&dsp->regs->dsp_read_status); 55 } while (--attempts && ((status & DSP_READ_READY) == 0)); 56 57 if ((status & DSP_READ_READY) == 0) 58 return EIO; 59 60 *data = pio_read_8(&dsp->regs->dsp_data_read); 61 return EOK; 62 } 63 /*----------------------------------------------------------------------------*/ 64 static inline int sb_dsp_write(sb_dsp_t *dsp, uint8_t data) 65 { 66 assert(dsp); 67 uint8_t status; 68 size_t attempts = DSP_RETRY_COUNT; 69 do { 70 status = pio_read_8(&dsp->regs->dsp_write); 71 } while (--attempts && ((status & DSP_WRITE_BUSY) != 0)); 72 73 if ((status & DSP_WRITE_BUSY)) 74 return EIO; 75 76 pio_write_8(&dsp->regs->dsp_write, data); 77 return EOK; 78 } 79 /*----------------------------------------------------------------------------*/ 80 static inline void sb_dsp_reset(sb_dsp_t *dsp) 81 { 82 assert(dsp); 83 /* Reset DSP, see Chapter 2 of Sound Blaster HW programming guide */ 84 pio_write_8(&dsp->regs->dsp_reset, 1); 85 udelay(3); /* Keep reset for 3 us */ 86 pio_write_8(&dsp->regs->dsp_reset, 0); 87 } 88 /*----------------------------------------------------------------------------*/ 89 int sb_dsp_init(sb_dsp_t *dsp, sb16_regs_t *regs) 90 { 91 assert(dsp); 92 dsp->regs = regs; 93 sb_dsp_reset(dsp); 94 /* "DSP takes about 100 microseconds to initialize itself" */ 95 udelay(100); 96 uint8_t response; 97 const int ret = sb_dsp_read(dsp, &response); 98 if (ret != EOK) { 99 ddf_log_error("Failed to read DSP reset response value.\n"); 100 return ret; 101 } 102 if (response != DSP_RESET_RESPONSE) { 103 ddf_log_error("Invalid DSP reset response: %x.\n", response); 104 return EIO; 105 } 106 107 /* Get DSP version number */ 108 sb_dsp_write(dsp, DSP_VERSION); 109 sb_dsp_read(dsp, &dsp->version.major); 110 sb_dsp_read(dsp, &dsp->version.minor); 111 return EOK; 112 } 113 /*----------------------------------------------------------------------------*/ 114 int sb_dsp_play_direct(sb_dsp_t *dsp, const uint8_t *data, size_t size, 39 115 unsigned sampling_rate, unsigned channels, unsigned bit_depth) 40 116 { 117 assert(dsp); 41 118 if (channels != 1 || bit_depth != 8) 42 119 return EIO; … … 44 121 const unsigned wait_period = 1000000 / sampling_rate; 45 122 while (size--) { 46 pio_write_8(& regs->dsp_write, DIRECT_8B_OUTPUT);47 pio_write_8(& regs->dsp_write, *data++);123 pio_write_8(&dsp->regs->dsp_write, DIRECT_8B_OUTPUT); 124 pio_write_8(&dsp->regs->dsp_write, *data++); 48 125 udelay(wait_period); 49 126 } -
uspace/drv/audio/sb16/dsp.h
rbde691c rbf38143 39 39 40 40 #include "registers.h" 41 #include "dsp_commands.h"42 41 43 #ifndef DSP_PIO_DELAY 44 #define DSP_PIO_DELAY udelay(10) 45 #endif 42 typedef struct sb_dsp_t { 43 sb16_regs_t *regs; 44 struct { 45 uint8_t major; 46 uint8_t minor; 47 } version; 48 uint8_t *data_buffer; 49 uint8_t *buffer_position; 50 size_t buffer_size; 51 } sb_dsp_t; 46 52 47 #ifndef DSP_RETRY_COUNT48 #define DSP_RETRY_COUNT 10049 #endif50 53 51 #define DSP_RESET_RESPONSE 0xaa52 54 53 static inline int dsp_write(sb16_regs_t *regs, uint8_t data)54 {55 uint8_t status;56 size_t attempts = DSP_RETRY_COUNT;57 do {58 DSP_PIO_DELAY;59 status = pio_read_8(®s->dsp_write);60 } while (--attempts && ((status & DSP_WRITE_BUSY) != 0));61 if ((status & DSP_WRITE_BUSY))62 return EIO;63 DSP_PIO_DELAY;64 pio_write_8(®s->dsp_write, data);65 return EOK;66 }67 55 /*----------------------------------------------------------------------------*/ 68 static inline int dsp_read(sb16_regs_t *regs, uint8_t *data) 69 { 70 assert(data); 71 uint8_t status; 72 size_t attempts = DSP_RETRY_COUNT; 73 do { 74 DSP_PIO_DELAY; 75 status = pio_read_8(®s->dsp_read_status); 76 } while (--attempts && ((status & DSP_READ_READY) == 0)); 77 78 if ((status & DSP_READ_READY) == 0) 79 return EIO; 80 81 DSP_PIO_DELAY; 82 *data = pio_read_8(®s->dsp_data_read); 83 return EOK; 84 } 56 int sb_dsp_init(sb_dsp_t *dsp, sb16_regs_t *regs); 85 57 /*----------------------------------------------------------------------------*/ 86 static inline void dsp_reset(sb16_regs_t *regs) 87 { 88 /* Reset DSP, see Chapter 2 of Sound Blaster HW programming guide */ 89 pio_write_8(®s->dsp_reset, 1); 90 udelay(3); /* Keep reset for 3 us */ 91 pio_write_8(®s->dsp_reset, 0); 92 } 93 /*----------------------------------------------------------------------------*/ 94 int dsp_play_direct(sb16_regs_t *regs, const uint8_t *data, size_t size, 58 int sb_dsp_play_direct(sb_dsp_t *dsp, const uint8_t *data, size_t size, 95 59 unsigned sample_rate, unsigned channels, unsigned bit_depth); 96 60 #endif -
uspace/drv/audio/sb16/sb16.c
rbde691c rbf38143 68 68 ddf_log_debug("PIO registers at %p accessible.\n", drv->regs); 69 69 70 dsp_reset(drv->regs); 71 /* "DSP takes about 100 microseconds to initialize itself" */ 72 udelay(100); 73 74 uint8_t response; 75 ret = dsp_read(drv->regs, &response); 70 /* Initialize DSP */ 71 ret = sb_dsp_init(&drv->dsp, drv->regs); 76 72 if (ret != EOK) { 77 ddf_log_error("Failed to read DSP reset response value.\n"); 73 ddf_log_error("Failed to initialize SB DSP: %s.\n", 74 str_error(ret)); 78 75 return ret; 79 76 } 80 81 if (response != DSP_RESET_RESPONSE) {82 ddf_log_error("Invalid DSP reset response: %x.\n", response);83 return EIO;84 }85 86 /* Get DSP version number */87 dsp_write(drv->regs, DSP_VERSION);88 dsp_read(drv->regs, &drv->dsp_version.major);89 dsp_read(drv->regs, &drv->dsp_version.minor);90 77 ddf_log_note("Sound blaster DSP (%x.%x) initialized.\n", 91 drv->dsp _version.major, drv->dsp_version.minor);78 drv->dsp.version.major, drv->dsp.version.minor); 92 79 93 80 /* Initialize mixer */ 94 81 const sb_mixer_type_t mixer_type = sb_mixer_type_by_dsp_version( 95 drv->dsp _version.major, drv->dsp_version.minor);82 drv->dsp.version.major, drv->dsp.version.minor); 96 83 97 84 ret = sb_mixer_init(&drv->mixer, drv->regs, mixer_type); -
uspace/drv/audio/sb16/sb16.h
rbde691c rbf38143 39 39 #include <ddi.h> 40 40 41 #include "dsp.h" 41 42 #include "mixer.h" 42 43 #include "registers.h" … … 45 46 sb16_regs_t *regs; 46 47 mpu_regs_t *mpu_regs; 47 struct { 48 uint8_t major; 49 uint8_t minor; 50 } dsp_version; 48 sb_dsp_t dsp; 51 49 sb_mixer_t mixer; 52 50 } sb16_drv_t;
Note:
See TracChangeset
for help on using the changeset viewer.