-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserial_IN.h
More file actions
74 lines (54 loc) · 1.1 KB
/
Copy pathserial_IN.h
File metadata and controls
74 lines (54 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* serial_IN.h
*
* Created: 10-11-2016
* Author: Steven & Gaauwe
*/
#ifndef SERIAL_IN_H_
#define SERIAL_IN_H_
#include <avr/io.h>
#include <avr/interrupt.h>
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#define F_CPU 16000000
#define BUAD 9600
#define BRC ((F_CPU/16/BUAD) - 1)
#define RX_BUFFER_SIZE 514
char rxBuffer[RX_BUFFER_SIZE];
uint8_t rxReadPos = 0;
uint8_t rxWritePos = 0;
char getChar(void);
char peekChar(void);
char peekChar(void)
{
char ret = '\0';
if(rxReadPos != rxWritePos)
{
ret = rxBuffer[rxReadPos];
}
return ret;
}
char getChar(void)
{
char ret = '\0';
if(rxReadPos != rxWritePos)
{
ret = rxBuffer[rxReadPos];
rxReadPos++;
if(rxReadPos >= RX_BUFFER_SIZE)
{
rxReadPos = 0;
}
}
return ret;
}
ISR(USART_RX_vect)
{
rxBuffer[rxWritePos] = UDR0;
rxWritePos++;
if(rxWritePos >= RX_BUFFER_SIZE)
{
rxWritePos = 0;
}
}
#endif /* SERIAL_IN_H_ */