Revision aadf0a75

View differences:

scout_avr/Makefile
25 25
	avr-g++ $(FLAGS) $(SRC) -o scout_avr.elf
26 26

  
27 27
program: scout_avr.hex
28
	avrdude -p $(PART) -c $(PROG) -P usb -B 5 -U flash:w:scout_avr.hex
28
	avrdude -p $(PART) -c $(PROG) -P usb -B 1 -U flash:w:scout_avr.hex
29 29

  
30 30
clean:
31 31
	rm -f scout_avr.elf scout_avr.hex
scout_avr/src/Atmega128rfa1.cpp
15 15
unsigned char t0_count, t0_error;
16 16
unsigned long millis;
17 17

  
18
int rx_start = 0, rx_end = 0;
18
int rx_start, rx_end;
19 19
char rx_buffer[RX_BUFFER_SIZE];
20 20

  
21 21
Atmega128rfa1::Atmega128rfa1()
......
45 45
ISR(USART0_RX_vect)
46 46
{
47 47
  char data = UDR0;
48
  if (rx_end == rx_start-1 || (rx_start == 0 && rx_end == RX_BUFFER_SIZE-1))
48
  int new_end = rx_end+1;
49
  if (new_end == RX_BUFFER_SIZE) {
50
    new_end = 0;
51
  }
52
  if (new_end == rx_start)
49 53
  {
50 54
    // TODO warn of buffer overflow?
51 55
  }
52 56
  else
53 57
  {
54 58
    rx_buffer[rx_end] = data;
55
    rx_end++;
56
    if (rx_end == RX_BUFFER_SIZE)
57
      rx_end = 0;
59
    rx_end = new_end;
58 60
  }
59 61
}
60 62

  
......
88 90

  
89 91
int Atmega128rfa1::read()
90 92
{
93
  int ret;
91 94
  cli();
92 95
  if (rx_start == rx_end)
93
    return -1;
96
    ret = -1;
94 97
  else
95 98
  {
96
    int ret = rx_buffer[rx_start];
99
    ret = rx_buffer[rx_start];
97 100
    rx_start++;
98 101
    if (rx_start == RX_BUFFER_SIZE)
99 102
      rx_start = 0;
100
    return ret;
101 103
  }
102 104
  sei();
105
  return ret;
103 106
}
104 107

  
105 108
void Atmega128rfa1::write(uint8_t* data, int length)

Also available in: Unified diff