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

Subversion Repositories ssbcc

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

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 2 Rev 6
Line 1... Line 1...
################################################################################
################################################################################
#
#
# Copyright 2013, Sinclair R.F., Inc.
# Copyright 2013-2014, Sinclair R.F., Inc.
#
#
################################################################################
################################################################################
 
 
import math;
import math;
import re;
import re;
Line 27... Line 27...
                       [outsignal=o_name]          \\
                       [outsignal=o_name]          \\
                       [noSync|sync=n]             \\
                       [noSync|sync=n]             \\
                       [noDeglitch|deglitch=n]     \\
                       [noDeglitch|deglitch=n]     \\
                       [noInFIFO|inFIFO=n]         \\
                       [noInFIFO|inFIFO=n]         \\
                       [noOutFIFO|outFIFO=n]       \\
                       [noOutFIFO|outFIFO=n]       \\
 
                       [{CTS|CTSn}=i_cts_name]     \\
 
                       [{RTR|RTRn}=i_rtr_name]     \\
                       [nStop={1|2}]               \n
                       [nStop={1|2}]               \n
  Where:
  Where:
    inport=I_inport_name
    inport=I_inport_name
      specifies the symbol used by the inport instruction to read a received by
      specifies the symbol used by the inport instruction to read a received by
      from the peripheral
      from the peripheral
Line 95... Line 97...
      optionally state that the peripheral will not have an output FIFO
      optionally state that the peripheral will not have an output FIFO
      Note:  This is the default.
      Note:  This is the default.
    outFIFO=n
    outFIFO=n
      optionally add a FIFO of depth n to the output side of the UART
      optionally add a FIFO of depth n to the output side of the UART
      Note:  n must be a power of 2.
      Note:  n must be a power of 2.
 
    CTS=i_cts_name or CTSn=i_cts_name
 
      optionally specify an input handshake signal to control whether or not the
 
      peripheral transmits data
 
      Note:  If CTS is specified then the transmitter is active when i_cts_name
 
             is high.  If CTSn is specified then the transmitter is active when
 
             i_cts_name is low.
 
      Note:  The default, i.e., neither CTS nor CTSn is specified, is to always
 
             enable the transmitter.
 
      Note:  If there is no FIFO and the CTS/CTSn handshake indicates that the
 
             data flow is disabled, then the busy signal will be high and the
 
             processor code must not transmit the next byte.
 
    RTR=i_rtr_name or RTRn=i_rtr_name
 
      optionally specify an output handshake signal to indicate that the
 
      peripheral is ready to receive data
 
      Note:  If RTR is specified then the receiver indicates it is ready when
 
             i_rtr_name is high.  If RTRn is specified then the transmitter
 
             indicates it is ready when i_rtr_name is low.
 
      Note:  The default, i.e., neither CTS nor CTSn is specified, is to always
 
             enable the receiver.
 
      Note:  If there is no FIFO and the RTR/RTRn handshake indicates that the
 
             receiver is not ready as soon as it starts receiving data and
 
             until that data is read from the peripheral.
    nStop=n
    nStop=n
      optionally configure the peripheral for n stop bits
      optionally configure the peripheral for n stop bits
      default:  1 stop bit
      default:  1 stop bit
      Note:  n must be 1 or 2
      Note:  n must be 1 or 2
      Note:  the peripheral does not accept 1.5 stop bits
      Note:  the peripheral does not accept 1.5 stop bits\n
  The following ports are provided by this peripheral:
  The following ports are provided by this peripheral:
    I_inport_name
    I_inport_name
      input a recieved byte from the peripheral
      input a recieved byte from the peripheral
      Note:  If there is no input FIFO, then this is the last received byte.
      Note:  If there is no input FIFO, then this is the last received byte.
             If there is an input FIFO, then this is the next byte in the FIFO.
             If there is an input FIFO, then this is the next byte in the FIFO.
Line 132... Line 156...
        accept more writes
        accept more writes
        Note:  If there is no FIFO this means that the peripheral is still
        Note:  If there is no FIFO this means that the peripheral is still
               transmitting the last byte.  If there is an output FIFO it means
               transmitting the last byte.  If there is an output FIFO it means
               that it is full.\n
               that it is full.\n
        Note:  "Busy" is used rather that "ready" to facilitate loops that wait
        Note:  "Busy" is used rather that "ready" to facilitate loops that wait
               for a not-busy status to send the next byte.  See the examples below.
               for a not-busy status to send the next byte.  See the examples below.\n
  WARNING:  The peripheral is very simple and does not protect against writing a
  WARNING:  The peripheral is very simple and does not protect against writing a
            new value in the middle of a transmition or writing to a full FIFO.
            new value in the middle of a transmition or writing to a full FIFO.
            Adding such logic would be contrary to the design principle of
            Adding such logic would be contrary to the design principle of
            keeping the HDL small and relying on the assembly code to provide
            keeping the HDL small and relying on the assembly code to provide
            the protection.\n
            the protection.\n
Line 152... Line 176...
 
 
  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.
    for param_tuple in param_list:
    allowables = (
      param = param_tuple[0];
      ( 'CTS',          r'i_\w+$',      None,           ),
      param_arg = param_tuple[1];
      ( 'CTSn',         r'i_\w+$',      None,           ),
      for param_test in (
      ( 'RTR',          r'o_\w+$',      None,           ),
 
      ( 'RTRn',         r'o_\w+$',      None,           ),
 
      ( 'baudmethod',   r'\S+$',        lambda v : self.RateMethod(config,v), ),
          ('deglitch',   r'[1-9]\d*$', int,   ),
          ('deglitch',   r'[1-9]\d*$', int,   ),
 
      ( 'inFIFO',       r'[1-9]\d*$',   lambda v : self.IntPow2(v), ),
          ('inempty',    r'I_\w+$',    None,  ),
          ('inempty',    r'I_\w+$',    None,  ),
          ('inport',     r'I_\w+$',    None,  ),
          ('inport',     r'I_\w+$',    None,  ),
          ('insignal',   r'i_\w+$',    None,  ),
          ('insignal',   r'i_\w+$',    None,  ),
          ('noDeglitch', None,         None,  ),
          ('noDeglitch', None,         None,  ),
          ('noInFIFO',   None,         None,  ),
          ('noInFIFO',   None,         None,  ),
          ('noOutFIFO',  None,         None,  ),
          ('noOutFIFO',  None,         None,  ),
          ('noSync',     None,         None,  ),
          ('noSync',     None,         None,  ),
          ('nStop',      r'[12]$',     int,   ),
          ('nStop',      r'[12]$',     int,   ),
 
      ( 'outFIFO',      r'[1-9]\d*$',   lambda v : self.IntPow2(v), ),
          ('outport',    r'O_\w+$',    None,  ),
          ('outport',    r'O_\w+$',    None,  ),
          ('outsignal',  r'o_\w+$',    None,  ),
          ('outsignal',  r'o_\w+$',    None,  ),
          ('outstatus',  r'I_\w+$',    None,  ),
          ('outstatus',  r'I_\w+$',    None,  ),
          ('sync',       r'[1-9]\d*$', int,   ),
          ('sync',       r'[1-9]\d*$', int,   ),
        ):
    );
        if param == param_test[0]:
    names = [a[0] for a in allowables];
          self.AddAttr(config,param,param_arg,param_test[1],loc,param_test[2]);
    for param_tuple in param_list:
          break;
      param = param_tuple[0];
      else:
      if param not in names:
        if param == 'baudmethod':
        raise SSBCCException('Unrecognized parameter "%s" at %s' % (param,loc,));
          self.AddRateMethod(config,param,param_arg,loc);
      param_test = allowables[names.index(param)];
        elif param in ('inFIFO','outFIFO',):
      self.AddAttr(config,param,param_tuple[1],param_test[1],loc,param_test[2]);
          self.AddAttr(config,param,param_arg,r'[1-9]\d*$',loc,int);
 
          x = getattr(self,param);
 
          if not IsPowerOf2(x):
 
            raise SSBCCException('%s=%d must be a power of 2 at %s' % (param,x,loc,));
 
        else:
 
          raise SSBCCException('Unrecognized parameter at %s: %s' % (loc,param,));
 
    # Ensure the required parameters are provided.
    # Ensure the required parameters are provided.
    for paramname in (
    for paramname in (
        'baudmethod',
        'baudmethod',
        'inempty',
        'inempty',
        'inport',
        'inport',
Line 203... Line 225...
      ):
      ):
      if not hasattr(self,optionalpair[0]):
      if not hasattr(self,optionalpair[0]):
        setattr(self,optionalpair[0],optionalpair[1]);
        setattr(self,optionalpair[0],optionalpair[1]);
    # Ensure exclusive pair configurations are set and consistent.
    # Ensure exclusive pair configurations are set and consistent.
    for exclusivepair in (
    for exclusivepair in (
 
        ( 'CTS',        'CTSn',         None,           None,   ),
 
        ( 'RTR',        'RTRn',         None,           None,   ),
        ('noSync',     'sync',     'sync',       3,    ),
        ('noSync',     'sync',     'sync',       3,    ),
        ('noDeglitch', 'deglitch', 'noDeglitch', True, ),
        ('noDeglitch', 'deglitch', 'noDeglitch', True, ),
        ('noInFIFO',   'inFIFO',   'noInFIFO',   True, ),
        ('noInFIFO',   'inFIFO',   'noInFIFO',   True, ),
        ('noOutFIFO',  'outFIFO',  'noOutFIFO',  True, ),
        ('noOutFIFO',  'outFIFO',  'noOutFIFO',  True, ),
      ):
      ):
      if hasattr(self,exclusivepair[0]) and hasattr(self,exclusivepair[1]):
      if hasattr(self,exclusivepair[0]) and hasattr(self,exclusivepair[1]):
        raise SSBCCException('Only one of "%s" and "%s" can be specified at %s' % (exclusivepair[0],exclusivepair[1],loc,));
        raise SSBCCException('Only one of "%s" and "%s" can be specified at %s' % (exclusivepair[0],exclusivepair[1],loc,));
      if not hasattr(self,exclusivepair[0]) and not hasattr(self,exclusivepair[1]):
      if not hasattr(self,exclusivepair[0]) and not hasattr(self,exclusivepair[1]) and exclusivepair[2]:
        setattr(self,exclusivepair[2],exclusivepair[3]);
        setattr(self,exclusivepair[2],exclusivepair[3]);
      if hasattr(self,exclusivepair[0]):
    # Convert configurations to alternative format.
        delattr(self,exclusivepair[0]);
    for equivalent in (
        setattr(self,exclusivepair[1],0);
        ( 'noDeglitch', 'deglitch',     0,      ),
 
        ( 'noInFIFO',   'inFIFO',       0,      ),
 
        ( 'noOutFIFO',  'outFIFO',      0,      ),
 
        ( 'noSync',     'sync',         0,      ),
 
      ):
 
      if hasattr(self,equivalent[0]):
 
        delattr(self,equivalent[0]);
 
        setattr(self,equivalent[1],equivalent[2]);
    # Set the string used to identify signals associated with this peripheral.
    # Set the string used to identify signals associated with this peripheral.
    self.namestring = self.outsignal;
    self.namestring = self.outsignal;
    # 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.insignal,1,'input',loc);
    for ioEntry in (
    config.AddIO(self.outsignal,1,'output',loc);
        ( 'insignal',   1,      'input',        ),
 
        ( 'outsignal',  1,      'output',       ),
 
        ( 'CTS',        1,      'input',        ),
 
        ( 'CTSn',       1,      'input',        ),
 
        ( 'RTR',        1,      'output',       ),
 
        ( 'RTRn',       1,      'output',       ),
 
      ):
 
      if hasattr(self,ioEntry[0]):
 
        config.AddIO(getattr(self,ioEntry[0]),ioEntry[1],ioEntry[2],loc);
    config.AddSignal('s__%s__Rx'          % self.namestring,8,loc);
    config.AddSignal('s__%s__Rx'          % self.namestring,8,loc);
    config.AddSignal('s__%s__Rx_empty'    % self.namestring,1,loc);
    config.AddSignal('s__%s__Rx_empty'    % self.namestring,1,loc);
    config.AddSignal('s__%s__Rx_rd'       % self.namestring,1,loc);
    config.AddSignal('s__%s__Rx_rd'       % self.namestring,1,loc);
    config.AddSignal('s__%s__Tx'          % self.namestring,8,loc);
    config.AddSignal('s__%s__Tx'          % self.namestring,8,loc);
    config.AddSignal('s__%s__Tx_busy'     % self.namestring,1,loc);
    config.AddSignal('s__%s__Tx_busy'     % self.namestring,1,loc);
Line 246... Line 285...
    config.functions['clog2'] = True;
    config.functions['clog2'] = True;
 
 
  def GenVerilog(self,fp,config):
  def GenVerilog(self,fp,config):
    for bodyextension in ('_Rx.v','_Tx.v',):
    for bodyextension in ('_Rx.v','_Tx.v',):
      body = self.LoadCore(self.peripheralFile,bodyextension);
      body = self.LoadCore(self.peripheralFile,bodyextension);
 
      if hasattr(self,'RTR') or hasattr(self,'RTRn'):
 
        body = re.sub(r'@RTR_BEGIN@\n','',body);
 
        body = re.sub(r'@RTR_END@\n','',body);
 
      else:
 
        if re.search(r'@RTR_BEGIN@',body):
 
          body = re.sub(r'@RTR_BEGIN@.*?@RTR_END@\n','',body,flags=re.DOTALL);
      for subpair in (
      for subpair in (
 
          ( r'@RTR_SIGNAL@',    self.RTR if hasattr(self,'RTR') else self.RTRn if hasattr(self,'RTRn') else '', ),
 
          ( r'@RTR_INVERT@',    '' if hasattr(self,'RTR') else '!', ),
                    (r'\bL__',          'L__@NAME@__', ),
                    (r'\bL__',          'L__@NAME@__', ),
                    (r'\bgen__',        'gen__@NAME@__', ),
                    (r'\bgen__',        'gen__@NAME@__', ),
                    (r'\bs__',          's__@NAME@__', ),
                    (r'\bs__',          's__@NAME@__', ),
                    (r'@INPORT@',       self.insignal, ),
                    (r'@INPORT@',       self.insignal, ),
                    (r'@BAUDMETHOD@',   str(self.baudmethod), ),
                    (r'@BAUDMETHOD@',   str(self.baudmethod), ),
                    (r'@SYNC@',         str(self.sync), ),
                    (r'@SYNC@',         str(self.sync), ),
                    (r'@DEGLITCH@',     str(self.deglitch), ),
                    (r'@DEGLITCH@',     str(self.deglitch), ),
                    (r'@INFIFO@',       str(self.inFIFO), ),
                    (r'@INFIFO@',       str(self.inFIFO), ),
 
          ( r'@ENABLED@',       self.CTS if hasattr(self,'CTS') else ('!%s' % self.CTSn) if hasattr(self,'CTSn') else '1\'b1', ),
                    (r'@NSTOP@',        str(self.nStop), ),
                    (r'@NSTOP@',        str(self.nStop), ),
                    (r'@OUTFIFO@',      str(self.outFIFO), ),
                    (r'@OUTFIFO@',      str(self.outFIFO), ),
                    (r'@NAME@',         self.namestring, ),
                    (r'@NAME@',         self.namestring, ),
                  ):
                  ):
 
        if re.search(subpair[0],body):
        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);
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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