Project

General

Profile

Revision b3a1dae4

IDb3a1dae46e7cddabec7c90824b515cf26c574420
Parent 240c122b
Child 619a1b8d

Added by Thomas Mullins over 10 years ago

Added send queue

View differences:

scout_avr/bom/tiny-twi.c
7 7
#define SCL PB2
8 8

  
9 9
#define RECV_BUF_SIZE 2
10
#define SEND_BUF_SIZE 100
10 11

  
11 12
uint8_t address;
12 13

  
......
24 25
uint8_t recv_idx;
25 26
uint8_t recv_data[RECV_BUF_SIZE];
26 27
slave_rx_t onDataRecieved;
27
uint8_t temp;
28
struct {
29
  uint8_t start;
30
  uint8_t end;
31
  uint8_t data[SEND_BUF_SIZE];
32
  bool    full;
33
} send_queue;
28 34

  
29 35
static void twi_set_ctr(char n) {
30 36
  USISR = n;
......
72 78

  
73 79
static void twi_send_data() {
74 80
  twi_set_ctr(0);
75
  // TODO set USIDR from buffer
76
  USIDR = ++temp;
81
  if (send_queue.start == send_queue.end && !send_queue.full) {
82
    USIDR = 0;
83
  } else {
84
    USIDR = send_queue.data[send_queue.start++];
85
    if (send_queue.start == SEND_BUF_SIZE)
86
      send_queue.start = 0;
87
    send_queue.full = 0;
88
  }
77 89
  DDRB |= _BV(SDA);
78 90
  state = SEND_DATA;
79 91
}
......
156 168
  address = addr;
157 169
}
158 170

  
171
void send_data(uint8_t* data, uint8_t length) {
172
  uint8_t i;
173
  for (i=0; i<length && !send_queue.full; i++) {
174
    send_queue.data[send_queue.end++] = data[i];
175
    if (send_queue.end == SEND_BUF_SIZE)
176
      send_queue.end = 0;
177
    if (send_queue.end == send_queue.start)
178
      send_queue.full = 1;
179
  }
180
}
181

  
159 182
void testCB(uint8_t* data, int length) {
183
  send_data(data, length);
160 184
}
161 185

  
162 186

  

Also available in: Unified diff