aboutsummaryrefslogtreecommitdiff
path: root/KSDK_1.2.0/platform/composite/src/soundcard/fsl_soundcard.c
blob: 8edeeb91a85a3982be8bff7abc43ee9a03796469 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
/*
 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


#include "fsl_soundcard.h"
#include <assert.h>
#include <string.h>
#include "fsl_os_abstraction.h"

/*******************************************************************************
 *Definitation
 ******************************************************************************/
#if SOUNDCARD_USE_STATIC_MEM
#if defined( __ICCCF__ ) || defined( __ICCARM__ )
#pragma segment="SAI_BDT_Z"
#pragma data_alignment=4
__no_init static uint8_t s_tx_buffer[AUDIO_CONTROLLER_NUM][AUDIO_BUFFER_SIZE] @ "SAI_BDT_Z";
__no_init static uint8_t s_rx_buffer[AUDIO_CONTROLLER_NUM][AUDIO_BUFFER_SIZE] @ "SAI_BDT_Z";
#elif defined(__GNUC__)
__attribute__((aligned(4))) static uint8_t s_tx_buffer[AUDIO_CONTROLLER_NUM][AUDIO_BUFFER_SIZE];
__attribute__((aligned(4))) static uint8_t s_rx_buffer[AUDIO_CONTROLLER_NUM][AUDIO_BUFFER_SIZE];
#elif defined (__CC_ARM)
__align(4) static uint8_t s_tx_buffer[AUDIO_CONTROLLER_NUM][AUDIO_BUFFER_SIZE];
__align(4) static uint8_t s_rx_buffer[AUDIO_CONTROLLER_NUM][AUDIO_BUFFER_SIZE];
#endif
#endif

#if USEDMA
void SND_TxDmaCallback(void *param, edma_chn_status_t status);
void SND_RxDmaCallback(void *param, edma_chn_status_t status);
#else
void SND_TxCallback(void *param);
void SND_RxCallback(void *param);
#endif

/* The instance for sai operation structure. */
audio_ctrl_operation_t g_sai_ops =
{
    SAI_DRV_TxInit,
    SAI_DRV_RxInit,
    SAI_DRV_TxDeinit,
    SAI_DRV_RxDeinit,
    SAI_DRV_TxConfigDataFormat,
    SAI_DRV_RxConfigDataFormat,
    SAI_DRV_TxStartModule,
    SAI_DRV_RxStartModule,
    SAI_DRV_TxStopModule,
    SAI_DRV_RxStopModule,
    SAI_DRV_TxRegisterCallback,
    SAI_DRV_RxRegisterCallback,
    SAI_DRV_TxSetIntCmd,
    SAI_DRV_RxSetIntCmd,
    SAI_DRV_TxSetDmaCmd,
    SAI_DRV_RxSetDmaCmd,
    SAI_DRV_TxGetWatermark,
    SAI_DRV_RxGetWatermark,
    SAI_DRV_TxGetFifoAddr,
    SAI_DRV_RxGetFifoAddr,
    SAI_DRV_SendDataInt,
    SAI_DRV_ReceiveDataInt
};

/* Instance of codec operation for sgtl5000. */
audio_codec_operation_t g_sgtl_ops =
{
    SGTL_Init,
    SGTL_Deinit,
    SGTL_ConfigDataFormat,
    SGTL_SetDACMute,
    SGTL_SetDACVoulme,
    SGTL_GetDACVolume
};

/*******************************************************************************
 *Code
 ******************************************************************************/

/*FUNCTION**********************************************************************
*
* Function Name : SND_TxInit
* Description	: Initialize the soundcard.
*  The soundcard includes a controller and a codec.
*END**************************************************************************/
snd_status_t SND_TxInit(
    sound_card_t * card, void * ctrl_config, void * codec_config, ctrl_state_t *state)
{
    audio_controller_t *ctrl = &card->controller;
    audio_codec_t *codec = &card->codec;
    /* Allocate space for buffer */
    audio_buffer_t *buffer = &card->buffer;
    /* Buffer size and block settings */
    if ((buffer->blocks == 0) || (buffer->size == 0))
    {
        buffer->blocks = AUDIO_BUFFER_BLOCK;
        buffer->size = AUDIO_BUFFER_BLOCK_SIZE;
    }
#if SOUNDCARD_USE_STATIC_MEM
    buffer->buff = &s_tx_buffer[ctrl->instance][0];
#else
    buffer->buff = (uint8_t *)OSA_MemAllocZero(buffer->size * buffer->blocks);
    if(!buffer->buff)
    {
        return kStatus_SND_BufferAllocateFail;
    }
#endif
    buffer->input_curbuff = buffer->buff;
    buffer->output_curbuff = buffer->buff;
    /* Initialize the status structure */
    buffer->empty_block = buffer->blocks;
    buffer->full_block = 0;
    OSA_SemaCreate(&buffer->sem, buffer->blocks); 
    /* Initialize audio controller and codec */
    ctrl->ops->Ctrl_TxInit(ctrl->instance, ctrl_config, state);
    codec->ops->Codec_Init((void *)codec->handler, codec_config);
#if USEDMA
    EDMA_DRV_RequestChannel(kEDMAAnyChannel, ctrl->dma_source, &ctrl->dma_channel);
    EDMA_DRV_InstallCallback(&ctrl->dma_channel, SND_TxDmaCallback, (void *)card);
#else
    ctrl->ops->Ctrl_TxRegisterCallback(ctrl->instance,  SND_TxCallback, card);
#endif   
    return kStatus_SND_Success;
}

/*FUNCTION**********************************************************************
*
* Function Name : SND_RxInit
* Description	: Initialize the Rx soundcard.
*  The soundcard includes a controller and a codec.
*END**************************************************************************/
snd_status_t SND_RxInit(
sound_card_t * card, void * ctrl_config, void * codec_config, ctrl_state_t *state)
{
    audio_controller_t *ctrl = &card->controller;
    audio_codec_t *codec = &card->codec;
    /* Allocate space for buffer */
    audio_buffer_t *buffer = &card->buffer;
    /* Buffer size and block settings */
    if ((buffer->blocks == 0) || (buffer->size == 0))
    {
        buffer->blocks = AUDIO_BUFFER_BLOCK;
        buffer->size = AUDIO_BUFFER_BLOCK_SIZE;
    }
#if SOUNDCARD_USE_STATIC_MEM
    buffer->buff = &s_rx_buffer[ctrl->instance][0];
#else
    buffer->buff = (uint8_t *)OSA_MemAllocZero(buffer->size * buffer->blocks);
    if(!buffer->buff)
    {
        return kStatus_SND_BufferAllocateFail;
    }
#endif
    buffer->input_curbuff = buffer->buff;
    buffer->output_curbuff = buffer->buff;
    /* Initialize the status structure */
    buffer->empty_block = buffer->blocks;
    buffer->full_block = 0;
    OSA_SemaCreate(&buffer->sem, 0);
    /* Initialize audio controller and codec */
    ctrl->ops->Ctrl_RxInit(ctrl->instance, ctrl_config,state);
    codec->ops->Codec_Init((void *)codec->handler, codec_config);
#if USEDMA
    EDMA_DRV_RequestChannel(kEDMAAnyChannel, ctrl->dma_source, &ctrl->dma_channel);
    EDMA_DRV_InstallCallback(&ctrl->dma_channel, SND_RxDmaCallback, (void *)card);
#else
    ctrl->ops->Ctrl_RxRegisterCallback(ctrl->instance,  SND_RxCallback, card);
#endif   
    return kStatus_SND_Success;
}

/*FUNCTION*********************************************************************
*
* Function Name : SND_TxDeinit
* Description	: Deinit the tx soundcard.
*  The soundcard includes a controller and a codec.
*END**************************************************************************/
snd_status_t SND_TxDeinit(sound_card_t *card)
{
    audio_controller_t *ctrl = &card->controller;
    audio_codec_t *codec = &card->codec;
    audio_buffer_t *buffer = &card->buffer;
    /* Call the deinit function of the ctrl and codec. */
    ctrl->ops->Ctrl_TxDeinit(ctrl->instance);
    codec->ops->Codec_Deinit((void *)codec->handler);
#if USEDMA
    /* Deinit the dma resource */
    EDMA_DRV_StopChannel(&ctrl->dma_channel);
    EDMA_DRV_ReleaseChannel(&ctrl->dma_channel);
#endif
    OSA_SemaDestroy(&buffer->sem);
#if !SOUNDCARD_USE_STATIC_MEM
    /* Free the tx and rx buffer. */
    OSA_MemFree(buffer->buff);
#endif
    return kStatus_SND_Success;
}

/*FUNCTION*********************************************************************
*
* Function Name : SND_RxDeinit
* Description	: Deinit the rx soundcard.
*  The soundcard includes a controller and a codec.
*END**************************************************************************/
snd_status_t SND_RxDeinit(sound_card_t *card)
{
    audio_controller_t *ctrl = &card->controller;
    audio_codec_t *codec = &card->codec;
    audio_buffer_t *buffer = &card->buffer;
    /* Call the deinit function of the ctrl and codec. */
    ctrl->ops->Ctrl_RxDeinit(ctrl->instance);
    codec->ops->Codec_Deinit((void *)codec->handler);
#if USEDMA
    /* Deinit the dma resource */
    EDMA_DRV_StopChannel(&ctrl->dma_channel);
    EDMA_DRV_ReleaseChannel(&ctrl->dma_channel);
#endif
    OSA_SemaDestroy(&buffer->sem);
#if !SOUNDCARD_USE_STATIC_MEM
    /* Free the tx and rx buffer. */
    OSA_MemFree(buffer->buff);
#endif
    return kStatus_SND_Success;
}

/*FUNCTION**********************************************************************
*
* Function Name : SND_TxConfigDataFormat
* Description	: Configure the audio file format in tx soundcard.
*  The soundcard includes a controller and a codec. The audio format includes 
*  sample rate, bit length and so on.
*END**************************************************************************/
snd_status_t SND_TxConfigDataFormat(sound_card_t *card, ctrl_data_format_t *format)
{
    audio_controller_t *ctrl = &card->controller;
    audio_codec_t *codec = &card->codec;

    ctrl->ops->Ctrl_TxConfigDataFormat(ctrl->instance, format);
    codec->ops->Codec_ConfigDataFormat(codec->handler, format->mclk, format->sample_rate, 
                                                                    format->bits);
    /* Configure dma */
#if USEDMA
    audio_buffer_t *buffer = &card->buffer;
    uint32_t watermark = ctrl->ops->Ctrl_TxGetWatermark(ctrl->instance);
    uint8_t sample_size = format->bits/8;
    if((sample_size == 3) || (format->bits & 0x7))
    {
        sample_size = 4;
    }
    uint32_t desAddr = ctrl->ops->Ctrl_TxGetFifoAddr(ctrl->instance, ctrl->fifo_channel);
    EDMA_DRV_ConfigLoopTransfer(
            &ctrl->dma_channel, ctrl->stcd, kEDMAMemoryToPeripheral,
            (uint32_t)buffer->buff, (uint32_t)desAddr, sample_size,
            sample_size * (AUDIO_FIFO_LEN -watermark) , AUDIO_BUFFER_SIZE, AUDIO_BUFFER_BLOCK);
    EDMA_DRV_StartChannel(&ctrl->dma_channel); 
#endif
    return kStatus_SND_Success;
}

/*FUNCTION**********************************************************************
*
* Function Name : SND_RxConfigDataFormat
* Description	: Configure the audio file format in rx soundcard.
*  The soundcard includes a controller and a codec. The audio format includes 
*  sample rate, bit length and so on.
*END**************************************************************************/
snd_status_t SND_RxConfigDataFormat(sound_card_t *card, ctrl_data_format_t *format)
{
    audio_controller_t *ctrl = &card->controller;
    audio_codec_t *codec = &card->codec;

    ctrl->ops->Ctrl_RxConfigDataFormat(ctrl->instance, format);
    codec->ops->Codec_ConfigDataFormat(codec->handler, format->mclk, format->sample_rate, 
                                                                    format->bits);
    /* Configure dma */
#if USEDMA
    audio_buffer_t *buffer = &card->buffer;
    uint8_t sample_size = format->bits/8;
    uint32_t watermark = ctrl->ops->Ctrl_RxGetWatermark(ctrl->instance);
    if((sample_size == 3) || (format->bits & 0x7))
    {
        sample_size = 4;
    }
    uint32_t desAddr = ctrl->ops->Ctrl_RxGetFifoAddr(ctrl->instance,ctrl->fifo_channel);
    EDMA_DRV_ConfigLoopTransfer(
            &ctrl->dma_channel, ctrl->stcd, kEDMAPeripheralToMemory,
             (uint32_t)desAddr, (uint32_t)buffer->buff, sample_size,
            sample_size * watermark, AUDIO_BUFFER_SIZE, AUDIO_BUFFER_BLOCK);
    EDMA_DRV_StartChannel(&ctrl->dma_channel);
#endif
    return kStatus_SND_Success;
}

/*FUNCTION**********************************************************************
*
* Function Name : SND_TxUpdateStatus
* Description	: Update the status of tx soundcard internal logic
* The function would tell tx soundcard how many data applications have written
* to the ring buffer.
*END**************************************************************************/
uint32_t SND_TxUpdateStatus(sound_card_t * card, uint32_t len)
{
    audio_buffer_t * buffer = &card->buffer;
    uint32_t blocks = len/buffer->size;
    /* Update the buffer information */
    buffer->requested += len;
    buffer->queued += len;

    if(buffer->input_index + blocks < buffer->blocks)
    {
        buffer->input_index += blocks;
    }
    else
    {
        buffer->input_index = blocks - (buffer->blocks - 1 - buffer->input_index) - 1;
    }
    buffer->input_curbuff = buffer->buff + buffer->input_index * buffer->size;
    buffer->empty_block -= blocks;
    buffer->full_block += blocks;
    /* If sai is not enable, enable the sai */
    if (buffer->first_io)
    {
        buffer->first_io = false;
        SND_TxStart(card);
    }
    return len;
}

/*FUNCTION**********************************************************************
*
* Function Name : SND_RxUpdateStatus
* Description	: Update the status of rx soundcard internal logic
* The function would tell rx soundcard how many data applications have received
* from the ring buffer.
*END**************************************************************************/
uint32_t SND_RxUpdateStatus(sound_card_t * card, uint32_t len)
{
    audio_buffer_t * buffer = &card->buffer;
    uint32_t blocks = len/buffer->size;
    /* Update inner information */
    buffer->requested += len;
    buffer->processed += len;
    buffer->queued -= len;
    /* Switch the buffer */
    if(buffer->output_index + blocks < buffer->blocks)
    {
        buffer->output_index += blocks;
    }
    else
    {
        buffer->output_index = blocks - (buffer->blocks - 1 - buffer->output_index) - 1;
    }
    buffer->output_curbuff = buffer->buff + buffer->output_index * buffer->size;
    buffer->full_block -= blocks;
    buffer->empty_block += blocks;  
    /* If sai is not enable, enable the sai */
    if (buffer->first_io)
    {
        buffer->first_io = false;
        SND_RxStart(card);
    }
    return len;
}

/*FUNCTION**********************************************************************
*
* Function Name : SND_TxCallback
* Description	: Callback function to tell that audio controller have finished 
* a period data.
* The function would update the buffer status information.
*END**************************************************************************/
void SND_TxCallback(void *param)
{
    sound_card_t *card = (sound_card_t *)param;
    audio_buffer_t *buffer = &card->buffer;
    if(buffer->queued == 0)
    {
        return;
    }
    buffer->processed += buffer->size;
    buffer->queued -= buffer->size;

    /* Change the current buffer */
    if (buffer->output_index == buffer->blocks - 1)
    {
        buffer->output_curbuff = buffer->buff;
        buffer->output_index = 0;
    }
    else
    {
        buffer->output_index ++;
        buffer->output_curbuff += buffer->size;
    }
    /* Update the status */
    buffer->empty_block += 1;
    buffer->full_block -= 1;
    /* Judge if need to close the SAI transfer. */
    if (buffer->input_index == buffer->output_index)
    {
        SND_TxStop(card);
        buffer->buffer_error ++;
        buffer->first_io = true;
    }
    else
    {
#if !USEDMA
    audio_controller_t * ctrl = &card->controller;
    ctrl->ops->Ctrl_SendData(ctrl->instance, buffer->output_curbuff, buffer->size);
#endif
    }
    /* post the sync */
    OSA_SemaPost(&buffer->sem);
}

/*FUNCTION**********************************************************************
*
* Function Name : SND_RxCallback
* Description	: Callback function to tell that audio controller have finished
*  a period data.
* The function would update the buffer status information.
*END**************************************************************************/
void SND_RxCallback(void *param)
{
    sound_card_t *card = (sound_card_t *)param;
    audio_buffer_t *buffer = &card->buffer;
    buffer->queued += buffer->size;
    /* Change the current buffer. */
    if (buffer->input_index == buffer->blocks - 1)
    {  
        buffer->input_curbuff = buffer->buff;
        buffer->input_index = 0;
    }
    else
    {
        buffer->input_index ++;
        buffer->input_curbuff += buffer->size;
    }
    buffer->empty_block -= 1;
    buffer->full_block += 1;
    /* Judge if need to close the SAI transfer, while the buffer is full, 
     * we need to close the SAI */
    if (buffer->input_index == buffer->output_index)
    {
        SND_RxStop(card);
        buffer->buffer_error ++;
        buffer->first_io = true;
    }
    else
     {
#if !USEDMA
    audio_controller_t *ctrl = &card->controller;
    ctrl->ops->Ctrl_ReceiveData(ctrl->instance, buffer->input_curbuff, buffer->size);
#endif
    }
    OSA_SemaPost(&buffer->sem);
}

/*FUNCTION**********************************************************************
 *
 * Function Name : SND_GetStatus
 * Description   : Get the status of audio buffer, the status includes the empty
 *  blocks, full blocks and the starting address.
 *END**************************************************************************/
 void SND_GetStatus(sound_card_t *card, snd_state_t *status)
{
    audio_buffer_t *buffer = &card->buffer;
    status->size = buffer->size;
    status->empty_block = buffer->empty_block;
    status->full_block = buffer->full_block;
    status->input_address = buffer->input_curbuff;
    status->output_address = buffer->output_curbuff;
}

/*FUNCTION**********************************************************************
 *
 * Function Name : SND_WaitEvent
 * Description   : This function is used for appliaction to wait for the semaphore
 * to copy data in/out the sai buffer.
 *END**************************************************************************/
void SND_WaitEvent(sound_card_t *card)
{
    osa_status_t syncStatus;
    audio_buffer_t *buffer = &card->buffer;
    do
    {
        syncStatus = OSA_SemaWait(&buffer->sem, OSA_WAIT_FOREVER);
    }while(syncStatus == kStatus_OSA_Idle);
}

/*FUNCTION**********************************************************************
 *
 * Function Name : SND_TxStart
 * Description   : This function is used to start tx transfer.
 *END**************************************************************************/
void SND_TxStart(sound_card_t *card)
{
    audio_controller_t *ctrl = &card->controller;
#if !USEDMA
    audio_buffer_t *buffer = &card->buffer;
    ctrl->ops->Ctrl_SendData(ctrl->instance, buffer->output_curbuff, buffer->size);
    ctrl->ops->Ctrl_TxSetIntCmd(ctrl->instance, true);
#else
    ctrl->ops->Ctrl_TxSetDmaCmd(ctrl->instance,true);
    EDMA_DRV_StartChannel(&card->controller.dma_channel);
#endif
    ctrl->ops->Ctrl_TxStart(ctrl->instance);
}

/*FUNCTION**********************************************************************
 *
 * Function Name : SND_RxStart
 * Description   : This function is used to start rx receive.
 *END**************************************************************************/
void SND_RxStart(sound_card_t *card)
{
    audio_controller_t *ctrl = &card->controller;
#if !USEDMA
    audio_buffer_t *buffer = &card->buffer;
    ctrl->ops->Ctrl_ReceiveData(ctrl->instance, buffer->input_curbuff, buffer->size);
    ctrl->ops->Ctrl_RxSetIntCmd(ctrl->instance, true);
#else
    ctrl->ops->Ctrl_RxSetDmaCmd(ctrl->instance,true);
    EDMA_DRV_StartChannel(&card->controller.dma_channel);
#endif
    ctrl->ops->Ctrl_RxStart(ctrl->instance);
}

/*FUNCTION**********************************************************************
 *
 * Function Name : SND_SetMuteCmd
 * Description   : This function is used to mute or unmute the soundcard.
 *END**************************************************************************/
snd_status_t SND_SetMuteCmd(sound_card_t * card,bool enable)
{
    audio_codec_t *codec = &card->codec;
    codec->ops->Codec_SetMuteCmd(codec->handler, enable);
    return kStatus_SND_Success;
}

/*FUNCTION**********************************************************************
 *
 * Function Name : SND_SetVolume
 * Description   : This function is used to set the volume of soundcard.
 *END**************************************************************************/
snd_status_t SND_SetVolume(sound_card_t * card,uint32_t volume)
{
    audio_codec_t *codec = &card->codec;
    codec->ops->Codec_SetMuteCmd(codec->handler, false);
    codec->ops->Codec_SetVolume(codec->handler,volume);
    return kStatus_SND_Success;
}

/*FUNCTION**********************************************************************
 *
 * Function Name : SND_GetVolume
 * Description   : This function is used to get the volume of soundcard.
 *END**************************************************************************/
uint32_t SND_GetVolume(sound_card_t * card)
{
    audio_codec_t *codec = &card->codec;
    return codec->ops->Codec_GetVolume(codec->handler);
}

/*FUNCTION**********************************************************************
 *
 * Function Name : SND_TxDmaCallback
 * Description   : This function is as the tx callback function registered to dma module.
 *END**************************************************************************/
void SND_TxDmaCallback(void *param, edma_chn_status_t status)
{
    SND_TxCallback(param);
}

/*FUNCTION**********************************************************************
 *
 * Function Name : SND_RxDmaCallback
 * Description   : This function is as the rx callback function registered to dma module.
 *END**************************************************************************/
void SND_RxDmaCallback(void *param, edma_chn_status_t status)
{
    SND_RxCallback(param);    
}

/*******************************************************************************
 *EOF
 ******************************************************************************/