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

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [core/] [9x8/] [peripherals/] [outFIFO_async.py] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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 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
      ('depth',         r'[1-9]\d*$',   int,    ),
72
    );
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
    # Ensure the depth is a power of 2.
85
    if not IsPowerOf2(self.depth):
86
      raise SSBCCException('depth=%d must be a power of 2 at %s' % (self.depth,loc,));
87
    if self.depth < 16:
88
      raise SSBCCException('depth=%d must be at least 16 at %s' % (self.depth,loc,));
89
    # Add the I/O port, internal signals, and the INPORT and OUTPORT symbols for this peripheral.
90
    config.AddIO(self.outclk,1,'input',loc);
91
    config.AddIO(self.data,8,'output',loc);
92
    config.AddIO(self.data_rd,1,'input',loc);
93
    config.AddIO(self.data_empty,1,'output',loc);
94
    config.AddSignal('s__%s__full' % self.data,1,loc);
95
    self.ix_outport = config.NOutports();
96
    config.AddOutport((self.outport,False,
97
                      # empty list
98
                      ),loc);
99
    config.AddInport((self.infull,
100
                     ('s__%s__full' % self.data,1,'data',),
101
                    ),loc);
102
 
103
  def GenVerilog(self,fp,config):
104
    body = self.LoadCore(self.peripheralFile,'.v');
105
    for subpair in (
106
      (r'@DATA@',               self.data,                      ),
107
      (r'@DATA_EMPTY@',         self.data_empty,                 ),
108
      (r'@DATA_RD@',            self.data_rd,                   ),
109
      (r'@DEPTH@',              str(self.depth),                ),
110
      (r'@DEPTH-1@',            str(self.depth-1),              ),
111
      (r'@DEPTH_NBITS@',        str(CeilLog2(self.depth)),      ),
112
      (r'@DEPTH_NBITS-1@',      str(CeilLog2(self.depth)-1),    ),
113
      (r'@OUTCLK@',             self.outclk,                    ),
114
      (r'@IX_OUTPORT@',         str(self.ix_outport),           ),
115
      (r'@NAME@',               self.data,                      ),
116
      (r'\bgen__',              'gen__%s__' % self.data,        ),
117
      (r'\bix__',               'ix__%s__' % self.data,         ),
118
      (r'\bs__',                's__%s__' % self.data,          ),
119
    ):
120
      body = re.sub(subpair[0],subpair[1],body);
121
    body = self.GenVerilogFinal(config,body);
122
    fp.write(body);

powered by: WebSVN 2.1.0

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