TI中文支持网
TI专业的中文技术问题搜集分享网站

cc2640r2f i2s的使用問題

各位好:

在2640r2f调试音频wm8978芯片的时候碰到问题,使用协议栈1.4

示波器看bclk wclk sdin (sdin为wm8978 i2s数据输出)均有输出波形,但是我在回调中一直没有进去,使用的是i2s的原例程移植,附上部分初始化代码以及操作过程,感谢!!

static I2SCC26XX_Params i2sParams =
{
    .requestMode            = I2SCC26XX_CALLBACK_MODE,
    .ui32requestTimeout     = BIOS_WAIT_FOREVER,
    .callbackFxn            = i2sCallbackFxn,
    .blockSize              = FRAME_SIZE,
    .pvContBuffer           = (void *)i2sSampleBuffer,
    .ui32conBufTotalSize    = (sizeof(int16_t) * I2S_SAMPLE_MEMORY_SZ),
    .pvContMgtBuffer        = (void *)i2sQueueMemory,
    .ui32conMgtBufTotalSize = I2S_TOTAL_QUEUE_MEM_SZ,
    .currentStream          = &i2sStream
};
/*
 *  ======== i2sCallbackFxn ========
 */
volatile uint8_t event_id_8978=0;
static void i2sCallbackFxn(I2SCC26XX_Handle handle,
                            I2SCC26XX_StreamNotification *notification)
{
    if (notification->status == I2SCC26XX_STREAM_ERROR)
    {
        /* I2S_ERROR_EVENT */
        event_id_8978  |= 0x01;
    //    Event_post(i2sTaskEvent, I2S_ERROR_EVENT);
    }
    else if (notification->status ==I2SCC26XX_STREAM_BUFFER_READY_BUT_NO_AVAILABLE_BUFFERS )
    {
        /* I2S_FRAME_EVENT */
     //   Event_post(i2sTaskEvent, I2S_FRAME_EVENT);
         event_id_8978  |= 0x02;
    }
    else if (notification->status ==                                            \
                I2SCC26XX_STREAM_BUFFER_READY)
    {
        /* I2S_FRAME_EVENT */
        event_id_8978  |= 0x04;
    }
}
uint8_t wm8978_i2s_init()
{
     i2sHandle = (I2SCC26XX_Handle)&(I2SCC26XX_config);
    I2SCC26XX_init(i2sHandle);
    I2SCC26XX_Handle i2sHandleTmp = NULL;
    i2sHandleTmp = I2SCC26XX_open(i2sHandle, &i2sParams);
    if(i2sHandleTmp == NULL)
    {
       // Display_printf(dispHandle, 3,0,
                        //"Can't open I2S, check memory allocation");
        return false;
    }
    
    return true;
}
uint8_t start_wm8978_stream()
{
    return I2SCC26XX_startStream(i2sHandle);
}
uint8_t start_wm8978_request()
{
  if(event_id_8978 == 0)
  {
    return false;
  }else
      {
    if(event_id_8978 & 0x01)
    {
        I2SCC26XX_stopStream(i2sHandle);
        event_id_8978 &= ~0x01;
        
    }
    if(event_id_8978 & 0x02)
    {
      /* Stop the stream if an error occurred */
        I2SCC26XX_stopStream(i2sHandle);
        event_id_8978 &= ~0x02;
    }
    if(event_id_8978 & 0x04)
    {
        
        /* Since we are looping back, request input and output buffer */
#if 1
        I2SCC26XX_BufferRequest bufferRequest;
        I2SCC26XX_BufferRelease bufferRelease;
        bufferRequest.buffersRequested =I2SCC26XX_BUFFER_IN;// I2SCC26XX_BUFFER_IN_AND_OUT;
        
        bool gotBuffer = I2SCC26XX_requestBuffer(i2sHandle,
                                                 &bufferRequest);
        
        /* If we received a buffer, pass to output stream */
        if(gotBuffer)
        {
            /* Do frame specific processing here */
            
            /* Copy the frame directly to the output buffer */
            memcpy(bufferRequest.bufferOut, bufferRequest.bufferIn,
                   FRAME_SIZE*sizeof(uint16_t));
        }else
        {
          event_id_8978 &= ~0x04;
        }
        
        /* Release the buffer back to the I2S driver */
        bufferRelease.bufferHandleIn = bufferRequest.bufferHandleIn;
        bufferRelease.bufferHandleOut = bufferRequest.bufferHandleOut;
        bufferRelease.bufferHandleOut  = NULL;
        I2SCC26XX_releaseBuffer(i2sHandle, &bufferRelease);
#endif
        
        return true;
    }
    return true;
    
  }
  
}
Viki Shi:

协议栈太旧了,现在已经是3.20版本了,修复了以前的很多bug,建议在新版本协议栈上测试

admin admin1:

回复 Viki Shi:

你好,谢谢回复

我把协议栈更新成3.2版本的,使用例程,但是在read callback中我打了断点,刚开始运行时会进去几次,后面就进不去了。

另外,这里readBuf的数据长度如果像例程那样,会一直报ICALL error,这个是否是内存设置问题,如果是又如何避免这个错误?

附上现在使用的方式,非常期望解答,感谢!

static I2S_Handle i2sHandle;
static I2S_Config i2sConfig;

static uint16_t readBuf1[50]; // the data read will end up in this buffer 500
static uint16_t readBuf2[50]; // the data read will end up in this buffer 500
static uint16_t readBuf3[50]; // the data read will end up in this buffer 500
static uint16_t writeBuf1[25] = {0}; // this buffer will be sent out 250
static uint16_t writeBuf2[25] = {0}; // this buffer will be sent out 250
static uint16_t writeBuf3[25] = {0}; // this buffer will be sent out 250

static I2S_Transaction i2sRead1;
static I2S_Transaction i2sRead2;
static I2S_Transaction i2sRead3;
static I2S_Transaction i2sWrite1;
static I2S_Transaction i2sWrite2;
static I2S_Transaction i2sWrite3;

List_List i2sReadList;
List_List i2sWriteList;

static volatile bool readStopped = (bool)true;
static volatile bool writeStopped = (bool)true;

static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {

    if(status & I2S_ALL_TRANSACTIONS_SUCCESS){

        // Note: Here we do not queue new transfers or set a new queue-head.
        // The driver will stop sending out data on its own.
        writeStopped = (bool)true;
    }
}

static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {

    if(status & I2S_ALL_TRANSACTIONS_SUCCESS){

        // Note: Here we do not queue new transfers or set a new queue-head.
        // The driver will stop receiving data on its own.
        readStopped = (bool)true;
    }
}

static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {

    // Handle the I2S error
}

uint8_t wm8978_i2s_init()
{
      I2S_Params i2sParams;

    I2S_init();

    // Initialize I2S opening parameters
    I2S_Params_init(&i2sParams);
    i2sParams.fixedBufferLength     =  50;//500; // fixedBufferLength is the greatest common
                                            // divisor of all the different buffers
                                            // (here buffers' size are 500 and 1000 bytes)
    i2sParams.writeCallback         =  writeCallbackFxn ;
    i2sParams.readCallback          =  readCallbackFxn ;
    i2sParams.errorCallback         =  errCallbackFxn;
    i2sParams.samplingEdge          = I2S_SAMPLING_EDGE_FALLING;
    i2sParams.SD1Use = I2S_SD1_INPUT;
    i2sParams.SD1Channels = I2S_CHANNELS_MONO;
    i2sParams.SD0Use = I2S_SD0_OUTPUT;
    i2sParams.SD0Channels = I2S_CHANNELS_MONO;
    i2sParams.phaseType = I2S_PHASE_TYPE_DUAL;
    i2sParams.fixedBufferLength = 2;
    i2sParams.isMSBFirst = true;
    i2sParams.moduleRole = I2S_MASTER;
    i2sParams.memorySlotLength = I2S_MEMORY_LENGTH_16BITS;        
    i2sParams.beforeWordPadding = 1;
    i2sParams.afterWordPadding  =1;
    i2sParams.bitsPerWord = 16;
    
    i2sHandle = I2S_open(Board_I2S0, &i2sParams);

    // Initialize the read-transactions
    I2S_Transaction_init(&i2sRead1);
    I2S_Transaction_init(&i2sRead2);
    I2S_Transaction_init(&i2sRead3);
    i2sRead1.bufPtr            = readBuf1;
    i2sRead2.bufPtr            = readBuf2;
    i2sRead3.bufPtr            = readBuf3;
    i2sRead1.bufSize           = sizeof(readBuf1);
    i2sRead2.bufSize           = sizeof(readBuf2);
    i2sRead3.bufSize           = sizeof(readBuf3);
    List_put(&i2sReadList, (List_Elem*)&i2sRead1);
    List_put(&i2sReadList, (List_Elem*)&i2sRead2);
    List_put(&i2sReadList, (List_Elem*)&i2sRead3);

    I2S_setReadQueueHead(i2sHandle, &i2sRead1);

    // Initialize the write-transactions
    I2S_Transaction_init(&i2sWrite1);
    I2S_Transaction_init(&i2sWrite2);
    I2S_Transaction_init(&i2sWrite3);
    i2sWrite1.bufPtr           = writeBuf1;
    i2sWrite2.bufPtr           = writeBuf2;
    i2sWrite3.bufPtr           = writeBuf3;
    i2sWrite1.bufSize          = sizeof(writeBuf1);
    i2sWrite2.bufSize          = sizeof(writeBuf2);
    i2sWrite3.bufSize          = sizeof(writeBuf3);
    List_put(&i2sWriteList, (List_Elem*)&i2sWrite1);
    List_put(&i2sWriteList, (List_Elem*)&i2sWrite2);
    List_put(&i2sWriteList, (List_Elem*)&i2sWrite3);

    I2S_setWriteQueueHead(i2sHandle, &i2sWrite1);

    I2S_startClocks(i2sHandle);
    I2S_startWrite(i2sHandle);
    I2S_startRead(i2sHandle);

    readStopped = (bool)false;
    writeStopped = (bool)false;
}

赞(0)
未经允许不得转载:TI中文支持网 » cc2640r2f i2s的使用問題
分享到: 更多 (0)