Created
August 6, 2015 17:53
-
-
Save makestuff/dd3e6e2284a96dcda887 to your computer and use it in GitHub Desktop.
Raspberry Pi GPIO->JTAG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <makestuff.h> | |
#include <liberror.h> | |
#include <wiringPi.h> | |
#include "parser.h" | |
typedef enum { | |
TCK = 7, | |
TDO = 0, | |
TDI = 9, | |
TMS = 8 | |
} Pins; | |
void setTCK(bool x) { | |
digitalWrite(TCK, x ? HIGH : LOW); | |
} | |
void setTDI(bool x) { | |
digitalWrite(TDI, x ? HIGH : LOW); | |
} | |
void setTMS(bool x) { | |
digitalWrite(TMS, x ? HIGH : LOW); | |
} | |
bool getTDO(void) { | |
return digitalRead(TDO) == HIGH; | |
} | |
int main(int argc, const char *argv[]) { | |
int retVal; | |
// Init library | |
wiringPiSetup(); | |
// Validate command-line args | |
if ( argc != 2 ) { | |
fprintf(stderr, "Synopsis: %s <svf-file>\n", argv[0]); | |
FAIL(1, exit); | |
} | |
// Setup pins | |
pinMode(TCK, OUTPUT); | |
pinMode(TMS, OUTPUT); | |
pinMode(TDI, OUTPUT); | |
pinMode(TDO, INPUT); | |
// Parse .svf file | |
const char *error = NULL; | |
const struct ParserCallbacks cb = { | |
setTCK, setTMS, setTDI, getTDO | |
}; | |
ParserStatus pStatus = parse(&cb, argv[1], &error); | |
CHECK_STATUS(pStatus, 2, cleanup); | |
retVal = 0; | |
cleanup: | |
if ( error ) { | |
printf("%s\n", error); | |
errFree(error); | |
} | |
exit: | |
pinMode(TCK, INPUT); | |
pinMode(TMS, INPUT); | |
pinMode(TDI, INPUT); | |
pinMode(TDO, INPUT); | |
return retVal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment