Skip to content

Commit

Permalink
initial checkin of firmware project
Browse files Browse the repository at this point in the history
  • Loading branch information
EmbedME committed Oct 6, 2013
1 parent 32d9e30 commit ab8bf01
Show file tree
Hide file tree
Showing 13 changed files with 2,926 additions and 1 deletion.
1,880 changes: 1,880 additions & 0 deletions Doxyfile

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
PRG = main
OBJ = main.o clock.o isp.o counter.o script.o
MCU_TARGET = atmega1284p
#MCU_TARGET = atmega8
OPTIMIZE = -O2

DEFS =
LIBS =

# You should not have to change anything below here.

CC = avr-gcc

# Override is only needed by avr-lib build system.

override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
override LDFLAGS = -Wl,-Map,$(PRG).map -Wl,--section-start=.script_section=0x1000

OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size

all: $(PRG).elf lst text

$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)

clean:
rm -rf *.o $(PRG).elf *.eps *.png *.pdf *.bak
rm -rf *.lst *.map $(EXTRA_CLEAN_FILES)

lst: $(PRG).lst

%.lst: %.elf
$(OBJDUMP) -h -S $< > $@

# Rules for building the .text rom images

text: hex bin srec

hex: $(PRG).hex
bin: $(PRG).bin
srec: $(PRG).srec

%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@

%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@

%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@

# Rules for building the .eeprom rom images

eeprom: ehex ebin esrec

ehex: $(PRG)_eeprom.hex
ebin: $(PRG)_eeprom.bin
esrec: $(PRG)_eeprom.srec

%_eeprom.hex: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@

%_eeprom.srec: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@

%_eeprom.bin: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@

# Every thing below here is used by avr-libc's build system and can be ignored
# by the casual user.

FIG2DEV = fig2dev
EXTRA_CLEAN_FILES = *.hex *.bin *.srec

dox: eps png pdf

eps: $(PRG).eps
png: $(PRG).png
pdf: $(PRG).pdf

%.eps: %.fig
$(FIG2DEV) -L eps $< $@

%.pdf: %.fig
$(FIG2DEV) -L pdf $< $@

%.png: %.fig
$(FIG2DEV) -L png $< $@

size:
$(SIZE) $(PRG).elf

# Documentation
docu:
doxygen
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
ISPnub
======

Firmware for stand-alone AVR programmer module
Firmware for stand-alone AVR programmer module.

ISPnub is a stand-alone AVR programming module. The programming instructions
are defined within scripts. These scripts are converted with an additional
tool (ISPnubCreator) into a binary format and are stored in the flash of
ISPnub's ATmega1284P. This firmware interprets the binary programming
instructions and executes it on the connected target controller.

The firmware hex file is packed into the JAR file of ISPnubCreator which
merges the firmware hex data with programming instructions from scripts.

111 changes: 111 additions & 0 deletions clock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* @file clock.c
*
* @brief This file contains clock and timing functions
*
* @author Thomas Fischl
* @copyright (c) 2013 Thomas Fischl
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "hal.h"
#include "clock.h"

/**
* @brief This variable ticks slow generated with timer interrupt
*/
uint8_t slowticker;


/**
* @brief Initialize timer
*/
void clock_init() {

// set timer 0 prescaler to 1/1024
TCCR0 = (1 << CS02) | (1 << CS00);

// reset slow ticking variable
slowticker = 0;

// enable timer0 interrupt
TIMSK |= (1 << TOIE0);
}


/**
* @brief Get current value of slow-ticker
* @return Current slow-ticker
*/
uint8_t clock_getTickerSlow() {
return slowticker;
}

/**
* @brief Get difference between given ticker and current slow-ticker
* @param ticker Ticker to compare with current slow-ticker
* @return Difference of current ticker and given ticker
*/
uint8_t clock_getTickerSlowDiff(uint8_t ticker) {
return (uint8_t) (clock_getTickerSlow() - ticker);
}

/**
* @brief Wait given ticks (reference is slow-ticker)
* @param ticks Ticks to wait
*/
void clock_delaySlow(uint8_t ticks) {
uint8_t ticker = clock_getTickerSlow();
while (clock_getTickerSlowDiff(ticker) < ticks) {
};
}

/**
* @brief Get current value of fast-ticker
* @return
*/
uint8_t clock_getTickerFast() {
return TCNT0;
}

/**
* @brief Get difference between given ticker and current fast-ticker
* @param ticker Ticker to compare with current fast-ticker
* @return Ticks between current and given fast-ticker
*/
uint8_t clock_getTickerFastDiff(uint8_t ticker) {
return (uint8_t) (clock_getTickerFast() - ticker);
}

/**
* @brief Wait given ticks (reference is fast-ticker)
* @param ticks Ticks to wait
*/
void clock_delayFast(uint8_t ticks) {
uint8_t ticker = clock_getTickerFast();
while (clock_getTickerFastDiff(ticker) < ticks) {
};
}

/**
* @brief Timer 0 overflow interrupt
*/
ISR(TIMER0_OVF_vect) {
slowticker++;
}
48 changes: 48 additions & 0 deletions clock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @file clock.h
*
* @brief This file contains definitons for clock and timing functions
*
* @author Thomas Fischl
* @copyright (c) 2013 Thomas Fischl
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef CLOCK_H
#define CLOCK_H

// 8 MHz / 1024 / 256 = 30.52 Hz
#define CLOCK_TICKER_SLOW_1S 31 ///< 1s slow ticks
#define CLOCK_TICKER_SLOW_500MS 15 ///< 500ms slow ticks
#define CLOCK_TICKER_SLOW_250MS 8 ///< 250ms slow ticks
#define CLOCK_TICKER_SLOW_100MS 3 ///< 100ms slow ticks

// 8 MHz / 1024 = 7812.5 Hz
#define CLOCK_TICKER_FAST_1MS 8 ///< 1ms fast ticks
#define CLOCK_TICKER_FAST_5MS 39 ///< 5ms fast ticks
#define CLOCK_TICKER_FAST_10MS 78 ///< 10ms fast ticks
#define CLOCK_TICKER_FAST_20MS 156 ///< 20ms fast ticks
#define CLOCK_TICKER_FAST_25MS 195 ///< 25ms fast ticks

void clock_init();
uint8_t clock_getTickerSlow();
uint8_t clock_getTickerSlowDiff(uint8_t ticker);
void clock_delaySlow(uint8_t ticks);
uint8_t clock_getTickerFast();
uint8_t clock_getTickerFastDiff(uint8_t ticker);
void clock_delayFast(uint8_t ticks);

#endif
87 changes: 87 additions & 0 deletions counter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* @file counter.c
*
* @brief This file contains programming counter functions
*
* @author Thomas Fischl
* @copyright (c) 2013 Thomas Fischl
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include <inttypes.h>
#include <avr/eeprom.h>

/**
* @brief Defines how often the counter value is stored in EEPROM
*/
#define COUNTER_REDUNCY 3

/**
* @brief Read current programming counter value from EEPROM
* @return Programming counter value
*/
uint16_t counter_read() {

uint16_t counter = 0xffff;
uint8_t i;
uint16_t * eeadr = 0;

for (i = 0; i < COUNTER_REDUNCY; i++) {

uint16_t eeval = eeprom_read_word(eeadr++);

if (eeval == ~eeprom_read_word(eeadr++)) {
// valid value

if (eeval < counter) counter = eeval;
}
}

return counter;
}

/**
* @brief Write given programming counter value to EEPROM
* @param counter Programming counter value
*/
void counter_write(uint16_t counter) {

uint8_t i;
uint16_t * eeadr = 0;

for (i = 0; i < COUNTER_REDUNCY; i++) {

eeprom_write_word(eeadr++, counter);
eeprom_write_word(eeadr++, ~counter);
}

}

/**
* @brief Decrement the programming counter
* @param startvalue Initial value of programming counter
*/
void counter_decrement(uint16_t startvalue) {

uint16_t counter = counter_read();

if (counter == 0xffff) counter = startvalue;
if (counter == 0) return;

counter--;

counter_write(counter);
}
32 changes: 32 additions & 0 deletions counter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @file counter.h
*
* @brief This file contains definitions for programming counter functions
*
* @author Thomas Fischl
* @copyright (c) 2013 Thomas Fischl
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef COUNTER_H
#define COUNTER_H

uint16_t counter_read();
void counter_write(uint16_t counter);
void counter_decrement(uint16_t startvalue);

#endif

Loading

0 comments on commit ab8bf01

Please sign in to comment.