dpcnt001h.vmd 3 KB
/**************************************************************/
/*    Verilog module of datapath cell DPCNT001H               */
/*    Designed by    Lin Yang    VLSI Technology  Nov. 5, 90  */
/*    Designed by    Chunling Liu   Compass       July 6, 92  */
/*    Modified by    Linda J. Xu    Compass       Nov. 2, 92  */
/*                                                            */
/*    The following is the port description                   */
/*    Data ports                                              */
/*        D    : the input port                               */
/*        Q    : the output port                              */
/*        QN   : the output port                              */
/*    Control ports                                           */
/*        INST_CP    : the clock signal                       */
/*        INST_CLEAR : the clear signal                       */
/*        INST_CIN   : the carry input                        */
/*        INST_COUT  : the carry output                       */
/*        INST_LOAD  : the load enable signal                 */
/*        INST_COUNT : the count enable signal                */
/*        INST_ID    : the increment/decrement control signal */
/*    Parameters                                              */
/*        WORDSIZE  : the word size of the datapath cell      */
/*        DELAY     : the delay time from input to output     */
/*        BF    : the  with/without buffer flag           */
/*                    0 for without buffer; 1 for with buffer */
/**************************************************************/
module dpcnt001h(D, Q, QN, INST_CP, INST_CLEAR, INST_CIN,
                  INST_COUT, INST_LOAD, INST_COUNT, INST_ID);

  parameter WORDSIZE = 8, DELAY = 3, SETUP = 1, HOLD = 1, BF = 1;
  input  [WORDSIZE-1:0] D;
  output [WORDSIZE-1:0] Q, QN;
  input  INST_CP, INST_CLEAR, INST_CIN;
  output INST_COUT;
  input  INST_LOAD, INST_COUNT, INST_ID;

  reg    [WORDSIZE-1:0] dff;
  reg    cout;

  function [WORDSIZE:0] cnt;
  input  [WORDSIZE-1:0] d;

  reg flag;

    begin
      flag = WORDSIZE-1;
      if (BF ==1)
        flag = 1'b0;

      if (INST_CLEAR == 0)
        cnt = {WORDSIZE{1'b0}};
      else if (INST_CLEAR == 1)
      begin
        if (INST_LOAD == 1)
           cnt = ~(~d);
        else if (INST_LOAD == 0)
        begin
          case ({INST_COUNT,INST_CIN,INST_ID})
            3'b 101 : cnt = dff + 'b1;
            3'b 100 : cnt = dff + {WORDSIZE{1'b1}};
            3'b 000 ,
            3'b 001 ,
            3'b 010 ,
            3'b 011 ,
            3'b 110 ,
            3'b 111 : cnt = dff;
            default cnt = {WORDSIZE{1'b x}};
          endcase
        end
        else
          cnt[WORDSIZE-1:0] = {WORDSIZE{1'bx}};
      end
      else
        cnt[WORDSIZE-1:0] = {WORDSIZE{1'bx}};

      cnt[WORDSIZE] = flag ^ (&cnt[WORDSIZE-1:0]);
    end
  endfunction
  always @ ( posedge INST_CP or negedge INST_CLEAR)
         {cout, dff} = cnt(D);

  assign #DELAY INST_COUT = cout, Q = dff, QN = ~dff;

endmodule