Skip to content

Instantly share code, notes, and snippets.

@makestuff
Created August 6, 2015 17:53
Show Gist options
  • Save makestuff/dd3e6e2284a96dcda887 to your computer and use it in GitHub Desktop.
Save makestuff/dd3e6e2284a96dcda887 to your computer and use it in GitHub Desktop.
Raspberry Pi GPIO->JTAG
#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