| 1 |
63 |
julius |
// ----------------------------------------------------------------------------
|
| 2 |
|
|
|
| 3 |
|
|
// The TAP state machine: implementation
|
| 4 |
|
|
|
| 5 |
|
|
// Copyright (C) 2009 Embecosm Limited <info@embecosm.com>
|
| 6 |
|
|
|
| 7 |
|
|
// Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
| 8 |
|
|
|
| 9 |
|
|
// This file is part of the Embecosm cycle accurate SystemC JTAG library.
|
| 10 |
|
|
|
| 11 |
|
|
// This program is free software: you can redistribute it and/or modify it
|
| 12 |
|
|
// under the terms of the GNU Lesser General Public License as published by
|
| 13 |
|
|
// the Free Software Foundation, either version 3 of the License, or (at your
|
| 14 |
|
|
// option) any later version.
|
| 15 |
|
|
|
| 16 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
| 17 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 18 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
| 19 |
|
|
// License for more details.
|
| 20 |
|
|
|
| 21 |
|
|
// You should have received a copy of the GNU Lesser General Public License
|
| 22 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 23 |
|
|
|
| 24 |
|
|
// The C/C++ parts of this program are commented throughout in a fashion
|
| 25 |
|
|
// suitable for processing with Doxygen.
|
| 26 |
|
|
|
| 27 |
|
|
// The C/C++ parts of this program are commented throughout in a fashion
|
| 28 |
|
|
// suitable for processing with Doxygen.
|
| 29 |
|
|
|
| 30 |
|
|
// ----------------------------------------------------------------------------
|
| 31 |
|
|
|
| 32 |
|
|
// $Id$
|
| 33 |
|
|
|
| 34 |
|
|
#include "TapStateMachine.h"
|
| 35 |
|
|
|
| 36 |
|
|
//! Constructor
|
| 37 |
|
|
|
| 38 |
|
|
//! Start in the Test-Logic-Reset state, although we cannot know this reflects
|
| 39 |
|
|
//! the hardware until it has been through a TAP reset sequence. This is
|
| 40 |
|
|
//! reflected in the ::tapResetDone flag.
|
| 41 |
|
|
|
| 42 |
|
|
TapStateMachine::TapStateMachine () :
|
| 43 |
|
|
state (TAP_TEST_LOGIC_RESET),
|
| 44 |
|
|
resetDone (false)
|
| 45 |
|
|
{
|
| 46 |
|
|
|
| 47 |
|
|
} // TapStateMachine ()
|
| 48 |
|
|
|
| 49 |
|
|
|
| 50 |
|
|
//! Accessor to get the current TAP state
|
| 51 |
|
|
|
| 52 |
|
|
//! Only guaranteed to match the target hardware if it has been through a
|
| 53 |
|
|
//! reset sequence.
|
| 54 |
|
|
|
| 55 |
|
|
//! @return The current TAP state
|
| 56 |
|
|
TapState
|
| 57 |
|
|
TapStateMachine::getState ()
|
| 58 |
|
|
{
|
| 59 |
|
|
return state;
|
| 60 |
|
|
|
| 61 |
|
|
} // getState ()
|
| 62 |
|
|
|
| 63 |
|
|
|
| 64 |
|
|
//! Accessor to get the current TAP reset state.
|
| 65 |
|
|
|
| 66 |
|
|
//! It is the responsibility of classes using this class to correctly set this
|
| 67 |
|
|
//! state.
|
| 68 |
|
|
|
| 69 |
|
|
//! @return The current TAP reset state
|
| 70 |
|
|
bool
|
| 71 |
|
|
TapStateMachine::getResetDone ()
|
| 72 |
|
|
{
|
| 73 |
|
|
return resetDone;
|
| 74 |
|
|
|
| 75 |
|
|
} // getResetDone ()
|
| 76 |
|
|
|
| 77 |
|
|
|
| 78 |
|
|
//! Accessor to set the current TAP reset state.
|
| 79 |
|
|
|
| 80 |
|
|
//! It is the responsibility of classes using this class to correctly set this
|
| 81 |
|
|
//! state.
|
| 82 |
|
|
|
| 83 |
|
|
//! @param[in] The desired TAP reset state
|
| 84 |
|
|
void
|
| 85 |
|
|
TapStateMachine::setResetDone (bool _resetDone)
|
| 86 |
|
|
{
|
| 87 |
|
|
resetDone = _resetDone;
|
| 88 |
|
|
|
| 89 |
|
|
} // setResetDone ()
|
| 90 |
|
|
|
| 91 |
|
|
|
| 92 |
|
|
//! Drive the TAP state machine
|
| 93 |
|
|
|
| 94 |
|
|
//! @param tms The JTAG TMS pin
|
| 95 |
|
|
void
|
| 96 |
|
|
TapStateMachine::nextState (bool tms)
|
| 97 |
|
|
{
|
| 98 |
|
|
static const TapState mapHigh[TAP_SIZE] = { // When TMS = 1/true
|
| 99 |
|
|
TAP_TEST_LOGIC_RESET, // from TAP_TEST_LOGIC_RESET
|
| 100 |
|
|
TAP_SELECT_DR_SCAN, // from TAP_RUN_TEST_IDLE
|
| 101 |
|
|
TAP_SELECT_IR_SCAN, // from TAP_SELECT_DR_SCAN
|
| 102 |
|
|
TAP_EXIT1_DR, // from TAP_CAPTURE_DR
|
| 103 |
|
|
TAP_EXIT1_DR, // from TAP_SHIFT_DR
|
| 104 |
|
|
TAP_UPDATE_DR, // from TAP_EXIT1_DR
|
| 105 |
|
|
TAP_EXIT2_DR, // from TAP_PAUSE_DR
|
| 106 |
|
|
TAP_UPDATE_DR, // from TAP_EXIT2_DR
|
| 107 |
|
|
TAP_SELECT_DR_SCAN, // from TAP_UPDATE_DR
|
| 108 |
|
|
TAP_TEST_LOGIC_RESET, // from TAP_SELECT_IR_SCAN
|
| 109 |
|
|
TAP_EXIT1_IR, // from TAP_CAPTURE_IR
|
| 110 |
|
|
TAP_EXIT1_IR, // from TAP_SHIFT_IR
|
| 111 |
|
|
TAP_UPDATE_IR, // from TAP_EXIT1_IR
|
| 112 |
|
|
TAP_EXIT2_IR, // from TAP_PAUSE_IR
|
| 113 |
|
|
TAP_UPDATE_IR, // from TAP_EXIT2_IR
|
| 114 |
|
|
TAP_SELECT_DR_SCAN}; // from TAP_UPDATE_IR
|
| 115 |
|
|
|
| 116 |
|
|
static const TapState mapLow[TAP_SIZE] = { // When TMS = 0/false
|
| 117 |
|
|
TAP_RUN_TEST_IDLE, // from TAP_TEST_LOGIC_RESET
|
| 118 |
|
|
TAP_RUN_TEST_IDLE, // from TAP_RUN_TEST_IDLE
|
| 119 |
|
|
TAP_CAPTURE_DR, // from TAP_SELECT_DR_SCAN
|
| 120 |
|
|
TAP_SHIFT_DR, // from TAP_CAPTURE_DR
|
| 121 |
|
|
TAP_SHIFT_DR, // from TAP_SHIFT_DR
|
| 122 |
|
|
TAP_PAUSE_DR, // from TAP_EXIT1_DR
|
| 123 |
|
|
TAP_PAUSE_DR, // from TAP_PAUSE_DR
|
| 124 |
|
|
TAP_SHIFT_DR, // from TAP_EXIT2_DR
|
| 125 |
|
|
TAP_RUN_TEST_IDLE, // from TAP_UPDATE_DR
|
| 126 |
|
|
TAP_CAPTURE_IR, // from TAP_SELECT_IR_SCAN
|
| 127 |
|
|
TAP_SHIFT_IR, // from TAP_CAPTURE_IR
|
| 128 |
|
|
TAP_SHIFT_IR, // from TAP_SHIFT_IR
|
| 129 |
|
|
TAP_PAUSE_IR, // from TAP_EXIT1_IR
|
| 130 |
|
|
TAP_PAUSE_IR, // from TAP_PAUSE_IR
|
| 131 |
|
|
TAP_SHIFT_IR, // from TAP_EXIT2_IR
|
| 132 |
|
|
TAP_RUN_TEST_IDLE }; // from TAP_UPDATE_IR
|
| 133 |
|
|
|
| 134 |
|
|
state = tms ? mapHigh[state] : mapLow[state];
|
| 135 |
|
|
|
| 136 |
|
|
} // nextState()
|
| 137 |
|
|
|
| 138 |
|
|
|
| 139 |
|
|
//! Determine if we are in a particular TAP state
|
| 140 |
|
|
|
| 141 |
|
|
//! Set TMS to get there optimally
|
| 142 |
|
|
|
| 143 |
|
|
//! @param[in] target The desired TAP state
|
| 144 |
|
|
//! @param[out] tms Value of TMS to move towards the target state. Set
|
| 145 |
|
|
//! even if we are already in the state (in case we want
|
| 146 |
|
|
//! to loop).
|
| 147 |
|
|
|
| 148 |
|
|
//! @return True if we are already in the target state
|
| 149 |
|
|
bool
|
| 150 |
|
|
TapStateMachine::targetState (TapState target,
|
| 151 |
|
|
bool &tms)
|
| 152 |
|
|
{
|
| 153 |
|
|
// Map of the value of TMS which moves the state machine from the the state
|
| 154 |
|
|
// in the row (first) to the state in the column (second)
|
| 155 |
|
|
static const bool map[TAP_SIZE][TAP_SIZE] = {
|
| 156 |
|
|
// T R S C S E P E U S C S E P E U
|
| 157 |
|
|
// L T D D D 1 D 2 D I I I 1 I 2 I
|
| 158 |
|
|
// R I R R R D R D R R R R I R I R
|
| 159 |
|
|
// S R R S R R
|
| 160 |
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // map[TLR][x]
|
| 161 |
|
|
{ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, // map[RTI][x]
|
| 162 |
|
|
{ 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 }, // map[SDRS][x]
|
| 163 |
|
|
{ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, // map[CDR][x]
|
| 164 |
|
|
{ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, // map[SDR][x]
|
| 165 |
|
|
{ 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 }, // map[E1DR][x]
|
| 166 |
|
|
{ 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, // map[PDR][x]
|
| 167 |
|
|
{ 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 }, // map[E2DR][x]
|
| 168 |
|
|
{ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, // map[UDR][x]
|
| 169 |
|
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 }, // map[SIRS][x]
|
| 170 |
|
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1 }, // map[CIR][x]
|
| 171 |
|
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1 }, // map[SIR][x]
|
| 172 |
|
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1 }, // map[E1IR][x]
|
| 173 |
|
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 }, // map[PIR][x]
|
| 174 |
|
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1 }, // map[E2IR][x]
|
| 175 |
|
|
{ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }}; // map[UIR][x]
|
| 176 |
|
|
|
| 177 |
|
|
tms = map[state][target];
|
| 178 |
|
|
return state == target;
|
| 179 |
|
|
|
| 180 |
|
|
} // targetState()
|