
\ -----------------------------------------------------------------------------
\  Warteroutinen für 16 MHz
\ -----------------------------------------------------------------------------

: us ( u -- )    16 * delay-cycles ;
: ms ( u -- ) 16000 * delay-cycles ;

\ -----------------------------------------------------------------------------
\  Basisdefinitionen fürs echte Tiva Connected Launchpad
\ -----------------------------------------------------------------------------

$40060000 constant PORTJ_BASE

PORTJ_BASE $3FC + constant PORTJ_DATA ( IO Data Register, all bits selected )
PORTJ_BASE $400 + constant PORTJ_DIR  ( Pin Direction )
PORTJ_BASE $500 + constant PORTJ_DR2R ( 2 mA drive current )
PORTJ_BASE $504 + constant PORTJ_DR4R ( 4 mA )
PORTJ_BASE $508 + constant PORTJ_DR8R ( 8 mA )
PORTJ_BASE $53C + constant PORTJ_DR12R ( 12 mA )
PORTJ_BASE $50C + constant PORTJ_ODR  ( Open Drain )
PORTJ_BASE $510 + constant PORTJ_PUR  ( Pullup Resistor )
PORTJ_BASE $514 + constant PORTJ_PDR  ( Pulldown Resistor )
PORTJ_BASE $518 + constant PORTJ_SLR  ( Slew Rate )
PORTJ_BASE $51C + constant PORTJ_DEN  ( Digital Enable )


1 0 lshift  constant switch-1 \ On Port J Bit 0
1 1 lshift  constant switch-2 \ On Port J Bit 1

: switch1? ( -- ? ) switch-1 portj_data bit@ not ;
: switch2? ( -- ? ) switch-2 portj_data bit@ not ;

: hw-init ( -- )
  switch-1 switch-2 or portj_den ! \ Switch connections as digital lines, inputs
  switch-1 switch-2 or portj_pur ! \ Activate pullup resistors for switches
;

\ SBW-JTAG für einen MSP430F2012
\ Läuft auf einem TM4C1294 mit Mecrisp-Stellaris (klassisch, des Timings wegen ohne RA).

\ Verbinden mit vier Drähten:
\ 3.3V an Vcc
\ PA4 an /Reset
\ PA5 an Test
\ GND an GND

\ ------------------------------------------------------------------------------
\ Portadressen, die nur im TM4C1294 benötigt werden

$40058000 constant PORTA_BASE

PORTA_BASE $3FC + constant PORTA_DATA ( IO Data Register, all bits selected )
PORTA_BASE $400 + constant PORTA_DIR  ( Pin Direction )
PORTA_BASE $500 + constant PORTA_DR2R ( 2 mA drive current )
PORTA_BASE $504 + constant PORTA_DR4R ( 4 mA )
PORTA_BASE $508 + constant PORTA_DR8R ( 8 mA )
PORTA_BASE $53C + constant PORTA_DR12R ( 12 mA )
PORTA_BASE $50C + constant PORTA_ODR  ( Open Drain )
PORTA_BASE $510 + constant PORTA_PUR  ( Pullup Resistor )
PORTA_BASE $514 + constant PORTA_PDR  ( Pulldown Resistor )
PORTA_BASE $518 + constant PORTA_SLR  ( Slew Rate )
PORTA_BASE $51C + constant PORTA_DEN  ( Digital Enable )

PORTA_DATA constant JTAGIN
PORTA_DATA constant JTAGOUT
PORTA_DIR  constant JTAGDIR

\ Pin-Bitmuster

\ Firmware benutzt 2 und 8. Leitungen noch einmal gründlich prüfen.
\ Leitung 2 wird an P5DIR geschaltet. Die Leitung 8 nicht.
\ Es gibt genau eine Stelle, wo die Leitung 2 in P5IN abgefragt wird.

1 4 lshift constant SBWDATO \ PA4 JTAG data_out pin in SBW mode
1 4 lshift constant SBWDATI \ PA4 JTAG data in pin in SBW mode
1 5 lshift constant SBWCLK  \ PA5 JTAG clock pin in SBW mode

\ -----------------------------------------------------------------------------
: InitTarget ( -- )

  SBWDATO SBWCLK or PORTA_DEN  bis! \ Digitale Leitungen...
  SBWDATO SBWCLK or PORTA_DATA bis!  \ Und beide High.
  SBWDATO SBWCLK or PORTA_DIR  bis!   \ Die beiden sbw-Pins seien Ausgänge
;

\ -----------------------------------------------------------------------------
: ReleaseTarget ( -- )
  SBWDATO SBWCLK or JTAGDIR cbic!  \ Einfach nur die beiden Leitungen in Hi-Z-Modus schalten.
;

