Working version - missing comments

parent cc2785cc
......@@ -24,9 +24,9 @@ void JTAGPort::reset() {
void JTAGPort::clockPulse() {
PORTB |= _BV(TCK);
delayMicroseconds(10);
delayMicroseconds(3);
PORTB &= ~_BV(TCK);
delayMicroseconds(10);
delayMicroseconds(3);
}
void JTAGPort::sendBits(uint8_t tms, uint8_t tdo) {
......@@ -37,11 +37,11 @@ void JTAGPort::sendBits(uint8_t tms, uint8_t tdo) {
void JTAGPort::sendBits(uint8_t tms, uint8_t tdo, uint8_t size) {
for(int i = 0; i < size; i++)
this->sendBits((tms && _BV(i)), (tdo && _BV(i)));
this->sendBits((tms & _BV(i)), (tdo & _BV(i)));
}
void JTAGPort::setDR() {
this->reset();
//this->reset();
this->sendBits(DR_SELECT_TMS, DR_SELECT_TDO, DR_SELECT_SIZE);
}
......@@ -51,20 +51,29 @@ void JTAGPort::setIR() {
}
void JTAGPort::sendData(uint8_t tdo_pos, uint8_t value) {
this->reset();
this->setDR();
this->sendBits(0, 1);
uint8_t i = 0;
for(int i = 0; i < tdo_pos - 2; i++)
this->sendBits(0, 0);
this->setDR();
while(i < BOUNDARY_SIZE - 1) {
if(i == _INPUT(tdo_pos))
this->sendBits(0, 0);
else if(i == _OUTPUT(tdo_pos))
this->sendBits(0, value);
else if(i == _CONTROL(tdo_pos))
this->sendBits(0, 1);
else if(i == 129)
this->sendBits(0, 1);
else
this->sendBits(0, 0);
i++;
}
this->sendBits(EXIT_SHIFT_TMS, EXIT_SHIFT_TDO, EXIT_SHIFT_SIZE);
}
void JTAGPort::sendInst(uint8_t instruction) {
this->reset();
this->setIR();
this->sendBits(IR_UPDATE_TMS, instruction, IR_UPDATE_SIZE);
......@@ -75,33 +84,31 @@ void JTAGPort::sendInst(uint8_t instruction) {
uint8_t JTAGPort::readData(uint8_t tdo_pos) {
uint8_t value = 0;
this->reset();
this->setDR();
for(int i = 0; i < (BOUNDARY_SIZE - tdo_pos); i++)
for(int i = 0; i < tdo_pos; i++)
this->sendBits(0, 0);
value = PORTB && _BV(TDO);
value = (PINB & _BV(TDI)) ? 1 : 0;
this->sendBits(EXIT_SHIFT_TMS, EXIT_SHIFT_TDO, EXIT_SHIFT_SIZE);
return value;
}
uint8_t JTAGPort::readData() {
uint32_t JTAGPort::readData() {
uint32_t value = (PINB & _BV(TDI) ? 1 : 0);
this->sendBits(0, 0);
return (PORTB && _BV(TDI));
return value;
}
uint32_t JTAGPort::getID() {
uint32_t value;
uint32_t value = 0;
this->reset();
this->sendInst(IDCODE_TDO);
this->reset();
this->setDR();
for(int i = 0; i < IDCODE_SIZE; i++)
value |= (this->readData() << i);
......@@ -111,28 +118,18 @@ uint32_t JTAGPort::getID() {
}
void JTAGPort::setLED(uint8_t value) {
this->reset();
this->sendInst(EXTERNAL_TEST_TDO);
this->reset();
this->setDR();
this->sendInst(EXTERNAL_TEST_TDO);
this->sendData(LED_PIN, value);
this->sendBits(EXIT_SHIFT_TMS, EXIT_SHIFT_TDO, EXIT_SHIFT_SIZE);
}
uint8_t JTAGPort::checkButton() {
uint8_t value = 0;
this->reset();
this->sendInst(SAMPLE_PRELOAD_TDO);
this->reset();
this->setDR();
this->sendInst(SAMPLE_PRELOAD_TDO);
value = this->readData(BUTTON_PIN);
this->sendBits(EXIT_SHIFT_TMS, EXIT_SHIFT_TDO, EXIT_SHIFT_SIZE);
return value;
}
\ No newline at end of file
#include <Arduino.h>
#define IR_SELECT_TMS 0b01100
#define IR_SELECT_TMS 0b00110
#define IR_SELECT_TDO 0b00000
#define IR_SELECT_SIZE 5
#define DR_SELECT_TMS 0b0100
#define DR_SELECT_TMS 0b0010
#define DR_SELECT_TDO 0b0000
#define DR_SELECT_SIZE 4
......@@ -12,13 +12,17 @@
#define EXIT_SHIFT_TDO 0b000
#define EXIT_SHIFT_SIZE 3
#define _INPUT(bit) (bit + 0)
#define _OUTPUT(bit) (bit + 1)
#define _CONTROL(bit) (bit + 2)
// Instruction codes
#define IDCODE_TDO 0b00001
#define SAMPLE_PRELOAD_TDO 0b00010
#define EXTERNAL_TEST_TDO 0b00110
#define IR_UPDATE_TMS 0b00001
#define IR_UPDATE_TMS 0b10000
#define IR_UPDATE_SIZE 5
#define BOUNDARY_SIZE 148
......@@ -46,7 +50,7 @@ class JTAGPort {
void sendData(uint8_t tdo, uint8_t value);
void sendInst(uint8_t instruction);
uint8_t readData(uint8_t tdo_pos);
uint8_t readData();
uint32_t readData();
public:
// High level methods
void begin();
......
......@@ -12,4 +12,5 @@
platform = atmelavr
board = ATmega328P
framework = arduino
upload_port = COM13
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