ParaNut SystemC Model
A SystemC Model of the ParaNut architecture
jtag_dtm.h
Go to the documentation of this file.
1 /*************************************************************************
2 
3  This file was copied and modified from the Spike ISA Simulator project:
4  https://github.com/riscv/riscv-isa-sim
5 
6 Copyright (c) 2010-2017, The Regents of the University of California
7 (Regents). All Rights Reserved.
8 
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright
12  notice, this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14  notice, this list of conditions and the following disclaimer in the
15  documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Regents nor the
17  names of its contributors may be used to endorse or promote products
18  derived from this software without specific prior written permission.
19 
20 IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
21 SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
22 OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
23 BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
28 HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
29 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
30 
31  *************************************************************************/
32 
33 #ifndef JTAG_DTM_H
34 #define JTAG_DTM_H
35 
36 #include <stdint.h>
37 #include <systemc.h>
38 
39 #include "base.h"
40 
41 #define DTM_ADDR_WIDTH 6
42 #define DTM_IR_WIDTH 5
43 
44 typedef enum {
60  UPDATE_IR
62 
63 typedef enum {
64  IDCODE = 0x1,
65  DTMCS = 0x10,
66  DMI = 0x11,
67 } jtag_regs_t;
68 
69 #if !defined(__SYNTHESIS__)
70 class jtag_dtm_t;
71 #endif
72 
73 // Only include this if we are not synthesizing AND simulating
74 #if !defined(__SYNTHESIS__) && defined(SIMBUILD)
75 class MDtm;
76 
77 class jtag_dtm_t {
78  static const unsigned idcode = 0xdeadbeef;
79 
80  public:
81  jtag_dtm_t (MDtm *dtm, unsigned required_rti_cycles);
82  void reset ();
83 
84  void set_pins (bool tck, bool tms, bool tdi);
85 
86  bool tdo () const { return _tdo; }
87 
88  jtag_state_t state () const { return _state; }
89 
90  private:
91  MDtm *dtm;
92  // The number of Run-Test/Idle cycles required before a DMI access is
93  // complete.
94  unsigned required_rti_cycles;
95  bool _tck, _tms, _tdi, _tdo;
96  uint32_t ir;
97  const unsigned ir_length = 5;
98  uint64_t dr;
99  unsigned dr_length;
100 
101  // abits must come before dtmcontrol so it can easily be used in the
102  // constructor.
103  const unsigned abits = 6;
104  uint32_t dtmcontrol;
105  uint64_t dmi;
106  // Number of Run-Test/Idle cycles needed before we call this access
107  // complete.
108  unsigned rti_remaining;
109  bool busy_stuck;
110 
111  jtag_state_t _state;
112 
113  void capture_dr ();
114  void update_dr ();
115 };
116 #endif
117 
118 // **************** MDtm *************
119 class MDtm : ::sc_core::sc_module {
120 public:
121  // Ports JTAG (Don't do anything during simulation, just for routing the toplevel JTAG signals)
122  sc_in<bool> tck;
123  sc_in<bool> tms;
124  sc_in<bool> tdi;
125  sc_out<bool> tdo;
126 
127  // Ports DMI Master
128  // sc_in_clk clk;
129  sc_in<bool> reset;
130 
131  sc_out<sc_uint<DTM_ADDR_WIDTH> > dmi_adr; // address output
132  sc_out<sc_uint<32> > dmi_dat_o; // output data
133  sc_in<sc_uint<32> > dmi_dat_i; // input data
134  sc_out<bool> dmi_rd, dmi_wr;
135 
136  // Constructor...
137  SC_HAS_PROCESS (MDtm);
138  MDtm (sc_module_name name)
139  : sc_module (name) {
140  SC_METHOD (JTAGMethod);
141  sensitive << tck.pos ();
142  SC_METHOD (OutputMethod);
143  sensitive << dr << dmi_op << ir << state;
144  }
145 
146  // Functions...
147  void Trace (sc_trace_file * tf, int levels = 1);
148 #ifndef __SYNTESIS__
150  bool dmi_read (TWord adr, uint64_t * val);
151 #endif
152 
153  // Processes...
154  // void DMIMethod ();
155  void OutputMethod ();
156  void JTAGMethod ();
157 
158 protected:
159  // Simulation members...
160 #ifndef __SYNTHESIS__
161  sc_uint<DTM_ADDR_WIDTH> adr;
162  sc_uint<32> val;
163  uint64_t *val_out;
164  bool write;
165  bool read, dmi_rd_last[3];
166 #endif
167 
168  // Synthesis registers ...
169  sc_signal<sc_uint<34 + DTM_ADDR_WIDTH> > dmi, dr;
170 
171  sc_signal<sc_uint<4> > state;
172  sc_signal<sc_uint<DTM_IR_WIDTH> > ir;
173  sc_signal<bool> dmi_length;
174 
175  sc_signal<bool> dmi_op;
176 };
177 
178 
179 #endif
Helpers, Makros and performance measuring Classes used in most ParaNut files.
Definition: jtag_dtm.h:119
uint64_t * val_out
Definition: jtag_dtm.h:163
MDtm(sc_module_name name)
Definition: jtag_dtm.h:138
sc_in< bool > tdi
Definition: jtag_dtm.h:124
sc_signal< sc_uint< DTM_IR_WIDTH > > ir
Definition: jtag_dtm.h:172
sc_out< sc_uint< 32 > > dmi_dat_o
Definition: jtag_dtm.h:132
sc_signal< sc_uint< 4 > > state
Definition: jtag_dtm.h:171
bool dmi_write(TWord adr, TWord val)
bool dmi_rd_last[3]
Definition: jtag_dtm.h:165
void JTAGMethod()
Definition: jtag_dtm.cpp:379
sc_signal< sc_uint< 34+DTM_ADDR_WIDTH > > dr
Definition: jtag_dtm.h:169
bool write
Definition: jtag_dtm.h:164
void OutputMethod()
Definition: jtag_dtm.cpp:489
void Trace(sc_trace_file *tf, int levels=1)
Definition: jtag_dtm.cpp:352
bool read
Definition: jtag_dtm.h:165
sc_in< sc_uint< 32 > > dmi_dat_i
Definition: jtag_dtm.h:133
bool dmi_read(TWord adr, uint64_t *val)
sc_out< bool > dmi_rd
Definition: jtag_dtm.h:134
sc_in< bool > tck
Definition: jtag_dtm.h:122
sc_signal< bool > dmi_op
Definition: jtag_dtm.h:175
sc_uint< 32 > val
Definition: jtag_dtm.h:162
sc_in< bool > tms
Definition: jtag_dtm.h:123
sc_in< bool > reset
Definition: jtag_dtm.h:129
sc_uint< DTM_ADDR_WIDTH > adr
Definition: jtag_dtm.h:161
sc_out< sc_uint< DTM_ADDR_WIDTH > > dmi_adr
Definition: jtag_dtm.h:131
sc_out< bool > tdo
Definition: jtag_dtm.h:125
sc_signal< bool > dmi_length
Definition: jtag_dtm.h:173
sc_signal< sc_uint< 34+DTM_ADDR_WIDTH > > dmi
Definition: jtag_dtm.h:169
sc_out< bool > dmi_wr
Definition: jtag_dtm.h:134
sc_signal< bool > reset
Definition: dm_tb.cpp:54
unsigned TWord
Word type (32 Bit).
Definition: base.h:147
jtag_regs_t
Definition: jtag_dtm.h:63
@ DMI
Definition: jtag_dtm.h:66
@ IDCODE
Definition: jtag_dtm.h:64
@ DTMCS
Definition: jtag_dtm.h:65
jtag_state_t
Definition: jtag_dtm.h:44
@ EXIT2_DR
Definition: jtag_dtm.h:52
@ SELECT_DR_SCAN
Definition: jtag_dtm.h:47
@ TEST_LOGIC_RESET
Definition: jtag_dtm.h:45
@ UPDATE_DR
Definition: jtag_dtm.h:53
@ CAPTURE_DR
Definition: jtag_dtm.h:48
@ SHIFT_IR
Definition: jtag_dtm.h:56
@ PAUSE_DR
Definition: jtag_dtm.h:51
@ CAPTURE_IR
Definition: jtag_dtm.h:55
@ UPDATE_IR
Definition: jtag_dtm.h:60
@ SHIFT_DR
Definition: jtag_dtm.h:49
@ RUN_TEST_IDLE
Definition: jtag_dtm.h:46
@ SELECT_IR_SCAN
Definition: jtag_dtm.h:54
@ EXIT2_IR
Definition: jtag_dtm.h:59
@ EXIT1_DR
Definition: jtag_dtm.h:50
@ EXIT1_IR
Definition: jtag_dtm.h:57
@ PAUSE_IR
Definition: jtag_dtm.h:58
sc_signal< bool > tdi
Definition: jtag_dtm_tb.cpp:51
sc_signal< bool > tdo
Definition: jtag_dtm_tb.cpp:51
sc_signal< bool > tms
Definition: jtag_dtm_tb.cpp:51
sc_signal< bool > tck
Definition: jtag_dtm_tb.cpp:51
sc_trace_file * tf
Definition: tlb_tb.cpp:94