11bd4fe43Sopenharmony_ci/**
21bd4fe43Sopenharmony_ci* @file hi_dma.h
31bd4fe43Sopenharmony_ci*
41bd4fe43Sopenharmony_ci* Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
51bd4fe43Sopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License");
61bd4fe43Sopenharmony_ci* you may not use this file except in compliance with the License.
71bd4fe43Sopenharmony_ci* You may obtain a copy of the License at
81bd4fe43Sopenharmony_ci*
91bd4fe43Sopenharmony_ci*     http://www.apache.org/licenses/LICENSE-2.0
101bd4fe43Sopenharmony_ci*
111bd4fe43Sopenharmony_ci* Unless required by applicable law or agreed to in writing, software
121bd4fe43Sopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS,
131bd4fe43Sopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141bd4fe43Sopenharmony_ci* See the License for the specific language governing permissions and
151bd4fe43Sopenharmony_ci* limitations under the License.
161bd4fe43Sopenharmony_ci*
171bd4fe43Sopenharmony_ci* 描述:DMA module. CNcomment:DMA调用接口。CNend
181bd4fe43Sopenharmony_ci* @li The DMA transfer is realized by calling internal DMA driver.
191bd4fe43Sopenharmony_ciCNcomment:通过调用内部DMA驱动实现DMA传输CNend
201bd4fe43Sopenharmony_ci* @li Supports four transmission modes: Memory to storage, memory to peripheral, peripheral to memory,
211bd4fe43Sopenharmony_ciand peripheral to peripheral.CNcomment:支持存储器到存储器、存储器到外设、外设到存储器、
221bd4fe43Sopenharmony_ci外设到外设四种传输方式CNend
231bd4fe43Sopenharmony_ci* @li The DMA has four channels. If there is no idle channel, the HI_ERR_DMA_BUSY error is returned.
241bd4fe43Sopenharmony_ciCNcomment:DMA共有4通道,无空闲通道时返回HI_ERR_DMA_BUSY错误CNend
251bd4fe43Sopenharmony_ci* @li The callback function is executed in the interrupt context, so you need to comply with the programming
261bd4fe43Sopenharmony_ciprecautions for the interrupt context.CNcomment:回调函数执行在中断上下文,
271bd4fe43Sopenharmony_ci因此需要遵守中断上下文的编程注意事项。CNend
281bd4fe43Sopenharmony_ci* @li Before enabling the DMA channel, you need to set the channel parameters. After the channel parameters
291bd4fe43Sopenharmony_ciare enabled and then modified, an unpredictable result is generated.CNcomment:在DMA通道使能前需设置完通道参数,
301bd4fe43Sopenharmony_ci使能通道后再修改通道参数会产生无法预知的结果。CNend \n
311bd4fe43Sopenharmony_ci*/
321bd4fe43Sopenharmony_ci
331bd4fe43Sopenharmony_ci/** @defgroup iot_dma DMA
341bd4fe43Sopenharmony_ci *  @ingroup drivers
351bd4fe43Sopenharmony_ci */
361bd4fe43Sopenharmony_ci
371bd4fe43Sopenharmony_ci#ifndef _HI_DMA_H
381bd4fe43Sopenharmony_ci#define _HI_DMA_H
391bd4fe43Sopenharmony_ci
401bd4fe43Sopenharmony_ci#include <hi_types.h>
411bd4fe43Sopenharmony_ci#include "hi_mdm_types.h"
421bd4fe43Sopenharmony_ci
431bd4fe43Sopenharmony_ci#ifdef __cplusplus
441bd4fe43Sopenharmony_ciextern "C" {
451bd4fe43Sopenharmony_ci#endif
461bd4fe43Sopenharmony_ci
471bd4fe43Sopenharmony_ci/**
481bd4fe43Sopenharmony_ci * @ingroup iot_dma
491bd4fe43Sopenharmony_ci *
501bd4fe43Sopenharmony_ci * DMA Interruption type. CNcomment: DMA 中断类型。CNend
511bd4fe43Sopenharmony_ci */
521bd4fe43Sopenharmony_ci /* 传输完成中断类型 */
531bd4fe43Sopenharmony_ci#define DMA_INT_TC  1
541bd4fe43Sopenharmony_ci/* 传输错误中断类型 */
551bd4fe43Sopenharmony_ci#define DMA_INT_ERR 2
561bd4fe43Sopenharmony_ci
571bd4fe43Sopenharmony_ci/**
581bd4fe43Sopenharmony_ci * @ingroup iot_dma
591bd4fe43Sopenharmony_ci *
601bd4fe43Sopenharmony_ci * DMA transfer bit width. CNcomment:DMA传输位宽。CNend
611bd4fe43Sopenharmony_ci */
621bd4fe43Sopenharmony_citypedef enum {
631bd4fe43Sopenharmony_ci    WIDTH_BIT8 = 0,
641bd4fe43Sopenharmony_ci    WIDTH_BIT16,
651bd4fe43Sopenharmony_ci    WIDTH_BIT32,
661bd4fe43Sopenharmony_ci} hi_dma_data_width;
671bd4fe43Sopenharmony_ci
681bd4fe43Sopenharmony_ci/**
691bd4fe43Sopenharmony_ci * @ingroup iot_dma
701bd4fe43Sopenharmony_ci *
711bd4fe43Sopenharmony_ci * DMA configuration structure transferred. CNcomment:用户传入的DMA设置结构体。CNend
721bd4fe43Sopenharmony_ci */
731bd4fe43Sopenharmony_citypedef struct hi_dma_user_para {
741bd4fe43Sopenharmony_ci    hi_u32 ch_idx;         /* 接收DMA传输使用的channel id,不需用户设置, 通道申请成功时赋值 */
751bd4fe43Sopenharmony_ci    uintptr_t src_addr;    /* 源地址,源地址必须4字节对齐 */
761bd4fe43Sopenharmony_ci    uintptr_t dst_addr;    /* 目标地址,目的地址必须4字节对齐 */
771bd4fe43Sopenharmony_ci    hi_u32 size_bytes;     /* 传输长度,以BYTE单位 */
781bd4fe43Sopenharmony_ci    hi_void (*cb)(hi_u32);  /* 传输结束回调,参数为传输完成或传输错误 #DMA_INT_XXX */
791bd4fe43Sopenharmony_ci} hi_dma_user_para;
801bd4fe43Sopenharmony_ci
811bd4fe43Sopenharmony_ci/**
821bd4fe43Sopenharmony_ci* @ingroup  iot_dma
831bd4fe43Sopenharmony_ci* @brief  Create the dma transmission linked list. CNcomment:创建dma传输链表。CNend
841bd4fe43Sopenharmony_ci*
851bd4fe43Sopenharmony_ci* @par 描述:
861bd4fe43Sopenharmony_ci*           Create the dma transmission linked list. CNcomment:创建dma传输链表,分配通道。CNend
871bd4fe43Sopenharmony_ci*           After the command is executed successfully, the channel resources are allocated.
881bd4fe43Sopenharmony_ci*           If the channel resources are not transmitted, the hi_dma_ch_close(usr_para->ch_idx) is invoked to
891bd4fe43Sopenharmony_ci*           release the channels. CNcomment:执行成功后会分配通道资源,如果没有实际进行传输需要调用
901bd4fe43Sopenharmony_cihi_dma_ch_close(usr_para->ch_idx)释放通道。CNend
911bd4fe43Sopenharmony_ci*
921bd4fe43Sopenharmony_ci* @attention
931bd4fe43Sopenharmony_ci* @param  usr_para         [IN/OUT] type #hi_dma_user_para,Transfer DMA transfer parameter settings
941bd4fe43Sopenharmony_ciCNcomment:传入DMA传输参数设置。CNend
951bd4fe43Sopenharmony_ci*
961bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS  Success.
971bd4fe43Sopenharmony_ci* @retval #Other values    Failure. For details, see hi_errno.h.
981bd4fe43Sopenharmony_ci* @par 依赖:
991bd4fe43Sopenharmony_ci*            @li hi_dma.h:   Describes DMA driver APIs. CNcomment:DMA驱动实现接口。CNend
1001bd4fe43Sopenharmony_ci* @see  None
1011bd4fe43Sopenharmony_ci */
1021bd4fe43Sopenharmony_cihi_u32 hi_dma_create_link_list(hi_dma_user_para *usr_para);
1031bd4fe43Sopenharmony_ci
1041bd4fe43Sopenharmony_ci/**
1051bd4fe43Sopenharmony_ci* @ingroup  iot_dma
1061bd4fe43Sopenharmony_ci* @brief  Insert the DMA transmission linked list at behind. CNcomment:dma传输链表末尾添加结点。CNend
1071bd4fe43Sopenharmony_ci*
1081bd4fe43Sopenharmony_ci* @par 描述:
1091bd4fe43Sopenharmony_ci*           Insert the DMA transmission linked list at behind. CNcomment:dma传输链表末尾添加结点CNend
1101bd4fe43Sopenharmony_ci*
1111bd4fe43Sopenharmony_ci* @attention
1121bd4fe43Sopenharmony_ci* @param  usr_para         [IN] type #const hi_dma_user_para,Transfer DMA transfer parameter settings.
1131bd4fe43Sopenharmony_ciCNcomment:传入DMA传输参数设置。CNend
1141bd4fe43Sopenharmony_ci*
1151bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS  Success.
1161bd4fe43Sopenharmony_ci* @retval #Other values    Failure. For details, see hi_errno.h.
1171bd4fe43Sopenharmony_ci* @par 依赖:
1181bd4fe43Sopenharmony_ci*            @li hi_dma.h:   Describes DMA driver APIs. CNcomment:DMA驱动实现接口。CNend
1191bd4fe43Sopenharmony_ci* @see  None
1201bd4fe43Sopenharmony_ci */
1211bd4fe43Sopenharmony_cihi_u32 hi_dma_add_link_list_item(const hi_dma_user_para *usr_para);
1221bd4fe43Sopenharmony_ci
1231bd4fe43Sopenharmony_ci/**
1241bd4fe43Sopenharmony_ci* @ingroup  iot_dma
1251bd4fe43Sopenharmony_ci* @brief  Start DMA linked list transmission. CNcomment:启动dma链表传输。CNend
1261bd4fe43Sopenharmony_ci*
1271bd4fe43Sopenharmony_ci* @par 描述:
1281bd4fe43Sopenharmony_ci*           Start DMA linked list transmission, channel would be released, no matter about the result.
1291bd4fe43Sopenharmony_ciCNcomment:启动dma链表传输,成功或失败后会释放通道。CNend
1301bd4fe43Sopenharmony_ci*
1311bd4fe43Sopenharmony_ci* @attention
1321bd4fe43Sopenharmony_ci* @param  ch_num           [IN]     type #hi_u32,Linked list transmission channel.
1331bd4fe43Sopenharmony_ciThis parameter is assigned by the API when a linked list is created.
1341bd4fe43Sopenharmony_ciCNcomment:链表传输通道,创建链表时API内部赋值。CNend
1351bd4fe43Sopenharmony_ci* @param  block            [IN]     type #hi_bool,Indicates whether to block waiting for transmission completion.
1361bd4fe43Sopenharmony_ciCNcomment:是否阻塞等待传输完成。CNend
1371bd4fe43Sopenharmony_ci*
1381bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS  Success.
1391bd4fe43Sopenharmony_ci* @retval #Other values    Failure. For details, see hi_errno.h.
1401bd4fe43Sopenharmony_ci* @par 依赖:
1411bd4fe43Sopenharmony_ci*            @li hi_dma.h:   Describes DMA driver APIs. CNcomment:DMA驱动实现接口。CNend
1421bd4fe43Sopenharmony_ci* @see  None
1431bd4fe43Sopenharmony_ci */
1441bd4fe43Sopenharmony_cihi_u32 hi_dma_link_list_transfer(hi_u32 ch_num, hi_bool block);
1451bd4fe43Sopenharmony_ci
1461bd4fe43Sopenharmony_ci/**
1471bd4fe43Sopenharmony_ci* @ingroup  iot_dma
1481bd4fe43Sopenharmony_ci* @brief  Data transmission from the memory to the memory through DMA.
1491bd4fe43Sopenharmony_ciCNcomment:通过DMA进行存储器到存储器数据传输。CNend
1501bd4fe43Sopenharmony_ci*
1511bd4fe43Sopenharmony_ci* @par 描述:
1521bd4fe43Sopenharmony_ci*           Data transmission from the memory to the memory through DMA.
1531bd4fe43Sopenharmony_ciCNcomment:通过DMA进行存储器到存储器数据传输。CNend
1541bd4fe43Sopenharmony_ci*
1551bd4fe43Sopenharmony_ci* @attention
1561bd4fe43Sopenharmony_ci* @param  dst_addr         [IN]     type #hi_u32,Destination address, which must be 4-byte-aligned.
1571bd4fe43Sopenharmony_ciCNcomment:目标地址,需4字节对齐。CNend
1581bd4fe43Sopenharmony_ci* @param  src_addr         [IN]     type #hi_u32,Source address, which must be 4-byte-aligned.
1591bd4fe43Sopenharmony_ciCNcomment:源地址,需4字节对齐。CNend
1601bd4fe43Sopenharmony_ci* @param  size_bytes       [IN]     type #hi_u32,Transmission length, in bytes.
1611bd4fe43Sopenharmony_ciCNcomment:传输长度,以BYTE为单位。CNend
1621bd4fe43Sopenharmony_ci* @param  block            [IN]     type #hi_bool,Indicates whether to block waiting for transmission completion.
1631bd4fe43Sopenharmony_ciCNcomment:是否阻塞等待传输完成。CNend
1641bd4fe43Sopenharmony_ci* @param  cb_func          [IN]     type #hi_void,Callback function for non-blocking transmission.
1651bd4fe43Sopenharmony_ciThe parameter is the DMA interrupt type. Set this parameter to HI_NULL when blocking transmission.
1661bd4fe43Sopenharmony_ciCNcomment:非阻塞传输的回调函数,参数为DMA中断类型,阻塞传输时设为HI_NULL。CNend
1671bd4fe43Sopenharmony_ci*
1681bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS  Success.
1691bd4fe43Sopenharmony_ci* @retval #HI_ERR_DMA_BUSY Channel busy. CNcomment:通道全忙。CNend
1701bd4fe43Sopenharmony_ci* @retval #Other values    Failure. For details, see hi_errno.h.
1711bd4fe43Sopenharmony_ci* @par 依赖:
1721bd4fe43Sopenharmony_ci*            @li hi_dma.h:   Describes DMA driver APIs. CNcomment:DMA驱动实现接口。CNend
1731bd4fe43Sopenharmony_ci* @see  None
1741bd4fe43Sopenharmony_ci */
1751bd4fe43Sopenharmony_cihi_u32 hi_dma_mem2mem_transfer(hi_u32 dst_addr, hi_u32 src_addr, hi_u32 size_bytes,
1761bd4fe43Sopenharmony_ci                               hi_bool block, hi_void (*cb_func)(hi_u32 int_type));
1771bd4fe43Sopenharmony_ci
1781bd4fe43Sopenharmony_ci/**
1791bd4fe43Sopenharmony_ci* @ingroup  iot_dma
1801bd4fe43Sopenharmony_ci* @brief  Disables the DMA specified channel. CNcomment:关闭DMA指定通道。CNend
1811bd4fe43Sopenharmony_ci*
1821bd4fe43Sopenharmony_ci* @par 描述:
1831bd4fe43Sopenharmony_ci*           Disables the DMA specified channel and release rource.
1841bd4fe43Sopenharmony_ciCNcomment:关闭DMA指定通道并释放资源。CNend
1851bd4fe43Sopenharmony_ci*
1861bd4fe43Sopenharmony_ci* @attention None
1871bd4fe43Sopenharmony_ci* @param  ch_num           [IN]     type #hi_u32,DMA channel ID. Value range: 0-3.
1881bd4fe43Sopenharmony_ciCNcomment:DMA通道ID 取值0~3。CNend
1891bd4fe43Sopenharmony_ci*
1901bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS  Success.
1911bd4fe43Sopenharmony_ci* @retval #Other values    Failure. For details, see hi_errno.h.
1921bd4fe43Sopenharmony_ci* @par 依赖:
1931bd4fe43Sopenharmony_ci*            @li hi_dma.h:   Describes DMA driver APIs. CNcomment:DMA驱动实现接口。CNend
1941bd4fe43Sopenharmony_ci* @see  hi_dma_create_link_list。
1951bd4fe43Sopenharmony_ci */
1961bd4fe43Sopenharmony_cihi_u32 hi_dma_ch_close(hi_u32 ch_num);
1971bd4fe43Sopenharmony_ci
1981bd4fe43Sopenharmony_ci/**
1991bd4fe43Sopenharmony_ci* @ingroup  iot_dma
2001bd4fe43Sopenharmony_ci* @brief  DMA module initialization.CNcomment:DMA模块初始化。CNend
2011bd4fe43Sopenharmony_ci*
2021bd4fe43Sopenharmony_ci* @par 描述:
2031bd4fe43Sopenharmony_ci*           DMA module initialization, apply for rources. CNcomment:DMA模块初始化, 申请资源。CNend
2041bd4fe43Sopenharmony_ci*
2051bd4fe43Sopenharmony_ci* @attention None
2061bd4fe43Sopenharmony_ci* @param  None
2071bd4fe43Sopenharmony_ci*
2081bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS  Success.
2091bd4fe43Sopenharmony_ci* @retval #Other values    Failure. For details, see hi_errno.h.
2101bd4fe43Sopenharmony_ci* @par 依赖:
2111bd4fe43Sopenharmony_ci*            @li hi_dma.h:   Describes DMA driver APIs. CNcomment:DMA驱动实现接口。CNend
2121bd4fe43Sopenharmony_ci* @see  None
2131bd4fe43Sopenharmony_ci */
2141bd4fe43Sopenharmony_cihi_u32 hi_dma_init(hi_void);
2151bd4fe43Sopenharmony_ci
2161bd4fe43Sopenharmony_ci/**
2171bd4fe43Sopenharmony_ci* @ingroup  iot_dma
2181bd4fe43Sopenharmony_ci* @brief  Deinitializes the DMA module. CNcomment:DMA模块去初始化。CNend
2191bd4fe43Sopenharmony_ci*
2201bd4fe43Sopenharmony_ci* @par 描述:
2211bd4fe43Sopenharmony_ci*           Deinitializes the DMA module and release rources. CNcomment:DMA模块去初始化,释放资源。CNend
2221bd4fe43Sopenharmony_ci*
2231bd4fe43Sopenharmony_ci* @attention None
2241bd4fe43Sopenharmony_ci* @param  None
2251bd4fe43Sopenharmony_ci*
2261bd4fe43Sopenharmony_ci* @retval None
2271bd4fe43Sopenharmony_ci* @par 依赖:
2281bd4fe43Sopenharmony_ci*            @li hi_dma.h:   Describes DMA driver APIs. CNcomment:DMA驱动实现接口。CNend
2291bd4fe43Sopenharmony_ci* @see  None
2301bd4fe43Sopenharmony_ci*/
2311bd4fe43Sopenharmony_cihi_void hi_dma_deinit(hi_void);
2321bd4fe43Sopenharmony_ci
2331bd4fe43Sopenharmony_ci/**
2341bd4fe43Sopenharmony_ci* @ingroup  iot_dma
2351bd4fe43Sopenharmony_ci* @brief  Judge is DMA module init. CNcomment:DMA模块是否初始化。CNend
2361bd4fe43Sopenharmony_ci*
2371bd4fe43Sopenharmony_ci* @par 描述:
2381bd4fe43Sopenharmony_ci*           Is DMA module init. CNcomment:DMA模块是否初始化。CNend
2391bd4fe43Sopenharmony_ci*
2401bd4fe43Sopenharmony_ci* @attention None
2411bd4fe43Sopenharmony_ci* @param  None
2421bd4fe43Sopenharmony_ci*
2431bd4fe43Sopenharmony_ci* @retval #HI_TURE   dma has been initialized.
2441bd4fe43Sopenharmony_ci* @retval #HI_FALSE  DMA has not been initialized.
2451bd4fe43Sopenharmony_ci* @par 依赖:
2461bd4fe43Sopenharmony_ci*            @li hi_dma.h:   Describes DMA driver APIs. CNcomment:DMA驱动实现接口。CNend
2471bd4fe43Sopenharmony_ci* @see  None
2481bd4fe43Sopenharmony_ci */
2491bd4fe43Sopenharmony_cihi_bool hi_dma_is_init(hi_void);
2501bd4fe43Sopenharmony_ci
2511bd4fe43Sopenharmony_ci#ifdef __cplusplus
2521bd4fe43Sopenharmony_ci}
2531bd4fe43Sopenharmony_ci#endif
2541bd4fe43Sopenharmony_ci
2551bd4fe43Sopenharmony_ci#endif
256