#include "platform.h"
#include "hal_headfile.h"
#include "board.h"
#include "Plxc_Algo_Api.h"
#include "debug.h"
void algo_data_full_cplt(DMA_HandleTypeDef dma, void *param);

DMA_HandleTypeDef      aigo_dma;

static void (*gDmaListener)(void);


/**
* @brief        降噪算法搬运模式数据到RAM的DMA通道初始化
* @details      none
* @param[in]    none
* @return       none
* @note
*/
void algo_dma_init(void)
{
    /*目标地址*/
    aigo_dma.init.dst_data_loc = DMA_Data_Location_Select_Low;
    aigo_dma.init.dst_data_width = DMA_Data_Width_32Bit;
    aigo_dma.init.dst_inc = DMA_Address_Type_Inc;
    /*源地址*/
    aigo_dma.init.src_data_loc = DMA_Data_Location_Select_Low;
    aigo_dma.init.src_data_width = DMA_Data_Width_32Bit;
    aigo_dma.init.src_inc = DMA_Address_Type_Inc;
    /*DMA*/
    aigo_dma.init.memory_burst = DMA_Burst_Length_Burst4;
    aigo_dma.init.priority = 7;
    aigo_dma.init.channel = CH7;
    aigo_dma.init.mode = DMA_Mode_Single;
    hal_dma_init((DMA_HandleTypeDef *)&aigo_dma);
    hal_dma_register_callback((DMA_HandleTypeDef *)&aigo_dma, HAL_DMA_XFER_CPLT_CB_ID, (void *)algo_data_full_cplt); /*注册完成中断服务函数*/
}


void algo_dma_deinit(void)
{
	hal_dma_deinit((DMA_HandleTypeDef *)&aigo_dma);
}

void Dma_Init(void (*dmaListener)(void))
{
    gDmaListener = dmaListener;
}

/**
* @brief        降噪算法搬运模式数据到RAM的DMA搬运完成中断回调函数
* @details      none
* @param[in]    dma:DMA句柄；
* @return       none
* @note
*/
void algo_data_full_cplt(DMA_HandleTypeDef dma, void *param)
{
    if ((gDmaListener != (void *)0))
    {
        gDmaListener();
    }
}

/**
* @brief        DMA发起一次搬运
* @details      none
* @param[in]    SouAddr：源地址； DisAddr：目的地址;   WordLen:word（4字节）的长度;  IntEn:NULL; channel:NULL
* @return       none
* @note
*/
void Dma_Start(uint32_t SouAddr, uint32_t DisAddr, uint32_t WordLen, uint8_t IntEn, uint32_t channel)
{
    hal_dma_start_it((DMA_HandleTypeDef *)&aigo_dma, SouAddr, DisAddr, WordLen * 4, NULL); /*dma开始传输*/
}
