ready for testing

parent b070258e
......@@ -3,9 +3,9 @@
void JTAGPort::begin() {
DDRB |= _BV(TMS) |
_BV(TCK) |
_BV(TDI);
_BV(TDO);
DDRB &= ~_BV(TDO);
DDRB &= ~_BV(TDI);
PORTB &= ~(_BV(TMS) |
_BV(TCK) |
......@@ -29,37 +29,37 @@ void JTAGPort::clockPulse() {
delayMicroseconds(10);
}
void JTAGPort::sendBits(uint8_t tms, uint8_t tdi) {
void JTAGPort::sendBits(uint8_t tms, uint8_t tdo) {
PORTB = tms ? PORTB | _BV(TMS) : PORTB & ~_BV(TMS);
PORTB = tdi ? PORTB | _BV(TDI) : PORTB & ~_BV(TDI);
PORTB = tdo ? PORTB | _BV(TDO) : PORTB & ~_BV(TDO);
this->clockPulse();
}
void JTAGPort::sendBits(uint8_t tms, uint8_t tdi, uint8_t size) {
void JTAGPort::sendBits(uint8_t tms, uint8_t tdo, uint8_t size) {
for(int i = 0; i < size; i++)
this->sendBits((tms && _BV(i)), (tms && _BV(i)));
this->sendBits((tms && _BV(i)), (tdo && _BV(i)));
}
void JTAGPort::setDR() {
this->reset();
this->sendBits(DR_SELECT_TMS, DR_SELECT_TDI, DR_SELECT_SIZE);
this->sendBits(DR_SELECT_TMS, DR_SELECT_TDO, DR_SELECT_SIZE);
}
void JTAGPort::setIR() {
this->reset();
this->sendBits(IR_SELECT_TMS, IR_SELECT_TDI, IR_SELECT_SIZE);
this->sendBits(IR_SELECT_TMS, IR_SELECT_TDO, IR_SELECT_SIZE);
}
void JTAGPort::sendData(uint8_t tdi_pos, uint8_t value) {
void JTAGPort::sendData(uint8_t tdo_pos, uint8_t value) {
this->reset();
this->setDR();
this->sendBits(0, 1);
for(int i = 0; i < tdi_pos - 2; i++)
for(int i = 0; i < tdo_pos - 2; i++)
this->sendBits(0, 0);
this->sendBits(EXIT_SHIFT_TMS, EXIT_SHIFT_TDI, EXIT_SHIFT_SIZE);
this->sendBits(EXIT_SHIFT_TMS, EXIT_SHIFT_TDO, EXIT_SHIFT_SIZE);
}
......@@ -69,22 +69,70 @@ void JTAGPort::sendInst(uint8_t instruction) {
this->sendBits(IR_UPDATE_TMS, instruction, IR_UPDATE_SIZE);
this->sendBits(EXIT_SHIFT_TMS >> 1, EXIT_SHIFT_TDI, EXIT_SHIFT_SIZE - 1);
this->sendBits(EXIT_SHIFT_TMS >> 1, EXIT_SHIFT_TDO, EXIT_SHIFT_SIZE - 1);
}
uint8_t JTAGPort::readData(uint8_t tdi_pos) {
uint8_t JTAGPort::readData(uint8_t tdo_pos) {
uint8_t value = 0;
this->reset();
this->setDR();
for(int i = 0; i < (BOUNDARY_SIZE - tdi_pos); i++)
for(int i = 0; i < (BOUNDARY_SIZE - tdo_pos); i++)
this->sendBits(0, 0);
value = PORTB && _BV(TDO);
this->sendBits(EXIT_SHIFT_TMS, EXIT_SHIFT_TDI, EXIT_SHIFT_SIZE);
this->sendBits(EXIT_SHIFT_TMS, EXIT_SHIFT_TDO, EXIT_SHIFT_SIZE);
return value;
}
uint8_t JTAGPort::readData() {
this->sendBits(0, 0);
return (PORTB && _BV(TDI));
}
uint32_t JTAGPort::getID() {
uint32_t value;
this->reset();
this->sendInst(IDCODE_TDO);
this->reset();
this->setDR();
for(int i = 0; i < IDCODE_SIZE; i++)
value |= (this->readData() << i);
this->sendBits(EXIT_SHIFT_TMS, EXIT_SHIFT_TDO, EXIT_SHIFT_SIZE);
return value;
}
void JTAGPort::setLED(uint8_t value) {
this->reset();
this->sendInst(EXTERNAL_TEST_TDO);
this->reset();
this->setDR();
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();
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_TDI 0b00000
#define IR_SELECT_TDO 0b00000
#define IR_SELECT_SIZE 5
#define DR_SELECT_TMS 0b0100
#define DR_SELECT_TDI 0b0000
#define DR_SELECT_TDO 0b0000
#define DR_SELECT_SIZE 4
#define EXIT_SHIFT_TMS 0b011
#define EXIT_SHIFT_TDI 0b000
#define EXIT_SHIFT_TDO 0b000
#define EXIT_SHIFT_SIZE 3
#define IDCODE_TDI 0b00001
// Instruction codes
#define IDCODE_TDO 0b00001
#define SAMPLE_PRELOAD_TDO 0b00010
#define EXTERNAL_TEST_TDO 0b00110
#define IR_UPDATE_TMS 0b00001
#define IR_UPDATE_SIZE 5
#define BOUNDARY_SIZE 148
#define ID_CODE_SIZE 32
#define IDCODE_SIZE 32
#define TMS PORTB0
#define TCK PORTB1
#define TDI PORTB2
#define TDO PORTB3
#define LED_PIN 18
#define BUTTON_PIN 3
class JTAGPort {
public:
void begin();
void reset();
void clockPulse();
void sendBits(uint8_t tms, uint8_t tdi);
void sendBits(uint8_t tms, uint8_t tdi, uint8_t size);
void sendBits(uint8_t tms, uint8_t tdo);
void sendBits(uint8_t tms, uint8_t tdo, uint8_t size);
void setDR();
void setIR();
void sendData(uint8_t tdi, uint8_t value);
void sendData(uint8_t tdo, uint8_t value);
void sendInst(uint8_t instruction);
uint8_t readData(uint8_t tdi_pos);
uint8_t readData(uint8_t tdo_pos);
uint8_t readData();
// High level methods
uint32_t getID();
void setLED(uint8_t value);
uint8_t checkButton();
};
JTAGPort JTAG;
\ No newline at end of file
extern JTAGPort JTAG;
\ No newline at end of file
......@@ -4,18 +4,20 @@
#define BAUD 9600
void print_commands() {
Serial.println("Command list");
Serial.println("d - get ID CODE in hex");
Serial.println("1 - turn on LED");
Serial.println("0 - turn off LED");
Serial.println("b - get state of button in pin 29");
Serial.println("i - print command list");
Serial.println("Command list:");
Serial.println("d - get ID CODE in hex;");
Serial.println("1 - turn on LED;");
Serial.println("0 - turn off LED;");
Serial.println("b - get state of button in pin 29;");
Serial.println("i - print command list.");
}
void setup() {
JTAG.begin();
Serial.begin(BAUD);
Serial.println("Welcome\n\n");
Serial.println("Welcome to JTAG controller!\n\n");
print_commands();
}
......@@ -23,22 +25,32 @@ void loop() {
if(Serial.available()){
switch(Serial.read()) {
case 'd':
Serial.println("Getting ID CODE...");
Serial.print("ID CODE is 0x");
Serial.print(JTAG.getID(), HEX);
Serial.println(".");
break;
case '1':
Serial.println("Turning on LED...");
JTAG.setLED(HIGH);
Serial.println("LED is on!");
break;
case '0':
Serial.println("Turning off LED...");
JTAG.setLED(LOW);
Serial.println("LED is off!");
break;
case 'b':
Serial.println("Checking button state...");
Serial.print("Button is ");
Serial.print(JTAG.checkButton() ? "not pressed" : "pressed");
Serial.println("!");
break;
case 'i':
print_commands();
break;
default:
Serial.println("Command not available!");
}
}
}
\ 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