Commits

Trammell Hudson committed 3dd0f57

assembly looks correct

  • Participants
  • Parent commits 318bd2a

Comments (0)

Files changed (1)

 volatile  register  uint8_t r16 __asm__("r16"); 
 volatile  register  uint8_t r17 __asm__("r17"); 
 
-
+/**
+ * Delay a specific number of clock cycles.
+ *
+ * rjmp is 2 clocks, nop is 1.
+ * So do one nop if the delay is an odd value and then rjmp's for n/2.
+ */
 static inline void
 delay(
 	const uint8_t n
 )
 {
-	switch (n)
+	if (n % 2 == 1)
+		asm("nop");
+
+	switch (n/2)
 	{
-	case 8: asm("nop");
-	case 7: asm("nop");
-	case 6: asm("nop");
-	case 5: asm("nop");
-	case 4: asm("nop");
-	case 3: asm("nop");
-	case 2: asm("nop");
-	case 1: asm("nop");
+	case 8: asm("rjmp .+0");
+	case 7: asm("rjmp .+0");
+	case 6: asm("rjmp .+0");
+	case 5: asm("rjmp .+0");
+	case 4: asm("rjmp .+0");
+	case 3: asm("rjmp .+0");
+	case 2: asm("rjmp .+0");
+	case 1: asm("rjmp .+0");
 	case 0: break;
 	}
 }
 
 
-static inline void
+static void
+__attribute__((__always_inline__))
 toggle(	
 	const uint8_t n
 )
 
 
 static void
+__attribute__((__always_inline__))
 baseband_0(void
 	//uint8_t startloop
 )
 
 
 static void
+__attribute__((__always_inline__))
 baseband_1(void
 	//uint8_t startloop
 )
 {
 	//if (startloop)
-		toggle(3);
+		toggle(2);
 	//else
 		//toggle(5);
 
 
 
 static void
+__attribute__((__always_inline__))
 manchester_bit(
 	const uint8_t x
 )
 #define HID_SITE_CODE       42
 #define HID_UNIQUE_ID       23946     // May be written on the back of the card
 
+static void
+__attribute__((__noinline__))
+//__attribute__((section(".fini8")))
+hid_output(void)
+{
+	header();
+	manchester(HID_MFG_CODE, 20);
+	manchester(HID_SITE_CODE, 8);
+	manchester(HID_UNIQUE_ID, 16);
+	manchester(0, 1);
+}
+
 int
+__attribute__((section(".init9")))
 main(void)
 {
 	r16 = 0;
 	r17 = 3;
 
 	while (1)
-	{
-		header();
-		manchester(HID_MFG_CODE, 20);
-		manchester(HID_SITE_CODE, 8);
-		manchester(HID_UNIQUE_ID, 16);
-		manchester(0, 1);
-	}
+		hid_output();
 }
+