1 |
2 |
sinclairrf |
################################################################################
|
2 |
|
|
#
|
3 |
6 |
sinclairrf |
# Copyright 2013-2014, Sinclair R.F., Inc.
|
4 |
2 |
sinclairrf |
#
|
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 outFIFO_async(SSBCCperipheral):
|
16 |
|
|
"""
|
17 |
|
|
Output FIFO with an asynchronous clock.\n
|
18 |
|
|
Usage:
|
19 |
|
|
PERIPHERAL outFIFO_async outclk=<i_clock> \\
|
20 |
|
|
data=<o_data> \\
|
21 |
|
|
data_rd=<i_data_rd> \\
|
22 |
|
|
data_empty=<o_data_empty> \\
|
23 |
|
|
outport=<O_data> \\
|
24 |
|
|
infull=<I_full> \\
|
25 |
|
|
depth=<N> \n
|
26 |
|
|
Where:
|
27 |
|
|
outclk=<i_clock>
|
28 |
|
|
specifies the name of the asynchronous read clock
|
29 |
|
|
data=<o_data>
|
30 |
|
|
specifies the name of the 8-bit outgoing data
|
31 |
|
|
data_rd=<i_data_rd>
|
32 |
|
|
specifies the name if the read strobe
|
33 |
|
|
data_empty=<o_data_empty>
|
34 |
|
|
specifies the name of the output "empty" status of the FIFO
|
35 |
|
|
outport=<O_data>
|
36 |
|
|
specifies the name of the port to write to the FIFO
|
37 |
|
|
infull=<I_full>
|
38 |
|
|
specifies the symbol used by the inport instruction to read the "full"
|
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 to an external device or IP.\n
|
44 |
|
|
The PERIPHERAL statement would be:\n
|
45 |
|
|
PERIPHERAL outFIFO_async outclk=i_dev_clk \\
|
46 |
|
|
data=o_dev_data \\
|
47 |
|
|
data_rd=i_dev_data_rd \\
|
48 |
|
|
data_empty=o_dev_empty \\
|
49 |
|
|
outport=O_DATA_FIFO \\
|
50 |
|
|
infull=I_DATA_FIFO_FULL \\
|
51 |
|
|
depth=32\n
|
52 |
|
|
To put a text message in the FIFO, similarly to a UART, do the following:\n
|
53 |
|
|
N"message"
|
54 |
|
|
:loop
|
55 |
|
|
.inport(I_DATA_FIFO_FULL) .jumpc(loop)
|
56 |
|
|
.outport(O_DATA_FIFO)
|
57 |
|
|
.jumpc(loop,nop)
|
58 |
|
|
"""
|
59 |
|
|
|
60 |
|
|
def __init__(self,peripheralFile,config,param_list,loc):
|
61 |
|
|
# Use the externally provided file name for the peripheral
|
62 |
|
|
self.peripheralFile = peripheralFile;
|
63 |
|
|
# Get the parameters.
|
64 |
|
|
allowables = (
|
65 |
|
|
('outclk', r'i_\w+$', None, ),
|
66 |
|
|
('data', r'o_\w+$', None, ),
|
67 |
|
|
('data_rd', r'i_\w+$', None, ),
|
68 |
|
|
('data_empty', r'o_\w+$', None, ),
|
69 |
|
|
('outport', r'O_\w+$', None, ),
|
70 |
|
|
('infull', r'I_\w+$', None, ),
|
71 |
9 |
sinclairrf |
('depth', r'[1-9]\d*$', lambda v : self.IntPow2Method(config,v,lowLimit=16), ),
|
72 |
2 |
sinclairrf |
);
|
73 |
|
|
names = [a[0] for a in allowables];
|
74 |
|
|
for param_tuple in param_list:
|
75 |
|
|
param = param_tuple[0];
|
76 |
|
|
if param not in names:
|
77 |
|
|
raise SSBCCException('Unrecognized parameter "%s" at %s' % (param,loc,));
|
78 |
|
|
param_test = allowables[names.index(param)];
|
79 |
|
|
self.AddAttr(config,param,param_tuple[1],param_test[1],loc,param_test[2]);
|
80 |
|
|
# Ensure the required parameters are provided.
|
81 |
|
|
for paramname in names:
|
82 |
|
|
if not hasattr(self,paramname):
|
83 |
|
|
raise SSBCCException('Required parameter "%s" is missing at %s' % (paramname,loc,));
|
84 |
|
|
# Add the I/O port, internal signals, and the INPORT and OUTPORT symbols for this peripheral.
|
85 |
|
|
config.AddIO(self.outclk,1,'input',loc);
|
86 |
|
|
config.AddIO(self.data,8,'output',loc);
|
87 |
|
|
config.AddIO(self.data_rd,1,'input',loc);
|
88 |
|
|
config.AddIO(self.data_empty,1,'output',loc);
|
89 |
|
|
config.AddSignal('s__%s__full' % self.data,1,loc);
|
90 |
|
|
self.ix_outport = config.NOutports();
|
91 |
|
|
config.AddOutport((self.outport,False,
|
92 |
|
|
# empty list
|
93 |
|
|
),loc);
|
94 |
|
|
config.AddInport((self.infull,
|
95 |
|
|
('s__%s__full' % self.data,1,'data',),
|
96 |
|
|
),loc);
|
97 |
|
|
|
98 |
|
|
def GenVerilog(self,fp,config):
|
99 |
|
|
body = self.LoadCore(self.peripheralFile,'.v');
|
100 |
|
|
for subpair in (
|
101 |
6 |
sinclairrf |
( r'@DATA@', self.data, ),
|
102 |
|
|
( r'@DATA_EMPTY@', self.data_empty, ),
|
103 |
|
|
( r'@DATA_RD@', self.data_rd, ),
|
104 |
|
|
( r'@DEPTH@', str(self.depth), ),
|
105 |
|
|
( r'@DEPTH-1@', str(self.depth-1), ),
|
106 |
|
|
( r'@DEPTH_NBITS@', str(CeilLog2(self.depth)), ),
|
107 |
|
|
( r'@DEPTH_NBITS-1@', str(CeilLog2(self.depth)-1), ),
|
108 |
|
|
( r'@OUTCLK@', self.outclk, ),
|
109 |
|
|
( r'@IX_OUTPORT@', str(self.ix_outport), ),
|
110 |
|
|
( r'@NAME@', self.data, ),
|
111 |
|
|
( r'\bgen__', 'gen__%s__' % self.data, ),
|
112 |
|
|
( r'\bix__', 'ix__%s__' % self.data, ),
|
113 |
|
|
( r'\bs__', 's__%s__' % self.data, ),
|
114 |
|
|
):
|
115 |
2 |
sinclairrf |
body = re.sub(subpair[0],subpair[1],body);
|
116 |
|
|
body = self.GenVerilogFinal(config,body);
|
117 |
|
|
fp.write(body);
|