-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhserial.h
57 lines (49 loc) · 1.48 KB
/
hserial.h
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
/*
* hserial.h
*
* Created on: Jul 25, 2009
* Author: Orlando Arias
* License: GPLv3
*
* Based off: HardwareSerial.h
*/
#ifndef HSERIAL_H_
#define HSERIAL_H_
#include <inttypes.h>
#include "wiring.h"
#include "wiring_private.h"
#define RX_BUFFER_SIZE 128
typedef struct _ring_buffer {
unsigned char buffer[RX_BUFFER_SIZE];
int head;
int tail;
} ring_buffer_t;
typedef struct _hserial {
ring_buffer_t *rx_buffer;
volatile uint8_t *ubrrh;
volatile uint8_t *ubrrl;
volatile uint8_t *ucsra;
volatile uint8_t *ucsrb;
volatile uint8_t *udr;
uint8_t rxen;
uint8_t txen;
uint8_t rxcie;
uint8_t udre;
} hserial;
/* The ATmega1280 has 4 serial ports available
* thus we check whether we are cross compiling to
* this CPU and create as many serial ports as needed.
*/
#if defined(__AVR_ATmega1280__)
hserial Serial_[4];
#else
hserial Serial_[1];
#endif
void hs_init(); // Initializes all available serial ports.
void hs_start(const int port, unsigned long baud); // Sets up a serial port.
uint8_t hs_available(const int port); // Checks whether data is available on the port
void hs_flush(const int port); // Flushes the contents on the serial port.
int hs_getChar(const int port); // Gets next character (rx) on serial port.
void hs_writeChar(const int port, uint8_t c); // Write a character (tx) on serial port.
void hs_writeStr(const int port, const char str[]); // Write a string to serial port (tx).
#endif /* HSERIAL_H_ */