* @brief Init audio pipe * * In kernel, this function will set replay or record function depending on device * flag. For replaying, it will malloc for managing audio replay struct meanwhile * creating mempool and dataqueue.For recording, it will creat audio pipe and * it's ringbuffer. * In driver, this function will only execute hardware driver initialization code * and get hardware buffer
| 284 | * @return error code, RT_EOK is successful otherwise means failure |
| 285 | */ |
| 286 | static rt_err_t _audio_dev_init(struct rt_device *dev) |
| 287 | { |
| 288 | rt_err_t result = RT_EOK; |
| 289 | struct rt_audio_device *audio; |
| 290 | |
| 291 | RT_ASSERT(dev != RT_NULL); |
| 292 | audio = (struct rt_audio_device *) dev; |
| 293 | |
| 294 | /* initialize replay & record */ |
| 295 | audio->replay = RT_NULL; |
| 296 | audio->record = RT_NULL; |
| 297 | |
| 298 | /* initialize replay */ |
| 299 | if (dev->flag & RT_DEVICE_FLAG_WRONLY) |
| 300 | { |
| 301 | struct rt_audio_replay *replay = (struct rt_audio_replay *) rt_malloc(sizeof(struct rt_audio_replay)); |
| 302 | |
| 303 | if (replay == RT_NULL) |
| 304 | return -RT_ENOMEM; |
| 305 | rt_memset(replay, 0, sizeof(struct rt_audio_replay)); |
| 306 | |
| 307 | /* init memory pool for replay */ |
| 308 | replay->mp = rt_mp_create("adu_mp", RT_AUDIO_REPLAY_MP_BLOCK_COUNT, RT_AUDIO_REPLAY_MP_BLOCK_SIZE); |
| 309 | if (replay->mp == RT_NULL) |
| 310 | { |
| 311 | rt_free(replay); |
| 312 | LOG_E("create memory pool for replay failed"); |
| 313 | return -RT_ENOMEM; |
| 314 | } |
| 315 | |
| 316 | /* init queue for audio replay */ |
| 317 | rt_data_queue_init(&replay->queue, CFG_AUDIO_REPLAY_QUEUE_COUNT, 0, RT_NULL); |
| 318 | |
| 319 | /* init mutex lock for audio replay */ |
| 320 | rt_mutex_init(&replay->lock, "replay", RT_IPC_FLAG_PRIO); |
| 321 | |
| 322 | replay->activated = RT_FALSE; |
| 323 | audio->replay = replay; |
| 324 | } |
| 325 | |
| 326 | /* initialize record */ |
| 327 | if (dev->flag & RT_DEVICE_FLAG_RDONLY) |
| 328 | { |
| 329 | struct rt_audio_record *record = (struct rt_audio_record *) rt_malloc(sizeof(struct rt_audio_record)); |
| 330 | rt_uint8_t *buffer; |
| 331 | |
| 332 | if (record == RT_NULL) |
| 333 | return -RT_ENOMEM; |
| 334 | rt_memset(record, 0, sizeof(struct rt_audio_record)); |
| 335 | |
| 336 | /* init pipe for record*/ |
| 337 | buffer = rt_malloc(RT_AUDIO_RECORD_PIPE_SIZE); |
| 338 | if (buffer == RT_NULL) |
| 339 | { |
| 340 | rt_free(record); |
| 341 | LOG_E("malloc memory for for record pipe failed"); |
| 342 | return -RT_ENOMEM; |
| 343 | } |
nothing calls this directly
no test coverage detected