DSP

DSP48E1原语使用说明之一

2019-07-13 11:51发布

http://blog.163.com/sanlong_freedom/blog/static/25502028720151015111436185/


DSP48E1原语使用说明之一  

2015-11-16 00:28:29|  分类: 默认分类 |  标签:fpga  |举报|字号 订阅        下载LOFTER我的照片书  |           写此文档的目的是为了详细介绍7 Series FPGADSP48E1配置原理,结合手册,对每一个参数进行详细介绍。   1.     DSP48E1简介 翻开手册的DSP48E1 Slice Overview,可以看到一幅非常简介的dsp48e1功能图。如下图 1.1所示。 DSP48E1原语使用说明之一 - 三龙freedom - FREE   图1-1 功能简图 接着简明的列了很多条它的功能说明,懒得翻译了,自己认真看看。 其实从框图我们就能知道。首先,有4个输入,分别是ABCD。一个输出P。从输入得到输出,我们用一个函数公式表达:P=(D±A)*B±C。请把这个公式背下来,之后的变形使用也靠它了。这里面A30bitB18bitC48bitD25bit(D±A)出来是25bit,乘法就是25*18bitP48bit 这个式子就是dsp48e1的功能简介了。当然里面有更多的东西需要去配置和实现,但主体框架就是这个。我们用它来实现乘法加法这些东西。 如果你直接使用dsp48ip,通过简单的公式选择,动动鼠标就可以配置好公式。这里就不介绍这个了。 我们要通过原语来配置公式,就需要手动配置一些参数了。那么,为什么有人已经造好了现成的ip,我们还需要这么吃饱了没事干配这个更底层的原语呢。我当时也是这么觉得的。带我飞的老司机告诉我,这样有利于时序优化,也更好控制整个工程,特别是再做高频率,系统又很大的时候。鉴于我现在的水平,完全不知道他在说什么鬼,但是我姑且认为我还是需要写这个的。 放弃偷懒和挣扎后,我们开始进入正题。   2.     DSP48E1原语说明 原语调用如下所示 DSP48E1 #( // Feature Control Attributes: Data Path Selection .A_INPUT("DIRECT"),       // Selects A input source, "DIRECT" (A port) or "CASCADE" (ACIN port) .B_INPUT("DIRECT"),       // Selects B input source, "DIRECT" (B port) or "CASCADE" (BCIN port) .USE_DPORT("TRUE"),              // Select D port usage (TRUE or FALSE) .USE_MULT("MULTIPLY"),       // Select multiplier usage ("MULTIPLY", "DYNAMIC", or "NONE") .USE_SIMD("ONE48"),               // SIMD selection ("ONE48", "TWO24", "FOUR12") // Pattern Detector Attributes: Pattern Detection Configuration .AUTORESET_PATDET("NO_RESET"),    // "NO_RESET", "RESET_MATCH", "RESET_NOT_MATCH" .MASK(48'h3fffffffffff),          // 48-bit mask value for pattern detect (1=ignore) .PATTERN(48'h000000000000),       // 48-bit pattern match for pattern detect .SEL_MASK("MASK"),           // "C", "MASK", "ROUNDING_MODE1", "ROUNDING_MODE2" .SEL_PATTERN("PATTERN"),          // Select pattern value ("PATTERN" or "C") .USE_PATTERN_DETECT("NO_PATDET"),  // Enable pattern detect ("PATDET" or "NO_PATDET") // Register Control Attributes: Pipeline Register Configuration .ACASCREG(1),            // Number of pipeline stages between A/ACIN and ACOUT (0, 1 or 2) .ADREG(1),               // Number of pipeline stages for pre-adder (0 or 1) .ALUMODEREG(1),          // Number of pipeline stages for ALUMODE (0 or 1) .AREG(1),                 // Number of pipeline stages for A (0, 1 or 2) .BCASCREG(1),            // Number of pipeline stages between B/BCIN and BCOUT (0, 1 or 2) .BREG(1),                         // Number of pipeline stages for B (0, 1 or 2) .CARRYINREG(1),                   // Number of pipeline stages for CARRYIN (0 or 1) .CARRYINSELREG(1),                // Number of pipeline stages for CARRYINSEL (0 or 1) .CREG(1),                         // Number of pipeline stages for C (0 or 1) .DREG(1),                         // Number of pipeline stages for D (0 or 1) .INMODEREG(1),                    // Number of pipeline stages for INMODE (0 or 1) .MREG(1),                         // Number of multiplier pipeline stages (0 or 1) .OPMODEREG(1),                    // Number of pipeline stages for OPMODE (0 or 1) .PREG(1)                          // Number of pipeline stages for P (0 or 1)    ) DSP48E1_inst ( // Cascade: 30-bit (each) output: Cascade Ports .ACOUT(),                   // 30-bit output: A port cascade output .BCOUT(),                   // 18-bit output: B port cascade output .CARRYCASCOUT(),     // 1-bit output: Cascade carry output .MULTSIGNOUT(),       // 1-bit output: Multiplier sign cascade output .PCOUT(),                   // 48-bit output: Cascade output // Control: 1-bit (each) output: Control Inputs/Status Bits .OVERFLOW(OVERFLOW),             // 1-bit output: Overflow in add/acc output .PATTERNBDETECT(PATTERNBDETECT),        // 1-bit output: Pattern bar detect output .PATTERNDETECT(PATTERNDETECT),   // 1-bit output: Pattern detect output .UNDERFLOW(UNDERFLOW),           // 1-bit output: Underflow in add/acc output // Data: 4-bit (each) output: Data Ports .CARRYOUT(),             // 4-bit output: Carry output .P(P),                           // 48-bit output: Primary data output // Cascade: 30-bit (each) input: Cascade Ports .ACIN(),                     // 30-bit input: A cascade data input .BCIN(),                     // 18-bit input: B cascade input .CARRYCASCIN(),              // 1-bit input: Cascade carry input .MULTSIGNIN(),         // 1-bit input: Multiplier sign input .PCIN(),                     // 48-bit input: P cascade input // Control: 4-bit (each) input: Control Inputs/Status Bits .ALUMODE(ALUMODE),               // 4-bit input: ALU control input .CARRYINSEL(CARRYINSEL),         // 3-bit input: Carry select input .CLK(CLK),                       // 1-bit input: Clock input .INMODE(INMODE),                 // 5-bit input: INMODE control input .OPMODE(OPMODE),                 // 7-bit input: Operation mode input // Data: 30-bit (each) input: Data Ports .A(A),                           // 30-bit input: A data input .B(B),                           // 18-bit input: B data input .C(),                           // 48-bit input: C data input .CARRYIN(),               // 1-bit input: Carry input signal .D(D),                           // 25-bit input: D data input // Reset/Clock Enable: 1-bit (each) input: Reset/Clock Enable Inputs .CEA1(CEA1),                     // 1-bit input: Clock enable input for 1st stage AREG .CEA2(CEA2),                     // 1-bit input: Clock enable input for 2nd stage AREG .CEAD(CEAD),                     // 1-bit input: Clock enable input for ADREG .CEALUMODE(CEALUMODE),           // 1-bit input: Clock enable input for ALUMODE .CEB1(CEB1),                     // 1-bit input: Clock enable input for 1st stage BREG .CEB2(CEB2),                     // 1-bit input: Clock enable input for 2nd stage BREG .CEC(CEC),                       // 1-bit input: Clock enable input for CREG .CECARRYIN(CECARRYIN),           // 1-bit input: Clock enable input for CARRYINREG .CECTRL(CECTRL),       // 1-bit input: Clock enable input for OPMODEREG and CARRYINSELREG .CED(CED),                       // 1-bit input: Clock enable input for DREG .CEINMODE(CEINMODE),             // 1-bit input: Clock enable input for INMODEREG .CEM(CEM),                       // 1-bit input: Clock enable input for MREG .CEP(CEP),                       // 1-bit input: Clock enable input for PREG .RSTA(RSTA),                     // 1-bit input: Reset input for AREG .RSTALLCARRYIN(RSTALLCARRYIN),   // 1-bit input: Reset input for CARRYINREG .RSTALUMODE(RSTALUMODE),         // 1-bit input: Reset input for ALUMODEREG .RSTB(RSTB),                     // 1-bit input: Reset input for BREG .RSTC(RSTC),                     // 1-bit input: Reset input for CREG .RSTCTRL(RSTCTRL),           // 1-bit input: Reset input for OPMODEREG and CARRYINSELREG .RSTD(RSTD),                     // 1-bit input: Reset input for DREG and ADREG .RSTINMODE(RSTINMODE),           // 1-bit input: Reset input for INMODEREG .RSTM(RSTM),                     // 1-bit input: Reset input for MREG .RSTP(RSTP)                      // 1-bit input: Reset input for PREG    );    // End of DSP48E1_inst instantiation   看完后,心里是不是千万头羊驼呼啸而过。没有,那就好。反正笔者是个初学者,内心几乎是崩溃的。 然后上网度啊,也没有前辈仔细的写点汉语说明。老司机教育我,做工程你还指望有人跟你翻译手册,那是不可能的,大家都这么忙。有时间还要陪妹子呢。没有捷径,只能自己认真看手册。 那么我先为大家翻译一下原语的注释。下面很关键,请认真阅读。   3.     原语详细说明   DSP48E1 #( // Feature Control Attributes: Data Path Selection .A_INPUT("DIRECT"),        // Selects A input source, "DIRECT" (A port) or "CASCADE" (ACIN port) //选择A输入时用“直连”或者“级联”。假设你要用几个dsp48e1级联拼接起来做流水线,那么你从第二个开始就要选择CASCADE。也就是你的输入不能从A进入了,只能从ACIN 这个的作用是,A输入进去之后是没有打上reg,无法调节延时的。而ACIN进去之后可以选择打上reg,然后延时。   .B_INPUT("DIRECT"),        // Selects B input source, "DIRECT" (B port) or "CASCADE" (BCIN port) //A输入   .USE_DPORT("TRUE"),               // Select D port usage (TRUE or FALSE) //用不用D脚,根据自己的需要,用就TRUE   .USE_MULT("MULTIPLY"),        // Select multiplier usage ("MULTIPLY", "DYNAMIC", or "NONE") //选择用不用乘法,这个有什么用呢,一般都是要用乘法的,不然你用这个干嘛。手册上说为了节省能源,有时候流水线中的第一个可以不用。   .USE_SIMD("ONE48"),                // SIMD selection ("ONE48", "TWO24", "FOUR12") //这个没用上,不知道干嘛,默认用“ONE48”   // Pattern Detector Attributes: Pattern Detection Configuration .AUTORESET_PATDET("NO_RESET"),    // "NO_RESET", "RESET_MATCH", "RESET_NOT_MATCH" .MASK(48'h3fffffffffff),          // 48-bit mask value for pattern detect (1=ignore) .PATTERN(48'h000000000000),       // 48-bit pattern match for pattern detect .SEL_MASK("MASK"),           // "C", "MASK", "ROUNDING_MODE1", "ROUNDING_MODE2" .SEL_PATTERN("PATTERN"),          // Select pattern value ("PATTERN" or "C") .USE_PATTERN_DETECT("NO_PATDET"),  // Enable pattern detect ("PATDET" or "NO_PATDET") // 以上模式默认,没有认真看手册,不知道用来做什么。     // Register Control Attributes: Pipeline Register Configuration .ACASCREG(1),             // Number of pipeline stages between A/ACIN and ACOUT (0, 1 or 2) //看名字就知道选择A用法的寄存器。选0A输入,选1ACIN输入,选2ACOUT   .ADREG(1),               // Number of pipeline stages for pre-adder (0 or 1) //(D±A)的寄存器,选0加法后无延时,选1延一个始终   .ALUMODEREG(1),          // Number of pipeline stages for ALUMODE (0 or 1) //ALUMODE指令的寄存器,同样1延时一个始终。   .AREG(1),                 // Number of pipeline stages for A (0, 1 or 2) //A输入,0无延时,direct的时候用。12延时12个时钟,cascade的时候用。注意选12时,ACASCREG必须不为0   .BCASCREG(1),            // Number of pipeline stages between B/BCIN and BCOUT (0, 1 or 2)   .BREG(1),                         // Number of pipeline stages for B (0, 1 or 2)   //B的用法和A完全一样。不说了。 .CARRYINREG(1),                   // Number of pipeline stages for CARRYIN (0 or 1) .CARRYINSELREG(1),                // Number of pipeline stages for CARRYINSEL (0 or 1) .CREG(1),                         // Number of pipeline stages for C (0 or 1) .DREG(1),                         // Number of pipeline stages for D (0 or 1) .INMODEREG(1),                    // Number of pipeline stages for INMODE (0 or 1) .MREG(1),                         // Number of multiplier pipeline stages (0 or 1) .OPMODEREG(1),                    // Number of pipeline stages for OPMODE (0 or 1) .PREG(1)                          // Number of pipeline stages for P (0 or 1) // 以上看名字就知道是哪个输入的寄存器。同样0无延时,1有一个延时。    ) DSP48E1_inst ( // Cascade: 30-bit (each) output: Cascade Ports .ACOUT(),                   // 30-bit output: A port cascade output .BCOUT(),                   // 18-bit output: B port cascade output .CARRYCASCOUT(),     // 1-bit output: Cascade carry output .MULTSIGNOUT(),       // 1-bit output: Multiplier sign cascade output .PCOUT(),                   // 48-bit output: Cascade output //这些引脚空着就好   // Control: 1-bit (each) output: Control Inputs/Status Bits .OVERFLOW(OVERFLOW),             // 1-bit output: Overflow in add/acc output .PATTERNBDETECT(PATTERNBDETECT),        // 1-bit output: Pattern bar detect output .PATTERNDETECT(PATTERNDETECT),   // 1-bit output: Pattern detect output .UNDERFLOW(UNDERFLOW),           // 1-bit output: Underflow in add/acc output //这些引脚也空着,没用   // Data: 4-bit (each) output: Data Ports .CARRYOUT(),                               // 4-bit output: Carry output .P(P),                           // 48-bit output: Primary data output //P输出48bit   // Cascade: 30-bit (each) input: Cascade Ports .ACIN(),                     // 30-bit input: A cascade data input .BCIN(),                     // 18-bit input: B cascade input .CARRYCASCIN(),              // 1-bit input: Cascade carry input .MULTSIGNIN(),         // 1-bit input: Multiplier sign input .PCIN(),                     // 48-bit input: P cascade input //这些引脚很重要,做流水线时,数据又这几个引脚输入。   // Control: 4-bit (each) input: Control Inputs/Status Bits .ALUMODE(ALUMODE),               // 4-bit input: ALU control input .CARRYINSEL(CARRYINSEL),         // 3-bit input: Carry select input .CLK(CLK),                       // 1-bit input: Clock input .INMODE(INMODE),                 // 5-bit input: INMODE control input .OPMODE(OPMODE),                 // 7-bit input: Operation mode input //这几个引脚最为重要,如果大家有写过单片机,就会明白。单片机的功能其实就是配置各种寄存器来实现。这里也是同样的道理,dsp48e1的功能就是通过这几个寄存器的配置来达到。这几个脚里面隐藏了一个时钟脚,这个大家都懂的。   这几个脚太重要,详情见第4小节介绍。   // Data: 30-bit (each) input: Data Ports .A(A),                           // 30-bit input: A data input .B(B),                           // 18-bit input: B data input .C(),                           // 48-bit input: C data input .CARRYIN(),                                // 1-bit input: Carry input signal .D(D),                           // 25-bit input: D data input //这几个脚就是不做流水线时正常的输入。   // Reset/Clock Enable: 1-bit (each) input: Reset/Clock Enable Inputs .CEA1(CEA1),                     // 1-bit input: Clock enable input for 1st stage AREG .CEA2(CEA2),                     // 1-bit input: Clock enable input for 2nd stage AREG .CEAD(CEAD),                     // 1-bit input: Clock enable input for ADREG .CEALUMODE(CEALUMODE),           // 1-bit input: Clock enable input for ALUMODE .CEB1(CEB1),                     // 1-bit input: Clock enable input for 1st stage BREG .CEB2(CEB2),                     // 1-bit input: Clock enable input for 2nd stage BREG .CEC(CEC),                       // 1-bit input: Clock enable input for CREG .CECARRYIN(CECARRYIN),           // 1-bit input: Clock enable input for CARRYINREG .CECTRL(CECTRL),       // 1-bit input: Clock enable input for OPMODEREG and CARRYINSELREG .CED(CED),                       // 1-bit input: Clock enable input for DREG .CEINMODE(CEINMODE),             // 1-bit input: Clock enable input for INMODEREG .CEM(CEM),                       // 1-bit input: Clock enable input for MREG .CEP(CEP),                       // 1-bit input: Clock enable input for PREG //寄存器使能引脚的配置。前面不是让选用不用寄存器么,如果选0就不用使能了。用到哪个寄存器,哪个就需要使能。直接写1’b11’b0就可以了。   .RSTA(RSTA),                     // 1-bit input: Reset input for AREG .RSTALLCARRYIN(RSTALLCARRYIN),   // 1-bit input: Reset input for CARRYINREG .RSTALUMODE(RSTALUMODE),         // 1-bit input: Reset input for ALUMODEREG .RSTB(RSTB),                     // 1-bit input: Reset input for BREG .RSTC(RSTC),                     // 1-bit input: Reset input for CREG .RSTCTRL(RSTCTRL),           // 1-bit input: Reset input for OPMODEREG and CARRYINSELREG .RSTD(RSTD),                     // 1-bit input: Reset input for DREG and ADREG .RSTINMODE(RSTINMODE),           // 1-bit input: Reset input for INMODEREG .RSTM(RSTM),                     // 1-bit input: Reset input for MREG .RSTP(RSTP)                      // 1-bit input: Reset input for PREG //有使能当然一般也有rst。如果你想用就把大模块的rst引进来就行了。我的工程没有用,全部1’b0也并么有什么影响。这个根据你自己的需求就好。    );    // End of DSP48E1_inst instantiation   //---------------------------------------------------------------------------------------------------------------------------------------------   不想当rocker的攻城狮不是一个好诗人。。。有兴趣可移步新浪博客http://blog.sina.com.cn/hwlfree新浪微博