TC264 DMA相关部分代码
DMA
- DMA计脉冲数
- DMA处理UART中断
DMA计脉冲数
需要注意不要摄像头的中断冲突,优点就是不会占用cpu的时序,虽然影响也不是很大。
//dma计脉冲数
uint32 dummy = 0;//工具人参数
static IfxDma_Dma_Channel dmaChn_cnt_left;
static IfxDma_Dma_Channel dmaChn_cnt_right;void dma_cnt_pin(ERU_PIN_enum pin, uint8 l_or_r)
{boolean interrupt_state = disableInterrupts();IfxScu_Req_In *reqPin;reqPin = eru_mux(pin);IfxScuEru_initReqPin(reqPin, IfxPort_InputMode_pullUp);IfxScuEru_InputChannel inputChannel = (IfxScuEru_InputChannel)reqPin->channelId;IfxScuEru_InputNodePointer triggerSelect = (IfxScuEru_InputNodePointer)(pin/3);IfxScuEru_OutputChannel outputChannel = (IfxScuEru_OutputChannel)(pin/3);IfxScuEru_enableFallingEdgeDetection(inputChannel);IfxScuEru_enableRisingEdgeDetection(inputChannel); //统计上升下降沿IfxScuEru_enableTriggerPulse(inputChannel);IfxScuEru_connectTrigger(inputChannel, triggerSelect);//使能中断IfxScuEru_setFlagPatternDetection(outputChannel, inputChannel, TRUE);IfxScuEru_enablePatternDetectionTrigger(outputChannel);IfxScuEru_setInterruptGatingPattern(outputChannel, IfxScuEru_InterruptGatingPattern_alwaysActive);//配置中断volatile Ifx_SRC_SRCR *src = &MODULE_SRC.SCU.SCU.ERU[(int)outputChannel % 4];if (l_or_r){IfxSrc_init(src, IfxSrc_Tos_dma, dma_cnt_ch_left);}else{IfxSrc_init(src, IfxSrc_Tos_dma, dma_cnt_ch_right);}IfxSrc_enable(src);restoreInterrupts(interrupt_state);
}
//任意两个有外部外部中断功能的引脚
void dma_cnt_init(ERU_PIN_enum pin_eru, uint8 l_or_r)
{dma_cnt_pin(pin_eru, l_or_r);// 配置dmaIfxDma_Dma_Config dmaConfig;IfxDma_Dma_initModuleConfig(&dmaConfig, &MODULE_DMA);IfxDma_Dma dma;IfxDma_Dma_initModule(&dma, &dmaConfig);IfxDma_Dma_ChannelConfig cfg;IfxDma_Dma_initChannelConfig(&cfg, &dma);cfg.transferCount = 10000;cfg.moveSize = IfxDma_ChannelMoveSize_8bit;cfg.blockMode = IfxDma_ChannelMove_1;cfg.requestMode = IfxDma_ChannelRequestMode_oneTransferPerRequest;cfg.hardwareRequestEnabled = TRUE;cfg.operationMode = IfxDma_ChannelOperationMode_continuous;/*************** 源地址和目标地址 ***************/cfg.sourceCircularBufferEnabled = TRUE;cfg.sourceAddressCircularRange = IfxDma_ChannelIncrementCircular_none;cfg.destinationCircularBufferEnabled = TRUE;cfg.destinationAddressCircularRange = IfxDma_ChannelIncrementCircular_none;/*************** Channel specific configurations ***************/if (l_or_r)cfg.channelId = (IfxDma_ChannelId)dma_cnt_ch_left;elsecfg.channelId = (IfxDma_ChannelId)dma_cnt_ch_right;cfg.busPriority = IfxDma_ChannelBusPriority_low;cfg.sourceAddress = IFXCPU_GLB_ADDR_DSPR(IfxCpu_getCoreId(), &dummy);cfg.destinationAddress = IFXCPU_GLB_ADDR_DSPR(IfxCpu_getCoreId(), &dummy);//禁用中断cfg.channelInterruptEnabled = FALSE;cfg.channelInterruptPriority = 0;if (l_or_r)IfxDma_Dma_initChannel(&dmaChn_cnt_left, &cfg);elseIfxDma_Dma_initChannel(&dmaChn_cnt_right, &cfg);
}int16 dma_cnt_read(uint8 l_or_r)
{Ifx_DMA_CH *ch;int16 speed;if (l_or_r){ch = dmaChn_cnt_left.channel;speed = 10000 - ch->CHCSR.B.TCOUNT;speed = speed == 10000 ? 0 : speed;MODULE_DMA.TSR[dmaChn_cnt_left.channelId].B.RST = 1;ch->CHCFGR.B.TREL = 10000;MODULE_DMA.TSR[dmaChn_cnt_left.channelId].B.ECH = 1;}else{ch = dmaChn_cnt_right.channel;speed = 10000 - ch->CHCSR.B.TCOUNT;speed = speed == 10000 ? 0 : speed;MODULE_DMA.TSR[dmaChn_cnt_right.channelId].B.RST = 1;ch->CHCFGR.B.TREL = 10000;MODULE_DMA.TSR[dmaChn_cnt_right.channelId].B.ECH = 1;}
// printf("%d\n", speed);return speed;
}
DMA处理UART中断
尽量只用一个DMA通道进行传输,数据可能会错位。
Ifx_ASCLIN *DMA_UART_NUM = &MODULE_ASCLIN2;
#define DMA_UART_TX_DB ((uint8*)&(DMA_UART_NUM->TXDATA))
#define DMA_UART_TX_SB ((uint8*)&My_Send_Data)
static IfxDma_Dma_Channel dmaChn_uart;
uint32 time = 0;
static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
uint8 transfer_finish_flag = 0;
IFX_INTERRUPT(uart2_dma_tx_isr, 0, INTPRIO_DMA_UART)
{//禁用dmaenableInterrupts();transfer_finish_flag = 1;IfxDma_disableChannelTransaction(&MODULE_DMA, dmaChn_uart.channelId);IfxDma_clearChannelInterrupt(&MODULE_DMA, dmaChn_uart.channelId);
}//内部调用
void transfer_init_uart(void)
{/* Initialize an instance of IfxAsclin_Asc_Config with default values */IfxAsclin_Asc_Config ascConfig;IfxAsclin_Asc_initModuleConfig(&ascConfig, &MODULE_ASCLIN2);/* Set the desired baud rate */ascConfig.baudrate.baudrate = data_uart_baud;/* ISR priorities and interrupt service provider */ascConfig.interrupt.txPriority = data_uart_dma_ch;ascConfig.interrupt.rxPriority = UART2_RX_INT_PRIO;ascConfig.interrupt.typeOfService = IfxSrc_Tos_dma;/* FIFO configuration */ascConfig.txBuffer = &uart2_tx_buffer;ascConfig.txBufferSize = UART2_TX_BUFFER_SIZE;ascConfig.rxBuffer = &uart2_rx_buffer;ascConfig.rxBufferSize = UART2_RX_BUFFER_SIZE;/* Pin configuration */const IfxAsclin_Asc_Pins pins ={NULL_PTR, IfxPort_InputMode_pullUp, /* CTS port pin not used */&IfxAsclin2_RXE_P33_8_IN, IfxPort_InputMode_pullUp, /* RX port pin */NULL_PTR, IfxPort_OutputMode_pushPull, /* RTS port pin not used */&IfxAsclin2_TX_P33_9_OUT, IfxPort_OutputMode_pushPull, /* TX port pin */IfxPort_PadDriver_cmosAutomotiveSpeed1};ascConfig.pins = &pins;IfxAsclin_Asc_initModule(&uart2_handle, &ascConfig); /* Initialize module with above parameters */volatile Ifx_SRC_SRCR *src;src = IfxAsclin_getSrcPointerTx(ascConfig.asclin);IfxSrc_init(src, IfxSrc_Tos_dma, data_uart_dma_ch);IfxAsclin_enableTxFifoFillLevelFlag(ascConfig.asclin, TRUE);IfxSrc_enable(src);
}void transfer_init_dma(void)
{//配置dmaIfxDma_Dma_Config dmaConfig;IfxDma_Dma_initModuleConfig(&dmaConfig, &MODULE_DMA);IfxDma_Dma dma;IfxDma_Dma_initModule(&dma, &dmaConfig);IfxDma_Dma_ChannelConfig cfg;IfxDma_Dma_initChannelConfig(&cfg, &dma);cfg.transferCount = Send_Data_Len; //传输总字节数cfg.moveSize = IfxDma_ChannelMoveSize_8bit; //每次传输字节数cfg.blockMode = IfxDma_ChannelMove_1; //每次只用一个dmacfg.requestMode = IfxDma_ChannelRequestMode_oneTransferPerRequest; //完整传输完后中断请求cfg.hardwareRequestEnabled = TRUE; //UART触发cfg.operationMode = IfxDma_ChannelOperationMode_single; //触发一次/*************** 源地址和目标地址 ***************/cfg.sourceCircularBufferEnabled = FALSE; //每次+1cfg.sourceAddressCircularRange = IfxDma_ChannelIncrementCircular_none;cfg.sourceAddressIncrementStep = IfxDma_ChannelIncrementStep_1; //一个字节cfg.destinationCircularBufferEnabled = TRUE; //目标地址不变化cfg.destinationAddressCircularRange = IfxDma_ChannelIncrementCircular_none;/*************** Channel specific configurations ***************/cfg.channelId = (IfxDma_ChannelId) data_uart_dma_ch; //选择通道cfg.sourceAddress = IFXCPU_GLB_ADDR_DSPR(IfxCpu_getCoreId(), DMA_UART_TX_SB); //传输的源地址cfg.destinationAddress = IFXCPU_GLB_ADDR_DSPR(IfxCpu_getCoreId(), DMA_UART_TX_DB); //目标地址cfg.channelInterruptEnabled = TRUE;/* DMA triggers an interrupt once the full transaction is done */cfg.channelInterruptControl = IfxDma_ChannelInterruptControl_thresholdLimitMatch;/* Priority of the channel interrupt trigger */cfg.channelInterruptPriority = INTPRIO_DMA_UART;/* Interrupt service provider */cfg.channelInterruptTypeOfService = IfxSrc_Tos_cpu0;IfxDma_Dma_initChannel(&dmaChn_uart, &cfg);
}void My_Data_Uart_Init(void)
{transfer_init_uart();transfer_init_dma();
}void send_to_computer(void)
{Ifx_DMA_CH *ch = dmaChn_uart.channel;ch->SADR.U = IFXCPU_GLB_ADDR_DSPR(IfxCpu_getCoreId(), DMA_UART_TX_SB);ch->CHCFGR.B.TREL = Send_Data_Len;//tx中断IfxDma_enableChannelTransaction(&MODULE_DMA, dmaChn_uart.channelId);DMA_UART_NUM->FLAGSSET.B.TFLS = 1;
}
TC264 DMA相关部分代码相关推荐
- pcie dma 相关知识整理(xilinx平台)
PCIE的DMA和PIO介绍 DMA数据传输方式 DMA(Direct Memory Access),直接内存访问,在该模式下,数据传送不是由CPU负责处理,而是由一个特殊的处理器DMA控制器来完成, ...
- 提高C++性能的编程技术笔记:设计优化/可扩展性/系统体系结构相关+测试代码
1. 设计优化 我们可以粗略地将性能优化分为两种类型:编码优化和设计优化.编码优化定义为不需要完整理解要解决的问题或者应用程序的执行流程就能实施的优化.通过定义看出,编码优化用于局部代码,同时该过程不 ...
- 超全汇总 | ORB-SLAM2 / ORB-SLAM3 相关改进代码!
点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 作者丨小深 来源丨深话AI 本文总结了特征点法SLAM中目前效果最好的方法:ORB-SLAM2 / O ...
- MM模块操作流程及相关建议代码
1. 创建物料主数据,相关代码创建mm01:修改mm02:显示mm03 (财务业务支持部) 2. 创建供应商主数据,相关代码创建xk01:修改xk02:显示 ...
- C# CLRInsideOut 托管代码与非托管代码互操作,产生相关调用代码的好工具 C++ 头文件转C# 的好工具...
CLRInsideOut 托管代码与非托管代码互操作,产生相关调用代码的好工具 C++ 头文件转C# 的好工具 http://download.csdn.net/source/2914818 转载于 ...
- STM32学习心得二十一:实时时钟RTC和备份寄存器BKP特征、原理及相关实验代码解读
记录一下,方便以后翻阅~ 主要内容 1) RTC特征与原理: 2) BKP备份寄存器特征与原理: 3) RTC常用寄存器+库函数介绍: 4) 相关实验代码解读. 实验内容: 因为没有买LCD屏,所以计 ...
- FANUC机器人编码器相关报警代码及处理方法
FANUC机器人编码器相关报警代码及处理方法 本次和大家分享与编码器有关的报警及对应的处理方法. 1.SRVO-081 EROFL报警(追踪编码器:i) 原因: 线性追踪编码器中每个规定采样的计数值溢 ...
- Go : 与切片类型处理相关的代码(附完整源码)
Go : 与切片类型处理相关的代码 package codegenfunc SliceClear(s []int) []int {// amd64:`.*memclrNoHeapPointers`fo ...
- 力图搜集各种跟CV,AR相关的代码
这个页面力图搜集各种跟CV,AR相关的代码,如无特别声明,均是c/c++代码.还是一贯的标准,不求全面,只求质量. 如有特别推荐的代码,请在本页留言,或者email我:cvchina AT gmail ...
最新文章
- JavaWeb编程(十)Json语句
- 神策数据钟秉哲:一文了解用户标签画像,从洞察到突破
- 软件测试作业1 -- 关于c++项目中类相互调用的问题与解决
- JavaScript实现使用二元运算符将两个数字相加fullAdder算法(附完整源码)
- H.264(MPEG-4 AVC)级别(Level)、DPB 与 MaxDpbMbs 详解
- Java判断整数和浮点数
- python中的库及module的 路径
- c java c时间格式处理_c:foreach 对时间类型进行格式化
- IMail邮件服务-1
- Google Cloud Platform中没有Active Directory域的可用性组
- Aqara 2021发布会:万物互联的家庭智慧全景
- CCF201403-2 窗口(100分)
- ObjectARX动态添加AutoCAD传统下拉菜单入门篇(一)
- 计算机操作系统知识点总结
- Unity ToLua 使用教程
- 使用unity完成简单的打地鼠游戏2D制作
- 苹果支付 php,【苹果支付二】apple pay苹果支付以及自动续订订阅开发 - Laravel学习网...
- 开关Switch系列:Switch修改滑块(thumb)和滑道(track)的颜色(一)
- 微信小程序获取当前日期和时间
- Unity3D游戏开发初探—3.初步了解U3D物理引擎