Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ATtiny 4313 #1

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
06dc04c
- ported code to atmega32 running at 8MHz (not heavily tested, but wo…
May 18, 2010
5ef4f83
quite a lot of changes to make onewire.c uP independent, but binaries…
May 21, 2010
5c56844
more on portability, TIMESTAMP code removed (might return later), uni…
May 22, 2010
a6ce5b0
added flags for cortex-m3 compile (testing), moved -Os from the .c.o …
Jun 1, 2010
84e5cda
uart code complexity reduced, only blocks the related interrupt sourc…
Jun 1, 2010
eaf8230
moved avr specifics to a seperate file, added the project settings on…
Jun 1, 2010
f35656e
call uart_try_send() in update_idle() for the polled transmitter, com…
Jun 1, 2010
d7de064
more documentation, register stuff removed again, see note there, a b…
Jun 1, 2010
12035eb
fix compilability if HAVE_UART undefined
Jun 3, 2010
2708514
fixed typo in ATtiny13 settings
Jun 4, 2010
6a5e000
unified state error checks for xmit and recv (NOT tested yet), adapte…
Jun 4, 2010
0de2e4d
fixed compilability for m168
Jun 6, 2010
4468c12
CFLAGS to compile for Cortex M3, pass CC=arm-none-eabi-gcc on the com…
Jun 9, 2010
71a9370
just beautifying and more comments
Jun 9, 2010
5c80f37
fixed unused len in xmit_any, defined S_ROMCODE and more documentation
Jun 9, 2010
320d538
renamed uart.c to avr_uart.c, moved avr specifics to it, Makefile ada…
Jun 15, 2010
3e0c451
modified timer settings to allow 32bit values for cortex, timer_t added
Jun 15, 2010
3c463d2
moved cortex stuff to cortexm0.h
Jun 15, 2010
0bb0ec7
reduced cortex uart to the min, not tested yet
Jun 15, 2010
b776907
moved to avr_uart.c
Jun 15, 2010
182124b
minor cleanup, fixed avr make
Jun 19, 2010
1501e6c
LPC111x uart now works, line endings fixed, compiles with lpcxpresso …
Jun 19, 2010
7f84f76
fixed size of avr uart buffer (u_char)
Jul 4, 2010
16a787a
fixed bug in uart_puthex_long on cortexm0
Jul 4, 2010
c0af760
- renamed set_owtimer() to set_owtimeout()
Jul 4, 2010
6ac1ae8
ported to cortex M0, works, but still some TODOs
Jul 4, 2010
9364607
fixed AVR_ATtiny168_owtimer(), which is of course ATmega168
Aug 15, 2010
5e6ace1
Added ATtiny 4313 support
dirixmjm May 2, 2011
89e0b53
Makefile for my programmer
dirixmjm May 2, 2011
a7860eb
added ds2502 emulation with vbus input
dirixmjm May 6, 2011
1c381e4
Added CRC8
dirixmjm May 6, 2011
7bb0fd9
Compile DS2502
dirixmjm May 6, 2011
7a5d221
avr.h: fixed INT0 pin for ATmega8 (is D2)
Jun 21, 2011
f65bfac
Vbus is in the vbus branch, so code is removed from master
dirixmjm May 11, 2013
07ffb28
Merge remote-tracking branch 'taliesin/master'
dirixmjm May 11, 2013
7469a9f
Initial version of the ds2409, status still needs work
dirixmjm May 16, 2013
5856ebc
ATtiny84 also needs prescaler 1/64
dirixmjm May 16, 2013
65b030b
Add DS2409 to makefile
dirixmjm May 16, 2013
8240e14
Improved Status info
dirixmjm May 18, 2013
5fe400b
Improved Timing with xmit wait
dirixmjm May 18, 2013
bb1774d
xmit wait functions added
dirixmjm May 18, 2013
9440eea
Rudimentary events, I guess I dont use them much
dirixmjm May 18, 2013
4c8f932
Added transistor output
dirixmjm May 19, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
# makefile, written by guido socher
#MCU=atmega8
#MCU=attiny13
#MCU=attiny84
MCU=atmega168
MCU_PROG=m168
#MCU_PROG=t84
PROG=usbtiny
MCU=attiny84
#MCU=attiny4313
#MCU=atmega168
#MCU_PROG=m168
MCU_PROG=t84
#MCU_PROG=attiny4313
#PROG=usbtiny
PROG=avrispmkII
PORT=usb

CC=avr-gcc
OBJCOPY=avr-objcopy
OBJDUMP=avr-objdump
ARCH=avr
CC=$(ARCH)-gcc
OBJCOPY=$(ARCH)-objcopy
OBJDUMP=$(ARCH)-objdump

#-------------------
help:
@echo "Usage: make TYPE | TYPE_burn"
@echo "Known Types: ds2408 ds2423"
@echo "Known Types: ds2408 ds2409 ds2423"

#-------------------

# device codes
ds2408_CODE=29
ds2409_CODE=1F
ds2423_CODE=1D

DEVNAME=ds2408
all: $(DEVNAME).hex $(DEVNAME).lss $(DEVNAME).bin

ds2408 ds2423:
ds2408 ds2409 ds2423:
@make $@_dev

%_burn: %_dev
Expand All @@ -34,13 +39,19 @@ ds2408 ds2423:
%_dev:
@make DEVNAME=$(subst _dev,,$@) all

# optimize for size:
CFLAGS=-g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues
# optimize for size!
ifeq ($(ARCH),avr)
CFLAGS=-g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues
UART=avr_uart.o
else
CFLAGS=-g -mcpu=cortex-m0 -mthumb -Wall -Wstrict-prototypes -Os
UART=cortexm0_uart.o
endif
# -I/usr/local/avr/include -B/usr/local/avr/lib
#-------------------
%.o : %.c Makefile $(wildcard *.h)
$(CC) $(CFLAGS) -Os -c $<
$(DEVNAME).out : onewire.o uart.o $(DEVNAME).o
$(CC) $(CFLAGS) -c $<
$(DEVNAME).out : onewire.o $(DEVNAME).o $(UART)
$(CC) $(CFLAGS) -o $@ -Wl,-Map,$(DEVNAME).map,--cref $^
$(DEVNAME).hex : $(DEVNAME).out
$(OBJCOPY) -R .eeprom -O ihex $< $@
Expand All @@ -53,10 +64,14 @@ $(DEVNAME).eeprom:
python gen_eeprom.py $(DEVCODE) > $@
#------------------
burn: $(DEVNAME).hex $(DEVNAME).eeprom
avrdude -c $(PROG) -p $(MCU_PROG) -U flash:w:$(DEVNAME).hex:i -U eeprom:w:$(DEVNAME).eeprom:i
avrdude -V -c $(PROG) -p $(MCU_PROG) -P $(PORT) -U flash:w:$(DEVNAME).hex:i -U eeprom:w:$(DEVNAME).eeprom:i
#avrdude -V -c $(PROG) -p $(MCU_PROG) -U $(PRG).bin
#-------------------
fuse:
avrdude -c $(PROG) -p $(MCU_PROG) -P $(PORT) -U lfuse:w:0xCF:m -U hfuse:w:0xDF:m -U efuse:w:0xff:m
#0xEE
#-------------------
clean:
rm -f *.o *.map *.out *t.hex
rm -f *.o *.map *.out *.hex *.bin *.lss
#-------------------

274 changes: 274 additions & 0 deletions avr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
/*
* avr.h
* only included if compiling for AVR cpu
*/

#ifndef AVR_H_
#define AVR_H_

#include <avr/io.h>
#include <avr/interrupt.h>
// debugging only
#include "uart.h"

// AVRs use 8 bit timers
typedef unsigned char timer_t;

/* hardware specific settings, just as the cpu should come from
* either the makefile or better something like Kconfig
*/
#ifndef F_CPU
#warning "CPU frequency not defined, assuming 8MHz"
#define F_CPU 8000000
#endif

#ifndef PRESCALE
#define PRESCALE 64
#endif

/* macros to create timeout values in usec, e.g.
* 8MHz cpu clock, prescaled with 64 -> 8 usec per timer tick
* 120usec equals 15 ticks (8000000/64)/(1000000/120) = (8*120)/64 = 15
*
* for the above example:
* T_PRESENCE = 10
* T_PRESENCEWAIT = 2.5 -> 2
* T_RESET_ = (8*400)/64 = 50
* T_RESET = 50-1 = 49
*
* fallback values for 8MHz are
* T_SAMPLE = (8*25)/64-1 = 1
* T_XMIT = (8*60)/64-5 = 7.8..-5 ->7-5=2
*
*/
#define T_(c) ((F_CPU/PRESCALE)/(1000000/c))
#define T_PRESENCE T_(120)-5
#define T_PRESENCEWAIT T_(20)
#define T_RESET_ T_(400) // timestamp for sampling
#define T_RESET (T_RESET_-T_SAMPLE)

/* these are critical and may be set-up individually in the CPU specific sections below:
* #if F_CPU == 14736489
* #undef T_SAMPLE
* #define T_SAMPLE T_(37)-11
* #endif
* ... these fallbacks may be invalid
*/
#ifndef T_SAMPLE
#if F_CPU >= 12000000
#define T_SAMPLE T_(15)-1
#elif F_CPU > 9600000
#define T_SAMPLE T_(15)-2
#else
#warning "This will probably only work for relatively slow masters!"
#define T_SAMPLE T_(25)-1 // only tested for atmega32, works but out of specification!
#endif
#define T_XMIT T_(60)-4 // overhead (measured w/ scope on ATmega168)
#endif

// check timing setup, T_RESET depends on timer size (8bits for AVR)
#if (T_SAMPLE<1)
#error "Sample time too short, fix timing!"
#endif
#if (T_RESET>200)
#error "Reset slot is too wide, fix timing!"
#endif

// actually cpu specific, but AVRs work all the same
#undef owtimer_is_set_to_short_timeout
#define owtimer_is_set_to_short_timeout() (TCNT0 > 0xF0)

#define OW_PINCHANGE_ISR() ISR (INT0_vect)
#define OW_TIMER_ISR() ISR (TIMER0_OVF_vect)
// not used by owslave code directly
#define OW_OVFLOW_ISR() ISR (TIMER1_OVF_vect)
#define OW_PERIOD_ISR() ISR (TIMER1_CAPT_vect)

// stupidity
#ifndef TIMER0_OVF_vect
# define TIMER0_OVF_vect TIM0_OVF_vect
#endif

// for atmega8 and atmega32
#ifndef EEPE
#define EEPE EEWE
#endif
#ifndef EEMPE
#define EEMPE EEMWE
#endif

// this works for all AVRs, getting address from address 0..7
static inline void get_ow_address(u_char *addr)
{
u_char i;

// Wait for EPROM circuitry to be ready
while(EECR & (1<<EEPE));

for (i=8; i;) {
i--;
EEARL = 7-i; // set EPROM Address
EECR |= (1<<EERE); // Start eeprom read by writing EERE
addr[i] = EEDR; // Return data from data register
}
}

#ifdef HAVE_UART
static inline void init_debug(void) { uart_init(UART_BAUD_SELECT(BAUDRATE,F_CPU)); }
#else
#define init_debug()
#endif

/* define __CPU used as name prefix and
* their uP setup functions, they:
* - define appropriate clock settings
* - define the prescaler used by the OW_timer
* - setup the OW_pinchange interrupt
*/
#if defined(__AVR_ATtiny13__)
#define __CPU AVR_ATtiny13

static inline void AVR_ATtiny13_setup(void)
{
CLKPR = 0x80; // Prepare to ...
CLKPR = 0x00; // ... set to 9.6 MHz
TCCR0A = 0;
TCCR0B = 0x03; // Prescaler 1/64
MCUCR |= (1 << ISC00); // Interrupt on both level changes
}

static inline void AVR_ATtiny13_mask_owpin(void) { GIMSK &= ~(1 << INT0); }
static inline void AVR_ATtiny13_unmask_owpin(void) { GIFR |= (1 << INTF0); GIMSK |= (1 << INT0); }
static inline void AVR_ATtiny13_set_owtimeout(timer_t timeout)
{
TCNT0 = ~timeout; // overrun at 0xFF
TIFR0 |= (1 << TOV0);
TIMSK0 |= (1 << TOIE0);
}
static inline void AVR_ATtiny13_clear_owtimer(void) { TCNT0 = 0; TIMSK0 &= ~(1 << TOIE0); }
static inline timer_t AVR_ATtiny13_owtimer(void) { return TCNT0; }

// use INT0 pin (PORT B1)
static inline void AVR_ATtiny13_owpin_setup(void) { PORTB &= ~2; DDRB &= ~2; }
static inline void AVR_ATtiny13_owpin_low(void) { DDRB |= 2; }
static inline void AVR_ATtiny13_owpin_hiz(void) { DDRB &= ~2; }
static inline u_char AVR_ATtiny13_owpin_value(void) { return PINB & 2; }

#elif defined (__AVR_ATmega8__)
#define __CPU AVR_ATmega8

static inline void AVR_ATmega8_setup(void)
{
// Clock is set via fuse, at least to 8MHz
TCCR0 = 0x03; // Prescaler 1/64
MCUCR |= (1 << ISC00); // Interrupt on both level changes
}

static inline void AVR_ATmega8_mask_owpin(void) { GIMSK &= ~(1 << INT0); }
static inline void AVR_ATmega8_unmask_owpin(void) { GIFR |= (1 << INTF0); GIMSK |= (1 << INT0); }
static inline void AVR_ATmega8_set_owtimeout(timer_t timeout)
{
TCNT0 = ~timeout; // overrun at 0xFF
TIFR |= (1 << TOV0);
TIMSK |= (1 << TOIE0);
}
static inline void AVR_ATmega8_clear_owtimer(void) { TCNT0 = 0; TIMSK &= ~(1 << TOIE0); }
static inline timer_t AVR_ATmega8_owtimer(void) { return TCNT0; }

// use INT0 pin (PORT D2)
static inline void AVR_ATmega8_owpin_setup(void) { PORTD &= ~4; DDRD &= ~4; }
static inline void AVR_ATmega8_owpin_low(void) { DDRD |= 4; }
static inline void AVR_ATmega8_owpin_hiz(void) { DDRD &= ~4; }
static inline u_char AVR_ATmega8_owpin_value(void) { return PIND & 4; }

#elif defined (__AVR_ATmega32__)
#define __CPU AVR_ATmega32

static inline void AVR_ATmega32_setup(void)
{
// Clock is set via fuse, at least to 8MHz
// Clock is set via fuse to 8MHz
TCCR0 = 0x03; // Prescaler 1/64
MCUCR |= (1 << ISC00); // Interrupt on both level changes
}

static inline void AVR_ATmega32_mask_owpin(void) { GIMSK &= ~(1 << INT0); }
static inline void AVR_ATmega32_unmask_owpin(void) { GIFR |= (1 << INTF0); GIMSK |= (1 << INT0); }
static inline void AVR_ATmega32_set_owtimeout(timer_t timeout)
{
TCNT0 = ~timeout; // overrun at 0xFF
TIFR |= (1 << TOV0);
TIMSK |= (1 << TOIE0);
}
static inline void AVR_ATmega32_clear_owtimer(void) { TCNT0 = 0; TIMSK &= ~(1 << TOIE0); }
static inline timer_t AVR_ATmega32_owtimer(void) { return TCNT0; }

// use INT0 pin (PORT D2)
static inline void AVR_ATmega32_owpin_setup(void) { PORTD &= ~4; DDRD &= ~4; }
static inline void AVR_ATmega32_owpin_low(void) { DDRD |= 4; }
static inline void AVR_ATmega32_owpin_hiz(void) { DDRD &= ~4; }
static inline u_char AVR_ATmega32_owpin_value(void) { return PIND & 4; }

#elif defined (__AVR_ATtiny84__)
#define __CPU AVR_ATtiny84

static inline void AVR_ATtiny84_setup(void)
{
CLKPR = 0x80; // Prepare to ...
CLKPR = 0x00; // ... set to 16.0 MHz
TCCR0A = 0;
TCCR0B = 0x03; // Prescaler 1/64
MCUCR |= (1 << ISC00); // Interrupt on both level changes
}

static inline void AVR_ATtiny84_mask_owpin(void) { GIMSK &= ~(1 << INT0); }
static inline void AVR_ATtiny84_unmask_owpin(void) { GIFR |= (1 << INTF0); GIMSK |= (1 << INT0); }
static inline void AVR_ATtiny84_set_owtimeout(timer_t timeout)
{
TCNT0 = ~timeout; // overrun at 0xFF
TIFR0 |= (1 << TOV0);
TIMSK0 |= (1 << TOIE0);
}
static inline void AVR_ATtiny84_clear_owtimer(void) { TCNT0 = 0; TIMSK0 &= ~(1 << TOIE0); }
static inline timer_t AVR_ATtiny84_owtimer(void) { return TCNT0; }

// use INT0 pin (PORT B2)
static inline void AVR_ATtiny84_owpin_setup(void) { PORTB &= ~4; DDRB &= ~4; }
static inline void AVR_ATtiny84_owpin_low(void) { DDRB |= 4; }
static inline void AVR_ATtiny84_owpin_hiz(void) { DDRB &= ~4; }
static inline u_char AVR_ATtiny84_owpin_value(void) { return PINB & 4; }

#elif defined (__AVR_ATmega168__)
#define __CPU AVR_ATmega168

static inline void AVR_ATmega168_setup(void)
{
// Clock is set via fuse, at least to 8MHz
TCCR0A = 0;
TCCR0B = 0x03; // Prescaler 1/64
EICRA = (1<<ISC00); // interrupt of INT0 (pin D2) on both level changes
}

static inline void AVR_ATmega168_mask_owpin(void) { EIMSK &= ~(1 << INT0); }
static inline void AVR_ATmega168_unmask_owpin(void) { EIFR |= (1 << INTF0); EIMSK |= (1 << INT0); }
static inline void AVR_ATmega168_set_owtimeout(timer_t timeout)
{
TCNT0 = ~timeout; // overrun at 0xFF
TIFR0 |= (1 << TOV0);
TIMSK0 |= (1 << TOIE0);
}
static inline void AVR_ATmega168_clear_owtimer(void) { TCNT0 = 0; TIMSK0 &= ~(1 << TOIE0); }
static inline timer_t AVR_ATmega168_owtimer(void) { return TCNT0; }

// use INT0 pin (PORT D2)
static inline void AVR_ATmega168_owpin_setup(void) { PORTD &= ~4; DDRB &= ~4; }
static inline void AVR_ATmega168_owpin_low(void) { DDRD |= 4; }
static inline void AVR_ATmega168_owpin_hiz(void) { DDRD &= ~4; }
static inline u_char AVR_ATmega168_owpin_value(void) { return PIND & 4; }

#else
#error "Your AVR is not supported (or at least not tested)"
#endif


#endif /* AVR_H_ */
Loading