Line 1... |
Line 1... |
################################################################################
|
################################################################################
|
#
|
#
|
# Copyright 2012-2013, Sinclair R.F., Inc.
|
# Copyright 2012-2014, Sinclair R.F., Inc.
|
#
|
#
|
################################################################################
|
################################################################################
|
|
|
import math;
|
import math;
|
import re;
|
import re;
|
|
|
from ssbccPeripheral import SSBCCperipheral
|
from ssbccPeripheral import SSBCCperipheral
|
|
from ssbccUtil import IsPowerOf2;
|
from ssbccUtil import SSBCCException;
|
from ssbccUtil import SSBCCException;
|
|
|
class UART_Tx(SSBCCperipheral):
|
class UART_Tx(SSBCCperipheral):
|
"""
|
"""
|
Transmit side of a UART:
|
Transmit side of a UART:
|
Line 20... |
Line 21... |
PERIPHERAL UART_Tx outport=O_outport_name \\
|
PERIPHERAL UART_Tx outport=O_outport_name \\
|
outstatus=I_outstatus_name \\
|
outstatus=I_outstatus_name \\
|
baudmethod={clk/rate|count} \\
|
baudmethod={clk/rate|count} \\
|
[outsignal=o_name] \\
|
[outsignal=o_name] \\
|
[noOutFIFO|outFIFO=n] \\
|
[noOutFIFO|outFIFO=n] \\
|
|
[{CTS|CTSn}=i_cts_name] \\
|
[nStop={1|2}]\n
|
[nStop={1|2}]\n
|
Where:
|
Where:
|
outport=O_outport_name
|
outport=O_outport_name
|
specifies the symbol used by the outport instruction to write a byte to
|
specifies the symbol used by the outport instruction to write a byte to
|
the peripheral
|
the peripheral
|
Line 57... |
Line 59... |
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.
|
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\n
|
Note: the peripheral does not accept 1.5 stop bits\n
|
Line 97... |
Line 110... |
|
|
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 (
|
( 'baudmethod', r'\S+$', lambda v : self.RateMethod(config,v), ),
|
('noOutFIFO', None, None, ),
|
('noOutFIFO', 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, ),
|
):
|
);
|
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 ('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 math.modf(math.log(x,2))[0] != 0:
|
|
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',
|
'outport',
|
'outport',
|
'outstatus',
|
'outstatus',
|
Line 137... |
Line 145... |
):
|
):
|
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, ),
|
('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);
|
( 'noOutFIFO', 'outFIFO', 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.outsignal,1,'output',loc);
|
for ioEntry in (
|
|
( 'outsignal', 1, 'output', ),
|
|
( 'CTS', 1, 'input', ),
|
|
( 'CTSn', 1, 'input', ),
|
|
):
|
|
if hasattr(self,ioEntry[0]):
|
|
config.AddIO(getattr(self,ioEntry[0]),ioEntry[1],ioEntry[2],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);
|
config.AddSignal('s__%s__Tx_wr' % self.namestring,1,loc);
|
config.AddSignal('s__%s__Tx_wr' % self.namestring,1,loc);
|
config.AddOutport((self.outport,False,
|
config.AddOutport((self.outport,False,
|
('s__%s__Tx' % self.namestring,8,'data',),
|
('s__%s__Tx' % self.namestring,8,'data',),
|
Line 171... |
Line 190... |
for subpair in (
|
for subpair in (
|
(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'@BAUDMETHOD@', str(self.baudmethod), ),
|
(r'@BAUDMETHOD@', str(self.baudmethod), ),
|
|
( 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, ),
|
):
|
):
|
body = re.sub(subpair[0],subpair[1],body);
|
body = re.sub(subpair[0],subpair[1],body);
|