LowLevelFunc430Xv2.h
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 | LowLevelFunc430Xv2.h |
36 | |
37 | Low Level function prototypes, macros, and pin-to-signal assignments |
38 | regarding to user's hardware |
39 |----------------------------------------------------------------------------|
40 | Project: MSP430 Replicator |
41 | Developed using: IAR Embedded Workbench 6.20 |
42 | and: Code Composer Studio 6.0 |
43 |----------------------------------------------------------------------------|
44 | Version history: |
45 | 1.0 04/02 FRGR Initial version. |
46 | 1.1 04/02 FRGR Included SPI mode to speed up shifting function by 2.|
47 | (JTAG control now on Port5) |
48 | 1.2 06/02 ALB2 Formatting changes, added comments. Removed code used|
49 | for debug purposes during development. |
50 | 1.3 08/02 ALB2 Initial code release with Lit# SLAA149. |
51 | 1.4 09/05 SUN1 Software delays redesigned to use TimerA harware; |
52 | see MsDelay() routine. Added TA constant. |
53 | 1.5 12/05 STO Added RESET pin definition |
54 | 1.6 03/08 WLUT Removed reference to JTAGfunc430X.h file |
55 | Added data format definitions |
56 | 1.7 08/08 WLUT Added macros for RST and TEST pin handling |
57 | Added macros for Spy-Bi-Wire capability. |
58 | 1.8 10/08 WLUT Fixed macro DrvSignals to drive correct signals |
59 | for Spy-Bi-Wire. |
60 | 1.9 05/09 GC (Elprotronic) Added support for the new hardware - REP430F |
61 | 2.0 10/11 FB Added support for JSBW functions |
62 | 2.1 06/12 RL Updated commentaries |
63 |----------------------------------------------------------------------------|
64 | Designed 2002 by Texas Instruments Germany |
65 \*==========================================================================*/
68 /****************************************************************************/
69 /* INCLUDES */
70 /****************************************************************************/
71 
72 #include "Config430Xv2.h" // High-level user input
73 #include <msp430x54x.h>
74 
75 /****************************************************************************/
76 /* DEFINES & CONSTANTS */
77 /****************************************************************************/
78 
80 #define SPYBIWIREJTAG_IF 1
81 #define SPYBIWIRE_IF 2
83 
84 #if( INTERFACE == SPYBIWIRE_IF )
85 #define SPYBIWIRE_MODE
86 #else
87 #define JSBW
88 #endif
89 
90 #define RSTLOW_SBW 0
91 #define RSTLOW_JTAG 1
92 #define RSTHIGH_SBW 2
93 #define RSTHIGH_JTAG 3
94 
95 #ifndef __DATAFORMATS__
96 #define __DATAFORMATS__
97 #define F_BYTE 8
98 #define F_WORD 16
99 #define F_ADDR 20
100 #define F_LONG 32
101 #endif
102 
103 // Constants for runoff status
105 #define STATUS_ERROR 0 // false
106 #define STATUS_OK 1 // true
108 #define STATUS_FUSEBLOWN 2
110 
112 #define STATUS_ACTIVE 2
113 #define STATUS_IDLE 3
115 
116 /****************************************************************************/
117 /* Macros and Pin-to-Signal assignments which have to be programmed */
118 /* by the user. This implementation assumes use of an MSP430F5437 as the */
119 /* host controller and the corresponding hardware given in the MSP430 */
120 /* Programming Via the JTAG Interface User's Guide (SLAU320). */
121 /* */
122 /* The following MSP430 example acts as a hint of how to generally */
123 /* implement a micro-controller programmer solution for the MSP430 flash- */
124 /* based devices. */
125 /****************************************************************************/
126 
127 // I/O Level translators (SN74LVC1T45) direction setup
128 
129 #define TRSLDIR P2OUT
130 
131 #define TRSL_CDIR P2DIR
132 
135 #define BRX_DIR 0x01
136 #define BTX_DIR 0x02
139 #define TEST_DIR 0x04
141 #define RST_DIR 0x08
143 #define TCK_DIR 0x10
145 #define TMS_DIR 0x20
147 #define TDOI_DIR 0x40
149 #define TDI_DIR 0x80
151 
152 #define SW_OUT P1OUT
153 #define SW_IN P1IN
154 #define SW_DIR P1DIR
155 #define SW_PULLUP P1REN
156 #define LED_OUT P1OUT
158 #define LED_DIR P1DIR
160 
162 #define SW_MODE0 0x01
163 #define SW_MODE1 0x02
165 #define SW_VPPEN 0x04
167 #define LED_YELLOW 0x08
169 #define LED_GREEN 0x10
171 #define LED_RED 0x20
173 #define SW_1 0x40
175 
176 //#define spareP17 0x80
177 
179 #define TVCC_OUT P6OUT
180 #define TVCC_DIR P6DIR
182 #define TVCC_MASK 0xF0
184 #define TVCC_SHIFT 4
186 
187 #define TVCC_EN_DIR P5DIR
188 #define TVCC_EN_OUT P5OUT
189 #define TVCC_DIS_BIT 1
190 
192 #define LED_yellow_on() ( LED_OUT |= LED_YELLOW )
193 #define LED_yellow_off() ( LED_OUT &= ~LED_YELLOW )
195 #define LED_red_on() ( LED_OUT |= LED_RED )
197 #define LED_red_off() ( LED_OUT &= ~LED_RED )
199 #define LED_green_on() ( LED_OUT |= LED_GREEN )
201 #define LED_green_off() ( LED_OUT &= ~LED_GREEN )
203 #define All_LEDs_off() ( LED_OUT &= ~(LED_GREEN | LED_RED | LED_YELLOW ))
205 
206 // JTAG ports are P5.x
208 #define JTAGOUT P5OUT
209 #define JTAGIN P5IN
211 #define JTAGDIR P5DIR
213 #define JTAGSEL P5SEL
215 #define TMS 0x20
217 #define TDI 0x80
219 #define TDO 0x40
221 #define TCK 0x10
223 #define TEST 0x04
225 #define RST 0x08
227 #define TCLK TDI
229 
232 #define BSLOUT P3OUT
233 #define BSLIN P3IN
236 #define BSLDIR P3DIR
239 #define BSLSEL P3SEL
242 #define BSLTX 0x20
245 #define BSLRX 0x10
248 
249 // VPP ports are P8.x
251 #define VPPOUT P8OUT
252 #define VPPDIR P8DIR
254 #define VPPSEL P8SEL
256 
258 #define VPPONTEST 0x04
259 #define VPPONTDI 0x02
261 
262 // Constants for Setting up Timer A
264 #define ONEMS 0x05DC
265 
266 /****************************************************************************/
267 /* Macros for processing the JTAG port */
268 /****************************************************************************/
269 
271 #define ClrTMS() ((JTAGOUT) &= (~TMS))
272 #define SetTMS() ((JTAGOUT) |= (TMS))
274 #define ClrTDI() ((JTAGOUT) &= (~TDI))
276 #define SetTDI() ((JTAGOUT) |= (TDI))
278 #define ClrTCK() ((JTAGOUT) &= (~TCK))
280 #define SetTCK() ((JTAGOUT) |= (TCK))
282 #define StoreTCLK() ((JTAGOUT & TCLK))
284 #define RestoreTCLK(x) (x == 0 ? (JTAGOUT &= ~TCLK) : (JTAGOUT |= TCLK))
286 #define ScanTDO() ((JTAGIN & TDO))
288 #define VPPon(x) (x == VPP_ON_TEST ? (SetVpp(VPPONTEST)) : (SetVpp(VPPONTDI)))
290 #define VPPoff() (SetVpp(0))
292 
293 /****************************************************************************/
294 /* SBW2/4 (JSBW) Macros to control LPMx.5 */
295 /****************************************************************************/
296 #ifdef JSBW
297 
299 #define nNOPS { _NOP(); _NOP(); _NOP(); _NOP(); _NOP(); _NOP(); }
300 
302 #define SBWDATO RST
303 #define SBWCLK TEST
305 
307 #define TMSH JTAGOUT |= SBWDATO; usDelay(400); JTAGOUT &= ~SBWCLK; usDelay(1); JTAGOUT |= SBWCLK; usDelay(1);
308 #define TMSL JTAGOUT &= ~SBWDATO; usDelay(400); JTAGOUT &= ~SBWCLK; usDelay(1); JTAGOUT |= SBWCLK; usDelay(1);
310 #define TDIH JTAGOUT |= SBWDATO; usDelay(400); JTAGOUT &= ~SBWCLK; usDelay(1); JTAGOUT |= SBWCLK; usDelay(1);
312 #define TDIL JTAGOUT &= ~SBWDATO; usDelay(400); JTAGOUT &= ~SBWCLK; usDelay(1); JTAGOUT |= SBWCLK; usDelay(1);
314 #define TDOsbw TRSLDIR |= TDOI_DIR; nNOPS JTAGOUT &= ~SBWCLK; usDelay(1); JTAGOUT |= SBWCLK; usDelay(1); TRSLDIR &= ~TDOI_DIR;
316 #define TDO_RD TRSLDIR |= TDOI_DIR; nNOPS JTAGOUT &= ~SBWCLK; usDelay(1); tdo_bit = JTAGIN; usDelay(1); JTAGOUT |= SBWCLK; TRSLDIR &= ~TDOI_DIR;
318 
319 /****************************************************************************/
320 /* Macros to control Spy-Bi-Wire-IF */
321 /****************************************************************************/
322 #else
323 
325 #define SBWDATO TDI
326 #define SBWDATI TDO
328 #define SBWCLK TCK
330 
332 #define nNOPS { _NOP(); _NOP(); _NOP(); _NOP(); _NOP(); _NOP(); }
333 
335 #define TMSH {JTAGOUT |= SBWDATO; nNOPS ;JTAGOUT &= ~SBWCLK; nNOPS JTAGOUT |= SBWCLK; }
336 #define TMSL {JTAGOUT &= ~SBWDATO; nNOPS JTAGOUT &= ~SBWCLK; nNOPS JTAGOUT |= SBWCLK;}
338 #define TMSLDH {JTAGOUT &= ~SBWDATO; nNOPS JTAGOUT &= ~SBWCLK; nNOPS JTAGOUT |= SBWDATO; JTAGOUT |= SBWCLK;}
343 #define TDIH {JTAGOUT |= SBWDATO; nNOPS JTAGOUT &= ~SBWCLK; nNOPS JTAGOUT |= SBWCLK;}
345 #define TDIL {JTAGOUT &= ~SBWDATO; nNOPS JTAGOUT &= ~SBWCLK; nNOPS JTAGOUT |= SBWCLK;}
347 #define TDOsbw {TRSLDIR |= TDOI_DIR; nNOPS JTAGOUT &= ~SBWCLK; nNOPS JTAGOUT |= SBWCLK; TRSLDIR &= ~TDOI_DIR;}
349 #define TDO_RD {TRSLDIR |= TDOI_DIR; nNOPS JTAGOUT &= ~SBWCLK; nNOPS tdo_bit = JTAGIN; JTAGOUT |= SBWCLK; TRSLDIR &= ~TDOI_DIR;}
351 
353 #define SetSBWTCK() (JTAGOUT |= SBWCLK)
354 #define ClrSBWTCK() (JTAGOUT &= ~SBWCLK)
356 #define SetSBWTDIO() (JTAGOUT |= SBWDATO)
358 #define ClrSBWTDIO() (JTAGOUT &= ~SBWDATO)
360 
361 #endif
362 
363 #if ( INTERFACE == SPYBIWIRE_IF )
364 
365 void ClrTCLK_sbw(void);
366 void SetTCLK_sbw(void);
368 #define ClrTCLK() ClrTCLK_sbw()
369 #define SetTCLK() SetTCLK_sbw()
371 
373 #define SetRST() (JTAGOUT |= SBWDATO)
374 #define ClrRST() (JTAGOUT &= ~SBWDATO)
376 #define ReleaseRST() ()
378 #define SetTST() (JTAGOUT |= SBWCLK)
380 #define ClrTST() (JTAGOUT &= ~SBWCLK)
382 
383 #else
384 
386 #define ClrTCLK() ((JTAGOUT) &= ~(TCLK))
387 #define SetTCLK() ((JTAGOUT) |= (TCLK))
389 
391 #define SetRST() ((JTAGOUT) |= (RST))
392 #define ClrRST() ((JTAGOUT) &= (~RST))
394 #define ReleaseRST() ( RST_dir( 0 ))
396 #define SetTST() ((JTAGOUT) |= (TEST))
398 #define ClrTST() ((JTAGOUT) &= (~TEST))
400 
401 #endif
402 
403 /****************************************************************************/
404 /* TYPEDEFS */
405 /****************************************************************************/
406 
407 #ifndef __BYTEWORD__
408 #define __BYTEWORD__
409 typedef unsigned short word;
410 typedef unsigned char byte;
411 #endif
412 
413 /****************************************************************************/
414 /* FUNCTION PROTOTYPES */
415 /****************************************************************************/
416 
417 void TMSL_TDIL(void);
418 void TMSH_TDIL(void);
419 void TMSL_TDIH(void);
420 void TMSH_TDIH(void);
421 void TMSL_TDIH_TDOrd(void);
422 void TMSL_TDIL_TDOrd(void);
423 void TMSH_TDIH_TDOrd(void);
424 void TMSH_TDIL_TDOrd(void);
425 void MsDelay(word milliseconds); // millisecond delay loop, uses Timer_A
426 void usDelay(word microeconds); // microsecond delay loop, uses nops
427 void InitController(void);
428 void InitTarget(void);
429 void ReleaseTarget(void);
430 unsigned long AllShifts(word Format, unsigned long Data);
431 void TDOisInput(void);
432 void TCLKstrobes(word Amount);
433 void ShowStatus(word Status, word Index);
434 void TriggerPulse(word Mode); // optional for test
435 void DrvSignals( void );
436 void RlsSignals( void );
437 void SetTargetVcc (word level);
438 word Get_target_Vcc( void);
439 word Get_Ext_Vcc( void );
440 void SetVpp( word source );
441 void RST_dir( word dir );
442 void IO_3state(void);
443 void SetVCoreUp( word level);
444 word Get_Vx( word index );
445 void Enable_Vpp( void );
446 void Disable_Vpp( void );
447 void TDI_dir( word dir );
448 void TDOI_dir( word dir );
449 void TEST_dir( word dir );
450 void TMS_dir( word dir );
451 void TCK_dir( word dir );
452 void configure_IO_JTAG( void );
453 void configure_IO_SBW( void );
word Get_Vx(word index)
Measure different voltages via ADC12.
void ShowStatus(word Status, word Index)
This function controls the status LEDs depending on the status argument. It stops program in error ca...
void TCK_dir(word dir)
Set the direction for the TCK pin.
void MsDelay(word milliseconds)
Delay function (resolution is 1 ms)
void DrvSignals(void)
Set up I/O pins for JTAG communication.
Configurations for the MSP430 Replicator Xv2.
void TEST_dir(word dir)
Set the direction for the TEST pin.
void usDelay(word microeconds)
Delay function (resolution is ~1 us)
void ClrTCLK_sbw(void)
Clear TCLK in Spy-Bi-Wire mode.
void configure_IO_JTAG(void)
Set JTAG pins to output direction - from REP430F to target.
void IO_3state(void)
Set all JTAG pins to input direction - from target to REP430F.
void Disable_Vpp(void)
Disable fuse blow voltage Vpp.
void InitController(void)
Initialization of the Controller Board.
void TDOI_dir(word dir)
Set the direction for the TDO pin.
void InitTarget(void)
Initialization of the Target Board (switch voltages on, preset JTAG pins)
void TMS_dir(word dir)
Set the direction for the TMS pin.
void TDOisInput(void)
This function switches TDO to Input (used for fuse blowing)
void TCLKstrobes(word Amount)
This function generates Amount strobes with the Flash Timing Generator.
void SetVCoreUp(word level)
Function to set a specific voltage level via the PMM.
void RST_dir(word dir)
Set the direction for the RST pin.
unsigned long AllShifts(word Format, unsigned long Data)
Shift a value into TDI (MSB first) and simultaneously shift out a value from TDO (MSB first)...
void SetVpp(word source)
function to set the fuse blow voltage Vpp
word Get_Ext_Vcc(void)
Determine external VCC.
void SetTargetVcc(word level)
Set target Vcc (supplied from REP430F)
void TDI_dir(word dir)
Set the direction for the TDI pin.
word Get_target_Vcc(void)
Determine target VCC.
void configure_IO_SBW(void)
Set SBW pins to output direction - from REP430F to target.
void ReleaseTarget(void)
Release Target Board (switch voltages off, JTAG pins are HI-Z)
void RlsSignals(void)
Release I/O pins.
void SetTCLK_sbw(void)
Set TCLK in Spy-Bi-Wire mode.
void Enable_Vpp(void)
Enable fuse blow voltage Vpp.

Copyright 2016, Texas Instruments Incorporated