[avr] couple the LED heartbeat to activity on the SPI bus

This commit is contained in:
Bart Van Der Meerssche 2011-01-16 10:44:48 +01:00
parent 9c47f71514
commit 0af40cf27d
2 changed files with 23 additions and 14 deletions

View File

@ -1,14 +1,20 @@
#if DBG > 0
/* set LED pin high/low at the start/end of an ISR */
#define DBG_ISR_BEGIN PORTB |= (1<<PB0);
#define DBG_ISR_END PORTB &= ~(1<<PB0);
#define DBG_ISR_BEGIN() PORTB |= (1<<PB0)
#define DBG_ISR_END() PORTB &= ~(1<<PB0)
/* Set PB1=OC1A as output pin and toggle this pin on TIMER1 compare match */
#define DBG_OC1A_TOGGLE DDRB |= (1<<DDB1); \
TCCR1A |= 1<<COM1A0;
#else
#define DBG_ISR_BEGIN /* nothing */
#define DBG_ISR_END /* nothing */
#define DBG_OC1A_TOGGLE /* nothing */
#endif
#define DBG_OC1A_TOGGLE() DDRB |= (1<<DDB1); \
TCCR1A |= 1<<COM1A0
#define DBG_LED_ON() /* nothing */
#define DBG_LED_OFF() /* nothing */
#else
#define DBG_ISR_BEGIN() /* nothing */
#define DBG_ISR_END() /* nothing */
#define DBG_OC1A_TOGGLE() /* nothing */
/* LED behaviour in non-debugging mode */
#define DBG_LED_ON() PORTB &= ~(1<<PB0)
#define DBG_LED_OFF() PORTB |= (1<<PB0)
#endif

View File

@ -63,11 +63,12 @@ ISR(SPI_STC_vect)
uint8_t spi_rx, rx, tx;
uint16_t spi_tx;
DBG_ISR_BEGIN
DBG_ISR_BEGIN();
// the SPI is double-buffered, requiring two NO_OPs when switching from Tx to Rx
if (spi_status & (SPI_NO_OP_1 | SPI_NO_OP_2)) {
spi_status--;
DBG_LED_ON();
return;
}
@ -127,9 +128,11 @@ ISR(SPI_STC_vect)
break;
case SPI_FORWARD_TO_UART_PORT:
spi_status |= SPI_TO_FROM_UART;
DBG_LED_OFF();
break;
case SPI_FORWARD_TO_CTRL_PORT:
spi_status &= ~SPI_TO_FROM_UART;
DBG_LED_OFF();
break;
default:
if (spi_status & SPI_HIGH_HEX) {
@ -150,7 +153,7 @@ ISR(SPI_STC_vect)
spi_status ^= SPI_HIGH_HEX;
}
DBG_ISR_END
DBG_ISR_END();
}
ISR(INT0_vect)
@ -178,7 +181,7 @@ ISR(TIMER1_COMPA_vect)
{
uint8_t muxn_l = phy_to_log[muxn];
DBG_ISR_BEGIN
DBG_ISR_BEGIN();
MacU16X16to32(state[muxn_l].nano, sensor[muxn_l].meterconst, ADC);
@ -212,7 +215,7 @@ ISR(TIMER1_COMPA_vect)
/* Start a new ADC conversion. */
ADCSRA |= (1<<ADSC);
DBG_ISR_END
DBG_ISR_END();
}
ISR(ANALOG_COMP_vect)
@ -287,7 +290,7 @@ void setup_timer1(void)
// Enable output compare match interrupt for timer1 (DS p.136)
TIMSK1 |= (1<<OCIE1A);
DBG_OC1A_TOGGLE
DBG_OC1A_TOGGLE();
}
void setup_analog_comparator(void)