LowLevelFunc430X.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 | LowLevelFunc430X.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 05/12 RL Updated commentaries |
62 |----------------------------------------------------------------------------|
63 | Designed 2002 by Texas Instruments Germany |
64 \*==========================================================================*/
67 /****************************************************************************/
68 /* INCLUDES */
69 /****************************************************************************/
70 
71 #include <msp430x54x.h>
72 #include "Config430X.h" // High-level user input
73 
74 /****************************************************************************/
75 /* DEFINES & CONSTANTS */
76 /****************************************************************************/
77 
79 #define JTAG_IF 1
80 #define SPYBIWIREJTAG_IF 2
82 #define SPYBIWIRE_IF 3
84 
85 #if( INTERFACE == SPYBIWIRE_IF )
86 #define SPYBIWIRE_MODE
87 #endif
88 
89 #ifndef __DATAFORMATS__
90 #define __DATAFORMATS__
91 #define F_BYTE 8
92 #define F_WORD 16
93 #define F_ADDR 20
94 #define F_LONG 32
95 #endif
96 
97 // Constants for runoff status
99 #define STATUS_ERROR 0 // false
100 #define STATUS_OK 1 // true
102 #define STATUS_FUSEBLOWN 2
104 
106 #define STATUS_ACTIVE 2
107 #define STATUS_IDLE 3
109 
110 /****************************************************************************/
111 /* Macros and Pin-to-Signal assignments which have to be programmed */
112 /* by the user. This implementation assumes use of an MSP430F5437 as the */
113 /* host controller and the corresponding hardware given in the MSP430 */
114 /* Programming Via the JTAG Interface User's Guide (SLAU320). */
115 /* */
116 /* The following MSP430 example acts as a hint of how to generally */
117 /* implement a micro-controller programmer solution for the MSP430 flash- */
118 /* based devices. */
119 /****************************************************************************/
120 
121 // I/O Level translators (SN74LVC1T45) direction setup
122 
123 #define TRSLDIR P2OUT
124 
125 #define TRSL_CDIR P2DIR
126 
129 #define BRX_DIR 0x01
130 #define BTX_DIR 0x02
133 #define TEST_DIR 0x04
135 #define RST_DIR 0x08
137 #define TCK_DIR 0x10
139 #define TMS_DIR 0x20
141 #define TDOI_DIR 0x40
143 #define TDI_DIR 0x80
145 
146 #define SW_OUT P1OUT
147 #define SW_IN P1IN
148 #define SW_DIR P1DIR
149 #define SW_PULLUP P1REN
150 #define LED_OUT P1OUT
152 #define LED_DIR P1DIR
154 
156 #define SW_MODE0 0x01
157 #define SW_MODE1 0x02
159 #define SW_VPPEN 0x04
161 #define LED_YELLOW 0x08
163 #define LED_GREEN 0x10
165 #define LED_RED 0x20
167 #define SW_1 0x40
169 
170 //#define spareP17 0x80
171 
173 #define TVCC_OUT P6OUT
174 #define TVCC_DIR P6DIR
176 #define TVCC_MASK 0xF0
178 #define TVCC_SHIFT 4
180 
181 #define TVCC_EN_DIR P5DIR
182 #define TVCC_EN_OUT P5OUT
183 #define TVCC_DIS_BIT 1
184 
186 #define LED_yellow_on() ( LED_OUT |= LED_YELLOW )
187 #define LED_yellow_off() ( LED_OUT &= ~LED_YELLOW )
189 #define LED_red_on() ( LED_OUT |= LED_RED )
191 #define LED_red_off() ( LED_OUT &= ~LED_RED )
193 #define LED_green_on() ( LED_OUT |= LED_GREEN )
195 #define LED_green_off() ( LED_OUT &= ~LED_GREEN )
197 #define All_LEDs_off() ( LED_OUT &= ~(LED_GREEN | LED_RED | LED_YELLOW ))
199 
200 // JTAG ports are P5.x
202 #define JTAGOUT P5OUT
203 #define JTAGIN P5IN
205 #define JTAGDIR P5DIR
207 #define JTAGSEL P5SEL
209 #define TMS 0x20
211 #define TDI 0x80
213 #define TDO 0x40
215 #define TCK 0x10
217 #define TEST 0x04
219 #define RST 0x08
221 #define TCLK TDI
223 
226 #define BSLOUT P3OUT
227 #define BSLIN P3IN
230 #define BSLDIR P3DIR
233 #define BSLSEL P3SEL
236 #define BSLTX 0x20
239 #define BSLRX 0x10
242 
243 // VPP ports are P8.x
245 #define VPPOUT P8OUT
246 #define VPPDIR P8DIR
248 #define VPPSEL P8SEL
250 
252 #define VPPONTEST 0x04
253 #define VPPONTDI 0x02
255 
258 #define ONEMS 0x05DC
259 
260 /****************************************************************************/
261 /* Macros for processing the JTAG port */
262 /****************************************************************************/
263 
265 #define ClrTMS() ((JTAGOUT) &= (~TMS))
266 #define SetTMS() ((JTAGOUT) |= (TMS))
268 #define ClrTDI() ((JTAGOUT) &= (~TDI))
270 #define SetTDI() ((JTAGOUT) |= (TDI))
272 #define ClrTCK() ((JTAGOUT) &= (~TCK))
274 #define SetTCK() ((JTAGOUT) |= (TCK))
276 #define StoreTCLK() ((JTAGOUT & TCLK))
278 #define RestoreTCLK(x) (x == 0 ? (JTAGOUT &= ~TCLK) : (JTAGOUT |= TCLK))
280 #define ScanTDO() ((JTAGIN & TDO))
282 #define VPPon(x) (x == VPP_ON_TEST ? (SetVpp(VPPONTEST)) : (SetVpp(VPPONTDI)))
284 #define VPPoff() (SetVpp(0))
286 #define SetRST() ((JTAGOUT) |= (RST))
288 #define ClrRST() ((JTAGOUT) &= (~RST))
290 #define ReleaseRST() ( RST_dir( 0 ))
292 #define SetTST() ((JTAGOUT) |= (TEST))
294 #define ClrTST() ((JTAGOUT) &= (~TEST))
296 
297 /****************************************************************************/
298 /* Macros to control spy-by-wire-IF */
299 /****************************************************************************/
300 
302 #define SBWDATO TDI
303 #define SBWDATI TDO
305 #define SBWCLK TCK
307 
309 #define TMSH JTAGOUT |= SBWDATO; JTAGOUT &= ~SBWCLK; JTAGOUT |= SBWCLK;
310 #define TMSL JTAGOUT &= ~SBWDATO; JTAGOUT &= ~SBWCLK; JTAGOUT |= SBWCLK;
312 #define TMSLDH JTAGOUT &= ~SBWDATO; JTAGOUT &= ~SBWCLK; JTAGOUT |= SBWDATO; JTAGOUT |= SBWCLK;
317 #define TDIH JTAGOUT |= SBWDATO; JTAGOUT &= ~SBWCLK; JTAGOUT |= SBWCLK;
319 #define TDIL JTAGOUT &= ~SBWDATO; JTAGOUT &= ~SBWCLK; JTAGOUT |= SBWCLK;
321 #define TDOsbw TRSLDIR |= TDOI_DIR; JTAGOUT &= ~SBWCLK; JTAGOUT |= SBWCLK; TRSLDIR &= ~TDOI_DIR;
323 #define TDO_RD TRSLDIR |= TDOI_DIR; JTAGOUT &= ~SBWCLK; _NOP(); tdo_bit = JTAGIN; JTAGOUT |= SBWCLK; TRSLDIR &= ~TDOI_DIR;
325 
327 #define SetSBWTCK() (JTAGOUT |= SBWCLK)
328 #define ClrSBWTCK() (JTAGOUT &= ~SBWCLK)
330 #define SetSBWTDIO() (JTAGOUT |= SBWDATO)
332 #define ClrSBWTDIO() (JTAGOUT &= ~SBWDATO)
334 
335 #if ( INTERFACE == SPYBIWIRE_IF )
336 
337 void ClrTCLK_sbw(void);
338 void SetTCLK_sbw(void);
340 #define ClrTCLK() ClrTCLK_sbw()
341 #define SetTCLK() SetTCLK_sbw()
343 
344 #else
345 
347 #define ClrTCLK() ((JTAGOUT) &= ~(TCLK))
348 #define SetTCLK() ((JTAGOUT) |= (TCLK))
350 
351 #endif
352 
353 /*----------------------------------------------------------------------------
354  Definition of global variables
355 */
356 extern byte TCLK_saved; // holds the last value of TCLK before entering a JTAG sequence
357 
358 /****************************************************************************/
359 /* TYPEDEFS */
360 /****************************************************************************/
361 
362 #ifndef __BYTEWORD__
363 #define __BYTEWORD__
364 typedef unsigned short word;
365 typedef unsigned char byte;
366 #endif
367 
368 /****************************************************************************/
369 /* FUNCTION PROTOTYPES */
370 /****************************************************************************/
371 
372 void TMSL_TDIL(void);
373 void TMSH_TDIL(void);
374 void TMSL_TDIH(void);
375 void TMSH_TDIH(void);
376 void TMSL_TDIH_TDOrd(void);
377 void TMSL_TDIL_TDOrd(void);
378 void TMSH_TDIH_TDOrd(void);
379 void TMSH_TDIL_TDOrd(void);
380 void MsDelay(word milliseconds); // millisecond delay loop, uses Timer_A
381 void usDelay(word microeconds); // microsecond delay loop, uses nops
382 void InitController(void);
383 void InitTarget(void);
384 void ReleaseTarget(void);
385 unsigned long AllShifts(word Format, unsigned long Data);
386 void TDOisInput(void);
387 void TCLKstrobes(word Amount);
388 void ShowStatus(word Status, word Index);
389 void TriggerPulse(word Mode); // optional for test
390 void DrvSignals( void );
391 void RlsSignals( void );
392 void SetTargetVcc (word level);
393 word Get_target_Vcc( void);
394 word Get_Ext_Vcc( void );
395 void SetVpp( word source );
396 void RST_dir( word dir );
397 void SetVCoreUp( word level);
398 word Get_Vx( word index );
399 void Enable_Vpp( void );
400 void Disable_Vpp( void );
401 void TDI_dir( word dir );
402 void TDOI_dir( word dir );
403 void TEST_dir( word dir );
404 void TMS_dir( word dir );
405 void TCK_dir( word dir );
406 void configure_IO_JTAG( void );
407 void configure_IO_SBW( void );
408 void configure_IO_BSL( void );
409 void IO_3state( void );
void SetVCoreUp(word level)
Function to set a specific voltage level via the PMM.
void SetVpp(word source)
function to set the fuse blow voltage Vpp
void TMS_dir(word dir)
Set the direction for the TMS pin.
void Disable_Vpp(void)
Disable fuse blow voltage Vpp.
void ShowStatus(word Status, word Index)
This function controls the status LEDs depending on the status argument. It stops program in error ca...
void configure_IO_JTAG(void)
Set JTAG pins to output direction - from REP430F to target.
void ReleaseTarget(void)
Release Target Board (switch voltages off, JTAG pins are HI-Z)
void IO_3state(void)
Set all JTAG pins to input direction - from target to REP430F.
void TDOisInput(void)
This function switches TDO to Input (used for fuse blowing)
void MsDelay(word milliseconds)
Delay function (resolution is 1 ms)
void SetTargetVcc(word level)
Set target Vcc (supplied from REP430F)
void Enable_Vpp(void)
Enable fuse blow voltage Vpp.
word Get_Ext_Vcc(void)
Determine external VCC.
void InitTarget(void)
Initialization of the Target Board (switch voltages on, preset JTAG pins)
void RlsSignals(void)
Release I/O pins.
void DrvSignals(void)
Set up I/O pins for JTAG communication.
void TEST_dir(word dir)
Set the direction for the TEST pin.
void TDI_dir(word dir)
Set the direction for the TDI pin.
byte TCLK_saved
Holds the last value of TCLK before entering a JTAG sequence.
word Get_target_Vcc(void)
Determine target VCC.
void usDelay(word microeconds)
Delay function (resolution is ~1 us)
void TDOI_dir(word dir)
Set the direction for the TDO pin.
word Get_Vx(word index)
Measure different voltages via ADC12.
void TCLKstrobes(word Amount)
This function generates Amount strobes with the Flash Timing Generator.
void TCK_dir(word dir)
Set the direction for the TCK pin.
Configurations for the MSP430 Replicator X.
void configure_IO_SBW(void)
Set SBW pins to output direction - from REP430F to target.
void RST_dir(word dir)
Set the direction for the RST pin.
void InitController(void)
Initialization of the Controller Board.
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)...

Copyright 2016, Texas Instruments Incorporated