| 1 |
2 |
sinclairrf |
################################################################################
|
| 2 |
|
|
#
|
| 3 |
|
|
# Copyright 2013, Sinclair R.F., Inc.
|
| 4 |
|
|
#
|
| 5 |
|
|
################################################################################
|
| 6 |
|
|
|
| 7 |
|
|
import ssbccUtil
|
| 8 |
|
|
|
| 9 |
|
|
def genVhdlPkg(config):
|
| 10 |
|
|
"""
|
| 11 |
|
|
Method to generate a VHDL Package file corresponding to the instantiated micro
|
| 12 |
|
|
controller.
|
| 13 |
|
|
"""
|
| 14 |
|
|
coreName = config.Get('outCoreName');
|
| 15 |
|
|
packageName = '%s_pkg' % coreName;
|
| 16 |
|
|
packageFileName = '%s.vhd' % packageName;
|
| 17 |
|
|
try:
|
| 18 |
|
|
fp = open(packageFileName,'wt');
|
| 19 |
|
|
except:
|
| 20 |
|
|
raise SSBCCException('Could not open %s' % packageFileName);
|
| 21 |
|
|
fp.write('library ieee;\n');
|
| 22 |
|
|
fp.write('use ieee.std_logic_1164.all;\n');
|
| 23 |
|
|
fp.write('package %s is\n' % packageName);
|
| 24 |
|
|
fp.write('component %s is\n' % coreName);
|
| 25 |
|
|
# If any, write the generics.
|
| 26 |
|
|
if config.parameters:
|
| 27 |
|
|
fp.write('generic (\n');
|
| 28 |
|
|
lines = [' %s : std_logic_vector(31 downto 0) := x"%08X"' % (p[0],ssbccUtil.IntValue(p[1]),) for p in config.parameters];
|
| 29 |
|
|
for ix in range(len(lines)-1):
|
| 30 |
|
|
lines[ix] += ';'
|
| 31 |
|
|
for l in lines:
|
| 32 |
|
|
fp.write('%s\n' % l);
|
| 33 |
|
|
fp.write(');\n');
|
| 34 |
|
|
# Start the port list, initialize each line with two spaces, and make a list of the lines that are signal declarations.
|
| 35 |
|
|
fp.write('port (\n');
|
| 36 |
|
|
nIOs = len(config.ios);
|
| 37 |
|
|
lines = [' ' for ix in range(nIOs)];
|
| 38 |
|
|
signals = [i for i in range(nIOs) if config.ios[i][2] != 'comment'];
|
| 39 |
|
|
# Generate the comment lines.
|
| 40 |
|
|
for ix in [i for i in range(nIOs) if i not in signals]:
|
| 41 |
|
|
lines[ix] += '-- %s' % config.ios[ix][0];
|
| 42 |
|
|
# Add the signal name to each signal declaration and the trailing spaces and ':'.
|
| 43 |
|
|
for ix in signals:
|
| 44 |
|
|
lines[ix] += config.ios[ix][0];
|
| 45 |
|
|
maxLen = max([len(lines[ix]) for ix in signals]);
|
| 46 |
|
|
# Add the signal direction to each signal declararation.
|
| 47 |
|
|
for ix in signals:
|
| 48 |
|
|
lines[ix] += ' '*(maxLen-len(lines[ix])) + ' : ';
|
| 49 |
|
|
for ix in [i for i in signals if config.ios[i][2] == 'input']:
|
| 50 |
|
|
lines[ix] += 'in';
|
| 51 |
|
|
for ix in [i for i in signals if config.ios[i][2] == 'output']:
|
| 52 |
|
|
lines[ix] += 'out';
|
| 53 |
|
|
for ix in [i for i in signals if config.ios[i][2] == 'inout']:
|
| 54 |
|
|
lines[ix] += 'inout';
|
| 55 |
|
|
maxLen = max([len(lines[ix]) for ix in signals]);
|
| 56 |
|
|
for ix in signals:
|
| 57 |
|
|
lines[ix] += ' '*(maxLen-len(lines[ix])+1);
|
| 58 |
|
|
# Add the signal type to the signal declarations.
|
| 59 |
|
|
for ix in [i for i in signals if config.ios[i][1] == 1]:
|
| 60 |
|
|
lines[ix] += 'std_logic';
|
| 61 |
|
|
for ix in [i for i in signals if config.ios[i][1] != 1]:
|
| 62 |
|
|
lines[ix] += 'std_logic_vector(%d downto 0)' % (config.ios[ix][1]-1);
|
| 63 |
|
|
# Add the trailing ';' to all but the last signal declaration.
|
| 64 |
|
|
for ix in signals[:-1]:
|
| 65 |
|
|
lines[ix] += ';';
|
| 66 |
|
|
# Write the signal declarations and the associated comments.
|
| 67 |
|
|
for l in lines:
|
| 68 |
|
|
fp.write(l+'\n');
|
| 69 |
|
|
fp.write(');\n');
|
| 70 |
|
|
fp.write('end component %s;\n' % coreName);
|
| 71 |
|
|
fp.write('end package;\n');
|
| 72 |
|
|
fp.close();
|