test program to program CPLD from microcontroller
This commit is contained in:
@ -129,6 +129,8 @@ clean:
|
|||||||
$(Q)rm -f ../common/*.o
|
$(Q)rm -f ../common/*.o
|
||||||
$(Q)rm -f ../common/*.d
|
$(Q)rm -f ../common/*.d
|
||||||
$(Q)rm -f ../common/*.lst
|
$(Q)rm -f ../common/*.lst
|
||||||
|
$(Q)rm -f ../common/xapp058/*.o
|
||||||
|
$(Q)rm -f ../common/xapp058/*.d
|
||||||
|
|
||||||
.PHONY: images clean
|
.PHONY: images clean
|
||||||
|
|
||||||
|
78
firmware/common/cpld_jtag.c
Normal file
78
firmware/common/cpld_jtag.c
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 Michael Ossmann <mike@ossmann.com>
|
||||||
|
*
|
||||||
|
* This file is part of HackRF.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "cpld_jtag.h"
|
||||||
|
#include "hackrf_core.h"
|
||||||
|
#include "xapp058/micro.h"
|
||||||
|
#include <libopencm3/lpc43xx/gpio.h>
|
||||||
|
#include <libopencm3/lpc43xx/scu.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
uint32_t xsvf_len;
|
||||||
|
unsigned char* xsvf_data;
|
||||||
|
|
||||||
|
void cpld_jtag_setup(void) {
|
||||||
|
scu_pinmux(SCU_PINMUX_CPLD_TDO, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION4);
|
||||||
|
scu_pinmux(SCU_PINMUX_CPLD_TCK, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
|
||||||
|
scu_pinmux(SCU_PINMUX_CPLD_TMS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
|
||||||
|
scu_pinmux(SCU_PINMUX_CPLD_TDI, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
|
||||||
|
|
||||||
|
/* TDO is an input */
|
||||||
|
GPIO_DIR(PORT_CPLD_TDO) &= ~PIN_CPLD_TDO;
|
||||||
|
|
||||||
|
/* the rest are outputs */
|
||||||
|
GPIO_DIR(PORT_CPLD_TCK) |= PIN_CPLD_TCK;
|
||||||
|
GPIO_DIR(PORT_CPLD_TMS) |= PIN_CPLD_TMS;
|
||||||
|
GPIO_DIR(PORT_CPLD_TDI) |= PIN_CPLD_TDI;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set pins as inputs so we don't interfere with an external JTAG device */
|
||||||
|
void cpld_jtag_release(void) {
|
||||||
|
scu_pinmux(SCU_PINMUX_CPLD_TDO, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION4);
|
||||||
|
scu_pinmux(SCU_PINMUX_CPLD_TCK, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
|
||||||
|
scu_pinmux(SCU_PINMUX_CPLD_TMS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
|
||||||
|
scu_pinmux(SCU_PINMUX_CPLD_TDI, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
|
||||||
|
|
||||||
|
GPIO_DIR(PORT_CPLD_TDO) &= ~PIN_CPLD_TDO;
|
||||||
|
GPIO_DIR(PORT_CPLD_TCK) &= ~PIN_CPLD_TCK;
|
||||||
|
GPIO_DIR(PORT_CPLD_TMS) &= ~PIN_CPLD_TMS;
|
||||||
|
GPIO_DIR(PORT_CPLD_TDI) &= ~PIN_CPLD_TDI;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cpld_jtag_program(const uint32_t len, unsigned char* const data) {
|
||||||
|
cpld_jtag_setup();
|
||||||
|
xsvf_data = data;
|
||||||
|
xsvf_len = len;
|
||||||
|
xsvfExecute();
|
||||||
|
cpld_jtag_release();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* this gets called by the XAPP058 code */
|
||||||
|
unsigned char cpld_jtag_get_next_byte(void) {
|
||||||
|
unsigned char byte = *xsvf_data;
|
||||||
|
|
||||||
|
if (xsvf_len > 1) {
|
||||||
|
xsvf_data++;
|
||||||
|
xsvf_len--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return byte;
|
||||||
|
}
|
31
firmware/common/cpld_jtag.h
Normal file
31
firmware/common/cpld_jtag.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 Michael Ossmann <mike@ossmann.com>
|
||||||
|
*
|
||||||
|
* This file is part of HackRF.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CPLD_JTAG_H__
|
||||||
|
#define __CPLD_JTAG_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void cpld_jtag_release(void);
|
||||||
|
void cpld_jtag_program(const uint32_t len, unsigned char* const data);
|
||||||
|
unsigned char cpld_jtag_get_next_byte(void);
|
||||||
|
|
||||||
|
#endif//__CPLD_JTAG_H__
|
@ -1554,6 +1554,7 @@ int xsvfDoXCOMMENT( SXsvfInfo* pXsvfInfo )
|
|||||||
/* Otherwise, read through the comment to the end '\0' and ignore */
|
/* Otherwise, read through the comment to the end '\0' and ignore */
|
||||||
unsigned char ucText;
|
unsigned char ucText;
|
||||||
|
|
||||||
|
#ifdef DEBUG_MODE
|
||||||
if ( xsvf_iDebugLevel > 0 )
|
if ( xsvf_iDebugLevel > 0 )
|
||||||
{
|
{
|
||||||
putchar( ' ' );
|
putchar( ' ' );
|
||||||
@ -1567,6 +1568,7 @@ int xsvfDoXCOMMENT( SXsvfInfo* pXsvfInfo )
|
|||||||
putchar( ucText ? ucText : '\n' );
|
putchar( ucText ? ucText : '\n' );
|
||||||
}
|
}
|
||||||
} while ( ucText );
|
} while ( ucText );
|
||||||
|
#endif
|
||||||
|
|
||||||
pXsvfInfo->iErrorCode = XSVF_ERROR_NONE;
|
pXsvfInfo->iErrorCode = XSVF_ERROR_NONE;
|
||||||
|
|
||||||
|
@ -14,8 +14,10 @@
|
|||||||
|
|
||||||
//#include "stdio.h"
|
//#include "stdio.h"
|
||||||
#include "hackrf_core.h"
|
#include "hackrf_core.h"
|
||||||
|
#include "cpld_jtag.h"
|
||||||
|
#include <libopencm3/lpc43xx/gpio.h>
|
||||||
|
|
||||||
extern FILE *in;
|
//extern FILE *in;
|
||||||
//static int g_iTCK = 0; /* For xapp058_example .exe */
|
//static int g_iTCK = 0; /* For xapp058_example .exe */
|
||||||
//static int g_iTMS = 0; /* For xapp058_example .exe */
|
//static int g_iTMS = 0; /* For xapp058_example .exe */
|
||||||
//static int g_iTDI = 0; /* For xapp058_example .exe */
|
//static int g_iTDI = 0; /* For xapp058_example .exe */
|
||||||
@ -107,21 +109,22 @@ void setPort(short p,short val)
|
|||||||
printf( "TCK = %d; TMS = %d; TDI = %d\n", g_iTCK, g_iTMS, g_iTDI );
|
printf( "TCK = %d; TMS = %d; TDI = %d\n", g_iTCK, g_iTMS, g_iTDI );
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (p==TMS)
|
if (p==TMS) {
|
||||||
if (val)
|
if (val)
|
||||||
gpio_set(PORT_CPLD_TMS, PIN_CPLD_TMS);
|
gpio_set(PORT_CPLD_TMS, PIN_CPLD_TMS);
|
||||||
else
|
else
|
||||||
gpio_clear(PORT_CPLD_TMS, PIN_CPLD_TMS);
|
gpio_clear(PORT_CPLD_TMS, PIN_CPLD_TMS);
|
||||||
if (p==TDI)
|
} if (p==TDI) {
|
||||||
if (val)
|
if (val)
|
||||||
gpio_set(PORT_CPLD_TDI, PIN_CPLD_TDI);
|
gpio_set(PORT_CPLD_TDI, PIN_CPLD_TDI);
|
||||||
else
|
else
|
||||||
gpio_clear(PORT_CPLD_TDI, PIN_CPLD_TDI);
|
gpio_clear(PORT_CPLD_TDI, PIN_CPLD_TDI);
|
||||||
if (p==TCK)
|
} if (p==TCK) {
|
||||||
if (val)
|
if (val)
|
||||||
gpio_set(PORT_CPLD_TCK, PIN_CPLD_TCK);
|
gpio_set(PORT_CPLD_TCK, PIN_CPLD_TCK);
|
||||||
else
|
else
|
||||||
gpio_clear(PORT_CPLD_TCK, PIN_CPLD_TCK);
|
gpio_clear(PORT_CPLD_TCK, PIN_CPLD_TCK);
|
||||||
|
}
|
||||||
|
|
||||||
/* conservative delay */
|
/* conservative delay */
|
||||||
delay(20000);
|
delay(20000);
|
||||||
@ -143,8 +146,9 @@ void pulseClock()
|
|||||||
void readByte(unsigned char *data)
|
void readByte(unsigned char *data)
|
||||||
{
|
{
|
||||||
/* pretend reading using a file */
|
/* pretend reading using a file */
|
||||||
*data = (unsigned char)fgetc( in );
|
//*data = (unsigned char)fgetc( in );
|
||||||
/**data=*xsvf_data++;*/
|
/**data=*xsvf_data++;*/
|
||||||
|
*data = cpld_jtag_get_next_byte();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* readTDOBit: Implement to return the current value of the JTAG TDO signal.*/
|
/* readTDOBit: Implement to return the current value of the JTAG TDO signal.*/
|
||||||
|
35
firmware/cpldjtagprog/Makefile
Normal file
35
firmware/cpldjtagprog/Makefile
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# Hey Emacs, this is a -*- makefile -*-
|
||||||
|
#
|
||||||
|
# Copyright 2012 Michael Ossmann <mike@ossmann.com>
|
||||||
|
# Copyright 2012 Jared Boone <jared@sharebrained.com>
|
||||||
|
#
|
||||||
|
# This file is part of HackRF.
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under 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.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; see the file COPYING. If not, write to
|
||||||
|
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||||
|
# Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
|
||||||
|
BINARY = cpldjtagprog
|
||||||
|
|
||||||
|
SRC = $(BINARY).c \
|
||||||
|
../common/hackrf_core.c \
|
||||||
|
../common/si5351c.c \
|
||||||
|
../common/max2837.c \
|
||||||
|
../common/cpld_jtag.c \
|
||||||
|
../common/xapp058/lenval.c \
|
||||||
|
../common/xapp058/micro.c \
|
||||||
|
../common/xapp058/ports.c
|
||||||
|
|
||||||
|
include ../common/Makefile_inc.mk
|
1
firmware/cpldjtagprog/README
Normal file
1
firmware/cpldjtagprog/README
Normal file
@ -0,0 +1 @@
|
|||||||
|
This is a test program for CPLD JTAG programming.
|
53
firmware/cpldjtagprog/cpldjtagprog.c
Normal file
53
firmware/cpldjtagprog/cpldjtagprog.c
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010 - 2013 Michael Ossmann
|
||||||
|
*
|
||||||
|
* This file is part of HackRF.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <libopencm3/lpc43xx/gpio.h>
|
||||||
|
#include <libopencm3/lpc43xx/scu.h>
|
||||||
|
|
||||||
|
#include "hackrf_core.h"
|
||||||
|
#include "cpld_jtag.h"
|
||||||
|
#include "sgpio_if_xsvf.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
pin_setup();
|
||||||
|
|
||||||
|
/* Set 1V8 */
|
||||||
|
gpio_set(PORT_EN1V8, PIN_EN1V8);
|
||||||
|
|
||||||
|
/* program test bitstream to CPLD */
|
||||||
|
cpld_jtag_program(sgpio_if_xsvf_len, &sgpio_if_xsvf[0]);
|
||||||
|
|
||||||
|
/* blink LED1 and LED3 */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
gpio_set(PORT_LED1_3, (PIN_LED1|PIN_LED3)); /* LEDs on */
|
||||||
|
for (i = 0; i < 2000000; i++) /* Wait a bit. */
|
||||||
|
__asm__("nop");
|
||||||
|
gpio_clear(PORT_LED1_3, (PIN_LED1|PIN_LED3)); /* LED off */
|
||||||
|
for (i = 0; i < 2000000; i++) /* Wait a bit. */
|
||||||
|
__asm__("nop");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
3140
firmware/cpldjtagprog/sgpio_if_xsvf.h
Normal file
3140
firmware/cpldjtagprog/sgpio_if_xsvf.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user