/* $Id: hw_nexys2.c 447 2011-12-31 19:41:32Z mueller $ */
|
/* $Id: hw_nexys2.c 447 2011-12-31 19:41:32Z mueller $ */
|
/*
|
/*
|
* Copyright 2011- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
* Copyright 2011- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
* Code was forked from ixo-jtag.svn.sourceforge.net on 2011-07-17
|
* Code was forked from ixo-jtag.svn.sourceforge.net on 2011-07-17
|
*
|
*
|
* - original copyright and licence disclaimer --------------------------------
|
* - original copyright and licence disclaimer --------------------------------
|
* - Copyright (C) 2007 Kolja Waschk, ixo.de
|
* - Copyright (C) 2007 Kolja Waschk, ixo.de
|
* - This code is part of usbjtag. usbjtag is free software;
|
* - This code is part of usbjtag. usbjtag is free software;
|
* - This code was copied from hw_basic.c and adapted for the Digilent Nexys(2)
|
* - This code was copied from hw_basic.c and adapted for the Digilent Nexys(2)
|
* - boards by Sune Mai (Oct 2008) with minor cleanups by Hauke Daempfling
|
* - boards by Sune Mai (Oct 2008) with minor cleanups by Hauke Daempfling
|
* - (May 2010). See http://www.fpga4fun.com/forum/viewtopic.php?t=483&start=50
|
* - (May 2010). See http://www.fpga4fun.com/forum/viewtopic.php?t=483&start=50
|
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
*
|
*
|
* This program is free software; you may redistribute and/or modify it under
|
* This program is free software; you may redistribute and/or modify it under
|
* the terms of the GNU General Public License as published by the Free
|
* the terms of the GNU General Public License as published by the Free
|
* Software Foundation, either version 2, or at your option any later version.
|
* Software Foundation, either version 2, or at your option any later version.
|
*
|
*
|
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
* WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
* WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
* for complete details.
|
* for complete details.
|
*
|
*
|
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
* Hardware-dependent code for usb_jtag
|
* Hardware-dependent code for usb_jtag
|
*
|
*
|
* Revision History:
|
* Revision History:
|
*
|
*
|
* Date Rev Version Comment
|
* Date Rev Version Comment
|
* 2011-12-30 447 1.2.1 move JTAG pin OE intoProgIO_Set_State()
|
* 2011-12-30 447 1.2.1 move JTAG pin OE intoProgIO_Set_State()
|
* 2011-12-29 446 1.2 clean-out all code not relevant for nexys2
|
* 2011-12-29 446 1.2 clean-out all code not relevant for nexys2
|
* 2011-07-23 397 1.1 move IFCONFIG and CPUCS init to usb_fifo_init
|
* 2011-07-23 397 1.1 move IFCONFIG and CPUCS init to usb_fifo_init
|
* 2011-07-17 394 1.0 Initial version (from ixo-jtag/usb_jtag Rev 204)
|
* 2011-07-17 394 1.0 Initial version (from ixo-jtag/usb_jtag Rev 204)
|
*
|
*
|
*-----------------------------------------------------------------------------
|
*-----------------------------------------------------------------------------
|
*/
|
*/
|
|
|
#include <fx2regs.h>
|
#include <fx2regs.h>
|
#include "hardware.h"
|
#include "hardware.h"
|
#include "delay.h"
|
#include "delay.h"
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
|
|
/* JTAG TCK, AS/PS DCLK */
|
/* JTAG TCK, AS/PS DCLK */
|
|
|
sbit at 0xB4 TCK; /* Port D.4 */
|
sbit at 0xB4 TCK; /* Port D.4 */
|
#define bmTCKOE bmBIT4
|
#define bmTCKOE bmBIT4
|
#define SetTCK(x) do{TCK=(x);}while(0)
|
#define SetTCK(x) do{TCK=(x);}while(0)
|
|
|
/* JTAG TDI, AS ASDI, PS DATA0 */
|
/* JTAG TDI, AS ASDI, PS DATA0 */
|
|
|
sbit at 0xB2 TDI; /* Port D.2 */
|
sbit at 0xB2 TDI; /* Port D.2 */
|
#define bmTDIOE bmBIT2
|
#define bmTDIOE bmBIT2
|
#define SetTDI(x) do{TDI=(x);}while(0)
|
#define SetTDI(x) do{TDI=(x);}while(0)
|
|
|
/* JTAG TMS, AS/PS nCONFIG */
|
/* JTAG TMS, AS/PS nCONFIG */
|
|
|
sbit at 0xB3 TMS; /* Port D.3 */
|
sbit at 0xB3 TMS; /* Port D.3 */
|
#define bmTMSOE bmBIT3
|
#define bmTMSOE bmBIT3
|
#define SetTMS(x) do{TMS=(x);}while(0)
|
#define SetTMS(x) do{TMS=(x);}while(0)
|
|
|
/* JTAG TDO, AS/PS CONF_DONE */
|
/* JTAG TDO, AS/PS CONF_DONE */
|
|
|
sbit at 0xB0 TDO; /* Port D.0 */
|
sbit at 0xB0 TDO; /* Port D.0 */
|
#define bmTDOOE bmBIT0
|
#define bmTDOOE bmBIT0
|
#define GetTDO(x) TDO
|
#define GetTDO(x) TDO
|
|
|
/* USB Power-On (Nexys2 specific !!) */
|
/* USB Power-On (Nexys2 specific !!) */
|
|
|
sbit at 0xB7 USBPOW; /* Port D.7 */
|
sbit at 0xB7 USBPOW; /* Port D.7 */
|
#define bmUSBPOWOE bmBIT7
|
#define bmUSBPOWOE bmBIT7
|
#define SetUSBPOW(x) do{USBPOW=(x);}while(0)
|
#define SetUSBPOW(x) do{USBPOW=(x);}while(0)
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
|
|
#define bmPROGOUTOE (bmTCKOE|bmTDIOE|bmTMSOE)
|
#define bmPROGOUTOE (bmTCKOE|bmTDIOE|bmTMSOE)
|
#define bmPROGINOE (bmTDOOE)
|
#define bmPROGINOE (bmTDOOE)
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
|
|
void ProgIO_Poll(void) {}
|
void ProgIO_Poll(void) {}
|
void ProgIO_Enable(void) {}
|
void ProgIO_Enable(void) {}
|
// These aren't called anywhere in usbjtag.c so far, might come...
|
// These aren't called anywhere in usbjtag.c so far, might come...
|
void ProgIO_Disable(void) {}
|
void ProgIO_Disable(void) {}
|
void ProgIO_Deinit(void) {}
|
void ProgIO_Deinit(void) {}
|
|
|
|
|
void ProgIO_Init(void)
|
void ProgIO_Init(void)
|
{
|
{
|
/* The following code depends on your actual circuit design.
|
/* The following code depends on your actual circuit design.
|
Make required changes _before_ you try the code! */
|
Make required changes _before_ you try the code! */
|
|
|
// power on the onboard FPGA:
|
// power on the onboard FPGA:
|
// output enable and set to 1 the Nexys2 USB-Power-enable signal
|
// output enable and set to 1 the Nexys2 USB-Power-enable signal
|
SetUSBPOW(1);
|
SetUSBPOW(1);
|
OED=bmUSBPOWOE;
|
OED=bmUSBPOWOE;
|
// Note: JTAG signal output enables are in ProgIO_Set_State() below.
|
// Note: JTAG signal output enables are in ProgIO_Set_State() below.
|
|
|
mdelay(500); // wait for supply to come up
|
mdelay(500); // wait for supply to come up
|
}
|
}
|
|
|
void ProgIO_Set_State(unsigned char d)
|
void ProgIO_Set_State(unsigned char d)
|
{
|
{
|
/* Set state of output pins:
|
/* Set state of output pins:
|
*
|
*
|
* d.0 => TCK
|
* d.0 => TCK
|
* d.1 => TMS
|
* d.1 => TMS
|
* d.4 => TDI
|
* d.4 => TDI
|
*/
|
*/
|
|
|
// JTAG signal output enables done at first request:
|
// JTAG signal output enables done at first request:
|
// this allows to use the JTAG connector with another JTAG cable
|
// this allows to use the JTAG connector with another JTAG cable
|
// alternatively.
|
// alternatively.
|
OED=(OED&~bmPROGINOE) | bmPROGOUTOE; // Output enable
|
OED=(OED&~bmPROGINOE) | bmPROGOUTOE; // Output enable
|
|
|
SetTCK((d & bmBIT0) ? 1 : 0);
|
SetTCK((d & bmBIT0) ? 1 : 0);
|
SetTMS((d & bmBIT1) ? 1 : 0);
|
SetTMS((d & bmBIT1) ? 1 : 0);
|
SetTDI((d & bmBIT4) ? 1 : 0);
|
SetTDI((d & bmBIT4) ? 1 : 0);
|
}
|
}
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
// dummied AS/PS code
|
// dummied AS/PS code
|
#define GetASDO(x) 1
|
#define GetASDO(x) 1
|
|
|
unsigned char ProgIO_Set_Get_State(unsigned char d)
|
unsigned char ProgIO_Set_Get_State(unsigned char d)
|
{
|
{
|
/* Set state of output pins (s.a.)
|
/* Set state of output pins (s.a.)
|
* then read state of input pins:
|
* then read state of input pins:
|
*
|
*
|
* TDO => d.0
|
* TDO => d.0
|
* DATAOUT => d.1 (only #ifdef HAVE_AS_MODE)
|
* DATAOUT => d.1 (only #ifdef HAVE_AS_MODE)
|
*/
|
*/
|
|
|
ProgIO_Set_State(d);
|
ProgIO_Set_State(d);
|
return (GetASDO()<<1)|GetTDO();
|
return (GetASDO()<<1)|GetTDO();
|
}
|
}
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
|
|
void ProgIO_ShiftOut(unsigned char c)
|
void ProgIO_ShiftOut(unsigned char c)
|
{
|
{
|
/* Shift out byte C:
|
/* Shift out byte C:
|
*
|
*
|
* 8x {
|
* 8x {
|
* Output least significant bit on TDI
|
* Output least significant bit on TDI
|
* Raise TCK
|
* Raise TCK
|
* Shift c right
|
* Shift c right
|
* Lower TCK
|
* Lower TCK
|
* }
|
* }
|
*/
|
*/
|
|
|
(void)c; /* argument passed in DPL */
|
(void)c; /* argument passed in DPL */
|
|
|
_asm
|
_asm
|
MOV A,DPL
|
MOV A,DPL
|
;; Bit0
|
;; Bit0
|
RRC A
|
RRC A
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
;; Bit1
|
;; Bit1
|
RRC A
|
RRC A
|
CLR _TCK
|
CLR _TCK
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
;; Bit2
|
;; Bit2
|
RRC A
|
RRC A
|
CLR _TCK
|
CLR _TCK
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
;; Bit3
|
;; Bit3
|
RRC A
|
RRC A
|
CLR _TCK
|
CLR _TCK
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
;; Bit4
|
;; Bit4
|
RRC A
|
RRC A
|
CLR _TCK
|
CLR _TCK
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
;; Bit5
|
;; Bit5
|
RRC A
|
RRC A
|
CLR _TCK
|
CLR _TCK
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
;; Bit6
|
;; Bit6
|
RRC A
|
RRC A
|
CLR _TCK
|
CLR _TCK
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
;; Bit7
|
;; Bit7
|
RRC A
|
RRC A
|
CLR _TCK
|
CLR _TCK
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
NOP
|
NOP
|
CLR _TCK
|
CLR _TCK
|
ret
|
ret
|
_endasm;
|
_endasm;
|
}
|
}
|
|
|
/*
|
/*
|
;; For ShiftInOut, the timing is a little more
|
;; For ShiftInOut, the timing is a little more
|
;; critical because we have to read _TDO/shift/set _TDI
|
;; critical because we have to read _TDO/shift/set _TDI
|
;; when _TCK is low. But 20% duty cycle at 48/4/5 MHz
|
;; when _TCK is low. But 20% duty cycle at 48/4/5 MHz
|
;; is just like 50% at 6 Mhz, and that's still acceptable
|
;; is just like 50% at 6 Mhz, and that's still acceptable
|
*/
|
*/
|
|
|
unsigned char ProgIO_ShiftInOut(unsigned char c)
|
unsigned char ProgIO_ShiftInOut(unsigned char c)
|
{
|
{
|
/* Shift out byte C, shift in from TDO:
|
/* Shift out byte C, shift in from TDO:
|
*
|
*
|
* 8x {
|
* 8x {
|
* Read carry from TDO
|
* Read carry from TDO
|
* Output least significant bit on TDI
|
* Output least significant bit on TDI
|
* Raise TCK
|
* Raise TCK
|
* Shift c right, append carry (TDO) at left
|
* Shift c right, append carry (TDO) at left
|
* Lower TCK
|
* Lower TCK
|
* }
|
* }
|
* Return c.
|
* Return c.
|
*/
|
*/
|
|
|
(void)c; /* argument passed in DPL */
|
(void)c; /* argument passed in DPL */
|
|
|
_asm
|
_asm
|
MOV A,DPL
|
MOV A,DPL
|
|
|
;; Bit0
|
;; Bit0
|
MOV C,_TDO
|
MOV C,_TDO
|
RRC A
|
RRC A
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
CLR _TCK
|
CLR _TCK
|
;; Bit1
|
;; Bit1
|
MOV C,_TDO
|
MOV C,_TDO
|
RRC A
|
RRC A
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
CLR _TCK
|
CLR _TCK
|
;; Bit2
|
;; Bit2
|
MOV C,_TDO
|
MOV C,_TDO
|
RRC A
|
RRC A
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
CLR _TCK
|
CLR _TCK
|
;; Bit3
|
;; Bit3
|
MOV C,_TDO
|
MOV C,_TDO
|
RRC A
|
RRC A
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
CLR _TCK
|
CLR _TCK
|
;; Bit4
|
;; Bit4
|
MOV C,_TDO
|
MOV C,_TDO
|
RRC A
|
RRC A
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
CLR _TCK
|
CLR _TCK
|
;; Bit5
|
;; Bit5
|
MOV C,_TDO
|
MOV C,_TDO
|
RRC A
|
RRC A
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
CLR _TCK
|
CLR _TCK
|
;; Bit6
|
;; Bit6
|
MOV C,_TDO
|
MOV C,_TDO
|
RRC A
|
RRC A
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
CLR _TCK
|
CLR _TCK
|
;; Bit7
|
;; Bit7
|
MOV C,_TDO
|
MOV C,_TDO
|
RRC A
|
RRC A
|
MOV _TDI,C
|
MOV _TDI,C
|
SETB _TCK
|
SETB _TCK
|
NOP
|
NOP
|
CLR _TCK
|
CLR _TCK
|
|
|
MOV DPL,A
|
MOV DPL,A
|
ret
|
ret
|
_endasm;
|
_endasm;
|
|
|
/* return value in DPL */
|
/* return value in DPL */
|
|
|
return c;
|
return c;
|
}
|
}
|
|
|
|
|