jtag library added

parent de28634a
#include <jtag.h>
void JTAGPort::begin() {
DDRB |= _BV(TMS) |
_BV(TCK) |
_BV(TDI);
DDRB &= ~_BV(TDO);
PORTB &= ~(_BV(TMS) |
_BV(TCK) |
_BV(TDI) |
_BV(TDO));
this->reset();
}
void JTAGPort::reset() {
for(int i = 0; i < 5; i++) {
PORTB |= _BV(TMS);
this->clockPulse();
}
}
void JTAGPort::clockPulse() {
// pulse high
PORTB |= _BV(TCK);
delayMicroseconds(10);
// pulse low
PORTB &= ~_BV(TCK);
delayMicroseconds(10);
}
void JTAGPort::sendBits(uint8_t tms, uint8_t tdi, uint8_t size) {
for(int i = 0; i < size; i++) {
PORTB = (tms & _BV(i)) ? PORTB | _BV(TMS) : PORTB & ~_BV(TMS);
PORTB = (tdi & _BV(i)) ? PORTB | _BV(TDI) : PORTB & ~_BV(TDI);
this->clockPulse();
}
}
void JTAGPort::setDR() {
this->reset();
this->sendBits(DR_SELECT_TMS, DR_SELECT_TDI, DR_SELECT_SIZE);
}
void JTAGPort::setIR() {
this->reset();
this->sendBits(IR_SELECT_TMS, IR_SELECT_TDI, IR_SELECT_SIZE);
}
void JTAGPort::sendData(uint8_t tdi_pos, uint8_t value) {
this->reset();
this->setDR();
this->sendBits(0, 1, 1);
for(int i = 0; i < tdi_pos - 2; i++)
this->sendBits(0, 0, 1);
this->sendBits(EXIT_SHIFT_TMS, EXIT_SHIFT_TDI, EXIT_SHIFT_SIZE);
}
void JTAGPort::sendInst(uint8_t instruction) {
this->reset();
this->setIR();
this->sendBits(IR_UPDATE_TMS, instruction, IR_UPDATE_SIZE);
this->sendBits(EXIT_SHIFT_TMS >> 1, EXIT_SHIFT_TDI, EXIT_SHIFT_SIZE - 1);
}
uint8_t JTAGPort::readData(uint8_t tdi_pos) {
uint8_t value = 0;
this->reset();
this->setDR();
for(int i = 0; i < (BOUNDARY_SIZE - tdi_pos); i++)
this->sendBits(0, 0, 1);
value = PORTB && _BV(TDO);
this->sendBits(EXIT_SHIFT_TMS, EXIT_SHIFT_TDI, EXIT_SHIFT_SIZE);
return value;
}
#include <Arduino.h>
#define IR_SELECT_TMS 0b01100
#define IR_SELECT_TDI 0b00000
#define IR_SELECT_SIZE 5
#define DR_SELECT_TMS 0b0100
#define DR_SELECT_TDI 0b0000
#define DR_SELECT_SIZE 4
#define EXIT_SHIFT_TMS 0b011
#define EXIT_SHIFT_TDI 0b000
#define EXIT_SHIFT_SIZE 3
#define IDCODE_TDI 0b00001
#define IR_UPDATE_TMS 0b00001
#define IR_UPDATE_SIZE 5
#define BOUNDARY_SIZE 148
#define ID_CODE_SIZE 32
#define TMS PORTB0
#define TCK PORTB1
#define TDI PORTB2
#define TDO PORTB3
class JTAGPort {
public:
void begin();
void reset();
void clockPulse();
void sendBits(uint8_t tms, uint8_t tdi, uint8_t size);
void setDR();
void setIR();
void sendData(uint8_t tdi, uint8_t value);
void sendInst(uint8_t instruction);
uint8_t readData(uint8_t tdi_pos);
};
JTAGPort JTAG;
\ No newline at end of file
#include <Arduino.h>
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment