components/driver/i2s.c
/**
 * @brief   Create I2S DMA object
 * @note    This function only create I2S DMA object but will not allocate memory
 *          for DMA descriptor and buffer, call 'i2s_alloc_dma_buffer' additionally to
 *          allocate DMA buffer
 *
 * @param   i2s_num         I2S device number
 * @param   dma             The secondary pointer of DMA object
 * @return
 *      - ESP_OK                The pointer of DMA object
 *      - ESP_ERR_INVALID_ARG   NULL pointer error or DMA object has been created
 *      - ESP_ERR_NO_MEM        No memory for new DMA object
 */
@brief   Create I2S DMA object
@note    This function only create I2S DMA object but will not allocate memory
for DMA descriptor and buffer, call 'i2s_alloc_dma_buffer' additionally to
allocate DMA buffer

@param   i2s_num         I2S device number
@param   dma             The secondary pointer of DMA object
@return
- ESP_OK                The pointer of DMA object
- ESP_ERR_INVALID_ARG   NULL pointer error or DMA object has been created
- ESP_ERR_NO_MEM        No memory for new DMA object
@brief Create I2S DMA object @note This function only create I2S DMA object but will not allocate memory for DMA descriptor and buffer call ' i2s_alloc_dma_buffer ' additionally to allocate DMA buffer @param i2s_num I2S device number @param dma The secondary pointer of DMA object @return - ESP_OK The pointer of DMA object - ESP_ERR_INVALID_ARG NULL pointer error or DMA object has been created - ESP_ERR_NO_MEM No memory for new DMA object
static esp_err_t i2s_create_dma_object(i2s_port_t i2s_num, i2s_dma_t **dma)
{
    ESP_RETURN_ON_FALSE(dma, ESP_ERR_INVALID_ARG, TAG, "DMA object secondary pointer is NULL");
    ESP_RETURN_ON_FALSE((*dma == NULL), ESP_ERR_INVALID_ARG, TAG, "DMA object has been created");
    uint32_t buf_cnt = p_i2s[i2s_num]->dma_buf_count;
    *dma = (i2s_dma_t *) malloc(sizeof(i2s_dma_t));
    ESP_RETURN_ON_FALSE(*dma, ESP_ERR_NO_MEM, TAG, "DMA object allocate failed");
    (*dma)->buf = (char **)heap_caps_calloc(buf_cnt, sizeof(char *), MALLOC_CAP_DMA);
    if (!(*dma)->buf) {
        goto err;
    }
    (*dma)->desc = (lldesc_t **)heap_caps_calloc(buf_cnt, sizeof(lldesc_t *), MALLOC_CAP_DMA);
    if (!(*dma)->desc) {
        goto err;
    }
    (*dma)->queue = xQueueCreate(buf_cnt - 1, sizeof(char *));
    if (!(*dma)->queue) {
        goto err;
    }
    (*dma)->mux = xSemaphoreCreateMutex();
    if (!(*dma)->mux) {
        goto err;
    }
    return ESP_OK;
err:
    ESP_LOGE(TAG, "I2S DMA object create failed, preparing to uninstall");
    i2s_destroy_dma_object(i2s_num, dma);
    return ESP_ERR_NO_MEM;
}
static esp_err_t i2s_create_dma_object ( i2s_port_t i2s_num , i2s_dma_t * * dma ) { ESP_RETURN_ON_FALSE ( dma , ESP_ERR_INVALID_ARG , TAG , " " ) ; ESP_RETURN_ON_FALSE ( ( * dma == NULL ) , ESP_ERR_INVALID_ARG , TAG , " " ) ; uint32_t buf_cnt = p_i2s [ i2s_num ] -> dma_buf_count ; * dma = ( i2s_dma_t * ) malloc ( sizeof ( i2s_dma_t ) ) ; ESP_RETURN_ON_FALSE ( * dma , ESP_ERR_NO_MEM , TAG , " " ) ; ( * dma ) -> buf = ( char * * ) heap_caps_calloc ( buf_cnt , sizeof ( char * ) , MALLOC_CAP_DMA ) ; if ( ! ( * dma ) -> buf ) { goto err ; } ( * dma ) -> desc = ( lldesc_t * * ) heap_caps_calloc ( buf_cnt , sizeof ( lldesc_t * ) , MALLOC_CAP_DMA ) ; if ( ! ( * dma ) -> desc ) { goto err ; } ( * dma ) -> queue = xQueueCreate ( buf_cnt - 1 , sizeof ( char * ) ) ; if ( ! ( * dma ) -> queue ) { goto err ; } ( * dma ) -> mux = xSemaphoreCreateMutex ( ) ; if ( ! ( * dma ) -> mux ) { goto err ; } return ESP_OK ; err : ESP_LOGE ( TAG , " " ) ; i2s_destroy_dma_object ( i2s_num , dma ) ; return ESP_ERR_NO_MEM ; }
@brief   Create I2S DMA object
 @note    This function only create I2S DMA object but will not allocate memory
          for DMA descriptor and buffer, call 'i2s_alloc_dma_buffer' additionally to
          allocate DMA buffer
@brief Create I2S DMA object @note This function only create I2S DMA object but will not allocate memory for DMA descriptor and buffer call ' i2s_alloc_dma_buffer ' additionally to allocate DMA buffer
/* Allocate new DMA structure */ /* Allocate DMA buffer poiter */ /* Allocate secondary pointer of DMA descriptor chain */ /* Create queue and mutex */ /* Destroy DMA queue if failed to allocate memory */