[avr] add debug macros for tracing interrupts

This commit is contained in:
Bart Van Der Meerssche 2011-01-15 23:06:48 +01:00
parent f74b124884
commit 65db2fe1dd
3 changed files with 38 additions and 15 deletions

14
mote/v2/avr/debug.h Normal file
View File

@ -0,0 +1,14 @@
#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);
/* 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

View File

@ -27,6 +27,7 @@
#include <util/delay.h>
#include "debug.h"
#include "main.h"
#include "uart.h"
#include "spi.h"
@ -36,10 +37,10 @@
volatile uint8_t spi_status, spi_high_hex;
uint8_t EEMEM first_EEPROM_byte_not_used_to_protect_from_brownout_corruption = 0xab;
uint8_t EEMEM first_EEPROM_byte_not_used_to_protect_from_brownout_corruption = 0xbe;
uint16_t EEMEM EEPROM_version = 210;
uint16_t version;
uint8_t EEMEM EEPROM_version[2] = {2, 1};
uint8_t version[2];
volatile struct event_struct EEMEM EEPROM_event = {0, 0};
volatile struct event_struct event;
@ -62,6 +63,8 @@ ISR(SPI_STC_vect)
uint8_t spi_rx, rx, tx;
uint16_t spi_tx;
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--;
@ -146,6 +149,8 @@ ISR(SPI_STC_vect)
// toggle the HEX bit in spi_status
spi_status ^= SPI_HIGH_HEX;
}
DBG_ISR_END
}
ISR(INT0_vect)
@ -173,6 +178,8 @@ ISR(TIMER1_COMPA_vect)
{
uint8_t muxn_l = phy_to_log[muxn];
DBG_ISR_BEGIN
MacU16X16to32(state[muxn_l].nano, sensor[muxn_l].meterconst, ADC);
if (state[muxn_l].nano > WATT) {
@ -204,6 +211,8 @@ ISR(TIMER1_COMPA_vect)
ADMUX |= muxn;
/* Start a new ADC conversion. */
ADCSRA |= (1<<ADSC);
DBG_ISR_END
}
ISR(ANALOG_COMP_vect)
@ -237,6 +246,12 @@ void setup_datastructs(void)
eeprom_read_block((void*)&sensor, (const void*)&EEPROM_sensor, sizeof(sensor));
}
void setup_led(void)
{
// set LED pin (PB0) as output pin
DDRB |= (1<<DDB0);
}
void setup_pulse_input(void)
{
// PD2=INT0 and PD3=INT1 configuration
@ -271,12 +286,8 @@ void setup_timer1(void)
TCCR1B |= 1<<WGM12;
// Enable output compare match interrupt for timer1 (DS p.136)
TIMSK1 |= (1<<OCIE1A);
#if DBG > 0
// Set PB1=OC1A as output pin
DDRB |= (1<<DDB1);
// Toggle pin OC1A=PB1 on compare match
TCCR1A |= 1<<COM1A0;
#endif
DBG_OC1A_TOGGLE
}
void setup_analog_comparator(void)
@ -338,6 +349,7 @@ int main(void)
//PORTD |= (1<<PD5);
setup_datastructs();
setup_led();
setup_adc();
setup_timer1();
setup_pulse_input();
@ -365,10 +377,6 @@ int main(void)
state[i].flags |= STATE_POWER;
}
}
// toggle the LED=PB0 pin
_delay_ms(50);
DDRB ^= (1<<PB0);
}
return 0;

View File

@ -115,8 +115,9 @@ CSTANDARD = -std=gnu99
# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)UL
# Enable debugging mode
#CDEFS += -DDBG=1
# Debugging mode
DBG = 0
CDEFS += -D DBG=$(DBG)
# uncomment and adapt these line if you want different UART library buffer size
CDEFS += -DUART_RX_BUFFER_SIZE=64