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

Subversion Repositories ssbcc

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

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
    # Get the parameters.
52
    allowables = (
53
      ('outlatch',      r'O_\w+$',              None,           ),
54
      ('inport',        r'I_\w+$',              None,           ),
55
      ('insignal',      r'i_\w+$',              None,           ),
56
      ('width',         r'(9|[1-9]\d*)$',       int,            ),
57
    );
58
    names = [a[0] for a in allowables];
59
    for param_tuple in param_list:
60
      param = param_tuple[0];
61
      if param not in names:
62
        raise SSBCCException('Unrecognized parameter "%s" at %s' % (param,loc,));
63
      param_test = allowables[names.index(param)];
64
      self.AddAttr(config,param,param_tuple[1],param_test[1],loc,param_test[2]);
65
    # Ensure the required parameters are provided (all parameters are required).
66
    for paramname in names:
67
      if not hasattr(self,paramname):
68
        raise SSBCCException('Required parameter "%s" is missing at %s' % (paramname,loc,));
69
    # There are no optional parameters.
70
    # Add the I/O port, internal signals, and the INPORT and OUTPORT symbols for this peripheral.
71
    config.AddIO(self.insignal,self.width,'input',loc);
72
    config.AddSignal('s__%s__inport' % self.insignal, self.width, loc);
73
    self.ix_latch = config.NOutports();
74
    config.AddOutport((self.outlatch,True,
75
                      # empty list
76
                      ),loc);
77
    self.ix_inport = config.NInports();
78
    config.AddInport((self.inport,
79
                      ('s__%s__inport' % self.insignal, self.width, 'data', ),
80
                      ),loc);
81
 
82
  def GenVerilog(self,fp,config):
83
    body = """//
84
// PERIPHERAL big_inport:  @INSIGNAL@
85
//
86
always @ (posedge i_clk)
87
  if (i_rst)
88
    @NAME@ <= @WIDTH@'d0;
89
  else if (s_outport && (s_T == @IX_LATCH@))
90
    @NAME@ <= @INSIGNAL@;
91
  else if (s_inport && (s_T == @IX_INPORT@))
92
    @NAME@ <= { 8'd0, @NAME@[@WIDTH-1:8@] };
93
  else
94
    @NAME@ <= @NAME@;
95
"""
96
    for subpair in (
97
      (r'@IX_LATCH@',   "8'd%d" % self.ix_latch,                                ),
98
      (r'@IX_INPORT@',  "8'd%d" % self.ix_inport,                               ),
99
      (r'@WIDTH@',      str(self.width),                                        ),
100
      (r'@WIDTH-1:8@',  '%d:8' % (self.width-1) if self.width > 9 else '8'      ),
101
      (r'@NAME@',       's__@INSIGNAL@__inport',                                ),
102
      (r'@INSIGNAL@',   self.insignal,                                          ),
103
    ):
104
      body = re.sub(subpair[0],subpair[1],body);
105
    body = self.GenVerilogFinal(config,body);
106
    fp.write(body);

powered by: WebSVN 2.1.0

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