1 |
63 |
julius |
// ----------------------------------------------------------------------------
|
2 |
|
|
|
3 |
|
|
// SystemC JTAG driver header
|
4 |
|
|
|
5 |
|
|
// Copyright (C) 2008 Embecosm Limited <info@embecosm.com>
|
6 |
|
|
|
7 |
|
|
// Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
8 |
|
|
|
9 |
|
|
// This file is part of the cycle accurate model of the OpenRISC 1000 based
|
10 |
|
|
// system-on-chip, ORPSoC, built using Verilator.
|
11 |
|
|
|
12 |
|
|
// This program is free software: you can redistribute it and/or modify it
|
13 |
|
|
// under the terms of the GNU Lesser General Public License as published by
|
14 |
|
|
// the Free Software Foundation, either version 3 of the License, or (at your
|
15 |
|
|
// option) any later version.
|
16 |
|
|
|
17 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
18 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
20 |
|
|
// License for more details.
|
21 |
|
|
|
22 |
|
|
// You should have received a copy of the GNU Lesser General Public License
|
23 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
24 |
|
|
|
25 |
|
|
// ----------------------------------------------------------------------------
|
26 |
|
|
|
27 |
|
|
// $Id: JtagDriverSC.h 317 2009-02-22 19:52:12Z jeremy $
|
28 |
|
|
|
29 |
|
|
#ifndef JTAG_DRIVER_SC__H
|
30 |
|
|
#define JTAG_DRIVER_SC__H
|
31 |
|
|
|
32 |
|
|
#include <stdint.h>
|
33 |
|
|
|
34 |
|
|
#include "systemc"
|
35 |
|
|
|
36 |
64 |
julius |
#include "JtagSC_includes.h"
|
37 |
63 |
julius |
|
38 |
|
|
|
39 |
|
|
//! Module providing TAP requests to JTAG
|
40 |
|
|
|
41 |
|
|
//! Provides a queue of requests to the JTAG interface. Requests are at the
|
42 |
|
|
//! level of TAP actions for reset, DR-Scan or IR-Scan.
|
43 |
|
|
|
44 |
|
|
class JtagDriverSC
|
45 |
|
|
: public sc_core::sc_module
|
46 |
|
|
{
|
47 |
|
|
public:
|
48 |
|
|
|
49 |
|
|
// Constructor
|
50 |
|
|
JtagDriverSC (sc_core::sc_module_name name,
|
51 |
|
|
sc_core::sc_fifo<TapAction *> *_tapActionQueue);
|
52 |
|
|
|
53 |
|
|
private:
|
54 |
|
|
|
55 |
|
|
// JTAG instructions
|
56 |
|
|
static const uint32_t CHAIN_SELECT_IR = 0x3; //!< Chain Select instruction
|
57 |
|
|
static const uint32_t DEBUG_IR = 0x8; //!< Debug instruction
|
58 |
|
|
|
59 |
|
|
// JTAG register lengths (excluding CRC)
|
60 |
|
|
static const int JTAG_IR_LEN = 4; //!< JTAG instr reg length
|
61 |
|
|
static const int CHAIN_DR_LEN = 4; //!< Length of DR (excl CRC)
|
62 |
|
|
static const int RISC_DEBUG_DR_LEN = 65; //!< Length of DR (excl CRC)
|
63 |
|
|
static const int REGISTER_DR_LEN = 38; //!< Length of DR (excl CRC)
|
64 |
|
|
static const int WISHBONE_DR_LEN = 65; //!< Length of DR (excl CRC)
|
65 |
|
|
|
66 |
|
|
// JTAG register address masks
|
67 |
|
|
static const uint32_t RISC_DEBUG_ADDR_MASK = 0xffffffff; //!< Mask for addr
|
68 |
|
|
static const uint32_t REGISTER_ADDR_MASK = 0x0000001f; //!< Mask for addr
|
69 |
|
|
static const uint32_t WISHBONE_ADDR_MASK = 0xffffffff; //!< Mask for addr
|
70 |
|
|
|
71 |
|
|
// JTAG register R/W bit
|
72 |
|
|
static const uint64_t RISC_DEBUG_RW = 0x100000000ULL; //!< R/W bit mask
|
73 |
|
|
static const uint64_t REGISTER_RW = 0x000000020ULL; //!< R/W bit mask
|
74 |
|
|
static const uint64_t WISHBONE_RW = 0x100000000ULL; //!< R/W bit mask
|
75 |
|
|
|
76 |
|
|
// JTAG register data field offsets
|
77 |
|
|
static const int RISC_DEBUG_DATA_OFF = 33; //!< Offset to data field
|
78 |
|
|
static const int REGISTER_DATA_OFF = 6; //!< Offset to data field
|
79 |
|
|
static const int WISHBONE_DATA_OFF = 33; //!< Offset to data field
|
80 |
|
|
|
81 |
|
|
//! JTAG register data field sizes (all the same)
|
82 |
|
|
static const int DR_DATA_LEN = 32;
|
83 |
|
|
|
84 |
|
|
//! CRC length
|
85 |
|
|
static const int CRC_LEN = 8;
|
86 |
|
|
|
87 |
|
|
// OpenRISC 1000 scan chains
|
88 |
|
|
static const int OR1K_SC_UNDEF = -1; //!< Undefined OR1K scan chain
|
89 |
|
|
static const int OR1K_SC_RISC_DEBUG = 1; //!< for access to SPRs
|
90 |
|
|
static const int OR1K_SC_REGISTER = 4; //!< to stall/reset CPU
|
91 |
|
|
static const int OR1K_SC_WISHBONE = 5; //!< for memory access
|
92 |
|
|
|
93 |
|
|
//! Register addresses for the REGISTER scan chain
|
94 |
|
|
static const uint8_t OR1K_RSC_RISCOP = 0x04; //!< Used to reset/stall CPU
|
95 |
|
|
|
96 |
|
|
// Bits for the RISCOP register
|
97 |
|
|
static const uint32_t RISCOP_STALL = 0x00000001; //!< Stall the CPU
|
98 |
|
|
static const uint32_t RISCOP_RESET = 0x00000002; //!< Reset the CPU
|
99 |
|
|
|
100 |
|
|
//! The JTAG fifo we queue on
|
101 |
|
|
sc_core::sc_fifo<TapAction *> *tapActionQueue;
|
102 |
|
|
|
103 |
|
|
//! The currently selected scan chain
|
104 |
|
|
int currentScanChain;
|
105 |
|
|
|
106 |
|
|
// SystemC thread to queue actions
|
107 |
|
|
void queueActions ();
|
108 |
|
|
|
109 |
|
|
// Or1k JTAG actions
|
110 |
|
|
void reset ();
|
111 |
|
|
void selectChain (int chain);
|
112 |
|
|
uint32_t readReg (uint32_t addr);
|
113 |
|
|
uint32_t readReg1 (uint32_t addr,
|
114 |
|
|
int bitSizeNoCrc);
|
115 |
|
|
uint32_t readReg1 (uint64_t *dRegArray,
|
116 |
|
|
uint32_t addr,
|
117 |
|
|
int bitSizeNoCrc);
|
118 |
|
|
void writeReg (uint32_t addr,
|
119 |
|
|
uint32_t data);
|
120 |
|
|
// Utilities to compute CRC-8 the OpenRISC way. Versions for "big" and
|
121 |
|
|
// "small" numbers.
|
122 |
|
|
uint8_t crc8 (uint64_t data,
|
123 |
|
|
int size);
|
124 |
|
|
uint8_t crc8 (uint64_t *dataArray,
|
125 |
|
|
int size);
|
126 |
|
|
|
127 |
|
|
// Utilities to insert and extract bit strings from vectors
|
128 |
|
|
void insertBits (uint64_t str,
|
129 |
|
|
int strLen,
|
130 |
|
|
uint64_t *array,
|
131 |
|
|
int startBit);
|
132 |
|
|
uint64_t extractBits (uint64_t *array,
|
133 |
|
|
int startBit,
|
134 |
|
|
int strLen);
|
135 |
|
|
|
136 |
|
|
}; // JtagDriverSC ()
|
137 |
|
|
|
138 |
|
|
#endif // JTAG_DRIVER_SC__H
|