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

Subversion Repositories ssbcc

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

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

Line No. Rev Author Line
1 3 sinclairrf
################################################################################
2
#
3
# Copyright 2014, Sinclair R.F., Inc.
4
#
5
################################################################################
6
 
7
import re;
8
 
9
from ssbccPeripheral import SSBCCperipheral
10
from ssbccUtil import SSBCCException;
11
 
12
class wide_strobe(SSBCCperipheral):
13
  """
14
  Generate more than one simultaneous strobe.\n
15
  Usage:
16
    PERIPHERAL wide_strobe                      \\
17
                        outport=O_name          \\
18
                        outsignal=o_name        \\
19
                        width=<N>\n
20
  Where:
21
    outport=O_name
22
      specifies the symbol used to write to the output port
23
    outsignal=o_name
24
      specifies the name of the signal output from the module
25
    width=<N>
26
      specifies the width of the I/O
27
      Note:  N must be between 1 and 8 inclusive.\n
28
  Example:  Generate up to 4 simultaneous strobes.\n
29
    PORTCOMMENT 4 bit wide strobe
30
    PERIPHERAL wide_strobe                      \\
31
                        outport=O_4BIT_STROBE   \\
32
                        outsignal=o_4bit_strobe \\
33
                        width=4\n
34
    Send strobes on bits 1 and 3 of the wide strobe as follows:\n
35
      ${2**1|2**3} .outport(O_4BIT_STROBE)
36
  """
37
 
38
  def __init__(self,peripheralFile,config,param_list,loc):
39
    # Get the parameters.
40
    allowables = (
41
      ('outport',       r'O_\w+$',              None,           ),
42
      ('outsignal',     r'o_\w+$',              None,           ),
43
      ('width',         r'(9|[1-9]\d*)$',       int,            ),
44
    );
45
    names = [a[0] for a in allowables];
46
    for param_tuple in param_list:
47
      param = param_tuple[0];
48
      if param not in names:
49
        raise SSBCCException('Unrecognized parameter "%s" at %s' % (param,loc,));
50
      param_test = allowables[names.index(param)];
51
      self.AddAttr(config,param,param_tuple[1],param_test[1],loc,param_test[2]);
52
    # Ensure the required parameters are provided (all parameters are required).
53
    for paramname in names:
54
      if not hasattr(self,paramname):
55
        raise SSBCCException('Required parameter "%s" is missing at %s' % (paramname,loc,));
56
    # There are no optional parameters.
57
    # Add the I/O port, internal signals, and the INPORT and OUTPORT symbols for this peripheral.
58
    config.AddIO(self.outsignal,self.width,'output',loc);
59
    self.ix_outport = config.NOutports();
60
    config.AddOutport((self.outport,False,
61
                      # empty list
62
                      ),
63
                      loc);
64
 
65
  def GenVerilog(self,fp,config):
66
    body = """//
67
// PERIPHERAL wide_strobe:  @NAME@
68
//
69
initial @NAME@ = @WIDTH@'d0;
70
always @ (posedge i_clk)
71
  if (i_rst)
72
    @NAME@ <= @WIDTH@'d0;
73
  else if (s_outport && (s_T == @IX_OUTPORT@))
74
    @NAME@ <= s_N[0+:@WIDTH@];
75
  else
76
    @NAME@ <= @WIDTH@'d0;
77
"""
78
    for subpair in (
79
      (r'@IX_OUTPORT@', "8'd%d" % self.ix_outport,                              ),
80
      (r'@WIDTH@',      str(self.width),                                        ),
81
      (r'@NAME@',       self.outsignal,                                         ),
82
    ):
83
      body = re.sub(subpair[0],subpair[1],body);
84
    body = self.GenVerilogFinal(config,body);
85
    fp.write(body);

powered by: WebSVN 2.1.0

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