| 1 |
2 |
sinclairrf |
################################################################################
|
| 2 |
|
|
#
|
| 3 |
|
|
# Copyright 2013, Sinclair R.F., Inc.
|
| 4 |
|
|
#
|
| 5 |
|
|
################################################################################
|
| 6 |
|
|
|
| 7 |
|
|
import math;
|
| 8 |
|
|
import re;
|
| 9 |
|
|
|
| 10 |
|
|
from ssbccPeripheral import SSBCCperipheral
|
| 11 |
|
|
from ssbccUtil import CeilLog2;
|
| 12 |
|
|
from ssbccUtil import IsPowerOf2;
|
| 13 |
|
|
from ssbccUtil import SSBCCException;
|
| 14 |
|
|
|
| 15 |
|
|
class inFIFO_async(SSBCCperipheral):
|
| 16 |
|
|
"""
|
| 17 |
|
|
Input FIFO with an asynchronous clock.\n
|
| 18 |
|
|
Usage:
|
| 19 |
|
|
PERIPHERAL inFIFO_async inclk=<i_clock> \\
|
| 20 |
|
|
data=<i_data> \\
|
| 21 |
|
|
data_wr=<i_data_wr> \\
|
| 22 |
|
|
data_full=<o_data_full> \\
|
| 23 |
|
|
inport=<I_data> \\
|
| 24 |
|
|
inempty=<I_empty> \\
|
| 25 |
|
|
depth=<N> \n
|
| 26 |
|
|
Where:
|
| 27 |
|
|
inclk=<i_clock>
|
| 28 |
|
|
specifies the name of the asynchronous clock
|
| 29 |
|
|
data=<i_data>
|
| 30 |
|
|
specifies the name of the 8-bit incoming data
|
| 31 |
|
|
data_wr=<i_data_wr>
|
| 32 |
|
|
specifies the name if the write strobe
|
| 33 |
|
|
data_full=<o_data_full>
|
| 34 |
|
|
specifies the name of the output "full" status of the FIFO
|
| 35 |
|
|
inport=<I_data>
|
| 36 |
|
|
specifies the name of the port to read from the FIFO
|
| 37 |
|
|
inempty=<I_empty>
|
| 38 |
|
|
specifies the symbol used by the inport instruction to read the "empty"
|
| 39 |
|
|
status of the FIFO
|
| 40 |
|
|
depth=<N>
|
| 41 |
|
|
specifies the depth of the FIFO
|
| 42 |
|
|
Note: N must be a power of 2 and must be at least 16.\n
|
| 43 |
|
|
Example: Provide a FIFO for an external device or IP that pushes 8-bit data
|
| 44 |
|
|
to the processor.\n
|
| 45 |
|
|
The PERIPHERAL statement would be:\n
|
| 46 |
|
|
PERIPHERAL inFIFO_async inclk=i_dev_clk \\
|
| 47 |
|
|
data=i_dev_data \\
|
| 48 |
|
|
data_wr=i_dev_data_wr \\
|
| 49 |
|
|
data_full=o_dev_full \\
|
| 50 |
|
|
inport=I_DATA_FIFO \\
|
| 51 |
|
|
inempty=I_DATA_FIFO_EMPTY \\
|
| 52 |
|
|
depth=32\n
|
| 53 |
|
|
To read from the FIFO and store the values on the data stack until the FIFO
|
| 54 |
|
|
is empty and to track the number of values received, do the following:\n
|
| 55 |
|
|
; ( - u_first ... u_last u_N )
|
| 56 |
|
|
0x00 :loop
|
| 57 |
|
|
.inport(I_DATA_FIFO_EMPTY) .jumpc(done)
|
| 58 |
|
|
.inport(I_DATA_FIFO) swap
|
| 59 |
|
|
.jump(loop,1+)
|
| 60 |
|
|
:done
|
| 61 |
|
|
"""
|
| 62 |
|
|
|
| 63 |
|
|
def __init__(self,peripheralFile,config,param_list,loc):
|
| 64 |
|
|
# Use the externally provided file name for the peripheral
|
| 65 |
|
|
self.peripheralFile = peripheralFile;
|
| 66 |
|
|
# Get the parameters.
|
| 67 |
|
|
allowables = (
|
| 68 |
|
|
('inclk', r'i_\w+$', None, ),
|
| 69 |
|
|
('data', r'i_\w+$', None, ),
|
| 70 |
|
|
('data_wr', r'i_\w+$', None, ),
|
| 71 |
|
|
('data_full', r'o_\w+$', None, ),
|
| 72 |
|
|
('inport', r'I_\w+$', None, ),
|
| 73 |
|
|
('inempty', r'I_\w+$', None, ),
|
| 74 |
|
|
('depth', r'[1-9]\d*$', int, ),
|
| 75 |
|
|
);
|
| 76 |
|
|
names = [a[0] for a in allowables];
|
| 77 |
|
|
for param_tuple in param_list:
|
| 78 |
|
|
param = param_tuple[0];
|
| 79 |
|
|
if param not in names:
|
| 80 |
|
|
raise SSBCCException('Unrecognized parameter "%s" at %s' % (param,loc,));
|
| 81 |
|
|
param_test = allowables[names.index(param)];
|
| 82 |
|
|
self.AddAttr(config,param,param_tuple[1],param_test[1],loc,param_test[2]);
|
| 83 |
|
|
# Ensure the required parameters are provided.
|
| 84 |
|
|
for paramname in names:
|
| 85 |
|
|
if not hasattr(self,paramname):
|
| 86 |
|
|
raise SSBCCException('Required parameter "%s" is missing at %s' % (paramname,loc,));
|
| 87 |
|
|
# Ensure the depth is a power of 2.
|
| 88 |
|
|
if not IsPowerOf2(self.depth):
|
| 89 |
|
|
raise SSBCCException('depth=%d must be a power of 2 at %s' % (self.depth,loc,));
|
| 90 |
|
|
if self.depth < 16:
|
| 91 |
|
|
raise SSBCCException('depth=%d must be at least 16 at %s' % (self.depth,loc,));
|
| 92 |
|
|
# Add the I/O port, internal signals, and the INPORT and OUTPORT symbols for this peripheral.
|
| 93 |
|
|
config.AddIO(self.inclk,1,'input',loc);
|
| 94 |
|
|
config.AddIO(self.data,8,'input',loc);
|
| 95 |
|
|
config.AddIO(self.data_wr,1,'input',loc);
|
| 96 |
|
|
config.AddIO(self.data_full,1,'output',loc);
|
| 97 |
|
|
config.AddSignal('s__%s__data' % self.data,8,loc);
|
| 98 |
|
|
config.AddSignal('s__%s__empty' % self.data,1,loc);
|
| 99 |
|
|
self.ix_data = config.NInports();
|
| 100 |
|
|
config.AddInport((self.inport,
|
| 101 |
|
|
('s__%s__data' % self.data,8,'data',),
|
| 102 |
|
|
),loc);
|
| 103 |
|
|
config.AddInport((self.inempty,
|
| 104 |
|
|
('s__%s__empty' % self.data,1,'data',),
|
| 105 |
|
|
),loc);
|
| 106 |
|
|
|
| 107 |
|
|
def GenVerilog(self,fp,config):
|
| 108 |
|
|
body = self.LoadCore(self.peripheralFile,'.v');
|
| 109 |
|
|
for subpair in (
|
| 110 |
|
|
(r'@DATA@', self.data, ),
|
| 111 |
|
|
(r'@DATA_FULL@', self.data_full, ),
|
| 112 |
|
|
(r'@DATA_WR@', self.data_wr, ),
|
| 113 |
|
|
(r'@DEPTH@', str(self.depth), ),
|
| 114 |
|
|
(r'@DEPTH-1@', str(self.depth-1), ),
|
| 115 |
|
|
(r'@DEPTH_NBITS@', str(CeilLog2(self.depth)), ),
|
| 116 |
|
|
(r'@DEPTH_NBITS-1@', str(CeilLog2(self.depth)-1), ),
|
| 117 |
|
|
(r'@INCLK@', self.inclk, ),
|
| 118 |
|
|
(r'@IX_DATA@', str(self.ix_data), ),
|
| 119 |
|
|
(r'@NAME@', self.data, ),
|
| 120 |
|
|
(r'\bgen__', 'gen__%s__' % self.data, ),
|
| 121 |
|
|
(r'\bix__', 'ix__%s__' % self.data, ),
|
| 122 |
|
|
(r'\bs__', 's__%s__' % self.data, ),
|
| 123 |
|
|
):
|
| 124 |
|
|
body = re.sub(subpair[0],subpair[1],body);
|
| 125 |
|
|
body = self.GenVerilogFinal(config,body);
|
| 126 |
|
|
fp.write(body);
|