diff --git a/firmware/common/cpld_jtag.c b/firmware/common/cpld_jtag.c index 02ce588a..ddeb13d9 100644 --- a/firmware/common/cpld_jtag.c +++ b/firmware/common/cpld_jtag.c @@ -57,12 +57,16 @@ void cpld_jtag_release(void) { GPIO_DIR(PORT_CPLD_TDI) &= ~PIN_CPLD_TDI; } -void cpld_jtag_program(const uint32_t len, unsigned char* const data) { +/* return 0 if success else return error code see xsvfExecute() */ +int cpld_jtag_program(const uint32_t len, unsigned char* const data) { + int error; cpld_jtag_setup(); xsvf_data = data; xsvf_len = len; - xsvfExecute(); + error = xsvfExecute(); cpld_jtag_release(); + + return error; } /* this gets called by the XAPP058 code */ diff --git a/firmware/common/cpld_jtag.h b/firmware/common/cpld_jtag.h index f6de2c97..ed42d782 100644 --- a/firmware/common/cpld_jtag.h +++ b/firmware/common/cpld_jtag.h @@ -25,7 +25,8 @@ #include void cpld_jtag_release(void); -void cpld_jtag_program(const uint32_t len, unsigned char* const data); +/* return 0 if success else return error code see xsvfExecute() see micro.h */ +int cpld_jtag_program(const uint32_t len, unsigned char* const data); unsigned char cpld_jtag_get_next_byte(void); #endif//__CPLD_JTAG_H__ diff --git a/firmware/common/xapp058/ports.c b/firmware/common/xapp058/ports.c index bb34c550..3c7c6e44 100644 --- a/firmware/common/xapp058/ports.c +++ b/firmware/common/xapp058/ports.c @@ -22,6 +22,28 @@ //static int g_iTMS = 0; /* For xapp058_example .exe */ //static int g_iTDI = 0; /* For xapp058_example .exe */ +void delay_jtag(uint32_t duration) +{ + #define DIVISOR (1024) + #define MIN_NOP (8) + + uint32_t i; + uint32_t delay_nop; + + /* @204Mhz duration of about 400ns for delay_nop=20 */ + if(duration < DIVISOR) + { + delay_nop = MIN_NOP; + }else + { + delay_nop = (duration / DIVISOR) + MIN_NOP; + } + + for (i = 0; i < delay_nop; i++) + __asm__("nop"); +} + + #ifdef WIN95PP #include "conio.h" @@ -127,7 +149,7 @@ void setPort(short p,short val) } /* conservative delay */ - delay(20000); + delay_jtag(20000); } @@ -135,9 +157,9 @@ void setPort(short p,short val) void pulseClock() { setPort(TCK,0); /* set the TCK port to low */ - delay(200); + delay_jtag(200); setPort(TCK,1); /* set the TCK port to high */ - delay(200); + delay_jtag(200); } @@ -169,7 +191,7 @@ unsigned char readTDOBit() /* You must return the current value of the JTAG TDO signal. */ //return( (unsigned char) 0 ); - delay(2000); + delay_jtag(2000); return CPLD_TDO_STATE; } diff --git a/firmware/cpldjtagprog/cpldjtagprog.c b/firmware/cpldjtagprog/cpldjtagprog.c index 06144c25..507f2370 100644 --- a/firmware/cpldjtagprog/cpldjtagprog.c +++ b/firmware/cpldjtagprog/cpldjtagprog.c @@ -26,26 +26,45 @@ #include "cpld_jtag.h" #include "sgpio_if_xsvf.h" +#define WAIT_LOOP_DELAY (6000000) + +#define ALL_LEDS (PIN_LED1|PIN_LED2|PIN_LED3) + int main(void) { int i; - + int error; + int LED; + pin_setup(); /* Set 1V8 */ gpio_set(PORT_EN1V8, PIN_EN1V8); + cpu_clock_init(); + /* program test bitstream to CPLD */ - cpld_jtag_program(sgpio_if_xsvf_len, &sgpio_if_xsvf[0]); + error = cpld_jtag_program(sgpio_if_xsvf_len, &sgpio_if_xsvf[0]); - /* blink LED1 and LED3 */ - while (1) + if(error == 0) { - gpio_set(PORT_LED1_3, (PIN_LED1|PIN_LED3)); /* LEDs on */ - for (i = 0; i < 2000000; i++) /* Wait a bit. */ + /* blink only LED1 (Green) on success */ + LED = PIN_LED1; + }else + { + /* blink LED3 (Red) on error */ + LED = PIN_LED3; + } + + gpio_clear(PORT_LED1_3, ALL_LEDS); /* All LEDs off */ + + while (1) + { + gpio_set(PORT_LED1_3, LED); /* LEDs on */ + for (i = 0; i < WAIT_LOOP_DELAY; 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. */ + gpio_clear(PORT_LED1_3, LED); /* LED off */ + for (i = 0; i < WAIT_LOOP_DELAY; i++) /* Wait a bit. */ __asm__("nop"); } diff --git a/firmware/cpldjtagprog_rom_to_ram/Makefile b/firmware/cpldjtagprog_rom_to_ram/Makefile new file mode 100644 index 00000000..e3a80e16 --- /dev/null +++ b/firmware/cpldjtagprog_rom_to_ram/Makefile @@ -0,0 +1,36 @@ +# Hey Emacs, this is a -*- makefile -*- +# +# Copyright 2012 Michael Ossmann +# Copyright 2012 Jared Boone +# +# 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_rom_to_ram + +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 + +LDSCRIPT = ../common/LPC4330_M4_rom_to_ram.ld +include ../common/Makefile_inc.mk diff --git a/firmware/cpldjtagprog_rom_to_ram/README b/firmware/cpldjtagprog_rom_to_ram/README new file mode 100644 index 00000000..82388a2c --- /dev/null +++ b/firmware/cpldjtagprog_rom_to_ram/README @@ -0,0 +1 @@ +This is a test program for CPLD JTAG programming. diff --git a/firmware/cpldjtagprog_rom_to_ram/cpldjtagprog_rom_to_ram.c b/firmware/cpldjtagprog_rom_to_ram/cpldjtagprog_rom_to_ram.c new file mode 100644 index 00000000..5cc9456c --- /dev/null +++ b/firmware/cpldjtagprog_rom_to_ram/cpldjtagprog_rom_to_ram.c @@ -0,0 +1,72 @@ +/* + * 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 +#include + +#include "hackrf_core.h" +#include "cpld_jtag.h" +#include "../cpldjtagprog/sgpio_if_xsvf.h" + +#define WAIT_LOOP_DELAY (6000000) + +#define ALL_LEDS (PIN_LED1|PIN_LED2|PIN_LED3) + +int main(void) +{ + int i; + int error; + int LED; + + pin_setup(); + + /* Set 1V8 */ + gpio_set(PORT_EN1V8, PIN_EN1V8); + + cpu_clock_init(); + + /* program test bitstream to CPLD */ + error = cpld_jtag_program(sgpio_if_xsvf_len, &sgpio_if_xsvf[0]); + + if(error == 0) + { + /* blink only LED1 (Green) on success */ + LED = PIN_LED1; + }else + { + /* blink LED3 (Red) on error */ + LED = PIN_LED3; + } + + gpio_clear(PORT_LED1_3, ALL_LEDS); /* All LEDs off */ + + while (1) + { + gpio_set(PORT_LED1_3, LED); /* LEDs on */ + for (i = 0; i < WAIT_LOOP_DELAY; i++) /* Wait a bit. */ + __asm__("nop"); + gpio_clear(PORT_LED1_3, LED); /* LED off */ + for (i = 0; i < WAIT_LOOP_DELAY; i++) /* Wait a bit. */ + __asm__("nop"); + } + + return 0; +}