aboutsummaryrefslogtreecommitdiff
path: root/include/usart.h
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2016-03-08 16:10:33 +0100
committerKarel Kočí <cynerd@email.cz>2016-03-08 16:10:33 +0100
commit5d29fe79d30f430ae326d9dc57ccfaed6fe61328 (patch)
tree8341804d561c0060176cbebc3f9a57c7c07f7816 /include/usart.h
parent4e773191d447ac434536262a6f204dd991d4ad77 (diff)
downloadavr-ioe-5d29fe79d30f430ae326d9dc57ccfaed6fe61328.tar.gz
avr-ioe-5d29fe79d30f430ae326d9dc57ccfaed6fe61328.tar.bz2
avr-ioe-5d29fe79d30f430ae326d9dc57ccfaed6fe61328.zip
Another full update of current work
Diffstat (limited to 'include/usart.h')
-rw-r--r--include/usart.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/include/usart.h b/include/usart.h
new file mode 100644
index 0000000..3ba5382
--- /dev/null
+++ b/include/usart.h
@@ -0,0 +1,64 @@
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#include "mcu/mcu_def.h"
+#include "tasks.h"
+#include "utils/buffer.h"
+
+#ifndef _USART_H_
+#define _USART_H_
+#ifdef CONFIG_USART
+
+// TODO clock polarity and synchronous mode
+
+#define USART_FRAMEERROR _BV(FE0)
+#define USART_DATAOVERRUN _BV(DOR0)
+#define USART_PARITYERROR _BV(UPE0)
+
+#if CONFIG_USART_INBUFFER_SIZE > 0
+#define _USART_INBUFFER
+volatile IOEBUFFER(uint8_t, _ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE);
+#endif
+#if CONFIG_USART_OUTBUFFER_SIZE > 0
+#define _USART_OUTBUFFER
+volatile IOEBUFFER(uint8_t, _ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE);
+#endif
+
+extern volatile int8_t _usart_busy;
+
+
+/*
+ * Initialize USART device.
+ */
+void usart_init_async(void);
+void usart_send(uint8_t data);
+#ifdef _USART_OUTBUFFER
+void usart_send_str(char *str);
+#endif
+#ifdef _USART_INBUFFER
+uint8_t usart_get(void);
+#endif
+static inline uint8_t usart_queryerror(void) {
+ return UCSR0A & (_BV(FE0) | _BV(DOR0) | _BV(UPE0));
+}
+static inline int8_t usart_busy(void) {
+ return _usart_busy;
+}
+#ifdef _USART_INBUFFER
+uint8_t usart_inbuffered(void);
+#endif
+#ifdef _USART_OUTBUFFER
+uint8_t usart_outbuffered(void);
+#endif
+#if (defined CONFIG_USART_INFILE) || (defined CONFIG_USART_OUTFILE)
+FILE *usart_async_open(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 /* CONFIG_USART */
+#endif /* _USART_H_ */