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

Subversion Repositories ssbcc

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

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 timer(SSBCCperipheral):
13
  """
14
  Simple timer to facilitate polled-loops.\n
15
  The timer sets a flag when the timer expires and clears the flag when it is
16
  read.\n
17
  Usage:
18
    PERIPHERAL timer inport=I_name \\
19
                     ratemethod={clk/rate|count}\n
20
  Where:
21
    inport=I_name
22
      specifies the symbol used by the inport instruction to get the
23
      unexpired/expired status of the timer
24
      Note:  The name must start with "I_"
25
    ratemethod
26
      specifies the method to generate the desired timer event rate:
27
      1st method:  clk/rate
28
        clk is the frequency of "i_clk" in Hz
29
          a number will be interpreted as the clock frequency in Hz
30
          a symbol will be interpreted as a parameter
31
            Note:  this parameter must have been declared with a "PARAMETER"
32
            command
33
        rate is the desired baud rate
34
          this is specified as per "clk"
35
      2nd method:
36
        specify the number of "i_clk" clock cycles between timer events
37
      Note:  clk, rate, and count can be parameters or constants.  For example,
38
             the following uses the parameter G_CLK_FREQ_HZ for the clock
39
             frequency and a hard-wired event rate of 1 kHz
40
             "baudmethod=G_CLK_FREQ_HZ/1000".
41
      Note:  The numeric values can have Verilog-style '_' separators between
42
               the digits.  For example, 100_000_000 represents 100 million.\n
43
  Example:  Configure the timer for 1000 kHz events and monitor for these events
44
            in the micro controller code.\n
45
            PARAMETER G_CLK_FREQ_HZ 100_000_000
46
            PERIPHERAL timer inport=I_TIMER ratemethod=G_CLK_FREQ_HZ/1000\n
47
            ; See if the timer has expired since the last time it was polled and
48
            ; conditionally call "timer_event" if it has.
49
            .inport(I_TIMER)
50
              .callc(timer_event)
51
  """
52
 
53
  def __init__(self,peripheralFile,config,param_list,loc):
54
    # Use the externally provided file name for the peripheral
55
    self.peripheralFile = peripheralFile;
56
    # Get the parameters.
57
    for param_tuple in param_list:
58
      param = param_tuple[0];
59
      param_arg = param_tuple[1];
60
      if param == 'inport':
61
        self.AddAttr(config,param,param_arg,'I_\w+$',loc);
62
      elif param == 'ratemethod':
63
        self.AddRateMethod(config,param,param_arg,loc);
64
      else:
65
        raise SSBCCException('Unrecognized parameter at %s: %s' % (loc,param,));
66
    # Ensure the required parameters are provided.
67
    for paramname in ('inport','ratemethod',):
68
      if not hasattr(self,paramname):
69
        raise SSBCCException('Required parameter "%s" is missing at %s' % (paramname,loc,));
70
    # Add the I/O port, internal signals, and the INPORT and OUTPORT symbols for this peripheral.
71
    name = 's__%s__expired' % self.inport;
72
    config.AddSignal(name, 1, loc);
73
    config.AddSignal('s_SETRESET_%s' % name,1,loc);
74
    config.AddInport((self.inport,
75
                     ('s__%s__expired' % self.inport, 1, 'set-reset'),
76
                    ),loc);
77
    # Add the 'clog2' function to the processor (if required).
78
    config.functions['clog2'] = True;
79
 
80
  def GenVerilog(self,fp,config):
81
    body = self.LoadCore(self.peripheralFile,'.v');
82
    for subs in (
83
                  (r'\bL__',            'L__@NAME@__',),
84
                  (r'\bs__',            's__@NAME@__',),
85
                  (r'@RATEMETHOD@',     str(self.ratemethod),),
86
                  (r'@NAME@',           self.inport,),
87
                ):
88
      body = re.sub(subs[0],subs[1],body);
89
    body = self.GenVerilogFinal(config,body);
90
    fp.write(body);

powered by: WebSVN 2.1.0

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