From b5bf389db17fe097150310989edfad64a52fa52c Mon Sep 17 00:00:00 2001 From: Alexey 'Cluster' Avdyukhin Date: Tue, 6 Jan 2015 15:24:49 +0300 Subject: Code clean up --- clujtag.c | 91 ++++++++++++++++++++++++++++++++------------------------------- clujtag.h | 12 +++++++++ defines.h | 18 +++++-------- 3 files changed, 65 insertions(+), 56 deletions(-) create mode 100644 clujtag.h diff --git a/clujtag.c b/clujtag.c index 56265d3..5392ea3 100644 --- a/clujtag.c +++ b/clujtag.c @@ -1,4 +1,5 @@ #include "USBtoSerial.h" +#include "clujtag.h" #include "defines.h" #include "jtag_commands.h" @@ -52,25 +53,25 @@ uint8_t get_usb_byte(void) void jtag_shutdown(void) { - PORT &= ~((1<> PIN_TDO) & 1); + CDC_Device_SendByte(&VirtualSerial_CDC_Interface, (PORT_PIN >> TDO_PIN) & 1); break; */ @@ -148,23 +149,23 @@ int main(void) data = get_usb_byte(); if (data == 0xff) continue; if (data&1) - PORT |= (1<> PIN_TDO) & 1); + PORT |= 1<> TDO_PIN) & 1); break; case JTAG_PULSE_SCK: - PORT &= ~(1<> 4)&1) != ((PORT_PIN >> PIN_TDO) & 1)) + if (((v >> 4)&1) != ((PORT_PIN >> TDO_PIN) & 1)) ok = 0; } } diff --git a/clujtag.h b/clujtag.h new file mode 100644 index 0000000..a525c19 --- /dev/null +++ b/clujtag.h @@ -0,0 +1,12 @@ +#include + +#define CLUJTAG_CONCAT(a, b) a ## b +#define CLUJTAG_OUTPORT(name) CLUJTAG_CONCAT(PORT, name) +#define CLUJTAG_INPORT(name) CLUJTAG_CONCAT(PIN, name) +#define CLUJTAG_DDRPORT(name) CLUJTAG_CONCAT(DDR, name) + +#define PORT CLUJTAG_OUTPORT(JTAG_PORT) +#define PORT_DDR CLUJTAG_DDRPORT(JTAG_PORT) +#define PORT_PIN CLUJTAG_INPORT(JTAG_PORT) +#define PORT_LED CLUJTAG_OUTPORT(LED_PORT) +#define PORT_LED_DDR CLUJTAG_DDRPORT(LED_PORT) diff --git a/defines.h b/defines.h index 6d3d7e8..6ff4d1c 100644 --- a/defines.h +++ b/defines.h @@ -1,12 +1,8 @@ -#define PORT PORTB -#define PORT_DDR DDRB -#define PORT_PIN PINB +#define JTAG_PORT B +#define TMS_PIN 0 +#define TCK_PIN 1 +#define TDO_PIN 2 +#define TDI_PIN 3 -#define PIN_TMS 0 -#define PIN_TCK 1 -#define PIN_TDO 2 -#define PIN_TDI 3 - -#define LED_PORT PORTD -#define LED_PORT_DDR DDRD -#define PIN_LED 6 +#define LED_PORT D +#define LED_PIN 6 -- cgit v1.2.3