Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rough parallel programming working

  • Loading branch information...
commit c390a3b98d944f6d2f9904b4e2d670642392d34b 1 parent 32fe000
@makestuff authored
Showing with 109 additions and 7 deletions.
  1. +17 −2 firmware/fx2/jtag.c
  2. +86 −0 jtag.c
  3. +4 −4 nero.c
  4. +2 −1  prog.h
View
19 firmware/fx2/jtag.c
@@ -113,7 +113,7 @@ static void shiftOut(uint8 c) {
// JTAG-clock all 512 bytes from the EP2OUT FIFO buffer
//
-static void blockShiftOut(uint8 count) {
+static void blockShiftBits(uint8 count) {
_asm
mov _AUTOPTRH1, #_EP1OUTBUF >> 8
mov _AUTOPTRL1, #_EP1OUTBUF
@@ -353,7 +353,7 @@ static void jtagIsSendingNotReceiving(void) {
}
} else {
// This is not the last chunk, so we've to 512 bytes to shift
- blockShiftOut(64);
+ blockShiftBits(64);
}
EP1OUTBC = 0x00; // ready to accept more data from host
m_numBits -= bitsRead;
@@ -432,6 +432,18 @@ static void jtagNotSendingNotReceiving(void) {
m_progOp = PROG_NOP;
}
+static void progParallel(void) {
+ xdata uint8 bytesRead;
+ while ( m_numBits ) {
+ while ( EP01STAT & bmEP1OUTBSY ); // Wait for some EP2OUT data
+ bytesRead = EP1OUTBC;
+ blockShiftBytes(bytesRead);
+ EP1OUTBC = 0x00; // ready to accept more data from host
+ m_numBits -= bytesRead;
+ }
+ m_progOp = PROG_NOP;
+}
+
// Actually execute the shift operation initiated by jtagBeginShift(). This is done in a
// separate method because vendor commands cannot read & write to bulk endpoints.
//
@@ -452,6 +464,9 @@ void jtagShiftExecute(void) {
case PROG_JTAG_NOTSENDING_NOTRECEIVING:
jtagNotSendingNotReceiving();
break;
+ case PROG_PARALLEL:
+ progParallel();
+ break;
case PROG_NOP:
default:
break;
View
86 jtag.c
@@ -23,6 +23,13 @@
#include "libfpgalink.h"
#include "private.h"
#include "csvfplay.h"
+#include "prog.h"
+
+NeroStatus beginShift(
+ struct FLContext *handle, uint32 numBits, ProgOp progOp, uint8 mode, const char **error);
+
+NeroStatus doSend(
+ struct FLContext *handle, const uint8 *sendPtr, uint16 chunkSize, const char **error);
#define GET_CHAR(func) \
ch = *ptr; \
@@ -142,6 +149,42 @@ static FLStatus portMap(struct FLContext *handle, uint8 patchClass, uint8 port,
return returnCode;
}
+static FLStatus dataWrite(struct FLContext *handle, ProgOp progOp, const uint8 *buf, uint32 len, const char **error) {
+ FLStatus returnCode = FL_SUCCESS;
+ NeroStatus nStatus = beginShift(handle, len, progOp, 0x00, error);
+ uint16 chunkSize;
+ CHECK_STATUS(nStatus, "dataWrite()", FL_JTAG_ERR);
+ while ( len ) {
+ chunkSize = (len >= 64) ? 64 : (uint16)len;
+ nStatus = doSend(handle, buf, chunkSize, error);
+ CHECK_STATUS(nStatus, "dataWrite()", FL_JTAG_ERR);
+ buf += chunkSize;
+ len -= chunkSize;
+ }
+cleanup:
+ return returnCode;
+}
+
+static FLStatus fileWrite(struct FLContext *handle, ProgOp progOp, const char *fileName, const char **error) {
+ FLStatus returnCode = FL_SUCCESS;
+ FLStatus fStatus;
+ uint8 *fileData = NULL;
+ uint32 fileLen;
+ fileData = flLoadFile(fileName, &fileLen);
+ if ( !fileData ) {
+ errRender(error, "fileWrite(): Unable to read from %s", fileName);
+ FAIL(FL_JTAG_ERR);
+ }
+ printf("Loaded %d bytes\n", fileLen);
+ fStatus = dataWrite(handle, progOp, fileData, fileLen, error);
+ CHECK_STATUS(fStatus, "fileWrite()", fStatus);
+cleanup:
+ if ( fileData ) {
+ flFreeFile(fileData);
+ }
+ return returnCode;
+}
+
static FLStatus xpProgram(struct FLContext *handle, const char *portConfig, const char *progFile, const char **error) {
FLStatus returnCode = FL_SUCCESS;
FLStatus fStatus;
@@ -286,6 +329,49 @@ static FLStatus xpProgram(struct FLContext *handle, const char *portConfig, cons
printf("Deasserted PROG, saw INIT go high: FPGA is ready for data\n");
+ fStatus = fileWrite(handle, PROG_PARALLEL, progFile, error);
+ CHECK_STATUS(fStatus, "xpProgram()", fStatus);
+
+ printf("Finished sending data\n");
+
+ fStatus = flPortAccess(
+ handle, progPort, // check INIT & DONE
+ 0x00, // mask: affect nothing
+ 0x00, // ddr: ignored
+ 0x00, // port: ignored
+ &tempByte,
+ error
+ );
+ CHECK_STATUS(fStatus, "xpProgram()", fStatus);
+ printf("init: %02X; done: %02X\n", tempByte&initMask, tempByte&doneMask);
+ if ( !(tempByte & doneMask) && !(tempByte & initMask) ) {
+ errRender(error, "xpProgram(): INIT unexpectedly low (CRC error during config)");
+ FAIL(FL_JTAG_ERR);
+ }
+
+ printf("Saw DONE go high\n");
+
+ for ( i = 0; i < 5; i++ ) {
+ mask = maskList[i];
+ if ( mask ) {
+ fStatus = flPortAccess(
+ handle, i,
+ mask,
+ (i == progPort) ? progMask : 0x00,
+ 0xFF,
+ NULL,
+ error
+ );
+ CHECK_STATUS(fStatus, "xpProgram()", fStatus);
+ }
+ }
+ printf("De-configured ports\n");
+
+ fStatus = flFifoMode(handle, true, error);
+ CHECK_STATUS(fStatus, "xpProgram()", fStatus);
+
+ printf("Enabled FIFO mode again\n");
+
cleanup:
return returnCode;
}
View
8 nero.c
@@ -27,11 +27,11 @@
// Declaration of private types & functions
// -------------------------------------------------------------------------------------------------
-static NeroStatus beginShift(
+NeroStatus beginShift(
struct FLContext *handle, uint32 numBits, ProgOp progOp, uint8 mode, const char **error
) WARN_UNUSED_RESULT;
-static NeroStatus doSend(
+NeroStatus doSend(
struct FLContext *handle, const uint8 *sendPtr, uint16 chunkSize, const char **error
) WARN_UNUSED_RESULT;
@@ -367,7 +367,7 @@ static NeroStatus portMap(
// Kick off a shift operation on the micro. This will be followed by a bunch of sends and receives.
//
-static NeroStatus beginShift(
+NeroStatus beginShift(
struct FLContext *handle, uint32 numBits, ProgOp progOp, uint8 mode, const char **error)
{
NeroStatus returnCode = NERO_SUCCESS;
@@ -394,7 +394,7 @@ static NeroStatus beginShift(
// Send a chunk of data to the micro.
//
-static NeroStatus doSend(
+NeroStatus doSend(
struct FLContext *handle, const uint8 *sendPtr, uint16 chunkSize, const char **error)
{
NeroStatus returnCode = NERO_SUCCESS;
View
3  prog.h
@@ -22,7 +22,8 @@ typedef enum {
PROG_JTAG_ISSENDING_ISRECEIVING,
PROG_JTAG_ISSENDING_NOTRECEIVING,
PROG_JTAG_NOTSENDING_ISRECEIVING,
- PROG_JTAG_NOTSENDING_NOTRECEIVING
+ PROG_JTAG_NOTSENDING_NOTRECEIVING,
+ PROG_PARALLEL
} ProgOp;
#define bmISLAST (1<<0)

0 comments on commit c390a3b

Please sign in to comment.
Something went wrong with that request. Please try again.