Skip to content

Commit

Permalink
One source of JTAG mode bits
Browse files Browse the repository at this point in the history
  • Loading branch information
makestuff committed Mar 16, 2013
1 parent a117078 commit 193a198
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 43 deletions.
7 changes: 1 addition & 6 deletions firmware/fx2/jtag.h
Expand Up @@ -18,6 +18,7 @@
#define JTAG_H

#include <makestuff.h>
#include "../../prog.h"

// Default TDO=PD0, TDI=PD1, TMS=PD2 & TCK=PD3. In reality this is overwritten
// at runtime by jtagPatch().
Expand All @@ -36,12 +37,6 @@ sbit at (0x80 + 16*JTAG_PORT + TCK_BIT) TCK; // Port bit to use for TCK

// Macros for NeroJTAG implementation
#define ENDPOINT_SIZE 64
#define bmNEEDRESPONSE (1<<0)
#define bmISLAST (1<<1)
#define bmSENDZEROS (0<<2)
#define bmSENDONES (1<<2)
#define bmSENDDATA (2<<2)
#define bmSENDMASK (3<<2)

// Error codes for jtagCsvfPlay(void);
#define ERROR_CSVF_FAILED_COMPARE 1
Expand Down
54 changes: 17 additions & 37 deletions nero.c
Expand Up @@ -21,27 +21,14 @@
#include "vendorCommands.h"
#include "private.h"
#include "nero.h"
#include "prog.h"

// -------------------------------------------------------------------------------------------------
// Declaration of private types & functions
// -------------------------------------------------------------------------------------------------

typedef enum {
SEND_ZEROS,
SEND_ONES,
SEND_DATA,
SEND_MASK
} SendType;

enum {
IS_RESPONSE_NEEDED = 0,
IS_LAST = 1,
SEND_TYPE = 2
};

static NeroStatus beginShift(
struct FLContext *handle, uint32 numBits, SendType sendType, bool isLast,
bool isResponseNeeded, const char **error
struct FLContext *handle, uint32 numBits, uint8 mode, const char **error
) WARN_UNUSED_RESULT;

static NeroStatus doSend(
Expand Down Expand Up @@ -230,32 +217,34 @@ NeroStatus neroShift(
NeroStatus returnCode, nStatus;
uint32 numBytes;
uint16 chunkSize;
SendType sendType;
bool isResponseNeeded;
uint8 mode = 0x00;
bool sendData = false;

if ( inData == ZEROS ) {
sendType = SEND_ZEROS;
mode |= bmSENDZEROS;
} else if ( inData == ONES ) {
sendType = SEND_ONES;
mode |= bmSENDONES;
} else {
sendType = SEND_DATA;
mode |= bmSENDDATA;
sendData = true;
}
if ( outData ) {
isResponseNeeded = true;
} else {
isResponseNeeded = false;
mode |= bmNEEDRESPONSE;
}
if ( isLast ) {
mode |= bmISLAST;
}
nStatus = beginShift(handle, numBits, sendType, isLast, isResponseNeeded, error);
nStatus = beginShift(handle, numBits, mode, error);
CHECK_STATUS(nStatus, "neroShift()", NERO_BEGIN_SHIFT);
numBytes = bitsToBytes(numBits);
while ( numBytes ) {
chunkSize = (numBytes>=handle->endpointSize) ? handle->endpointSize : (uint16)numBytes;
if ( sendType == SEND_DATA ) {
if ( sendData ) {
nStatus = doSend(handle, inData, chunkSize, error);
CHECK_STATUS(nStatus, "neroShift()", NERO_SEND);
inData += chunkSize;
}
if ( isResponseNeeded ) {
if ( outData ) {
nStatus = doReceive(handle, outData, chunkSize, error);
CHECK_STATUS(nStatus, "neroShift()", NERO_RECEIVE);
outData += chunkSize;
Expand Down Expand Up @@ -367,28 +356,19 @@ 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(
struct FLContext *handle, uint32 numBits, SendType sendType, bool isLast,
bool isResponseNeeded, const char **error)
struct FLContext *handle, uint32 numBits, uint8 mode, const char **error)
{
NeroStatus returnCode = NERO_SUCCESS;
uint16 wValue = 0x0000;
int uStatus;
union {
uint32 u32;
uint8 bytes[4];
} leNumBits;
leNumBits.u32 = littleEndian32(numBits);
if ( isLast ) {
wValue |= (1<<IS_LAST);
}
if ( isResponseNeeded ) {
wValue |= (1<<IS_RESPONSE_NEEDED);
}
wValue |= sendType << SEND_TYPE;
uStatus = usbControlWrite(
handle->device,
CMD_JTAG_CLOCK_DATA, // bRequest
wValue, // wValue
(uint8)mode, // wValue
0x0000, // wIndex
leNumBits.bytes, // send bit count
4, // wLength
Expand Down
27 changes: 27 additions & 0 deletions prog.h
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2009-2012 Chris McClelland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PROG_H
#define PROG_H

#define bmNEEDRESPONSE (1<<0)
#define bmISLAST (1<<1)
#define bmSENDZEROS (0<<2)
#define bmSENDONES (1<<2)
#define bmSENDDATA (2<<2)
#define bmSENDMASK (3<<2)

#endif

0 comments on commit 193a198

Please sign in to comment.