I'm using the 6450 in an application that requires every single IO line, including the JTAG ones on port F. Those particular pins read some DIP switches via the following code:
char read_switches(void){ char s; JTD_Clear(); // Disable JTAG interface s = (PINF & 0x70); JTD_Set(); // Re-enable JTAG interface return s; } void JTD_Set(void) { char x = 0; // JTD isn't supposed to be changed if OCDEN is programmed (== 0), // so test it and only set JTD if it's unprogrammed (== 1). x = read_fuse(); // Read fuse high byte to check OCDEN if ((x & (1 << OCDEN)) != 0) { SREG &= 0x7ff; // Disable interrupts to insure uninterrupted write to MCUCR. MCUCR |= 0x80; // Set JTD to disable JTAG interface MCUCR |= 0x80; // Must write it twice within 4 cycles SREG |= 0x80; // Re-enable interrupts } } void JTD_Clear(void) { char x = 0; // JTD isn't supposed to be changed if OCDEN is programmed (== 0), // so test it and only clear JTD if OCDEN's unprogrammed (== 1). x = read_fuse(); // Read fuse high byte to check OCDEN if ((x & (1 << OCDEN)) != 0) { SREG &= 0x7ff; // Disable interrupts to insure uninterrupted write to MCUCR. MCUCR &= 0x7f; // Clear JTD to enable JTAG interface MCUCR &= 0x7f; // Must write it twice within 4 cycles SREG |= 0x80; // Re-enable interrupts } } char read_fuse(void) { // point z to 0x0003 (high fuse byte ) asm("ldi R31,0x00\n" "ldi R30,0x03\n" "ldi R16,0x09\n" "out 0x37,R16\n" "lpm R16,z\n" "ret\n"); }
read_switches() is executed once per second and should prevent reads during debug sessions, which would disrupt the JTAG interface. I'm willing to live with the inability to use the debugger to debug my switch-related code. What I'm wondering is, what would happen in the (admittedly unlikely) event of my debugger (or programmer) trying to establish a connection during the brief period in JTD_set() after OCDEN is tested and JTD is set? I could move the disable interrupts line to before the test, to reduce the window of exposure, but it doesn't seem like I can eliminate it completely, which, of course, would be my preference. Is there a potential hosing in store for me (here or anyplace else you notice)? Thanks for your help.