OpenCores
URL https://opencores.org/ocsvn/ssbcc/ssbcc/trunk

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [core/] [9x8/] [peripherals/] [inFIFO_async.py] - Diff between revs 2 and 6

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 2 Rev 6
################################################################################
################################################################################
#
#
# Copyright 2013, Sinclair R.F., Inc.
# Copyright 2013-2014, Sinclair R.F., Inc.
#
#
################################################################################
################################################################################
 
 
import math;
import math;
import re;
import re;
 
 
from ssbccPeripheral import SSBCCperipheral
from ssbccPeripheral import SSBCCperipheral
from ssbccUtil import CeilLog2;
from ssbccUtil import CeilLog2;
from ssbccUtil import IsPowerOf2;
from ssbccUtil import IsPowerOf2;
from ssbccUtil import SSBCCException;
from ssbccUtil import SSBCCException;
 
 
class inFIFO_async(SSBCCperipheral):
class inFIFO_async(SSBCCperipheral):
  """
  """
  Input FIFO with an asynchronous clock.\n
  Input FIFO with an asynchronous clock.\n
  Usage:
  Usage:
    PERIPHERAL inFIFO_async     inclk=<i_clock>         \\
    PERIPHERAL inFIFO_async     inclk=<i_clock>         \\
                                data=<i_data>           \\
                                data=<i_data>           \\
                                data_wr=<i_data_wr>     \\
                                data_wr=<i_data_wr>     \\
                                data_full=<o_data_full> \\
                                data_full=<o_data_full> \\
                                inport=<I_data>         \\
                                inport=<I_data>         \\
                                inempty=<I_empty>       \\
                                inempty=<I_empty>       \\
                                depth=<N>               \n
                                depth=<N>               \n
  Where:
  Where:
    inclk=<i_clock>
    inclk=<i_clock>
      specifies the name of the asynchronous clock
      specifies the name of the asynchronous clock
    data=<i_data>
    data=<i_data>
      specifies the name of the 8-bit incoming data
      specifies the name of the 8-bit incoming data
    data_wr=<i_data_wr>
    data_wr=<i_data_wr>
      specifies the name if the write strobe
      specifies the name if the write strobe
    data_full=<o_data_full>
    data_full=<o_data_full>
      specifies the name of the output "full" status of the FIFO
      specifies the name of the output "full" status of the FIFO
    inport=<I_data>
    inport=<I_data>
      specifies the name of the port to read from the FIFO
      specifies the name of the port to read from the FIFO
    inempty=<I_empty>
    inempty=<I_empty>
      specifies the symbol used by the inport instruction to read the "empty"
      specifies the symbol used by the inport instruction to read the "empty"
      status of the FIFO
      status of the FIFO
    depth=<N>
    depth=<N>
      specifies the depth of the FIFO
      specifies the depth of the FIFO
      Note:  N must be a power of 2 and must be at least 16.\n
      Note:  N must be a power of 2 and must be at least 16.\n
  Example:  Provide a FIFO for an external device or IP that pushes 8-bit data
  Example:  Provide a FIFO for an external device or IP that pushes 8-bit data
    to the processor.\n
    to the processor.\n
    The PERIPHERAL statement would be:\n
    The PERIPHERAL statement would be:\n
      PERIPHERAL inFIFO_async   inclk=i_dev_clk           \\
      PERIPHERAL inFIFO_async   inclk=i_dev_clk           \\
                                data=i_dev_data           \\
                                data=i_dev_data           \\
                                data_wr=i_dev_data_wr     \\
                                data_wr=i_dev_data_wr     \\
                                data_full=o_dev_full      \\
                                data_full=o_dev_full      \\
                                inport=I_DATA_FIFO        \\
                                inport=I_DATA_FIFO        \\
                                inempty=I_DATA_FIFO_EMPTY \\
                                inempty=I_DATA_FIFO_EMPTY \\
                                depth=32\n
                                depth=32\n
    To read from the FIFO and store the values on the data stack until the FIFO
    To read from the FIFO and store the values on the data stack until the FIFO
    is empty and to track the number of values received, do the following:\n
    is empty and to track the number of values received, do the following:\n
      ; ( - u_first ... u_last u_N )
      ; ( - u_first ... u_last u_N )
      0x00 :loop
      0x00 :loop
        .inport(I_DATA_FIFO_EMPTY) .jumpc(done)
        .inport(I_DATA_FIFO_EMPTY) .jumpc(done)
        .inport(I_DATA_FIFO) swap
        .inport(I_DATA_FIFO) swap
        .jump(loop,1+)
        .jump(loop,1+)
      :done
      :done
  """
  """
 
 
  def __init__(self,peripheralFile,config,param_list,loc):
  def __init__(self,peripheralFile,config,param_list,loc):
    # Use the externally provided file name for the peripheral
    # Use the externally provided file name for the peripheral
    self.peripheralFile = peripheralFile;
    self.peripheralFile = peripheralFile;
    # Get the parameters.
    # Get the parameters.
    allowables = (
    allowables = (
      ('inclk',         r'i_\w+$',      None,   ),
      ( 'inclk',        r'i_\w+$',      None,   ),
      ('data',          r'i_\w+$',      None,   ),
      ( 'data',         r'i_\w+$',      None,   ),
      ('data_wr',       r'i_\w+$',      None,   ),
      ( 'data_wr',      r'i_\w+$',      None,   ),
      ('data_full',     r'o_\w+$',      None,   ),
      ( 'data_full',    r'o_\w+$',      None,   ),
      ('inport',        r'I_\w+$',      None,   ),
      ( 'inport',       r'I_\w+$',      None,   ),
      ('inempty',       r'I_\w+$',      None,   ),
      ('inempty',       r'I_\w+$',      None,   ),
      ('depth',         r'[1-9]\d*$',   int,    ),
      ( 'depth',        r'[1-9]\d*$',   lambda v : self.IntPow2(v,minValue=16), ),
    );
    );
    names = [a[0] for a in allowables];
    names = [a[0] for a in allowables];
    for param_tuple in param_list:
    for param_tuple in param_list:
      param = param_tuple[0];
      param = param_tuple[0];
      if param not in names:
      if param not in names:
        raise SSBCCException('Unrecognized parameter "%s" at %s' % (param,loc,));
        raise SSBCCException('Unrecognized parameter "%s" at %s' % (param,loc,));
      param_test = allowables[names.index(param)];
      param_test = allowables[names.index(param)];
      self.AddAttr(config,param,param_tuple[1],param_test[1],loc,param_test[2]);
      self.AddAttr(config,param,param_tuple[1],param_test[1],loc,param_test[2]);
    # Ensure the required parameters are provided.
    # Ensure the required parameters are provided.
    for paramname in names:
    for paramname in names:
      if not hasattr(self,paramname):
      if not hasattr(self,paramname):
        raise SSBCCException('Required parameter "%s" is missing at %s' % (paramname,loc,));
        raise SSBCCException('Required parameter "%s" is missing at %s' % (paramname,loc,));
    # Ensure the depth is a power of 2.
 
    if not IsPowerOf2(self.depth):
 
      raise SSBCCException('depth=%d must be a power of 2 at %s' % (self.depth,loc,));
 
    if self.depth < 16:
 
      raise SSBCCException('depth=%d must be at least 16 at %s' % (self.depth,loc,));
 
    # Add the I/O port, internal signals, and the INPORT and OUTPORT symbols for this peripheral.
    # Add the I/O port, internal signals, and the INPORT and OUTPORT symbols for this peripheral.
    config.AddIO(self.inclk,1,'input',loc);
    config.AddIO(self.inclk,1,'input',loc);
    config.AddIO(self.data,8,'input',loc);
    config.AddIO(self.data,8,'input',loc);
    config.AddIO(self.data_wr,1,'input',loc);
    config.AddIO(self.data_wr,1,'input',loc);
    config.AddIO(self.data_full,1,'output',loc);
    config.AddIO(self.data_full,1,'output',loc);
    config.AddSignal('s__%s__data' % self.data,8,loc);
    config.AddSignal('s__%s__data' % self.data,8,loc);
    config.AddSignal('s__%s__empty' % self.data,1,loc);
    config.AddSignal('s__%s__empty' % self.data,1,loc);
    self.ix_data = config.NInports();
    self.ix_data = config.NInports();
    config.AddInport((self.inport,
    config.AddInport((self.inport,
                     ('s__%s__data' % self.data,8,'data',),
                     ('s__%s__data' % self.data,8,'data',),
                    ),loc);
                    ),loc);
    config.AddInport((self.inempty,
    config.AddInport((self.inempty,
                     ('s__%s__empty' % self.data,1,'data',),
                     ('s__%s__empty' % self.data,1,'data',),
                    ),loc);
                    ),loc);
 
 
  def GenVerilog(self,fp,config):
  def GenVerilog(self,fp,config):
    body = self.LoadCore(self.peripheralFile,'.v');
    body = self.LoadCore(self.peripheralFile,'.v');
    for subpair in (
    for subpair in (
      (r'@DATA@',               self.data,                      ),
        ( r'@DATA@',            self.data,                      ),
      (r'@DATA_FULL@',          self.data_full,                 ),
        ( r'@DATA_FULL@',       self.data_full,                 ),
      (r'@DATA_WR@',            self.data_wr,                   ),
        ( r'@DATA_WR@',         self.data_wr,                   ),
      (r'@DEPTH@',              str(self.depth),                ),
        ( r'@DEPTH@',           str(self.depth),                ),
      (r'@DEPTH-1@',            str(self.depth-1),              ),
        ( r'@DEPTH-1@',         str(self.depth-1),              ),
      (r'@DEPTH_NBITS@',        str(CeilLog2(self.depth)),      ),
        ( r'@DEPTH_NBITS@',     str(CeilLog2(self.depth)),      ),
      (r'@DEPTH_NBITS-1@',      str(CeilLog2(self.depth)-1),    ),
        ( r'@DEPTH_NBITS-1@',   str(CeilLog2(self.depth)-1),    ),
      (r'@INCLK@',              self.inclk,                     ),
        ( r'@INCLK@',           self.inclk,                     ),
      (r'@IX_DATA@',            str(self.ix_data),              ),
        ( r'@IX_DATA@',         str(self.ix_data),              ),
      (r'@NAME@',               self.data,                      ),
        ( r'@NAME@',            self.data,                      ),
      (r'\bgen__',              'gen__%s__' % self.data,        ),
        ( r'\bgen__',           'gen__%s__' % self.data,        ),
      (r'\bix__',               'ix__%s__' % self.data,         ),
        ( r'\bix__',            'ix__%s__' % self.data,         ),
      (r'\bs__',                's__%s__' % self.data,          ),
        ( r'\bs__',             's__%s__' % self.data,          ),
    ):
      ):
      body = re.sub(subpair[0],subpair[1],body);
      body = re.sub(subpair[0],subpair[1],body);
    body = self.GenVerilogFinal(config,body);
    body = self.GenVerilogFinal(config,body);
    fp.write(body);
    fp.write(body);
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.