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

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [core/] [9x8/] [peripherals/] [big_outport.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_outport(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_outport                      \\
18
                        outport=O_name          \\
19
                        outsignal=o_name        \\
20
                        width=<N>\n
21
  Where:
22
    outport=O_name
23
      specifies the symbol used to write to the output port
24
    outsignal=o_name
25
      specifies the name of the signal output from the module
26
    width=<N>
27
      specifies the width of the I/O\n
28
  Example:  Create a 26-bit output signal for output of 26-bit or 18-bit values
29
  from the processor to external IP.\n
30
    PORTCOMMENT 26-bit output for use by other modules
31
    PERIPHERAL big_outport                             \\
32
                        output=O_26BIT_SIGNAL          \\
33
                        outsignal=o_26bit_signal       \\
34
                        width=26
35
    OUTPORT     strobe  o_wr_26bit      O_WR_26BIT
36
    OUTPORT     strobe  o_wr_18bit      O_WR_18BIT\n
37
  Writing a 26-bit value requires 4 successive outports to O_26BIT_SIGNAL,
38
  starting with the MSB as follows:\n
39
    ; Write 0x024a_5b6c to the XXX module
40
    0x02 .outport(O_26BIT_SIGNAL)
41
    0x4a .outport(O_26BIT_SIGNAL)
42
    0x5b .outport(O_26BIT_SIGNAL)
43
    0x6c .outport(O_26BIT_SIGNAL)
44
    .outstrobe(O_WR_26BIT)\n
45
  Writing an 18-bit value requires 3 successive outports to O_26BIT_SIGNAL
46
  starting with the MSB as illustrated by the following function:\n
47
    ; Read the 18-bit value from memory and then write it to a peripheral.
48
    ; Note:  The multi-byte value is stored MSB first in memory.
49
    ; ( u_addr - )
50
    .function write_18bit_from_memory
51
      ${3-1} :loop r>
52
        .fetch+(ram) .outport(O_26BIT_SIGNAL)
53
      >r .jumpc(loop,1-) drop
54
      .outstrobe(O_WR_18BIT)
55
      .return(drop)
56
  """
57
 
58
  def __init__(self,peripheralFile,config,param_list,loc):
59
    # Get the parameters.
60
    allowables = (
61
      ('outport',       r'O_\w+$',              None,           ),
62
      ('outsignal',     r'o_\w+$',              None,           ),
63
      ('width',         r'(9|[1-9]\d*)$',       int,            ),
64
    );
65
    names = [a[0] for a in allowables];
66
    for param_tuple in param_list:
67
      param = param_tuple[0];
68
      if param not in names:
69
        raise SSBCCException('Unrecognized parameter "%s" at %s' % (param,loc,));
70
      param_test = allowables[names.index(param)];
71
      self.AddAttr(config,param,param_tuple[1],param_test[1],loc,param_test[2]);
72
    # Ensure the required parameters are provided (all parameters are required).
73
    for paramname in names:
74
      if not hasattr(self,paramname):
75
        raise SSBCCException('Required parameter "%s" is missing at %s' % (paramname,loc,));
76
    # There are no optional parameters.
77
    # Add the I/O port, internal signals, and the INPORT and OUTPORT symbols for this peripheral.
78
    config.AddIO(self.outsignal,self.width,'output',loc);
79
    self.ix_outport = config.NOutports();
80
    config.AddOutport((self.outport,False,
81
                      # empty list
82
                      ),
83
                      loc);
84
 
85
  def GenVerilog(self,fp,config):
86
    body = """//
87
// PERIPHERAL big_outport:  @NAME@
88
//
89
initial @NAME@ = @WIDTH@'d0;
90
always @ (posedge i_clk)
91
  if (i_rst)
92
    @NAME@ <= @WIDTH@'d0;
93
  else if (s_outport && (s_T == @IX_OUTPORT@))
94
    @NAME@ <= { @NAME@[@WIDTH-9:0@], s_N };
95
  else
96
    @NAME@ <= @NAME@;
97
"""
98
    for subpair in (
99
      (r'@IX_OUTPORT@', "8'd%d" % self.ix_outport,                              ),
100
      (r'@WIDTH@',      str(self.width),                                        ),
101
      (r'@WIDTH-9:0@',  '%d:0' % (self.width-9) if self.width > 9 else '0'      ),
102
      (r'@NAME@',       self.outsignal,                                         ),
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.