Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Rough parallel programming working

  • Loading branch information...
commit c390a3b98d944f6d2f9904b4e2d670642392d34b 1 parent 32fe000
Chris McClelland authored

Showing 4 changed files with 109 additions and 7 deletions. Show diff stats Hide diff stats

  1. +17 2 firmware/fx2/jtag.c
  2. +86 0 jtag.c
  3. +4 4 nero.c
  4. +2 1  prog.h
19 firmware/fx2/jtag.c
@@ -113,7 +113,7 @@ static void shiftOut(uint8 c) {
113 113
114 114 // JTAG-clock all 512 bytes from the EP2OUT FIFO buffer
115 115 //
116   -static void blockShiftOut(uint8 count) {
  116 +static void blockShiftBits(uint8 count) {
117 117 _asm
118 118 mov _AUTOPTRH1, #_EP1OUTBUF >> 8
119 119 mov _AUTOPTRL1, #_EP1OUTBUF
@@ -353,7 +353,7 @@ static void jtagIsSendingNotReceiving(void) {
353 353 }
354 354 } else {
355 355 // This is not the last chunk, so we've to 512 bytes to shift
356   - blockShiftOut(64);
  356 + blockShiftBits(64);
357 357 }
358 358 EP1OUTBC = 0x00; // ready to accept more data from host
359 359 m_numBits -= bitsRead;
@@ -432,6 +432,18 @@ static void jtagNotSendingNotReceiving(void) {
432 432 m_progOp = PROG_NOP;
433 433 }
434 434
  435 +static void progParallel(void) {
  436 + xdata uint8 bytesRead;
  437 + while ( m_numBits ) {
  438 + while ( EP01STAT & bmEP1OUTBSY ); // Wait for some EP2OUT data
  439 + bytesRead = EP1OUTBC;
  440 + blockShiftBytes(bytesRead);
  441 + EP1OUTBC = 0x00; // ready to accept more data from host
  442 + m_numBits -= bytesRead;
  443 + }
  444 + m_progOp = PROG_NOP;
  445 +}
  446 +
435 447 // Actually execute the shift operation initiated by jtagBeginShift(). This is done in a
436 448 // separate method because vendor commands cannot read & write to bulk endpoints.
437 449 //
@@ -452,6 +464,9 @@ void jtagShiftExecute(void) {
452 464 case PROG_JTAG_NOTSENDING_NOTRECEIVING:
453 465 jtagNotSendingNotReceiving();
454 466 break;
  467 + case PROG_PARALLEL:
  468 + progParallel();
  469 + break;
455 470 case PROG_NOP:
456 471 default:
457 472 break;
86 jtag.c
@@ -23,6 +23,13 @@
23 23 #include "libfpgalink.h"
24 24 #include "private.h"
25 25 #include "csvfplay.h"
  26 +#include "prog.h"
  27 +
  28 +NeroStatus beginShift(
  29 + struct FLContext *handle, uint32 numBits, ProgOp progOp, uint8 mode, const char **error);
  30 +
  31 +NeroStatus doSend(
  32 + struct FLContext *handle, const uint8 *sendPtr, uint16 chunkSize, const char **error);
26 33
27 34 #define GET_CHAR(func) \
28 35 ch = *ptr; \
@@ -142,6 +149,42 @@ static FLStatus portMap(struct FLContext *handle, uint8 patchClass, uint8 port,
142 149 return returnCode;
143 150 }
144 151
  152 +static FLStatus dataWrite(struct FLContext *handle, ProgOp progOp, const uint8 *buf, uint32 len, const char **error) {
  153 + FLStatus returnCode = FL_SUCCESS;
  154 + NeroStatus nStatus = beginShift(handle, len, progOp, 0x00, error);
  155 + uint16 chunkSize;
  156 + CHECK_STATUS(nStatus, "dataWrite()", FL_JTAG_ERR);
  157 + while ( len ) {
  158 + chunkSize = (len >= 64) ? 64 : (uint16)len;
  159 + nStatus = doSend(handle, buf, chunkSize, error);
  160 + CHECK_STATUS(nStatus, "dataWrite()", FL_JTAG_ERR);
  161 + buf += chunkSize;
  162 + len -= chunkSize;
  163 + }
  164 +cleanup:
  165 + return returnCode;
  166 +}
  167 +
  168 +static FLStatus fileWrite(struct FLContext *handle, ProgOp progOp, const char *fileName, const char **error) {
  169 + FLStatus returnCode = FL_SUCCESS;
  170 + FLStatus fStatus;
  171 + uint8 *fileData = NULL;
  172 + uint32 fileLen;
  173 + fileData = flLoadFile(fileName, &fileLen);
  174 + if ( !fileData ) {
  175 + errRender(error, "fileWrite(): Unable to read from %s", fileName);
  176 + FAIL(FL_JTAG_ERR);
  177 + }
  178 + printf("Loaded %d bytes\n", fileLen);
  179 + fStatus = dataWrite(handle, progOp, fileData, fileLen, error);
  180 + CHECK_STATUS(fStatus, "fileWrite()", fStatus);
  181 +cleanup:
  182 + if ( fileData ) {
  183 + flFreeFile(fileData);
  184 + }
  185 + return returnCode;
  186 +}
  187 +
145 188 static FLStatus xpProgram(struct FLContext *handle, const char *portConfig, const char *progFile, const char **error) {
146 189 FLStatus returnCode = FL_SUCCESS;
147 190 FLStatus fStatus;
@@ -286,6 +329,49 @@ static FLStatus xpProgram(struct FLContext *handle, const char *portConfig, cons
286 329
287 330 printf("Deasserted PROG, saw INIT go high: FPGA is ready for data\n");
288 331
  332 + fStatus = fileWrite(handle, PROG_PARALLEL, progFile, error);
  333 + CHECK_STATUS(fStatus, "xpProgram()", fStatus);
  334 +
  335 + printf("Finished sending data\n");
  336 +
  337 + fStatus = flPortAccess(
  338 + handle, progPort, // check INIT & DONE
  339 + 0x00, // mask: affect nothing
  340 + 0x00, // ddr: ignored
  341 + 0x00, // port: ignored
  342 + &tempByte,
  343 + error
  344 + );
  345 + CHECK_STATUS(fStatus, "xpProgram()", fStatus);
  346 + printf("init: %02X; done: %02X\n", tempByte&initMask, tempByte&doneMask);
  347 + if ( !(tempByte & doneMask) && !(tempByte & initMask) ) {
  348 + errRender(error, "xpProgram(): INIT unexpectedly low (CRC error during config)");
  349 + FAIL(FL_JTAG_ERR);
  350 + }
  351 +
  352 + printf("Saw DONE go high\n");
  353 +
  354 + for ( i = 0; i < 5; i++ ) {
  355 + mask = maskList[i];
  356 + if ( mask ) {
  357 + fStatus = flPortAccess(
  358 + handle, i,
  359 + mask,
  360 + (i == progPort) ? progMask : 0x00,
  361 + 0xFF,
  362 + NULL,
  363 + error
  364 + );
  365 + CHECK_STATUS(fStatus, "xpProgram()", fStatus);
  366 + }
  367 + }
  368 + printf("De-configured ports\n");
  369 +
  370 + fStatus = flFifoMode(handle, true, error);
  371 + CHECK_STATUS(fStatus, "xpProgram()", fStatus);
  372 +
  373 + printf("Enabled FIFO mode again\n");
  374 +
289 375 cleanup:
290 376 return returnCode;
291 377 }
8 nero.c
@@ -27,11 +27,11 @@
27 27 // Declaration of private types & functions
28 28 // -------------------------------------------------------------------------------------------------
29 29
30   -static NeroStatus beginShift(
  30 +NeroStatus beginShift(
31 31 struct FLContext *handle, uint32 numBits, ProgOp progOp, uint8 mode, const char **error
32 32 ) WARN_UNUSED_RESULT;
33 33
34   -static NeroStatus doSend(
  34 +NeroStatus doSend(
35 35 struct FLContext *handle, const uint8 *sendPtr, uint16 chunkSize, const char **error
36 36 ) WARN_UNUSED_RESULT;
37 37
@@ -367,7 +367,7 @@ static NeroStatus portMap(
367 367
368 368 // Kick off a shift operation on the micro. This will be followed by a bunch of sends and receives.
369 369 //
370   -static NeroStatus beginShift(
  370 +NeroStatus beginShift(
371 371 struct FLContext *handle, uint32 numBits, ProgOp progOp, uint8 mode, const char **error)
372 372 {
373 373 NeroStatus returnCode = NERO_SUCCESS;
@@ -394,7 +394,7 @@ static NeroStatus beginShift(
394 394
395 395 // Send a chunk of data to the micro.
396 396 //
397   -static NeroStatus doSend(
  397 +NeroStatus doSend(
398 398 struct FLContext *handle, const uint8 *sendPtr, uint16 chunkSize, const char **error)
399 399 {
400 400 NeroStatus returnCode = NERO_SUCCESS;
3  prog.h
@@ -22,7 +22,8 @@ typedef enum {
22 22 PROG_JTAG_ISSENDING_ISRECEIVING,
23 23 PROG_JTAG_ISSENDING_NOTRECEIVING,
24 24 PROG_JTAG_NOTSENDING_ISRECEIVING,
25   - PROG_JTAG_NOTSENDING_NOTRECEIVING
  25 + PROG_JTAG_NOTSENDING_NOTRECEIVING,
  26 + PROG_PARALLEL
26 27 } ProgOp;
27 28
28 29 #define bmISLAST (1<<0)

0 comments on commit c390a3b

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