Commit 45b71964 authored by Hermann Mayer's avatar Hermann Mayer

Initial Commit.

parents
/build/*
/tags
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_C_COMPILER avr-gcc)
SET(CMAKE_CXX_COMPILER avr-g++)
SET(CSTANDARD "-std=gnu99")
#SET(CDEBUG "-gstabs")
SET(CWARN "-Wall -Wstrict-prototypes")
SET(CTUNING "-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums")
SET(COPT "-Os")
SET(CINCS "-I${CMAKE_SOURCE_DIR}/src/lib/arduino")
SET(CMCU "-mmcu=atmega328p")
SET(CDEFS "-DF_CPU=16000000")
SET(CFLAGS "${CMCU} ${CDEBUG} ${CDEFS} ${CINCS} ${COPT} ${CWARN} ${CSTANDARD} ${CEXTRA} ${CTUNING}")
SET(CXXSTANDARD "")
#SET(CDEBUG "-gstabs")
SET(CXXWARN "-Wall")
SET(CXXTUNING "-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -Wl,--gc-sections -fno-exceptions --pedantic")
SET(CXXOPT "-Os")
SET(CXXINCS "-I${CMAKE_SOURCE_DIR}/src/lib/arduino")
SET(CXXMCU "-mmcu=atmega328p")
SET(CXXDEFS "-DF_CPU=16000000")
SET(CXXFLAGS "${CXXMCU} ${CXXDEBUG} ${CXXDEFS} ${CXXINCS} ${CXXOPT} ${CXXWARN} ${CXXSTANDARD} ${CXXEXTRA} ${CXXTUNING}")
SET(CMAKE_C_FLAGS ${CFLAGS})
SET(CMAKE_CXX_FLAGS ${CXXFLAGS})
SET(LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build")
SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build")
# AVR Assembler
# AVR Compiler
# AVR C++ Compiler
# AVR C Linker
# AVR C++ Linker
# AVR Archiver
# AVR Create Extended Listing
# AVR Create Flash image
# AVR Create EEPROM image
# Print Size
# AVRDude
cmake_minimum_required(VERSION 2.6)
Project(Slave-Stack)
add_subdirectory(src/lib/arduino)
add_subdirectory(src/lib)
add_subdirectory(src)
Install Notes
=============
##Required Steps
Deploy Notes
============
This diff is collapsed.
README
======
What is the Slave-Stack?
------------------------
Requirements
------------
Installation
------------
Just have a look at the INSTALL.md located at the root of the project.
#!/bin/bash
# Get current location of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Configure current build path
buildPath="$DIR/../build"
# Prepare build path
rm -rf "$buildPath" && mkdir "$buildPath" && cd "$buildPath"
# Do the build
cmake ..
make
#!/bin/bash
# Get current location of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Configure current build path
buildPath="$DIR/../build"
# Goto build path and flash firmware on the device
cd "$buildPath" && avrdude -p m328p -c arduino -P /dev/ttyACM0 -U flash:w:Slave-Stack.hex
#!/bin/sh
COMMAND="$1"
FLAGS="$2"
PWD="$3"
FlashLog="${PWD}/bin/helper/.flash.log"
FirmwareLog="${PWD}/bin/helper/.firmware.log"
if [ ! -f "$FlashLog" ]; then
touch "$FlashLog";
fi
if [ ! -f "$FirmwareLog" ]; then
touch "$FirmwareLog";
fi
NColor="\E[0m";
Color0="\E[0;34m";
Color1="\E[1;37m";
Color2="\E[0;37m";
Color3="\E[0;35m";
Color4="\E[1;33m";
Color5="\E[1;31m";
j=0; k=0;
cd "${PWD}/build";
echo
echo "+-------------------------------------------------------------------------------";
for i in $(${COMMAND} ${FLAGS}); do
if [ $j -eq 0 ]; then
echo -n "|";
if [ $k -eq 0 ]; then
echo -en "${Color5}";
fi
fi
echo -n " $i "
j=$((j+1)); k=$((k+1))
if [ $j -eq 6 ]; then
echo -e "$NColor";
j=0;
fi
done
echo "+- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -";
FlashSize=`${COMMAND} ${FLAGS} |grep "(TOTALS)"|sed -e "s/\s\{3,\}/+/g"|cut -d "+" -f2-3|bc`;
OldFlashSize=$( cat "$FlashLog" )
FileSize=`ls -1lisa|grep hex|cut -d ' ' -f7;`;
OldFileSize=$( cat "$FirmwareLog" )
FlashRatio=`echo "scale=8;100-(($FlashSize/$OldFlashSize)*100)"|bc|awk '{printf "%0f\n", $0}'|cut -c1-5`;
FlashDiff=`echo "scale=8;$OldFlashSize-$FlashSize"|bc|cut -c1-5`;
if [ $FlashDiff -lt 0 ]; then
MsgColor=$Color1;
SL="gewonnen";
FlashDiff=`echo $FlashDiffDiff|cut -c2-32`;
elif [ $FlashDiff -eq 0 ]; then
MsgColor=$Color0;
SL="Differenz";
else
MsgColor=$Color0;
SL="verloren";
fi
FileRatio=`echo "scale=8;100-(($FileSize/$OldFileSize)*100)"|bc|awk '{printf "%0f\n", $0}'|cut -c1-5`;
FileDiff=`echo "scale=8;$OldFileSize-$FileSize"|bc|cut -c1-5`;
if [ $FileDiff -lt 0 ]; then
MsgColor2=$Color1;
SL2="gewonnen";
FileDiff=`echo $FileDiff|cut -c2-32`;
elif [ $FileDiff -eq 0 ]; then
MsgColor2=$Color0;
SL2="Differenz";
else
MsgColor2=$Color0;
SL2="verloren";
fi
echo -en "| ${Color5}Current Flash-Size:$NColor ${Color3}${FlashSize} byte$NColor ";
echo -en "(${Color4}`echo "scale=8;((${FlashSize})/32768)*100"|bc|cut -c1-5`% used$NColor) / ${Color3}32768 byte$NColor";echo ;
echo -e "| ${Color5}Flash-Size-Ratio:$NColor ${MsgColor}$FlashRatio%$NColor (${MsgColor}$FlashDiff byte $SL$NColor)"
echo -e "|";
echo -e "| ${Color5}Current File-Size:$NColor ${Color2}$FileSize Byte$NColor";
echo -e "| ${Color5}File-Size-Ratio:$NColor ${MsgColor2}$FileRatio%$NColor (${MsgColor2}$FileDiff byte $SL2$NColor)"
echo "+-------------------------------------------------------------------------------";
echo "$FlashSize" > "$FlashLog"
echo "$FileSize" > "$FirmwareLog"
echo
cmake_minimum_required(VERSION 2.6.0)
include(${CMAKE_SOURCE_DIR}/CMakeConfig.cmake)
include_directories(${CMAKE_SOURCE_DIR}/src/lib/arduino)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/lib/arduino)
link_libraries(Arduino)
include_directories(${CMAKE_SOURCE_DIR}/src/lib)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/lib)
link_libraries(Backend)
add_executable(Slave-Stack.elf main.cpp)
target_link_libraries (Slave-Stack.elf Backend Arduino)
add_custom_command(
TARGET Slave-Stack.elf
POST_BUILD
COMMAND avr-objcopy -R .eeprom -O ihex "${CMAKE_SOURCE_DIR}/build/Slave-Stack.elf" "${CMAKE_SOURCE_DIR}/build/Slave-Stack.hex"
COMMAND echo "Building Done.."
COMMAND ${CMAKE_SOURCE_DIR}/bin/helper/printFirmwareInfo.sh "avr-size" "--format=berkeley -t ${CMAKE_SOURCE_DIR}/build/Slave-Stack.elf" "${CMAKE_SOURCE_DIR}"
)
cmake_minimum_required(VERSION 2.6.0)
project(Backend)
include(${CMAKE_SOURCE_DIR}/CMakeConfig.cmake)
#include_directories(arduino)
add_library (Backend
libChip.cpp
libCommunication.cpp
libInputPanel.cpp
libMCP2301X.cpp
)
include(${CMAKE_SOURCE_DIR}/CMakeConfig.cmake)
add_library (Arduino
HardwareSerial.cpp
Print.cpp
WCharacter.h
WInterrupts.c
WMath.cpp
Wire.cpp
pins_arduino.c
twi.c
wiring.c
wiring_analog.c
wiring_digital.c
wiring_pulse.c
wiring_shift.c
)
/*
HardwareSerial.cpp - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 23 November 2006 by David A. Mellis
*/
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "wiring.h"
#include "wiring_private.h"
#include "HardwareSerial.h"
// Define constants and variables for buffering incoming serial data. We're
// using a ring buffer (I think), in which rx_buffer_head is the index of the
// location to which to write the next incoming character and rx_buffer_tail
// is the index of the location from which to read.
#define RX_BUFFER_SIZE 128
struct ring_buffer {
unsigned char buffer[RX_BUFFER_SIZE];
int head;
int tail;
};
ring_buffer rx_buffer = { { 0 }, 0, 0 };
#if defined(__AVR_ATmega1280__)
ring_buffer rx_buffer1 = { { 0 }, 0, 0 };
ring_buffer rx_buffer2 = { { 0 }, 0, 0 };
ring_buffer rx_buffer3 = { { 0 }, 0, 0 };
#endif
inline void store_char(unsigned char c, ring_buffer *rx_buffer)
{
int i = (rx_buffer->head + 1) % RX_BUFFER_SIZE;
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
if (i != rx_buffer->tail) {
rx_buffer->buffer[rx_buffer->head] = c;
rx_buffer->head = i;
}
}
#if defined(__AVR_ATmega1280__)
SIGNAL(SIG_USART0_RECV)
{
unsigned char c = UDR0;
store_char(c, &rx_buffer);
}
SIGNAL(SIG_USART1_RECV)
{
unsigned char c = UDR1;
store_char(c, &rx_buffer1);
}
SIGNAL(SIG_USART2_RECV)
{
unsigned char c = UDR2;
store_char(c, &rx_buffer2);
}
SIGNAL(SIG_USART3_RECV)
{
unsigned char c = UDR3;
store_char(c, &rx_buffer3);
}
#else
#if defined(__AVR_ATmega8__)
SIGNAL(SIG_UART_RECV)
#else
SIGNAL(USART_RX_vect)
#endif
{
#if defined(__AVR_ATmega8__)
unsigned char c = UDR;
#else
unsigned char c = UDR0;
#endif
store_char(c, &rx_buffer);
}
#endif
// Constructors ////////////////////////////////////////////////////////////////
HardwareSerial::HardwareSerial(ring_buffer *rx_buffer,
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *udr,
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre)
{
_rx_buffer = rx_buffer;
_ubrrh = ubrrh;
_ubrrl = ubrrl;
_ucsra = ucsra;
_ucsrb = ucsrb;
_udr = udr;
_rxen = rxen;
_txen = txen;
_rxcie = rxcie;
_udre = udre;
}
// Public Methods //////////////////////////////////////////////////////////////
void HardwareSerial::begin(long speed)
{
*_ubrrh = ((F_CPU / 16 + speed / 2) / speed - 1) >> 8;
*_ubrrl = ((F_CPU / 16 + speed / 2) / speed - 1);
sbi(*_ucsrb, _rxen);
sbi(*_ucsrb, _txen);
sbi(*_ucsrb, _rxcie);
}
uint8_t HardwareSerial::available(void)
{
return (RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
}
int HardwareSerial::read(void)
{
// if the head isn't ahead of the tail, we don't have any characters
if (_rx_buffer->head == _rx_buffer->tail) {
return -1;
} else {
unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
_rx_buffer->tail = (_rx_buffer->tail + 1) % RX_BUFFER_SIZE;
return c;
}
}
void HardwareSerial::flush()
{
// don't reverse this or there may be problems if the RX interrupt
// occurs after reading the value of rx_buffer_head but before writing
// the value to rx_buffer_tail; the previous value of rx_buffer_head
// may be written to rx_buffer_tail, making it appear as if the buffer
// don't reverse this or there may be problems if the RX interrupt
// occurs after reading the value of rx_buffer_head but before writing
// the value to rx_buffer_tail; the previous value of rx_buffer_head
// may be written to rx_buffer_tail, making it appear as if the buffer
// were full, not empty.
_rx_buffer->head = _rx_buffer->tail;
}
void HardwareSerial::write(uint8_t c)
{
while (!((*_ucsra) & (1 << _udre)))
;
*_udr = c;
}
// Preinstantiate Objects //////////////////////////////////////////////////////
#if defined(__AVR_ATmega8__)
HardwareSerial Serial(&rx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRE);
#else
HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0);
#endif
#if defined(__AVR_ATmega1280__)
HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1);
HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2);
HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3);
#endif
/*
HardwareSerial.h - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef HardwareSerial_h
#define HardwareSerial_h
#include <inttypes.h>
#include "Print.h"
struct ring_buffer;
class HardwareSerial : public Print
{
private:
ring_buffer *_rx_buffer;
volatile uint8_t *_ubrrh;
volatile uint8_t *_ubrrl;
volatile uint8_t *_ucsra;
volatile uint8_t *_ucsrb;
volatile uint8_t *_udr;
uint8_t _rxen;
uint8_t _txen;
uint8_t _rxcie;
uint8_t _udre;
public:
HardwareSerial(ring_buffer *rx_buffer,
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *udr,
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre);
void begin(long);
uint8_t available(void);
int read(void);
void flush(void);
virtual void write(uint8_t);
using Print::write; // pull in write(str) and write(buf, size) from Print
};
extern HardwareSerial Serial;
#if defined(__AVR_ATmega1280__)
extern HardwareSerial Serial1;
extern HardwareSerial Serial2;
extern HardwareSerial Serial3;
#endif
#endif
/*
Print.cpp - Base class that provides print() and println()
Copyright (c) 2008 David A. Mellis. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 23 November 2006 by David A. Mellis
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "wiring.h"
#include "Print.h"
// Public Methods //////////////////////////////////////////////////////////////
/* default implementation: may be overridden */
void Print::write(const char *str)
{
while (*str)
write(*str++);
}
/* default implementation: may be overridden */
void Print::write(const uint8_t *buffer, size_t size)
{
while (size--)
write(*buffer++);
}
void Print::print(uint8_t b)
{
this->write(b);
}
void Print::print(char c)
{
print((byte) c);
}
void Print::print(const char str[])
{
write(str);
}
void Print::print(int n)
{
print((long) n);
}
void Print::print(unsigned int n)
{
print((unsigned long) n);
}
void Print::print(long n)
{
if (n < 0) {
print('-');
n = -n;
}
printNumber(n, 10);
}
void Print::print(unsigned long n)
{
printNumber(n, 10);
}
void Print::print(long n, int base)
{
if (base == 0)
print((char) n);
else if (base == 10)
print(n);
else
printNumber(n, base);
}
void Print::print(double n)
{
printFloat(n, 2);
}
void Print::println(void)
{
print('\r');
print('\n');
}
void Print::println(char c)
{
print(c);
println();
}
void Print::println(const char c[])
{
print(c);
println();
}
void Print::println(uint8_t b)
{
print(b);
println();
}
void Print::println(int n)
{
print(n);
println();
}
void Print::println(unsigned int n)
{
print(n);
println();
}
void Print::println(long n)
{
print(n);
println();
}
void Print::println(unsigned long n)
{
print(n);
println();
}
void Print::println(long n, int base)
{
print(n, base);
println();
}
void Print::println(double n)
{
print(n);
println();
}
// Private Methods /////////////////////////////////////////////////////////////
void Print::printNumber(unsigned long n, uint8_t base)
{
unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
unsigned long i = 0;
if (n == 0) {
print('0');
return;
}
while (n > 0) {
buf[i++] = n % base;
n /= base;
}
for (; i > 0; i--)
print((char) (buf[i - 1] < 10 ?
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
}
void Print::printFloat(double number, uint8_t digits)
{
// Handle negative numbers
if (number < 0.0)
{
print('-');
number = -number;
}