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

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [core/] [9x8/] [peripherals/] [big_inport.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 re;
8
 
9
from ssbccPeripheral import SSBCCperipheral
10
from ssbccUtil import SSBCCException;
11
 
12
class big_inport(SSBCCperipheral):
13
  """
14
  Shift two or more writes to a single OUTPORT to construct a wide output
15
  signal.\n
16
  Usage:
17
    PERIPHERAL big_inport                       \\
18
                        outlatch=O_name         \\
19
                        inport=I_name           \\
20
                        insignal=i_name         \\
21
                        width=<N>\n
22
  Where:
23
    outlatch=O_name
24
      specifies the symbol used to latch the incoming value
25
    inport=I_name
26
      specifies the symbol used to read from the output port
27
    insignal=i_name
28
      specifies the name of the signal input to the module
29
    width=<N>
30
      specifies the width of the I/O register\n
31
  Example:  Create a 23-bit input signal to receive an external (synchronous)
32
  counter.\n
33
    PORTCOMMENT 23-bit counter
34
    PERIPHERAL big_inport                               \\
35
                        outlatch=O_LATCH_COUNTER        \\
36
                        inport=I_COUNTER                \\
37
                        insignal=i_counter              \\
38
                        width=23\n
39
  Reading the counter requires issuing a command to latch the current value and
40
  then 3 reads to the I/O port as follows:\n
41
    ; Latch the external counter.
42
    .outstrobe(O_LATCH_COUNTER)
43
    ; Read the 3-byte value of the count
44
    ; ( - u_LSB u u_MSB )
45
    .inport(I_COUNTER)
46
    .inport(I_COUNTER)
47
    .inport(I_COUNTER)
48
  """
49
 
50
  def __init__(self,peripheralFile,config,param_list,loc):
51
    # Use the externally provided file name for the peripheral
52
    self.peripheralFile = peripheralFile;
53
    # Get the parameters.
54
    allowables = (
55
      ('outlatch',      r'O_\w+$',              None,           ),
56
      ('inport',        r'I_\w+$',              None,           ),
57
      ('insignal',      r'i_\w+$',              None,           ),
58
      ('width',         r'(9|[1-9]\d*)$',       int,            ),
59
    );
60
    names = [a[0] for a in allowables];
61
    for param_tuple in param_list:
62
      param = param_tuple[0];
63
      if param not in names:
64
        raise SSBCCException('Unrecognized parameter "%s" at %s' % (param,loc,));
65
      param_test = allowables[names.index(param)];
66
      self.AddAttr(config,param,param_tuple[1],param_test[1],loc,param_test[2]);
67
    # Ensure the required parameters are provided (all parameters are required).
68
    for paramname in names:
69
      if not hasattr(self,paramname):
70
        raise SSBCCException('Required parameter "%s" is missing at %s' % (paramname,loc,));
71
    # There are no optional parameters.
72
    # Add the I/O port, internal signals, and the INPORT and OUTPORT symbols for this peripheral.
73
    config.AddIO(self.insignal,self.width,'input',loc);
74
    config.AddSignal('s__%s__inport' % self.insignal, self.width, loc);
75
    self.ix_latch = config.NOutports();
76
    config.AddOutport((self.outlatch,True,
77
                      # empty list
78
                      ),loc);
79
    self.ix_inport = config.NInports();
80
    config.AddInport((self.inport,
81
                      ('s__%s__inport' % self.insignal, self.width, 'data', ),
82
                      ),loc);
83
 
84
  def GenVerilog(self,fp,config):
85
    body = """//
86
// PERIPHERAL big_inport:  @INSIGNAL@
87
//
88
always @ (posedge i_clk)
89
  if (i_rst)
90
    @NAME@ <= @WIDTH@'d0;
91
  else if (s_outport && (s_T == @IX_LATCH@))
92
    @NAME@ <= @INSIGNAL@;
93
  else if (s_inport && (s_T == @IX_INPORT@))
94
    @NAME@ <= { 8'd0, @NAME@[@WIDTH-1:8@] };
95
  else
96
    @NAME@ <= @NAME@;
97
"""
98
    for subpair in (
99
      (r'@IX_LATCH@',   "8'd%d" % self.ix_latch,                                ),
100
      (r'@IX_INPORT@',  "8'd%d" % self.ix_inport,                               ),
101
      (r'@WIDTH@',      str(self.width),                                        ),
102
      (r'@WIDTH-1:8@',  '%d:8' % (self.width-1) if self.width > 9 else '8'      ),
103
      (r'@NAME@',       's__@INSIGNAL@__inport',                                ),
104
      (r'@INSIGNAL@',   self.insignal,                                          ),
105
    ):
106
      body = re.sub(subpair[0],subpair[1],body);
107
    body = self.GenVerilogFinal(config,body);
108
    fp.write(body);

powered by: WebSVN 2.1.0

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