JSBW.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32 */
33 /*=============================================================================\
34 | |
35 | JSBW.c |
36 | |
37 | This file contains the necessary high level routines to wake up an MSP430 |
38 | device from LPM5 in 4-wire mode and putting it in Reset State. Since the |
39 | 4-wire pins are locked by the JTAG lock, the JTAG access routine must be |
40 | emulated using Spy-Bi-Wire. |
41 |------------------------------------------------------------------------------|
42 | Project: MSP430 Replicator Xv2 |
43 | Developed using: IAR Embedded Workbench 6.20 |
44 |------------------------------------------------------------------------------|
45 | Version history: |
46 | 1.0 04/11 FB Initial Version |
47 |------------------------------------------------------------------------------|
48 | Designed 2011 by Texas Instruments Germany |
49 \=============================================================================*/
52 /****************************************************************************/
53 /* Includes */
54 /****************************************************************************/
55 
56 #include "JTAGfunc430Xv2.h" // JTAG functions
57 #include "LowLevelFunc430Xv2.h" // low level user functions
58 
59 // Spy-Bi-Wire addons --------------------------------------------------------
60 extern byte tdo_bit;
61 extern byte TCLK_saved; // holds the last value of TCLK before entering a JTAG sequence
62 
63 //----------------------------------------------------------------------------
65 void jRelease(void)
66 {
67  // drive target RST/SBWTDIO pin high
68  (JTAGOUT &= ~SBWDATO); // TDI drives target RST high // (JTAGOUT |= SBWDATO);
69 
70  MsDelay(1);
71 
72  // drive target TEST/SBWTCK pin low
73  (JTAGOUT &= ~SBWCLK); // TCK drives target TEST low - release Spy-Bi-Wire logic
74 }
75 
76 //----------------------------------------------------------------------------
79 void StartJtagJSbw(byte states)
80 {
81  // reset TEST logic
82  ClrTST();
83  MsDelay(20); // delay 20ms
84 
85  if(states == RSTLOW_SBW || states == RSTLOW_JTAG)
86  {
87  // Set Reset pin 0
88  (JTAGOUT) &= (~RST);
89  }
90  else
91  {
92  // Set Reset pin = 1
93  SetRST();
94  }
95 
96  SetTST();
97  // activate TEST logic
98  MsDelay(25);
99 
100  // phase 1
101  if(states == RSTLOW_JTAG || states == RSTHIGH_JTAG)
102  {
103  //Set Reset pin =0
104  ClrRST();
105  }
106  else
107  {
108  SetRST();
109  }
110  usDelay(40);
111 
112  // phase 2 -> TEST pin to 0, no change on RST pin
113  if(states == RSTLOW_SBW || states == RSTHIGH_SBW)
114  {
115  // for Spy-Bi-Wire
116  // JTAGOUT &= ~SBWCLK;
117  }
118  else
119  {
120  // for 4-wire JTAG
121  ClrTST();
122  }
123 
124  // phase 3
125  if(states == RSTLOW_JTAG)
126  {
127  SetRST();
128  }
129  usDelay(1);
130 
131  // phase 4 -> TEST pin to 1, no change on RST pin
132  if(states == RSTLOW_SBW || states == RSTHIGH_SBW)
133  {
134  // for Spy-Bi-Wire
135  // JTAGOUT |= SBWCLK;
136  }
137  else
138  {
139  // for 4-wire JTAG
140  SetTST();
141  }
142  usDelay(40);
143 
144  // phase 5
145  if(states == RSTHIGH_JTAG)
146  {
147  SetRST();
148  }
149  MsDelay(5);
150 }
151 
152 //----------------------------------------------------------------------------
154 void jResetJtagTap(void)
155 {
156  word i;
157  // Check Fuse, Reset JTAG FSM
158  for (i = 6; i > 0; i--) // 6 is nominal
159  {
160  TMSH_TDIH();
161  }
162  // JTAG FSM is now in Test-Logic-Reset
163  TMSL_TDIH(); // now in Run/Test Idle
164 }
165 
166 //----------------------------------------------------------------------------
173 long jsbw_Shift(word Format, long Data)
174 {
175  word tclk = StoreTCLK(); // Store TCLK state;
176  unsigned long TDOword = 0x00000000;
177  unsigned long MSB = 0x00000000;
178  word i;
179 
180  switch(Format)
181  {
182  case F_BYTE: MSB = 0x00000080;
183  break;
184  case F_WORD: MSB = 0x00008000;
185  break;
186  case F_ADDR: MSB = 0x00080000;
187  break;
188  case F_LONG: MSB = 0x80000000;
189  break;
190  default: // this is an unsupported format, function will just return 0
191  return TDOword;
192  }
193  for (i = Format; i > 0; i--)
194  {
195  ((Data & MSB) == 0) ? ClrTDI() : SetTDI();
196  Data <<= 1;
197  if (i == 1)
198  { // Last bit requires TMS=1
199  SetTMS();
200  }
201  ClrTCK();
202  SetTCK();
203  TDOword <<= 1; // TDO could be any port pin
204  if (ScanTDO() != 0)
205  {
206  TDOword++;
207  }
208  }
209  // common exit
210  RestoreTCLK(tclk); // restore TCLK state
211 
212  // JTAG FSM = Exit-DR
213  ClrTCK();
214  SetTCK();
215  // JTAG FSM = Update-DR
216  ClrTMS();
217  ClrTCK();
218  SetTCK();
219  // JTAG FSM = Run-Test/Idle
220  return(TDOword);
221 }
222 
223 //----------------------------------------------------------------------------
229 long jsbw_IR_Shift(byte instruction)
230 {
231  // JTAG FSM state = Select DR-Scan
232  TMSH_TDIH();
233 
234  // JTAG FSM state = Select IR-Scan
235  TMSL_TDIH();
236  // JTAG FSM state = Capture-IR
237  TMSL_TDIH();
238  // JTAG FSM state = Shift-IR, Shift in TDI (8-bit)
239  return(jsbw_Shift(F_BYTE, instruction));
240  // JTAG FSM state = Run-Test/Idle
241 }
242 
243 //----------------------------------------------------------------------------
249 long jsbw_DR_Shift(long data)
250 {
251  // JTAG FSM state = Run-Test/Idle
252  if (TCLK_saved & SBWDATO)
253  {
254  TMSH_TDIH();
255  }
256  else
257  {
258  TMSH_TDIL();
259  }
260  // JTAG FSM state = Select DR-Scan
261  TMSL_TDIH();
262  // JTAG FSM state = Capture-DR
263  TMSL_TDIH();
264  // JTAG FSM state = Shift-DR, Shift in TDI (16-bit)
265  return(jsbw_Shift(F_WORD, data));
266  // JTAG FSM state = Run-Test/Idle
267 }
268 
269 //----------------------------------------------------------------------------
272 {
274  MsDelay(10);
275  jsbw_DR_Shift(0x0001);
276  MsDelay(10);
277  jsbw_DR_Shift(0xA55A);
278  MsDelay(15);
279 }
280 
281 //----------------------------------------------------------------------------
283 void jsbwJtagUnlock(void)
284 {
286  MsDelay(10);
287  jsbw_DR_Shift(0x4020);
288  MsDelay(10);
289 }
290 
291 /****************************************************************************/
292 /* END OF SOURCE FILE */
293 /****************************************************************************/
void usDelay(word microseconds)
Delay function (resolution is ~1 us)
#define ClrTST()
SBW macro: clear TEST pin signal.
#define SBWCLK
JTAG clock pin in SBW mode.
JTAG Function Prototypes and Definitions.
byte tdo_bit
Holds the value of TDO-bit.
#define SetTST()
SBW macro: set TEST pin signal.
#define IR_TEST_3V_REG
Instruction for 3 volt test register in 5xx.
#define SBWDATO
JTAG data_out pin in SBW mode -separate pin in MSP430F5437 - common IO translator.
#define RestoreTCLK(x)
JTAG macro: restore TCLK signal on TDI pin (based on input: x)
byte TCLK_saved
Holds the last value of TCLK before entering a JTAG sequence.
void jResetJtagTap(void)
Reset target JTAG interface and perform fuse-HW check.
Definition: JSBW.c:154
void jsbwJtagUnlock(void)
Function for resetting the JTAG lock via JSBW.
Definition: JSBW.c:283
#define ClrTDI()
JTAG macro: clear TDI signal.
#define SetTCK()
JTAG macro: set TCK signal.
#define ClrRST()
SBW macro: clear RST signal.
#define SetTMS()
JTAG macro: set TMS signal.
#define StoreTCLK()
JTAG macro: return current TCLK signal (on TDI pin)
long jsbw_IR_Shift(byte instruction)
Function for shifting a new instruction into the JTAG instruction register through JSBW (MSB first...
Definition: JSBW.c:229
void StartJtagJSbw(byte states)
Start JTAG communication in JSBW mode.
Definition: JSBW.c:79
#define IR_JMB_EXCHANGE
Request a JTAG mailbox exchange.
void MsDelay(word milliseconds)
Delay function (resolution is 1 ms)
void jRelease(void)
Releases the JSBW logic.
Definition: JSBW.c:65
void JsbwMagicPattern(void)
Function for applying the magic pattern via JSBW.
Definition: JSBW.c:271
#define ClrTCK()
JTAG macro: clear TCK signal.
#define JTAGOUT
JTAG output register.
#define ScanTDO()
JTAG macro: return TDO value (result 0 or TDO (0x40))
#define SetTDI()
JTAG macro: set TDI signal.
Low Level function prototypes, macros, and pin-to-signal assignments regarding to user's hardware...
#define RST
P5.3 Hardware RESET input pin.
long jsbw_DR_Shift(long data)
Function for shifting data into the JTAG data register through JSBW (MSB first, but with interchanged...
Definition: JSBW.c:249
#define SetRST()
SBW macro: set RST signal.
long jsbw_Shift(word Format, long Data)
Shift a value into TDI (MSB first) and simultaneously shift out a value from TDO (MSB first)...
Definition: JSBW.c:173
#define ClrTMS()
JTAG macro: clear TMS signal.

Copyright 2016, Texas Instruments Incorporated