数据分离---verilog

数据分离---verilog

/****************************************************************/
/*模块名称:数据分流模块                                      ******/////

/*模块功能:1,缓存来自分组检测完成后的数据 包括了:          ******/////
/*            a)1个不完整的短训练序列(<16)                         ******/////
/*            b)9个完整的短训练序列(9*16)                          ******/////
/*            c)2个长训练序列(32+2*64)                             ******/////
/*            d)数据序列                                           ******/////
/*          2,对输入数据用DataIndex进行计数                      ******/////
/*            a)1<=DataIndex<=160短训练序列 直接输出               ******///// 
/*            b)1<=DataIndex<=5*16用做粗频率偏差估计的短训练序列   ******/////
/*                             送入估计缓存器                         ******/////
/*            c)160<DataIndex待检测的长训练序列和数据序列          ******/////
/*                         送入待检测的数据缓存器                    ******/////
/*          

/*模块端口:1,输入端口                                       ******/////
/*          Clk:       全局时钟                               ******/////
/*          Rst_n:        全局复位 异步                           ******/////
/*          DataInEnable: 输入分组检测完成有效                    ******/////
/*          DataInRe, DataInIm:  输入分组检测完成后的数据            ******/////                   
/*                    补码格式                                ******/////
/*                             8位位宽  1位符号位 1位整数位 6位小数位  ******///// 
/*          2,输出端口                                           ******/////
/*          ShortTrainingOutEnable: 短训练序列数据输出有效        ******/////
/*          ShortTrainingOutRe                                    ******/////
/*          ShortTrainingOutIm:     短训练序列数据输出            ******/////
/*                             补码格式                                ******/////
/*                             8位位宽  1位符号位 1位整数位 6位小数位  ******/////
/*          EstimationOutEnable:    粗频偏估计数据输出有效        ******/////
/*          EstimationOutRe                                       ******/////
/*          EstimationOutIm:         粗频偏估计数据输出             ******/////
/*                             补码格式                                ******/////
/*                             8位位宽  1位符号位 1位整数位 6位小数位  ******/////
/*          OtherDataOutEnable:     长训练序列和数据序列输出有效  ******///// 
/*          OtherDataOutRe                                        ******/////  
/*          OtherDataOutIm:         长训练序列和数据序列输出          ******/////
/*                             补码格式                                ******/////
/*                             8位位宽  1位符号位 1位整数位 6位小数位  ******/////

/**/////
/****************************************************************/

module Data_Separating(

    /*全局时钟*****//////
    input                wire                Clk,
    /*异步复位*****//////
    input                wire                Rst_n,
    /*输入分组检测完成有效*****//////
    input                wire                DataInEnable,
    /*输入分组检测完成后的数据*****//////
    /*补码格式   8位位位宽 1位符号位 1位整数位 6位小数位*****//////
    input                wire     [7:0]      DataInRe, 
    input                wire     [7:0]      DataInIm,

    /*短训练序列数据输出有效*****//////
    output               reg                 ShortTrainingOutEnable,
    /*短训练序列数据输出
    //补码格式
    //8位位宽  1位符号位 1位整数位 6位小数位*****//////
    output              reg       [7:0]      ShortTrainingOutRe, 
    output              reg       [7:0]      ShortTrainingOutIm,

    /*粗频偏估计数据输出有效*****//////
    output              reg                  EstimationOutEnable,
    /*粗频偏估计数据输出
    //补码格式
    //8位位宽  1位符号位 1位整数位 6位小数位*****//////
    output             reg        [7:0]      EstimationOutRe, 
    output             reg        [7:0]      EstimationOutIm,

    /*长训练序列和数据序列输出有效*****//////
    output             reg                   OtherDataOutEnable,
    /*长训练序列和数据序列输出
    //补码格式
    //8位位宽  1位符号位 1位整数位 6位小数位*****//////
    output            reg         [7:0]      OtherDataOutRe,
    output            reg         [7:0]      OtherDataOutIm);

//--------------------------------------------------------------------------------
//输入级数据缓存

/*输入数据有效缓存*****//////
reg TempDataInEnable;
/*输入数据缓存*****//////
reg [7:0] TempDataInRe;
reg [7:0] TempDataInIm;

/*数据计数器*****//////
reg [15:0] DataIndex;

always@(posedge Clk or negedge Rst_n)
begin
    if (!Rst_n)
    begin
        /*全局复位*****//////
        /*输入数据有效缓存*****//////
           TempDataInEnable <= 0;
        /*输入数据缓存*****//////
        TempDataInRe <= 8'b00000000;
        TempDataInIm <= 8'b00000000;

        /*数据计数器*****//////
        DataIndex <= 16'b00000000_00000000;
     end
    else
    begin
        if (DataInEnable)
           begin
              /*输入数据有效下*****//////
            /*输入数据有效缓存*****//////
            TempDataInEnable <= 1;
            /*输入数据缓存*****//////
            TempDataInRe <= DataInRe;
            TempDataInIm <=    DataInIm;
          
              /*数据计数器计数*****//////
            DataIndex <= DataIndex + 16'b00000000_00000001;
          end
        else
           begin
              /*输入数据无效下*****//////
            /*输入数据有效缓存*****//////
              TempDataInEnable <= 0;
               /*输入数据缓存*****//////
            TempDataInRe <= 8'b00000000;
            TempDataInIm <= 8'b00000000;          

            /*输入数据连续输入*****//////
            /*在输入数据停止后 1个数据帧结束*****//////
            DataIndex <= 16'b00000000_00000000;
          end
    end
end

//--------------------------------------------------------------------------------
// 根据DataIndex输出数据

/*短训练序列数据输出*****//////

always@(posedge Clk or negedge Rst_n)
begin
    if (!Rst_n)
    begin
        /*全局复位下*****//////
        /*短训练序列数据输出有效*****//////
        ShortTrainingOutEnable <= 0;
        /*短训练序列数据输出*****//////
        ShortTrainingOutRe <= 8'b00000000;
        ShortTrainingOutIm <= 8'b00000000;
    end
    else
      begin
        if (TempDataInEnable)
        begin
              /*输入数据有效缓存下*****//////
            if ((1<=DataIndex)&&(DataIndex<=160))
            begin
                /*1<=DataIndex<=160
                //短训练序列
                //可能已经超出短训练序列部分
                //但为能够全部进入长训练序列,故输出160个*****//////
                /*短训练序列数据输出有效*****//////
                ShortTrainingOutEnable <= 1;
                /*短训练序列数据输出*****//////
                ShortTrainingOutRe <= TempDataInRe;
                ShortTrainingOutIm <= TempDataInIm;  
            end
            else
            begin
                /*DataIndex>160个后
                //超出短训练序列部分*****//////
                /*短训练序列数据输出无效*****//////
                ShortTrainingOutEnable <= 0;
                /*短训练序列数据输出*****//////
                ShortTrainingOutRe <= 8'b00000000;
                ShortTrainingOutIm <= 8'b00000000;
            end
        end
        else
        begin
            /*没有数据缓存有效*****//////
            /*短训练序列数据输出有效*****//////
            ShortTrainingOutEnable <= 0;
            /*短训练序列数据输出*****//////
            ShortTrainingOutRe <= 8'b00000000;
            ShortTrainingOutIm <= 8'b00000000;
        end
    end
end

//--------------------------------------------------------------------------------

/*粗频偏估计数据输出*****//////
always@(posedge Clk or negedge Rst_n)
begin
    if (!Rst_n)
    begin
        /*全局复位下*******///////
        /*粗频偏估计数据输出有效*****//////
        EstimationOutEnable <= 0;
        /*粗频偏估计数据输出*****//////
        EstimationOutRe <= 8'b00000000;
        EstimationOutIm <= 8'b00000000;
    end
       else
    begin
        if (TempDataInEnable)
        begin
              /*输入数据有效缓存下*****//////
            if ((1<=DataIndex)&&(DataIndex<=80))
            begin
                   /* //1<=DataIndex<=5*16
                //用5个短训练序列做4次粗频偏校正*****//////
                 
                /*粗频偏估计数据输出有效*****//////
                EstimationOutEnable <= 1;                 
                /*粗频偏估计数据输出*****//////
                EstimationOutRe <= TempDataInRe;
                EstimationOutIm <= TempDataInIm;                       
            end
            else
            begin           
                /*DataIndex>=5*16
                //超出5个短训练序列*****//////

                /*粗频偏估计数据输出有效*****//////
                EstimationOutEnable <= 0;
                /*粗频偏估计数据输出*****//////
                EstimationOutRe <= 8'b00000000;
                EstimationOutIm <= 8'b00000000;
            end
        end
        else
        begin
            /*没有数据缓存有效*****//////
            /*粗频偏估计数据输出有效*****//////
            EstimationOutEnable <= 0;
            /*粗频偏估计数据输出*****//////
            EstimationOutRe <= 8'b00000000;
            EstimationOutIm <= 8'b00000000;
        end     
    end
end

//--------------------------------------------------------------------------------

/*长训练序列和数据序列输出*****//////
always@(posedge Clk or negedge Rst_n)
begin
    if (!Rst_n)
    begin
           /*全局复位*****//////
        /*长训练序列和数据序列输出有效*****//////
        OtherDataOutEnable <= 0;
        /*长训练序列和数据序列输出*****//////
        OtherDataOutRe <= 8'b00000000;
        OtherDataOutIm <= 8'b00000000;
     end
       else
      begin
        if (TempDataInEnable)
         begin
            /*输入数据有效缓存下*****//////
            if (DataIndex>160)
            begin
                   /* //DataIndex>160
                //超出短训练序列*****//////
                     
                /*长训练序列和数据序列输出有效*****//////
                OtherDataOutEnable <= 1;
                /*长训练序列和数据序列输出*****//////
                 OtherDataOutRe <= TempDataInRe;
                OtherDataOutIm <= TempDataInIm;
               end
            else
               begin
                /*//DataIndex
                //还没有到长训练序列和数据序列*****//////
                 
                /*长训练序列和数据序列输出有效*****//////
                 OtherDataOutEnable <= 0;
                /*长训练序列和数据序列输出*****//////
                  OtherDataOutRe <= 8'b00000000;
                 OtherDataOutIm <= 8'b00000000;
               end
          end
        else
        begin
            /*没有数据缓存有效*****//////
            /*长训练蛄泻数据序列输出有效*****//////
            OtherDataOutEnable <= 0;
            /*长训练序列和数据序列输出*****//////
            OtherDataOutRe <= 8'b00000000;
            OtherDataOutIm <= 8'b00000000;
          end     
     end
end

endmodule
原文地址:https://www.cnblogs.com/chensimin1990/p/13210525.html