Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding from softuart_gittins_avr_20101010.zip

  • Loading branch information...
commit da6b39ec0288e02f3db385af606b02828206fe32 1 parent bb5fa42
@blalor authored
View
33 Makefile
@@ -41,8 +41,8 @@
# MCU name
-#MCU = atmega644
-MCU = attiny85
+MCU = atmega324p
+
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
@@ -62,8 +62,8 @@ MCU = attiny85
# F_CPU = 16000000
# F_CPU = 18432000
# F_CPU = 20000000
-#F_CPU = 3686400
-F_CPU = 1000000
+F_CPU = 8000000
+
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
@@ -101,7 +101,7 @@ ASRC =
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
-#OPT = 0
+
# Debugging format.
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
@@ -129,6 +129,10 @@ CSTANDARD = -std=gnu99
CDEFS = -DF_CPU=$(F_CPU)UL
+# Place -D or -U options here for ASM sources
+ADEFS = -DF_CPU=$(F_CPU)
+
+
# Place -D or -U options here for C++ sources
CPPDEFS = -DF_CPU=$(F_CPU)UL
#CPPDEFS += -D__STDC_LIMIT_MACROS
@@ -160,6 +164,8 @@ CFLAGS += -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
+CFLAGS += -ffunction-sections -fdata-sections -fno-inline-small-functions
+
#---------------- Compiler Options C++ ----------------
@@ -178,7 +184,7 @@ CPPFLAGS += -fpack-struct
CPPFLAGS += -fshort-enums
CPPFLAGS += -fno-exceptions
CPPFLAGS += -Wall
-CFLAGS += -Wundef
+CPPFLAGS += -Wundef
#CPPFLAGS += -mshort-calls
#CPPFLAGS += -fno-unit-at-a-time
#CPPFLAGS += -Wstrict-prototypes
@@ -191,14 +197,14 @@ CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
#---------------- Assembler Options ----------------
# -Wa,...: tell GCC to pass this to the assembler.
-# -ahlms: create listing
+# -adhlns: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
# dump that will be displayed for a given single line of source input.
-ASFLAGS = -Wa,-adhlns=$(<:.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
+ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
#---------------- Library Options ----------------
@@ -260,14 +266,13 @@ LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
#LDFLAGS += -T linker_script.x
+LDFLAGS += -Wl,--gc-sections -Wl,--relax
#---------------- Programming Options (avrdude) ----------------
-# Programming hardware: alf avr910 avrisp bascom bsd
-# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
-#
+# Programming hardware
# Type: avrdude -c ?
# to get a full listing.
#
@@ -424,7 +429,7 @@ end:
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
-ELFSIZE = $(SIZE) --format=avr $(TARGET).elf
+ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
sizebefore:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
@@ -504,7 +509,7 @@ extcoff: $(TARGET).elf
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
- $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
+ $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
%.eep: %.elf
@echo
@@ -516,7 +521,7 @@ extcoff: $(TARGET).elf
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
- $(OBJDUMP) -h -S $< > $@
+ $(OBJDUMP) -h -S -z $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
View
81 default/Makefile
@@ -1,81 +0,0 @@
-###############################################################################
-# Makefile for the project softuart_tiny85
-###############################################################################
-
-## General Flags
-PROJECT = softuart_tiny85
-MCU = attiny85
-TARGET = tiny85_go.elf
-CC = avr-gcc.exe
-
-## Options common to compile, link and assembly rules
-COMMON = -mmcu=$(MCU)
-
-## Compile options common for all C compilation units.
-CFLAGS = $(COMMON)
-CFLAGS += -Wall -gdwarf-2 -DF_CPU=1000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
-CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d
-
-## Assembly specific flags
-ASMFLAGS = $(COMMON)
-ASMFLAGS += $(CFLAGS)
-ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
-
-## Linker flags
-LDFLAGS = $(COMMON)
-LDFLAGS += -Wl,-Map=tiny85_go.map
-
-
-## Intel Hex file production flags
-HEX_FLASH_FLAGS = -R .eeprom
-
-HEX_EEPROM_FLAGS = -j .eeprom
-HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
-HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
-
-
-## Libraries
-LIBS = -lm
-
-## Objects that must be built in order to link
-OBJECTS = softuart.o main.o
-
-## Objects explicitly added by the user
-LINKONLYOBJECTS =
-
-## Build
-all: $(TARGET) tiny85_go.hex tiny85_go.eep tiny85_go.lss size
-
-## Compile
-softuart.o: ../softuart.c
- $(CC) $(INCLUDES) $(CFLAGS) -c $<
-
-main.o: ../main.c
- $(CC) $(INCLUDES) $(CFLAGS) -c $<
-
-##Link
-$(TARGET): $(OBJECTS)
- $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)
-
-%.hex: $(TARGET)
- avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
-
-%.eep: $(TARGET)
- -avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
-
-%.lss: $(TARGET)
- avr-objdump -h -S $< > $@
-
-size: ${TARGET}
- @echo
- @avr-size -C --mcu=${MCU} ${TARGET}
-
-## Clean target
-.PHONY: clean
-clean:
- -rm -rf $(OBJECTS) tiny85_go.elf dep/* tiny85_go.hex tiny85_go.eep tiny85_go.lss tiny85_go.map
-
-
-## Other dependencies
--include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)
-
View
60 default/softuart_megaxx4.hex
@@ -0,0 +1,60 @@
+:1000000084C000009DC000009BC0000099C000009B
+:1000100097C0000095C0000093C0000091C0000090
+:100020008FC000008DC000008BC0000089C00000A0
+:1000300087C0000085C0000083C0000081C00000B0
+:10004000A8C000007DC000007BC0000079C0000097
+:1000500077C0000075C0000073C0000071C00000D0
+:100060006FC000006DC000006BC0000069C00000E0
+:1000700067C0000065C0000063C000002048656CD8
+:100080006C6F200067656E6572696320736F6674BC
+:10009000756172742064726976657220636F64653D
+:1000A00020627920436F6C696E2047697474696EB1
+:1000B000730D0A000D0A536F6674756172742044E3
+:1000C000656D6F2D4170706C69636174696F6E0D41
+:1000D0000A006164617074656420666F7220417407
+:1000E0006D656C2041565220616E6420746869739E
+:1000F0002064656D6F206279204D617274696E2095
+:1001000054686F6D61730D0A000011241FBECFEF9C
+:10011000D8E0DEBFCDBF11E0A0E0B1E0E8E9F3E058
+:1001200002C005900D92A630B107D9F711E0A6E004
+:10013000B1E001C01D92A433B107E1F702D02AC19A
+:100140005FCF1F93CF93DF93BBD0D2D0789484EB53
+:1001500090E013D184E890E010D182ED90E00DD1D1
+:1001600080E091E0FED0C0E0D0E0DAD0882341F01A
+:10017000C2D0182F8BE5DDD0812FDBD08DE5D9D013
+:1001800021968FEFCF3FD80781F78CE790E0F5D02D
+:10019000EACF1F920F920FB60F9211248F939F9365
+:1001A000EF93FF9380912F01813029F580913001E9
+:1001B0008150F9F4809132019091330180FF02C0A7
+:1001C000599A01C0599880913201909133019695C6
+:1001D0008795909333018093320180913101815052
+:1001E0008093310180913101882311F410922F0105
+:1001F00083E08093300180912D01882309F057C05E
+:1002000080910A01882301F1809108018150809337
+:100210000801882309F04BC010920A0110922E01A8
+:10022000E0912B01F0E080910601E55FFE4F8083B5
+:1002300080912B018F5F80932B0180912B01803265
+:10024000B0F110922B0133C080912E01882381F4EC
+:1002500048992DC081E080932E011092060194E010
+:100260009093080198E090930701809309011FC0C3
+:10027000809108018150C9F4489B07C08091060114
+:1002800090910901892B8093060180910901880FC3
+:100290008093090180910701815080930701882391
+:1002A00019F481E080930A0183E080930801FF91B3
+:1002B000EF919F918F910F900FBE0F901F90189507
+:1002C00010922F0110922E0110922D01599A519ADD
+:1002D00050989FB7F89489E887BD82E084BD85BDBA
+:1002E000EEE6F0E080818260808316BC9FBF0895B7
+:1002F00010922D01089590912C0180912B01981757
+:10030000E1F3E92FF0E0E55FFE4FE081892F8F5F99
+:1003100080932C01803210F010922C018E2F0895C2
+:1003200090912B0120E080912C01981321E0822FE5
+:100330000895982F80912F018130E1F383E080931D
+:1003400030018AE080933101892F90E0880F991F56
+:100350009260909333018093320181E080932F016A
+:100360000895CF93DF93EC0102C02196E2DF8881EC
+:100370008823D9F7DF91CF910895CF93DF93EC01D4
+:1003800001C0D7DFFE01219684918823D1F7DF9148
+:08039000CF910895F894FFCF0E
+:060398002D2D0D0A0000EE
+:00000001FF
View
31 main.c
@@ -1,6 +1,6 @@
/*
AVR Software-Uart Demo-Application
- Version 0.3, 4/2007
+ Version 0.4, 10/2010
by Martin Thomas, Kaiserslautern, Germany
<eversmith@heizung-thomas.de>
@@ -9,15 +9,28 @@
/*
Test environment/settings:
-- avr-gcc 4.1.1/avr-libc 1.4.5 (WinAVR 1/2007)
-- Atmel ATtiny85 @ 1MHz internal R/C
+- avr-gcc 4.3.3/avr-libc 1.6.7 (WinAVR 3/2010)
+- Atmel ATmega324P @ 8MHz internal RC, ATtiny85 @ 1MHz internal RC
- 2400bps
+*/
+
+/*
+AVR Memory Usage (-Os, no-inline small-functions, relax)
+----------------
+Device: atmega324p
+
+Program: 926 bytes (2.8% Full)
+(.text + .data + .bootloader)
+
+Data: 52 bytes (2.5% Full)
+(.data + .bss + .noinit)
+
AVR Memory Usage (-Os)
----------------
Device: attiny85
-Program: 874 bytes (10.7% Full)
+Program: 828 bytes (10.1% Full)
(.text + .data + .bootloader)
Data: 52 bytes (10.2% Full)
@@ -25,17 +38,17 @@ Data: 52 bytes (10.2% Full)
*/
-// #define WITH_STDIO_DEMO
+#define WITH_STDIO_DEMO 0 /* 1: enable, 0: disable */
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "softuart.h"
-#ifdef WITH_STDIO_DEMO
+#if WITH_STDIO_DEMO
#include <stdio.h>
-// interface between avr-libc stdio and the modified Fleury uart-lib:
+// interface between avr-libc stdio and software-UART
static int my_stdio_putchar( char c, FILE *stream )
{
if ( c == '\n' ) {
@@ -73,13 +86,13 @@ int main(void)
softuart_turn_rx_on(); /* redundant - on by default */
sei();
-
+
softuart_puts_P( "\r\nSoftuart Demo-Application\r\n" ); // "implicit" PSTR
softuart_puts_p( PSTR("generic softuart driver code by Colin Gittins\r\n") ); // explicit PSTR
softuart_puts_p( pstring ); // pstring defined with PROGMEM
softuart_puts( "--\r\n" ); // string "from RAM"
-#ifdef WITH_STDIO_DEMO
+#if WITH_STDIO_DEMO
stdio_demo_func();
#endif
View
143 softuart.c
@@ -3,14 +3,14 @@
//
// Generic code from
// Colin Gittins, Software Engineer, Halliburton Energy Services
-// (available from the iar.com web-site -> application notes)
+// (has been available from iar.com web-site -> application notes)
//
// Adapted to AVR using avr-gcc and avr-libc
// by Martin Thomas, Kaiserslautern, Germany
// <eversmith@heizung-thomas.de>
// http://www.siwawi.arubi.uni-kl.de/avr_projects
//
-// AVR-port Version 0.3 4/2007
+// AVR-port Version 0.4 10/2010
//
// ---------------------------------------------------------------------
//
@@ -61,20 +61,19 @@
// ---------------------------------------------------------------------
/*
-Remarks by Martin Thomas (avr-gcc):
-V0.1:
+Remarks by Martin Thomas (avr-gcc/avr-libc):
+V0.1 (2/2005)
- stdio.h not used
- AVR-Timer in CTC-Mode ("manual" reload may not be accurate enough)
- Timer1 used here (Timer0 CTC not available i.e. on ATmega8)
-- Global Interrupt Flag has to be enabled (see Demo-Application)
+- Global Interrupt Flag has to be enabled (see demo-application)
- Interface timer_set and set_timer_interrupt not used here
- internal_tx_buffer was defined as unsigned char - thas could not
- work since more than 8 bits needed, changed to unsigned short
+ work since more than 8 bits are needed, changed to unsigned short
- some variables moved from "global scope" into ISR function-scope
- GPIO initialisation included
- Added functions for string-output inspired by P. Fleury's AVR UART-lib.
-V0.2:
-- adjust num of RX-bits
+V0.2 (3/2007)
+- adjusted number of RX-bits
- adapted to avr-libc ISR-macro (replaces SIGNAL)
- disable interrupts during timer-init
- used unsigned char (uint8_t) where apropriate
@@ -87,58 +86,102 @@ V0.2:
- demonstrate usage of avr-libc's stdio in demo-applcation
- tested with ATmega644 @ 3,6864MHz system-clock using
avr-gcc 4.1.1/avr-libc 1.4.5 (WinAVR 1/2007)
-V0.3
+V0.3 (4/2007)
- better configuration options in softuart.h.
->should be easier to adapt to different AVRs
-- tested with ATtiny85 @ 1MHz (int R/C) with 2400 bps
+- tested with ATtiny85 @ 1MHz (internal RC) with 2400bps
- AVR-Studio Project-File
+V0.4 (10/2010)
+- added options for ATmega164P, ATmega32P, ATmega64P
+- changed some variable-types from char to unsigned char
+- changed some comparisons from <= to ==
+- small optimization in ISR for RX with temporary variable
+- minor modifications in comments and formating
+- added compiler options -fno-inline-small-functions, -Wl,--relax
+- renamed flag_tx_ready to flag_tx_busy
+- replaced softuart_can_transmit() by softuart_transmit_busy()
+- tested with ATmega324PV @ 1MHz internal RC and 2400bps
+ (options for ATtiny25/45/85 still available)
+- added 3BSD license
+- removed redundant zero-init in declaration of qin and qout
*/
+/* Copyright (c) 2003, Colin Gittins
+ Copyright (c) 2005, 2007, 2010, Martin Thomas
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "softuart.h"
-#define SU_TRUE 1
-#define SU_FALSE 0
+#define SU_TRUE 1
+#define SU_FALSE 0
-// startbit and stopbit parsed internaly (see ISR)
+// startbit and stopbit parsed internally (see ISR)
#define RX_NUM_OF_BITS (8)
-volatile static char inbuf[SOFTUART_IN_BUF_SIZE];
-volatile static unsigned char qin = 0;
-/*volatile*/ static unsigned char qout = 0;
-volatile static unsigned char flag_rx_off;
-volatile static unsigned char flag_rx_ready;
+volatile static char inbuf[SOFTUART_IN_BUF_SIZE];
+volatile static unsigned char qin;
+static unsigned char qout;
+volatile static unsigned char flag_rx_off;
+volatile static unsigned char flag_rx_ready;
// 1 Startbit, 8 Databits, 1 Stopbit = 10 Bits/Frame
#define TX_NUM_OF_BITS (10)
-volatile static unsigned char flag_tx_ready;
+volatile static unsigned char flag_tx_busy;
volatile static unsigned char timer_tx_ctr;
volatile static unsigned char bits_left_in_tx;
volatile static unsigned short internal_tx_buffer; /* ! mt: was type uchar - this was wrong */
-#define set_tx_pin_high() ( SOFTUART_TXPORT |= ( 1<<SOFTUART_TXBIT ) )
-#define set_tx_pin_low() ( SOFTUART_TXPORT &= ~( 1<<SOFTUART_TXBIT ) )
-#define get_rx_pin_status() ( SOFTUART_RXPIN & ( 1<<SOFTUART_RXBIT ) )
-// #define get_rx_pin_status() ( ( SOFTUART_RXPIN & ( 1<<SOFTUART_RXBIT ) ) ? 1 : 0 )
+#define set_tx_pin_high() ( SOFTUART_TXPORT |= ( 1 << SOFTUART_TXBIT ) )
+#define set_tx_pin_low() ( SOFTUART_TXPORT &= ~( 1 << SOFTUART_TXBIT ) )
+#define get_rx_pin_status() ( SOFTUART_RXPIN & ( 1 << SOFTUART_RXBIT ) )
ISR(SOFTUART_T_COMP_LABEL)
{
static unsigned char flag_rx_waiting_for_stop_bit = SU_FALSE;
static unsigned char rx_mask;
- static char timer_rx_ctr;
- static char bits_left_in_rx;
+ static unsigned char timer_rx_ctr;
+ static unsigned char bits_left_in_rx;
static unsigned char internal_rx_buffer;
- char start_bit, flag_in;
- char tmp;
+ unsigned char start_bit, flag_in;
+ unsigned char tmp;
// Transmitter Section
- if ( flag_tx_ready ) {
+ if ( flag_tx_busy == SU_TRUE ) {
tmp = timer_tx_ctr;
- if ( --tmp <= 0 ) { // if ( --timer_tx_ctr <= 0 )
+ if ( --tmp == 0 ) { // if ( --timer_tx_ctr <= 0 )
if ( internal_tx_buffer & 0x01 ) {
set_tx_pin_high();
}
@@ -147,8 +190,8 @@ ISR(SOFTUART_T_COMP_LABEL)
}
internal_tx_buffer >>= 1;
tmp = 3; // timer_tx_ctr = 3;
- if ( --bits_left_in_tx <= 0 ) {
- flag_tx_ready = SU_FALSE;
+ if ( --bits_left_in_tx == 0 ) {
+ flag_tx_busy = SU_FALSE;
}
}
timer_tx_ctr = tmp;
@@ -157,12 +200,12 @@ ISR(SOFTUART_T_COMP_LABEL)
// Receiver Section
if ( flag_rx_off == SU_FALSE ) {
if ( flag_rx_waiting_for_stop_bit ) {
- if ( --timer_rx_ctr <= 0 ) {
+ if ( --timer_rx_ctr == 0 ) {
flag_rx_waiting_for_stop_bit = SU_FALSE;
flag_rx_ready = SU_FALSE;
inbuf[qin] = internal_rx_buffer;
if ( ++qin >= SOFTUART_IN_BUF_SIZE ) {
- // overflow - rst inbuf-index
+ // overflow - reset inbuf-index
qin = 0;
}
}
@@ -180,24 +223,26 @@ ISR(SOFTUART_T_COMP_LABEL)
}
}
else { // rx_busy
- if ( --timer_rx_ctr <= 0 ) {
+ tmp = timer_rx_ctr;
+ if ( --tmp == 0 ) { // if ( --timer_rx_ctr == 0 ) {
// rcv
- timer_rx_ctr = 3;
+ tmp = 3;
flag_in = get_rx_pin_status();
if ( flag_in ) {
internal_rx_buffer |= rx_mask;
}
rx_mask <<= 1;
- if ( --bits_left_in_rx <= 0 ) {
+ if ( --bits_left_in_rx == 0 ) {
flag_rx_waiting_for_stop_bit = SU_TRUE;
}
}
+ timer_rx_ctr = tmp;
}
}
}
}
-static void avr_io_init(void)
+static void io_init(void)
{
// TX-Pin as output
SOFTUART_TXDDR |= ( 1 << SOFTUART_TXBIT );
@@ -205,7 +250,7 @@ static void avr_io_init(void)
SOFTUART_RXDDR &= ~( 1 << SOFTUART_RXBIT );
}
-static void avr_timer_init(void)
+static void timer_init(void)
{
unsigned char sreg_tmp;
@@ -226,16 +271,14 @@ static void avr_timer_init(void)
void softuart_init( void )
{
- flag_tx_ready = SU_FALSE;
+ flag_tx_busy = SU_FALSE;
flag_rx_ready = SU_FALSE;
flag_rx_off = SU_FALSE;
set_tx_pin_high(); /* mt: set to high to avoid garbage on init */
- avr_io_init();
- // timer_set( BAUD_RATE );
- // set_timer_interrupt( timer_isr );
- avr_timer_init(); // replaces the two calls above
+ io_init();
+ timer_init();
}
static void idle(void)
@@ -281,14 +324,14 @@ void softuart_flush_input_buffer( void )
qout = 0;
}
-unsigned char softuart_can_transmit( void )
+unsigned char softuart_transmit_busy( void )
{
- return ( flag_tx_ready );
+ return ( flag_tx_busy == SU_TRUE ) ? 1 : 0;
}
void softuart_putchar( const char ch )
{
- while ( flag_tx_ready ) {
+ while ( flag_tx_busy == SU_TRUE ) {
; // wait for transmitter ready
// add watchdog-reset here if needed;
}
@@ -296,8 +339,8 @@ void softuart_putchar( const char ch )
// invoke_UART_transmit
timer_tx_ctr = 3;
bits_left_in_tx = TX_NUM_OF_BITS;
- internal_tx_buffer = ( ch<<1 ) | 0x200;
- flag_tx_ready = SU_TRUE;
+ internal_tx_buffer = ( ch << 1 ) | 0x200;
+ flag_tx_busy = SU_TRUE;
}
void softuart_puts( const char *s )
@@ -316,3 +359,5 @@ void softuart_puts_p( const char *prg_s )
}
}
+
+
View
65 softuart.h
@@ -1,11 +1,13 @@
#if !defined(F_CPU)
-#warning F_CPU not defined in makefile - now defined in softuart.h
+#warning "F_CPU not defined in makefile - now defined in softuart.h"
#define F_CPU 3686400UL
#endif
#define SOFTUART_BAUD_RATE 2400
+#if defined (__AVR_ATtiny25__) || defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__)
+
#define SOFTUART_RXPIN PINB
#define SOFTUART_RXDDR DDRB
#define SOFTUART_RXBIT PB0
@@ -21,9 +23,46 @@
#define SOFTUART_T_CNT_REG TCNT0
#define SOFTUART_T_INTCTL_REG TIMSK
-#define SOFTUART_CMPINT_EN_MASK (1<<OCIE0A)
+#define SOFTUART_CMPINT_EN_MASK (1 << OCIE0A)
+
+#define SOFTUART_CTC_MASKA (1 << WGM01)
+#define SOFTUART_CTC_MASKB (0)
+
+/* "A timer interrupt must be set to interrupt at three times
+ the required baud rate." */
+#define SOFTUART_PRESCALE (8)
+// #define SOFTUART_PRESCALE (1)
+
+#if (SOFTUART_PRESCALE == 8)
+#define SOFTUART_PRESC_MASKA (0)
+#define SOFTUART_PRESC_MASKB (1 << CS01)
+#elif (SOFTUART_PRESCALE==1)
+#define SOFTUART_PRESC_MASKA (0)
+#define SOFTUART_PRESC_MASKB (1 << CS00)
+#else
+#error "prescale unsupported"
+#endif
+
+#elif defined (__AVR_ATmega324P__) || defined (__AVR_ATmega324A__) \
+ || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__) \
+ || defined (__AVR_ATmega164P__) || defined (__AVR_ATmega164A__)
+
+#define SOFTUART_RXPIN PIND
+#define SOFTUART_RXDDR DDRD
+#define SOFTUART_RXBIT PD0
+
+#define SOFTUART_TXPORT PORTD
+#define SOFTUART_TXDDR DDRD
+#define SOFTUART_TXBIT PD1
-#define SOFTUART_CTC_MASKA (1<<WGM01)
+#define SOFTUART_T_COMP_LABEL TIMER0_COMPA_vect
+#define SOFTUART_T_COMP_REG OCR0A
+#define SOFTUART_T_CONTR_REGA TCCR0A
+#define SOFTUART_T_CONTR_REGB TCCR0B
+#define SOFTUART_T_CNT_REG TCNT0
+#define SOFTUART_T_INTCTL_REG TIMSK0
+#define SOFTUART_CMPINT_EN_MASK (1 << OCIE0A)
+#define SOFTUART_CTC_MASKA (1 << WGM01)
#define SOFTUART_CTC_MASKB (0)
/* "A timer interrupt must be set to interrupt at three times
@@ -31,21 +70,25 @@
#define SOFTUART_PRESCALE (8)
// #define SOFTUART_PRESCALE (1)
-#if (SOFTUART_PRESCALE==8)
+#if (SOFTUART_PRESCALE == 8)
#define SOFTUART_PRESC_MASKA (0)
-#define SOFTUART_PRESC_MASKB (1<<CS01)
+#define SOFTUART_PRESC_MASKB (1 << CS01)
#elif (SOFTUART_PRESCALE==1)
#define SOFTUART_PRESC_MASKA (0)
-#define SOFTUART_PRESC_MASKB (1<<CS00)
+#define SOFTUART_PRESC_MASKB (1 << CS00)
#else
#error "prescale unsupported"
#endif
+#else
+#error "no defintions available for this AVR"
+#endif
+
-#define SOFTUART_TIMERTOP ( F_CPU/SOFTUART_PRESCALE/SOFTUART_BAUD_RATE/3 -1)
+#define SOFTUART_TIMERTOP ( F_CPU/SOFTUART_PRESCALE/SOFTUART_BAUD_RATE/3 - 1)
#if (SOFTUART_TIMERTOP > 0xff)
-#warning "Check SOFTUART_TIMERTOP"
+#warning "Check SOFTUART_TIMERTOP: increase prescaler, lower F_CPU or use a 16 bit timer"
#endif
#define SOFTUART_IN_BUF_SIZE 32
@@ -63,7 +106,7 @@ unsigned char softuart_kbhit( void );
char softuart_getchar( void );
// To check if transmitter is busy
-unsigned char softuart_can_transmit( void );
+unsigned char softuart_transmit_busy( void );
// Writes a character to the serial port.
void softuart_putchar( const char );
@@ -78,9 +121,9 @@ void softuart_turn_rx_off( void );
void softuart_puts( const char *s );
// Write a NULL-terminated string from program-space (flash)
-// to the serial port. i.e. softuart_puts_p(PSTR("test"))
+// to the serial port. example: softuart_puts_p(PSTR("test"))
void softuart_puts_p( const char *prg_s );
-// Helper-Macro - "automaticly" inserts PSTR
+// Helper-Macro - "automatically" inserts PSTR
// when used: include avr/pgmspace.h before this include-file
#define softuart_puts_P(s___) softuart_puts_p(PSTR(s___))
View
1  softuart_megaxx4.aps
@@ -0,0 +1 @@
+<AVRStudio><MANAGEMENT><ProjectName>softuart_megaxx4</ProjectName><Created>10-Oct-2010 20:17:34</Created><LastEdit>10-Oct-2010 21:20:29</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>10-Oct-2010 20:17:34</Created><Version>4</Version><Build>4, 18, 0, 685</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\softuart_megaxx4.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>D:\EigenMT\develop\uProz\softuart_gittins_avr\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator 2</CURRENT_TARGET><CURRENT_PART>ATmega324P.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>main.c</SOURCEFILE><SOURCEFILE>softuart.c</SOURCEFILE><HEADERFILE>softuart.h</HEADERFILE><OTHERFILE>default\softuart_megaxx4.lss</OTHERFILE><OTHERFILE>default\softuart_megaxx4.map</OTHERFILE><OTHERFILE>Makefile</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>atmega324p</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>softuart_megaxx4.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>0</ISDIRTY><OPTIONS><OPTION><FILE>main.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>softuart.c</FILE><OPTIONLIST></OPTIONLIST></OPTION></OPTIONS><INCDIRS/><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -fno-inline-small-functions</OPTIONSFORALL><LINKEROPTIONS>-Wl,--gc-sections -Wl,--relax</LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\WinAVR\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\WinAVR\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><IOView><usergroups/><sort sorted="0" column="0" ordername="0" orderaddress="0" ordergroup="0"/></IOView><Files></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>
View
1  softuart_megaxx4.aws
@@ -0,0 +1 @@
+<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA324P"/><Files/></AVRWorkspace>
View
2  softuart_tiny85.aps
@@ -1 +1 @@
-<AVRStudio><MANAGEMENT><Created>30-Apr-2007 13:25:05</Created><LastEdit>30-Apr-2007 17:16:59</LastEdit><ProjectType>0</ProjectType><Created>30-Apr-2007 13:25:05</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>AVR GCC</ProjectTypeName><ICON>241</ICON><ProjectName>softuart_tiny85</ProjectName><Created>30-Apr-2007 16:09:51</Created><LastEdit>30-Apr-2007 16:09:51</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>30-Apr-2007 16:09:51</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\tiny85_go.elf</ObjectFile><EntryFile></EntryFile><ObjectFile></ObjectFile><EntryFile></EntryFile><SaveFolder>D:\EigenMT\develop\uProz\softuart_gittins_attiny85\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_PART>ATtiny85.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATtiny85.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND></IO_EXPAND><REGISTERNAMES></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>softuart.c</SOURCEFILE><SOURCEFILE>main.c</SOURCEFILE><HEADERFILE>softuart.h</HEADERFILE><OTHERFILE>default\tiny85_go.lss</OTHERFILE><OTHERFILE>default\tiny85_go.map</OTHERFILE><OTHERFILE>Makefile</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>attiny85</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>tiny85_go.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>1</ISDIRTY><OPTIONS/><INCDIRS/><LIBDIRS/><LIBS><LIB>libm.a</LIB></LIBS><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -DF_CPU=1000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums</OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\WinAVR\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\WinAVR\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><MANAGEMENT></MANAGEMENT><CODE_CREATION></CODE_CREATION><DEBUG_TARGET></DEBUG_TARGET><Debugger></Debugger><IOView><usergroups/></IOView><Files></Files><Workspace></Workspace><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>
+<AVRStudio><MANAGEMENT><Created>30-Apr-2007 13:25:05</Created><LastEdit>10-Oct-2010 21:43:21</LastEdit><ProjectType>0</ProjectType><Created>30-Apr-2007 13:25:05</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>AVR GCC</ProjectTypeName><ICON>241</ICON><ProjectName>softuart_tiny85</ProjectName><Created>30-Apr-2007 16:09:51</Created><LastEdit>30-Apr-2007 16:09:51</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>30-Apr-2007 16:09:51</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\tiny85_go.elf</ObjectFile><EntryFile></EntryFile><ObjectFile></ObjectFile><EntryFile></EntryFile><SaveFolder>D:\EigenMT\develop\uProz\softuart_gittins_avr\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_PART>ATtiny85.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATtiny85.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND></IO_EXPAND><REGISTERNAMES></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>softuart.c</SOURCEFILE><SOURCEFILE>main.c</SOURCEFILE><HEADERFILE>softuart.h</HEADERFILE><OTHERFILE>default\tiny85_go.lss</OTHERFILE><OTHERFILE>default\tiny85_go.map</OTHERFILE><OTHERFILE>Makefile</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>attiny85</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>tiny85_go.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>0</ISDIRTY><OPTIONS><OPTION><FILE>main.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>softuart.c</FILE><OPTIONLIST></OPTIONLIST></OPTION></OPTIONS><INCDIRS/><LIBDIRS/><LIBS><LIB>libm.a</LIB></LIBS><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -fno-inline-small-functions -DF_CPU=1000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections -fdata-sections </OPTIONSFORALL><LINKEROPTIONS> -Wl,--relax -Wl,--gc-sections </LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\WinAVR\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\WinAVR\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><MANAGEMENT></MANAGEMENT><CODE_CREATION></CODE_CREATION><DEBUG_TARGET></DEBUG_TARGET><Debugger></Debugger><IOView><usergroups/><sort sorted="0" column="0" ordername="0" orderaddress="0" ordergroup="0"/></IOView><Files></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>
Please sign in to comment.
Something went wrong with that request. Please try again.