Skip to content

Commit

Permalink
Modularize sw_uart and hw_uart for later use
Browse files Browse the repository at this point in the history
  • Loading branch information
h5b committed Apr 14, 2012
1 parent 7f584dc commit 16bbf65
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 28 deletions.
2 changes: 1 addition & 1 deletion hw_uart/Makefile
Expand Up @@ -2,7 +2,7 @@ include ../Makefile.inc


PROG=main PROG=main
SRCS=$(PROG).c \ SRCS=$(PROG).c \
hw_uart.c uart.c


CLEANFILES=$(PROG).hex $(PROG).out CLEANFILES=$(PROG).hex $(PROG).out


Expand Down
2 changes: 1 addition & 1 deletion hw_uart/main.c
Expand Up @@ -21,7 +21,7 @@
#include <util/delay.h> #include <util/delay.h>


#include "board.h" #include "board.h"
#include "hw_uart.h" #include "uart.h"


/* Delay in milliseconds used to display the UART heartbeat */ /* Delay in milliseconds used to display the UART heartbeat */
#define DELAY 500 #define DELAY 500
Expand Down
2 changes: 1 addition & 1 deletion hw_uart/hw_uart.c → hw_uart/uart.c
Expand Up @@ -27,7 +27,7 @@
#include <util/delay.h> #include <util/delay.h>


#include "board.h" #include "board.h"
#include "hw_uart.h" #include "uart.h"


void void
uartInit(void) uartInit(void)
Expand Down
6 changes: 3 additions & 3 deletions hw_uart/hw_uart.h → hw_uart/uart.h
Expand Up @@ -15,8 +15,8 @@
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */


#ifndef _HW_UART_H_ #ifndef _UART_H_
#define _HW_UART_H_ #define _UART_H_


#define BAUDRATE 9600 #define BAUDRATE 9600
/* calculate the Baudrate Register Value based on F_CPU and BAUDRATE */ /* calculate the Baudrate Register Value based on F_CPU and BAUDRATE */
Expand Down Expand Up @@ -47,4 +47,4 @@ void uartPutString_P(const char*);
void uartTransmitByte(unsigned char); void uartTransmitByte(unsigned char);
unsigned char uartReceiveByte(void); unsigned char uartReceiveByte(void);


#endif /* _HW_UART_H_ */ #endif /* _UART_H_ */
5 changes: 3 additions & 2 deletions sw_uart/Makefile
@@ -1,7 +1,8 @@
include ../Makefile.inc include ../Makefile.inc


PROG=sw_uart PROG=main
SRCS=$(PROG).c SRCS=$(PROG).c \
uart.c


CLEANFILES=$(PROG).hex $(PROG).out CLEANFILES=$(PROG).hex $(PROG).out


Expand Down
44 changes: 44 additions & 0 deletions sw_uart/main.c
@@ -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;
}
21 changes: 1 addition & 20 deletions sw_uart/sw_uart.c → sw_uart/uart.c
Expand Up @@ -19,9 +19,7 @@
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include <util/delay.h> #include <util/delay.h>


#define BAUDRATE 9600 #include "uart.h"
/* calculate the Baudrate Register Value based on F_CPU and BAUDRATE */
#define UBRR_VAL ((F_CPU + BAUDRATE * 8L) / ((BAUDRATE * 16L) - 1))


void void
uartInit(void) uartInit(void)
Expand Down Expand Up @@ -66,20 +64,3 @@ uartPutString_P(const char *addr)
while ((c = pgm_read_byte(addr++))) while ((c = pgm_read_byte(addr++)))
uartTransmitByte(c); 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;
}
35 changes: 35 additions & 0 deletions sw_uart/uart.h
@@ -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.