ParaNut SystemC Model
A SystemC Model of the ParaNut architecture
mtimer.h
Go to the documentation of this file.
1  /*************************************************************************
2 
3  This file is part of the ParaNut project.
4 
5  Copyright (C) 2010-2022 Mark Endres <mark.endres@hs-augsburg.de>
6  Christian H. Meyer <christian.meyer@hs-augsburg.de>
7  Hochschule Augsburg, University of Applied Sciences
8 
9  Description:
10  This is a SystemC model of the mtimer module of the ParaNut.
11 
12  Redistribution and use in source and binary forms, with or without modification,
13  are permitted provided that the following conditions are met:
14 
15  1. Redistributions of source code must retain the above copyright notice, this
16  list of conditions and the following disclaimer.
17 
18  2. Redistributions in binary form must reproduce the above copyright notice,
19  this list of conditions and the following disclaimer in the documentation and/or
20  other materials provided with the distribution.
21 
22  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33  *************************************************************************/
34 
35 #pragma once
36 
37 #include "base.h"
38 #include "paranut-config.h"
39 
40 /*#define TIMEREG_LOW (reg_mtime.read () (31, 0))
41 #define TIMEREG_HIGH (reg_mtime.read () (63, 32))
42 #define TIMECMPREG_LOW (reg_mtimecmp.read () (31, 0))
43 #define TIMECMPREG_HIGH (reg_mtimecmp.read () (63, 32))*/
44 #define MTIMER_PRESCALER ((__uint64_t)((float)CFG_NUT_SIM_CLK_SPEED / (1.0f / ((float)CFG_NUT_MTIMER_TIMEBASE_US / (1000*1000)))))
45 
46 typedef enum {
47  mtime = 0, // 64 bit memory mapped machine timer register
48  mtimeh = 4,
49  mtimecmp = 8, // 64 bit memory mapped machine timer compare register
50  mtimecmph = 12
52 
53 class Mtimer : ::sc_core::sc_module {
54 public:
55  // ports
56  sc_in<bool> irq_out_enable;
57  sc_out<bool> irq_out;
58 
59  sc_in_clk wb_clk_i;
60  sc_in<bool> wb_rst_i;
61 
62  sc_in<bool> wb_stb_i;
63  sc_in<bool> wb_we_i;
64  //sc_in<sc_uint<CFG_MEMU_BUSIF_WIDTH/8> > wb_sel_i; ///< WB byte select inputs.
65  sc_out<bool> wb_ack_o;
66 
67  sc_in<sc_uint<32> > wb_adr_i;
68  sc_in<sc_uint<CFG_MEMU_BUSIF_WIDTH> > wb_dat_i;
69  sc_out<sc_uint<CFG_MEMU_BUSIF_WIDTH> > wb_dat_o;
70 
71  // processes
72  void TransitionMethod();
73 
74  //SC_CTOR (Mtimer) {
75  //typedef Mtimer SC_CURRENT_USER_MODULE; // damit geht make
76  SC_HAS_PROCESS(Mtimer);
77  Mtimer(const sc_module_name& name) : sc_module (name) {
78  SC_METHOD (TransitionMethod);
79  sensitive << wb_clk_i.pos ();
80  }
81 
82  // Functions ...
83  void Trace (sc_trace_file * tf, int levels = 1);
84 private:
85  // memory mapped registers
86  sc_signal<sc_uint<64> > reg_mtime;
87  sc_signal<sc_uint<64> > reg_mtimecmp;
88  // internal registers
89  sc_signal<sc_uint<32> > reg_mtime_prescale_cnt;
90 };
Helpers, Makros and performance measuring Classes used in most ParaNut files.
Definition: mtimer.h:53
sc_in< bool > irq_out_enable
Definition: mtimer.h:56
sc_in< bool > wb_stb_i
WB Strobe input.
Definition: mtimer.h:62
sc_in< sc_uint< CFG_MEMU_BUSIF_WIDTH > > wb_dat_i
WB input data bus.
Definition: mtimer.h:68
void TransitionMethod()
Definition: mtimer.cpp:46
Mtimer(const sc_module_name &name)
Definition: mtimer.h:77
sc_in_clk wb_clk_i
WB Clock input.
Definition: mtimer.h:59
void Trace(sc_trace_file *tf, int levels=1)
Definition: mtimer.cpp:27
sc_in< sc_uint< 32 > > wb_adr_i
WB address bus inputs.
Definition: mtimer.h:67
sc_out< sc_uint< CFG_MEMU_BUSIF_WIDTH > > wb_dat_o
WB output data bus.
Definition: mtimer.h:69
sc_out< bool > wb_ack_o
WB normal termination.
Definition: mtimer.h:65
sc_in< bool > wb_rst_i
WB Reset input.
Definition: mtimer.h:60
sc_in< bool > wb_we_i
WB write enable intput.
Definition: mtimer.h:63
sc_out< bool > irq_out
Definition: mtimer.h:57
ETIMER
Definition: mtimer.h:46
@ mtimecmp
Definition: mtimer.h:49
@ mtimeh
Definition: mtimer.h:48
@ mtimecmph
Definition: mtimer.h:50
@ mtime
Definition: mtimer.h:47
Configuration Makros used in most ParaNut files.
sc_trace_file * tf
Definition: tlb_tb.cpp:94