Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/clujtag-avr.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2015-01-06 15:24:49 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2015-01-06 15:24:49 +0300
commitb5bf389db17fe097150310989edfad64a52fa52c (patch)
treecae927d5907ecf25c700502b6a8d7a220ca41e9a
parentebf2d00be3d45f05caf7f059f6b252f5700e39ff (diff)
Code clean up
-rw-r--r--clujtag.c91
-rw-r--r--clujtag.h12
-rw-r--r--defines.h18
3 files changed, 65 insertions, 56 deletions
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_TMS) | (1<<PIN_TCK) | (1<<PIN_TDO) | (1<<PIN_TDI));
- PORT_DDR &= ~((1<<PIN_TMS) | (1<<PIN_TCK) | (1<<PIN_TDO) | (1<<PIN_TDI));
+ PORT &= ~((1<<TMS_PIN) | (1<<TCK_PIN) | (1<<TDO_PIN) | (1<<TDI_PIN));
+ PORT_DDR &= ~((1<<TMS_PIN) | (1<<TCK_PIN) | (1<<TDO_PIN) | (1<<TDI_PIN));
}
void jtag_setup(void)
{
- PORT &= ~((1<<PIN_TMS) | (1<<PIN_TCK) | (1<<PIN_TDO) | (1<<PIN_TDI));
- PORT_DDR |= (1<<PIN_TMS) | (1<<PIN_TCK) | (1<<PIN_TDI);
- PORT_DDR &= ~(1<<PIN_TDO);
+ PORT &= ~((1<<TMS_PIN) | (1<<TCK_PIN) | (1<<TDO_PIN) | (1<<TDI_PIN));
+ PORT_DDR |= (1<<TMS_PIN) | (1<<TCK_PIN) | (1<<TDI_PIN);
+ PORT_DDR &= ~(1<<TDO_PIN);
}
int main(void)
{
int initialized = 0;
jtag_shutdown();
-#ifdef PIN_LED
-#ifdef LED_PORT_DDR
- LED_PORT_DDR |= 1<<PIN_LED;
- LED_PORT &= ~(1<<PIN_LED);
+#ifdef LED_PIN
+#ifdef PORT_LED_DDR
+ PORT_LED_DDR |= 1<<LED_PIN;
+ PORT_LED &= ~(1<<LED_PIN);
#endif
#endif
@@ -82,10 +83,10 @@ int main(void)
{
uint8_t command = get_usb_byte();
uint8_t data, data2, ok, v, n;
-#ifdef PIN_LED
-#ifdef LED_PORT
+#ifdef LED_PIN
+#ifdef PORT_LED
if (initialized)
- LED_PORT ^= 1<<PIN_LED;
+ PORT_LED ^= 1<<LED_PIN;
#endif
#endif
@@ -94,9 +95,9 @@ int main(void)
case JTAG_SETUP:
jtag_setup();
initialized = 1;
-#ifdef PIN_LED
-#ifdef LED_PORT
- LED_PORT |= 1<<PIN_LED;
+#ifdef LED_PIN
+#ifdef PORT_LED
+ PORT_LED |= 1<<LED_PIN;
#endif
#endif
break;
@@ -104,9 +105,9 @@ int main(void)
case JTAG_SHUTDOWN:
jtag_shutdown();
initialized = 0;
-#ifdef PIN_LED
-#ifdef LED_PORT
- LED_PORT &= ~(1<<PIN_LED);
+#ifdef LED_PIN
+#ifdef PORT_LED
+ PORT_LED &= ~(1<<LED_PIN);
#endif
#endif
break;
@@ -116,31 +117,31 @@ int main(void)
data = get_usb_byte();
if (data == 0xff) continue;
if (data)
- PORT |= (1<<PIN_TMS);
+ PORT |= (1<<TMS_PIN);
else
- PORT &= ~(1<<PIN_TMS);
+ PORT &= ~(1<<TMS_PIN);
break;
case JTAG_SET_TCK:
data = get_usb_byte();
if (data == 0xff) continue;
if (data)
- PORT |= (1<<PIN_TCK);
+ PORT |= (1<<TCK_PIN);
else
- PORT &= ~(1<<PIN_TCK);
+ PORT &= ~(1<<TCK_PIN);
break;
case JTAG_SET_TDI:
data = get_usb_byte();
if (data == 0xff) continue;
if (data)
- PORT |= (1<<PIN_TDI);
+ PORT |= (1<<TDI_PIN);
else
- PORT &= ~(1<<PIN_TDI);
+ PORT &= ~(1<<TDI_PIN);
break;
case JTAG_GET_TDO:
- CDC_Device_SendByte(&VirtualSerial_CDC_Interface, (PORT_PIN >> 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_TMS);
+ PORT |= (1<<TMS_PIN);
else
- PORT &= ~(1<<PIN_TMS);
+ PORT &= ~(1<<TMS_PIN);
if (data&(1<<1))
- PORT |= (1<<PIN_TDI);
+ PORT |= (1<<TDI_PIN);
else
- PORT &= ~(1<<PIN_TDI);
- PORT &= ~(1<<PIN_TCK);
+ PORT &= ~(1<<TDI_PIN);
+ PORT &= ~(1<<TCK_PIN);
_delay_us(1);
- PORT |= 1<<PIN_TCK;
- CDC_Device_SendByte(&VirtualSerial_CDC_Interface, (PORT_PIN >> PIN_TDO) & 1);
+ PORT |= 1<<TCK_PIN;
+ CDC_Device_SendByte(&VirtualSerial_CDC_Interface, (PORT_PIN >> TDO_PIN) & 1);
break;
case JTAG_PULSE_SCK:
- PORT &= ~(1<<PIN_TCK);
+ PORT &= ~(1<<TCK_PIN);
_delay_us(1);
- PORT |= 1<<PIN_TCK;
+ PORT |= 1<<TCK_PIN;
break;
case JTAG_PULSE_TCK_DELAY:
@@ -173,14 +174,14 @@ int main(void)
data2 = get_usb_byte();
if (data2 == 0xff) continue;
if (data)
- PORT |= (1<<PIN_TMS);
+ PORT |= (1<<TMS_PIN);
else
- PORT &= ~(1<<PIN_TMS);
+ PORT &= ~(1<<TMS_PIN);
for (n = 0; n < data2; n++)
{
- PORT &= ~(1<<PIN_TCK);
+ PORT &= ~(1<<TCK_PIN);
_delay_us(1);
- PORT |= 1<<PIN_TCK;
+ PORT |= 1<<TCK_PIN;
_delay_us(1);
}
break;
@@ -195,23 +196,23 @@ int main(void)
v = get_usb_byte();
if (v == 0xff) break;
if (v&1)
- PORT |= (1<<PIN_TMS);
+ PORT |= (1<<TMS_PIN);
else
- PORT &= ~(1<<PIN_TMS);
+ PORT &= ~(1<<TMS_PIN);
if (v&(1<<1))
{
if (v&(1<<2))
- PORT |= (1<<PIN_TDI);
+ PORT |= (1<<TDI_PIN);
else
- PORT &= ~(1<<PIN_TDI);
+ PORT &= ~(1<<TDI_PIN);
}
- PORT &= ~(1<<PIN_TCK);
+ PORT &= ~(1<<TCK_PIN);
_delay_us(1);
- PORT |= 1<<PIN_TCK;
+ PORT |= 1<<TCK_PIN;
_delay_us(1);
if (v&(1<<3))
{
- if (((v >> 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 <defines.h>
+
+#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