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

Subversion Repositories ssbcc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 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 6 sinclairrf
      ( '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 9 sinclairrf
      ( 'depth',        r'[1-9]\d*$',   lambda v : self.IntPow2Method(config,v,lowLimit=16), ),
75 2 sinclairrf
    );
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
    # Add the I/O port, internal signals, and the INPORT and OUTPORT symbols for this peripheral.
88
    config.AddIO(self.inclk,1,'input',loc);
89
    config.AddIO(self.data,8,'input',loc);
90
    config.AddIO(self.data_wr,1,'input',loc);
91
    config.AddIO(self.data_full,1,'output',loc);
92
    config.AddSignal('s__%s__data' % self.data,8,loc);
93
    config.AddSignal('s__%s__empty' % self.data,1,loc);
94
    self.ix_data = config.NInports();
95
    config.AddInport((self.inport,
96
                     ('s__%s__data' % self.data,8,'data',),
97
                    ),loc);
98
    config.AddInport((self.inempty,
99
                     ('s__%s__empty' % self.data,1,'data',),
100
                    ),loc);
101
 
102
  def GenVerilog(self,fp,config):
103
    body = self.LoadCore(self.peripheralFile,'.v');
104
    for subpair in (
105 6 sinclairrf
        ( r'@DATA@',            self.data,                      ),
106
        ( r'@DATA_FULL@',       self.data_full,                 ),
107
        ( r'@DATA_WR@',         self.data_wr,                   ),
108
        ( r'@DEPTH@',           str(self.depth),                ),
109
        ( r'@DEPTH-1@',         str(self.depth-1),              ),
110
        ( r'@DEPTH_NBITS@',     str(CeilLog2(self.depth)),      ),
111
        ( r'@DEPTH_NBITS-1@',   str(CeilLog2(self.depth)-1),    ),
112
        ( r'@INCLK@',           self.inclk,                     ),
113
        ( r'@IX_DATA@',         str(self.ix_data),              ),
114
        ( r'@NAME@',            self.data,                      ),
115
        ( r'\bgen__',           'gen__%s__' % self.data,        ),
116
        ( r'\bix__',            'ix__%s__' % self.data,         ),
117
        ( r'\bs__',             's__%s__' % self.data,          ),
118
      ):
119 2 sinclairrf
      body = re.sub(subpair[0],subpair[1],body);
120
    body = self.GenVerilogFinal(config,body);
121
    fp.write(body);

powered by: WebSVN 2.1.0

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