Revision 277
New buffer size, prevents buffer overflows in cardreader
cardreader.c | ||
---|---|---|
19 | 19 |
// This is only written in the PCINT2 intterupt or in the main loop |
20 | 20 |
// but not concurrently. read_card acts as an implicit lock |
21 | 21 |
volatile cr_flag_t cr_flag; |
22 |
volatile uint8_t cr_buf[512];
|
|
22 |
volatile uint8_t cr_buf[CR_BUF_SIZE];
|
|
23 | 23 |
volatile uint16_t cr_buf_idx; |
24 | 24 |
volatile uint8_t read_card; |
25 | 25 |
|
... | ... | |
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
int8_t parse_card(uint8_t *buf, uint8_t *buflen) { |
56 |
int32_t i = cr_buf_idx - 1;
|
|
56 |
int16_t i = cr_buf_idx - 1;
|
|
57 | 57 |
uint8_t j = 0; |
58 | 58 |
uint8_t start_sentinal = 0; |
59 | 59 |
uint8_t byte_idx = 0; |
... | ... | |
142 | 142 |
} |
143 | 143 |
|
144 | 144 |
// Read data in on the downtick of the clock |
145 |
if (!(PIND & CR_CLK)) { |
|
145 |
if ((!(PIND & CR_CLK))) { |
|
146 |
if (cr_buf_idx < CR_BUF_SIZE) { |
|
146 | 147 |
// Read data from card reader and flip since ours inverts |
147 | 148 |
cr_buf[cr_buf_idx] = !(PIND & CR_DATA); |
148 | 149 |
cr_buf_idx++; |
150 |
} else { |
|
151 |
toggle_led(LED_RED, ON); |
|
152 |
} |
|
149 | 153 |
} |
150 | 154 |
} |
Also available in: Unified diff