aboutsummaryrefslogtreecommitdiff
path: root/usart.h
blob: 3a06baf9af9dfc0666fa66aff5f1d12666bb9191 (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>

#include "mcu/mcu_def.h"
#include "buffers.h"

#ifndef _IOE_USART_H_
#define _IOE_USART_H_

#ifndef MCUSUPPORT_USART
#error "No USART interface is known on your mcu."
#endif

enum usartBaudrate {
    USART_BAUDRATE_2400,
    USART_BAUDRATE_4800,
    USART_BAUDRATE_9600,
    USART_BAUDRATE_19200,
    USART_BAUDRATE_38400,
    USART_BAUDRATE_57600,
    USART_BAUDRATE_115200
};

enum usartParity {
    USART_PARITY_NONE,
    USART_PARITY_ODD,
    USART_PARITY_EVEN
};

enum usartStopBit {
    USART_STOPBIT_SINGLE = 1,
    USART_STOPBIT_DOUBLE = 2
};

enum usartDataBits {
    USART_DATABITS_5 = 5,
    USART_DATABITS_6 = 6,
    USART_DATABITS_7 = 7,
    USART_DATABITS_8 = 8,
    // USART_DATABITS_9 = 9 // Not supported yet
};

// Not supported yet. This is for synchronous mode only
//enum usartClockPolarity {
    //USART_CLOCKPOLARITY_FALLING,
    //USART_CLOCKPOLARITY_RISING
//};

#define USART_FRAMEERROR  _BV(FE0)
#define USART_DATAOVERRUN _BV(DOR0)
#define USART_PARITYERROR _BV(UPE0)

#if CONFIG_IOE_USART_INBUFFER_SIZE > 0
#define _IOE_USART_INBUFFER
volatile IOEBUFFER(_ioe_usart_inbuffer, CONFIG_IOE_USART_INBUFFER_SIZE);
#endif
#if CONFIG_IOE_USART_OUTBUFFER_SIZE > 0
#define _IOE_USART_OUTBUFFER
volatile IOEBUFFER(_ioe_usart_outbuffer, CONFIG_IOE_USART_OUTBUFFER_SIZE);
#endif


/*
 * Initialize USART device with 115200 baud rate, no parity, single stop bit,
 * and 8 data bits.
 * This function serves as fast default initialization.
 */
void usart_init_uart(void);
void usart_init_async(enum usartBaudrate,
                      enum usartParity, enum usartStopBit,
                      enum usartDataBits);
void usart_send(uint8_t data);
#ifdef _IOE_USART_OUTBUFFER
void usart_send_str(char *str);
#endif
#ifdef _IOE_USART_INBUFFER
uint8_t usart_get(void);
#endif
uint8_t usart_queryerror(void);
int8_t usart_busy(void);
#ifdef _IOE_USART_INBUFFER
uint8_t usart_inbuffered(void);
#endif
#ifdef _IOE_USART_OUTBUFFER
uint8_t usart_outbuffered(void);
#endif

// Following function must be user defined if relevant buffers not used.
extern void (*usart_receive)(uint8_t data);
extern void (*usart_sent)(void);

#endif /* _IOE_USART_H_ */