LowLevelFunc430.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 | LowLevelFunc430.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 08/08 WLUT Added DrvSignals and RlsSignals macros for clean |
55 | JTAG init sequence. |
56 | 1.7 05/09 GC (Elprotronic) Added support for the new hardware - REP430F |
57 | 1.8 07/09 FB Added macros for Spy-Bi-Wire support |
58 | 1.9 05/12 RL Updated commentaries |
59 |----------------------------------------------------------------------------|
60 | Designed 2002 by Texas Instruments Germany |
61 \*==========================================================================*/
64 /****************************************************************************/
65 /* INCLUDES */
66 /****************************************************************************/
67 
68 #include "Config430.h" // High-level user input
69 #include <msp430x54x.h>
70 
71 /****************************************************************************/
72 /* DEFINES & CONSTANTS */
73 /****************************************************************************/
74 
76 #define JTAG_IF 1
77 #define SPYBIWIREJTAG_IF 2
79 #define SPYBIWIRE_IF 3
81 
82 #if( INTERFACE == SPYBIWIRE_IF )
83 #define SPYBIWIRE_MODE
84 #endif
85 
86 #ifndef __DATAFORMATS__
87 #define __DATAFORMATS__
88 #define F_BYTE 8
89 #define F_WORD 16
90 #define F_ADDR 20
91 #define F_LONG 32
92 #endif
93 
94 // Constants for runoff status
96 #define STATUS_ERROR 0 // false
97 #define STATUS_OK 1 // true
99 #define STATUS_FUSEBLOWN 2
101 
103 #define STATUS_ACTIVE 2
104 #define STATUS_IDLE 3
106 
107 /****************************************************************************/
108 /* Macros and Pin-to-Signal assignments which have to be programmed */
109 /* by the user. This implementation assumes use of an MSP430F5437 as the */
110 /* host controller and the corresponding hardware given in the MSP430 */
111 /* Programming Via the JTAG Interface User's Guide (SLAU320). */
112 /* */
113 /* The following MSP430 example acts as a hint of how to generally */
114 /* implement a micro-controller programmer solution for the MSP430 flash- */
115 /* based devices. */
116 /****************************************************************************/
117 
118 // I/O Level translators (SN74LVC1T45) direction setup
119 
120 #define TRSLDIR P2OUT
121 
122 #define TRSL_CDIR P2DIR
123 
126 #define BRX_DIR 0x01
127 #define BTX_DIR 0x02
130 #define TEST_DIR 0x04
132 #define RST_DIR 0x08
134 #define TCK_DIR 0x10
136 #define TMS_DIR 0x20
138 #define TDOI_DIR 0x40
140 #define TDI_DIR 0x80
142 
143 #define SW_OUT P1OUT
144 #define SW_IN P1IN
145 #define SW_DIR P1DIR
146 #define SW_PULLUP P1REN
147 #define LED_OUT P1OUT
149 #define LED_DIR P1DIR
151 
153 #define SW_MODE0 0x01
154 #define SW_MODE1 0x02
156 #define SW_VPPEN 0x04
158 #define LED_YELLOW 0x08
160 #define LED_GREEN 0x10
162 #define LED_RED 0x20
164 #define SW_1 0x40
166 
167 //#define spareP17 0x80
168 
170 #define TVCC_OUT P6OUT
171 #define TVCC_DIR P6DIR
173 #define TVCC_MASK 0xF0
175 #define TVCC_SHIFT 4
177 
178 #define TVCC_EN_DIR P5DIR
179 #define TVCC_EN_OUT P5OUT
180 #define TVCC_DIS_BIT 1
181 
183 #define LED_yellow_on() ( LED_OUT |= LED_YELLOW )
184 #define LED_yellow_off() ( LED_OUT &= ~LED_YELLOW )
186 #define LED_red_on() ( LED_OUT |= LED_RED )
188 #define LED_red_off() ( LED_OUT &= ~LED_RED )
190 #define LED_green_on() ( LED_OUT |= LED_GREEN )
192 #define LED_green_off() ( LED_OUT &= ~LED_GREEN )
194 #define All_LEDs_off() ( LED_OUT &= ~(LED_GREEN | LED_RED | LED_YELLOW ))
196 
197 // JTAG ports are P5.x
199 #define JTAGOUT P5OUT
200 #define JTAGIN P5IN
202 #define JTAGDIR P5DIR
204 #define JTAGSEL P5SEL
206 #define TMS 0x20
208 #define TDI 0x80
210 #define TDO 0x40
212 #define TCK 0x10
214 #define TEST 0x04
216 #define RST 0x08
218 #define TCLK TDI
220 
223 #define BSLOUT P3OUT
224 #define BSLIN P3IN
227 #define BSLDIR P3DIR
230 #define BSLSEL P3SEL
233 #define BSLTX 0x20
236 #define BSLRX 0x10
239 
240 // VPP ports are P8.x
242 #define VPPOUT P8OUT
243 #define VPPDIR P8DIR
245 #define VPPSEL P8SEL
247 
249 #define VPPONTEST 0x04
250 #define VPPONTDI 0x02
252 
253 // Constants for Setting up Timer A
255 #define ONEMS 0x05DC
256 
257 /****************************************************************************/
258 /* Macros for processing the JTAG port */
259 /****************************************************************************/
260 
262 #define ClrTMS() ((JTAGOUT) &= (~TMS))
263 #define SetTMS() ((JTAGOUT) |= (TMS))
265 #define ClrTDI() ((JTAGOUT) &= (~TDI))
267 #define SetTDI() ((JTAGOUT) |= (TDI))
269 #define ClrTCK() ((JTAGOUT) &= (~TCK))
271 #define SetTCK() ((JTAGOUT) |= (TCK))
273 #define StoreTCLK() ((JTAGOUT & TCLK))
275 #define RestoreTCLK(x) (x == 0 ? (JTAGOUT &= ~TCLK) : (JTAGOUT |= TCLK))
277 #define ScanTDO() ((JTAGIN & TDO))
279 #define VPPon(x) (x == VPP_ON_TEST ? (SetVpp(VPPONTEST)) : (SetVpp(VPPONTDI)))
281 #define VPPoff() (SetVpp(0))
283 #define SetRST() ((JTAGOUT) |= (RST))
285 #define ClrRST() ((JTAGOUT) &= (~RST))
287 #define ReleaseRST() ( RST_dir( 0 ))
289 #define SetTST() ((JTAGOUT) |= (TEST))
291 #define ClrTST() ((JTAGOUT) &= (~TEST))
293 
294 /****************************************************************************/
295 /* Macros to control Spy-Bi-Wire-IF */
296 /****************************************************************************/
297 #define SBW_DELAY { _NOP();_NOP();_NOP();_NOP();_NOP();}
298 
300 #define SBWDATO TDI
301 #define SBWDATI TDO
303 #define SBWCLK TCK
305 
307 #define TMSH JTAGOUT |= SBWDATO; SBW_DELAY; JTAGOUT &= ~SBWCLK; SBW_DELAY; JTAGOUT |= SBWCLK;
308 #define TMSL JTAGOUT &= ~SBWDATO; SBW_DELAY; JTAGOUT &= ~SBWCLK; SBW_DELAY; JTAGOUT |= SBWCLK;
310 #define TMSLDH JTAGOUT &= ~SBWDATO; SBW_DELAY; JTAGOUT &= ~SBWCLK; SBW_DELAY; JTAGOUT |= SBWDATO; JTAGOUT |= SBWCLK;
315 #define TDIH JTAGOUT |= SBWDATO; SBW_DELAY; JTAGOUT &= ~SBWCLK; SBW_DELAY; JTAGOUT |= SBWCLK;
317 #define TDIL JTAGOUT &= ~SBWDATO; SBW_DELAY; JTAGOUT &= ~SBWCLK; SBW_DELAY; JTAGOUT |= SBWCLK;
319 #define TDOsbw TRSLDIR |= TDOI_DIR; SBW_DELAY; JTAGOUT &= ~SBWCLK; SBW_DELAY; JTAGOUT |= SBWCLK; TRSLDIR &= ~TDOI_DIR;
321 #define TDO_RD TRSLDIR |= TDOI_DIR; SBW_DELAY; JTAGOUT &= ~SBWCLK; SBW_DELAY; tdo_bit = JTAGIN; SBW_DELAY; JTAGOUT |= SBWCLK; TRSLDIR &= ~TDOI_DIR;
323 
325 #define SetSBWTCK() (JTAGOUT |= SBWCLK)
326 #define ClrSBWTCK() (JTAGOUT &= ~SBWCLK)
328 #define SetSBWTDIO() (JTAGOUT |= SBWDATO)
330 #define ClrSBWTDIO() (JTAGOUT &= ~SBWDATO)
332 
333 #if ( INTERFACE == SPYBIWIRE_IF )
334 
335 void ClrTCLK_sbw(void);
336 void SetTCLK_sbw(void);
338 #define ClrTCLK() ClrTCLK_sbw()
339 #define SetTCLK() SetTCLK_sbw()
341 
342 #else
343 
345 #define ClrTCLK() ((JTAGOUT) &= ~(TCLK))
346 #define SetTCLK() ((JTAGOUT) |= (TCLK))
348 
349 #endif
350 
351 /*----------------------------------------------------------------------------
352  Definition of global variables
353 */
354 extern byte TCLK_saved; // holds the last value of TCLK before entering a JTAG sequence
355 
356 /****************************************************************************/
357 /* TYPEDEFS */
358 /****************************************************************************/
359 
360 #ifndef __BYTEWORD__
361 #define __BYTEWORD__
362 typedef unsigned short word;
363 typedef unsigned char byte;
364 #endif
365 
366 /****************************************************************************/
367 /* FUNCTION PROTOTYPES */
368 /****************************************************************************/
369 
370 void TMSL_TDIL(void);
371 void TMSH_TDIL(void);
372 void TMSL_TDIH(void);
373 void TMSH_TDIH(void);
374 void TMSL_TDIH_TDOrd(void);
375 void TMSL_TDIL_TDOrd(void);
376 void TMSH_TDIH_TDOrd(void);
377 void TMSH_TDIL_TDOrd(void);
378 void IR_Ex_Blow_SBW_Shift(void);
379 void MsDelay(word milliseconds); // millisecond delay loop, uses Timer_A
380 void usDelay(word microeconds); // microsecond delay loop, uses nops
381 void InitController(void);
382 void InitTarget(void);
383 void ReleaseTarget(void);
384 word Shift(word Format, word Data); // used for IR- as well as DR-shift
385 void TDOisInput(void);
386 void TCLKstrobes(word Amount);
387 void ShowStatus(word Status, word Index);
388 void TriggerPulse(word Mode); // optional for test
389 void DrvSignals( void );
390 void RlsSignals( void );
391 void SetTargetVcc (word level);
392 word Get_target_Vcc( void);
393 word Get_Ext_Vcc( void );
394 void TDI_dir( word dir );
395 void TDOI_dir( word dir );
396 void TEST_dir( word dir );
397 void TMS_dir( word dir );
398 void RST_dir( word dir );
399 void TCK_dir( word dir );
400 void SetVpp( word source );
401 
402 void SetVCoreUp( word level);
403 word Get_Vx( word index );
404 void Enable_Vpp( void );
405 void Disable_Vpp( void );
406 void configure_IO_JTAG( void );
407 void configure_IO_BSL( void );
408 void IO_3state( void );
409 void configure_IO_SBW( void );
void Enable_Vpp(void)
Enable fuse blow voltage Vpp.
void TCK_dir(word dir)
Set the direction for the TCK pin.
void TMS_dir(word dir)
Set the direction for the TMS pin.
void TMSH_TDIH_TDOrd(void)
Combination of SBW macros: TMS high, TDI high, TDO read.
void RlsSignals(void)
Release I/O pins.
void IO_3state(void)
Set all JTAG pins to input direction - from target to REP430F.
byte TCLK_saved
Holds the last value of TCLK before entering a JTAG sequence.
void DrvSignals(void)
Set up I/O pins for JTAG communication.
void ShowStatus(word Status, word Index)
This function controls the status LEDs depending on the status argument. It stops program in error ca...
void TMSL_TDIL(void)
Combination of SBW macros: TMS low, TDI low, no TDO read.
void ClrTCLK_sbw(void)
Clear TCLK in Spy-Bi-Wire mode.
word Get_target_Vcc(void)
Determine target VCC.
void InitController(void)
Initialization of the Controller Board.
void configure_IO_JTAG(void)
Set JTAG pins to output direction - from REP430F to target.
void Disable_Vpp(void)
Disable fuse blow voltage Vpp.
void configure_IO_SBW(void)
Set SBW pins to output direction - from REP430F to target.
word Shift(word Format, word Data)
Shift a value into TDI (MSB first) and simultaneously shift out a value from TDO (MSB first)...
void usDelay(word microeconds)
Delay function (resolution is ~1 us)
void TDOI_dir(word dir)
Set the direction for the TDO pin.
void SetTCLK_sbw(void)
Set TCLK in Spy-Bi-Wire mode.
void SetVpp(word source)
function to set the fuse blow voltage Vpp
void TMSL_TDIH_TDOrd(void)
Combination of SBW macros: TMS low, TDI high, TDO read.
void IR_Ex_Blow_SBW_Shift(void)
Provide JTAG fuse blow instruction.
word Get_Vx(word index)
Measure different voltages via ADC12.
void SetVCoreUp(word level)
Function to set a specific voltage level via the PMM.
void TMSH_TDIH(void)
Combination of SBW macros: TMS high, TDI high, no TDO read.
void TDOisInput(void)
This function switches TDO to Input (used for fuse blowing)
void InitTarget(void)
Initialization of the Target Board (switch voltages on, preset JTAG pins)
void MsDelay(word milliseconds)
Delay function (resolution is 1 ms)
void TDI_dir(word dir)
Set the direction for the TDI pin.
void RST_dir(word dir)
Set the direction for the RST pin.
word Get_Ext_Vcc(void)
Determine external VCC.
void ReleaseTarget(void)
Release Target Board (switch voltages off, JTAG pins are HI-Z)
void TMSH_TDIL_TDOrd(void)
Combination of SBW macros: TMS high, TDI low, TDO read.
void SetTargetVcc(word level)
Set target Vcc (supplied from REP430F)
void TEST_dir(word dir)
Set the direction for the TEST pin.
void TMSL_TDIH(void)
Combination of SBW macros: TMS low, TDI high, no TDO read.
void TMSL_TDIL_TDOrd(void)
Combination of SBW macros: TMS low, TDI low, TDO read.
void TMSH_TDIL(void)
Combination of SBW macros: TMS high, TDI low, no TDO read.
Configurations for the MSP430 Replicator.

Copyright 2016, Texas Instruments Incorporated