Files
kunlun/export/inc/bsp/iot_sw_dma_api.h
2024-09-28 14:24:04 +08:00

181 lines
5.3 KiB
C
Executable File

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#ifndef IOT_SW_DMA_API_H
#define IOT_SW_DMA_API_H
#ifdef __cplusplus
extern "C" {
#endif
/** \defgroup SW_DMA_APIs SW_DMA APIs
* @brief SW_DMA APIs
*
*
*/
/** @addtogroup SW_DMA_APIs
* @{
*
*/
/**
* @brief Usage:
// init sw dma, selece channel 0
iot_dma_sw_init(0);
iot_dma_sw_cfg(output_buf, input_float_512, 2048, 0, NULL);
iot_dma_sw_start(0);
// get min
float output_min = 0;
uint32_t output_index = 0;
iot_dma_sw_cfg(output_buf, input_float_512, 512*4, DMA_FP_MIN, NULL);
iot_dma_sw_start(0);
iot_dma_sw_max_min(0, &output_min, &output_index);
// get sum
float output_sum = 0;
iot_dma_sw_cfg(output_buf, input_float_512, 512*4, DMA_FP_SUM, NULL);
iot_dma_sw_start(0);
iot_dma_sw_sum(0, &output_sum);
// input value multiply by fac_val
iot_fp_ctrl_t fp_ctrl = {0};
fp_ctrl.abs_ena = DMA_ABS_DIS;
fp_ctrl.fac_cfg = DMA_FAC_IN_MUL;
fp_ctrl.fac_val = 2;
iot_dma_sw_cfg(sw_out, input_float_512, 512*4, DMA_FP_LOG2, &fp_ctrl);
iot_dma_sw_start(0);
*/
/**
* @brief iot_dma_sw_fp_t - supported float point operation
* @param DMA_FP_SQRT output format is the square root of the input
* @param DMA_FP_1_SQRT output format is the inverse square of the input
* @param DMA_FP_LOG2 output format is the base-2 logarithmic of the input
* @param DMA_FP_EXP2 output format is the base-2 exponential of the input
* @param DMA_FP_MIN get the minimum of the input
* @param DMA_FP_MAX get the maximum of the input
* @param DMA_FP_SUM get the sum of the input
* @param DMA_FP_FTOI transform FLOAT input to INT32 output
* @param DMA_FP_ITOF transform INT32 input to FLOAT output
*/
typedef enum _iot_dma_sw_fp {
DMA_FP_SQRT = 0,
DMA_FP_1_SQRT = 1,
DMA_FP_LOG2 = 2,
DMA_FP_EXP2 = 3,
DMA_FP_MIN = 4,
DMA_FP_MAX = 5,
DMA_FP_SUM = 6,
DMA_FP_FTOI = 7,
DMA_FP_ITOF = 8,
DMA_FP_INVR = 9,
DMA_FP_NONE = 10,
} iot_dma_sw_fp_t;
/**
* @brief iot_fp_fac_t - configure float point factor
* @param DMA_FAC_NONE no additional multiplication
* @param DMA_FAC_IN_MUL input multiply by the factor
* @param DMA_FAC_OUT_MUL output multiply by the facotr
*/
typedef enum _iot_fp_fac {
DMA_FAC_NONE = 0,
DMA_FAC_IN_MUL = 1,
DMA_FAC_OUT_MUL = 2,
} iot_fp_fac_t;
/**
* @brief iot_fp_fac_t - configure float point factor
* @param DMA_ABS_DIS don't do abs before process max/min
* @param DMA_ABS_ENA do abs before process max/min
*/
typedef enum _iot_fp_abs {
DMA_ABS_DIS = 0,
DMA_ABS_ENA = 1,
} iot_fp_abs_t;
/**
* @brief iot_fp_ctrl_t - the structure of float point control
* @param abs_ena abs enable, reference to iot_fp_abs_t
* @param fac_cfg factor mode config, reference to iot_fp_fac_t
* @param fac_val the factor value
*/
typedef struct _iot_fp_ctrl_t {
uint8_t abs_ena;
uint8_t fac_cfg;
float fac_val;
} iot_fp_ctrl_t;
/**
* @brief iot_dma_sw_init() - init sw dma
* @param chl the sw dma channel
*/
void iot_dma_sw_init(uint8_t chl);
/**
* @brief iot_dma_sw_cfg() - configure input and output, with float operation
* @param dest the output buffer pointer
* @param src the input buffer pointer
* @param len the length of buffer, maximum is 4096 bype
* @param op the operation of float point
reference to iot_dma_sw_fp_t
* @param fp_ctrl float pointer control
*/
void iot_dma_sw_cfg(void *dest, void *src, uint16_t len,
uint8_t op, iot_fp_ctrl_t *fp_ctrl);
void iot_dma_sw_start(uint8_t chl);
/**
* @brief iot_dma_sw_max_min() - get the maximum or minimum value of the input,
the function can only valid if op select DMA_FP_MIN or
DMA_FP_MAX
* @param chl the sw dma channel
* @param value the pointer of output value
* @param value the index of max/min value
*/
void iot_dma_sw_max_min(uint8_t chl, void *value, uint32_t *index);
/**
* @brief iot_dma_sw_sum() - get the sum value of the input, the function
can only valid if op select DMA_FP_SUM
* @param chl the sw dma channel
* @param value the pointer of output value
*/
void iot_dma_sw_sum(uint8_t chl, void *value);
#ifdef __cplusplus
}
#endif
#endif //IOT_SW_DMA_API_H