Permalink
Browse files

Modularize sw_uart and hw_uart for later use

  • Loading branch information...
h5b committed Apr 14, 2012
1 parent 7f584dc commit 16bbf652446b3bfe99aad61be313e8ee534435fb
Showing with 89 additions and 28 deletions.
  1. +1 −1 hw_uart/Makefile
  2. +1 −1 hw_uart/main.c
  3. +1 −1 hw_uart/{hw_uart.c → uart.c}
  4. +3 −3 hw_uart/{hw_uart.h → uart.h}
  5. +3 −2 sw_uart/Makefile
  6. +44 −0 sw_uart/main.c
  7. +1 −20 sw_uart/{sw_uart.c → uart.c}
  8. +35 −0 sw_uart/uart.h
View
@@ -2,7 +2,7 @@ include ../Makefile.inc
PROG=main
SRCS=$(PROG).c \
- hw_uart.c
+ uart.c
CLEANFILES=$(PROG).hex $(PROG).out
View
@@ -21,7 +21,7 @@
#include <util/delay.h>
#include "board.h"
-#include "hw_uart.h"
+#include "uart.h"
/* Delay in milliseconds used to display the UART heartbeat */
#define DELAY 500
@@ -27,7 +27,7 @@
#include <util/delay.h>
#include "board.h"
-#include "hw_uart.h"
+#include "uart.h"
void
uartInit(void)
@@ -15,8 +15,8 @@
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef _HW_UART_H_
-#define _HW_UART_H_
+#ifndef _UART_H_
+#define _UART_H_
#define BAUDRATE 9600
/* calculate the Baudrate Register Value based on F_CPU and BAUDRATE */
@@ -47,4 +47,4 @@ void uartPutString_P(const char*);
void uartTransmitByte(unsigned char);
unsigned char uartReceiveByte(void);
-#endif /* _HW_UART_H_ */
+#endif /* _UART_H_ */
View
@@ -1,7 +1,8 @@
include ../Makefile.inc
-PROG=sw_uart
-SRCS=$(PROG).c
+PROG=main
+SRCS=$(PROG).c \
+ uart.c
CLEANFILES=$(PROG).hex $(PROG).out
View
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011 Sebastian Trahm
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <avr/io.h>
+#include <avr/pgmspace.h>
+#include <util/delay.h>
+
+#include <uart.h>
+
+/* Delay in milliseconds used to display the UART heartbeat */
+#define DELAY 500
+
+int
+main(void)
+{
+ static const char infostring[] = "SOFT-UART Demo\r\n";
+
+ uartInit();
+
+ uartPutString(infostring);
+
+ while (1) {
+ /* output a heartbeat */
+ uartPutString(".. ");
+ _delay_ms(DELAY);
+ }
+
+ /* never reached */
+ return 0;
+}
@@ -19,9 +19,7 @@
#include <avr/pgmspace.h>
#include <util/delay.h>
-#define BAUDRATE 9600
-/* calculate the Baudrate Register Value based on F_CPU and BAUDRATE */
-#define UBRR_VAL ((F_CPU + BAUDRATE * 8L) / ((BAUDRATE * 16L) - 1))
+#include "uart.h"
void
uartInit(void)
@@ -66,20 +64,3 @@ uartPutString_P(const char *addr)
while ((c = pgm_read_byte(addr++)))
uartTransmitByte(c);
}
-
-int
-main(void)
-{
- static const char infostring[] = "SOFT-UART Demo\r\n";
-
- uartInit();
-
- uartPutString(infostring);
-
- while (1) {
- /* do nothing */
- }
-
- /* never reached */
- return 0;
-}
View
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2011 Sebastian Trahm
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _UART_H_
+#define _UART_H_
+
+#include <avr/io.h>
+#include <avr/pgmspace.h>
+#include <util/delay.h>
+
+#define BAUDRATE 9600
+/* calculate the Baudrate Register Value based on F_CPU and BAUDRATE */
+#define UBRR_VAL ((F_CPU + BAUDRATE * 8L) / ((BAUDRATE * 16L) - 1))
+
+void uartInit(void);
+unsigned char uartReceiveByte(void);
+void uartTransmitByte(unsigned char);
+void uartPutString(const char*);
+void uartPutString_P(const char*);
+
+#endif /* _UART_H_ */

0 comments on commit 16bbf65

Please sign in to comment.