Commits

bsaid committed 4095188

Added RC receiver parser.
Added #ifndef to libraries.
Statements "todo" erased.

Comments (0)

Files changed (75)

firmware/YuniflyLibraries/accelerometer.hpp

-//todo: need debug
-
 //#include "basic.hpp"
 //#include "uart.hpp"
+#ifndef YuniflyAccelerometers
+#define YuniflyAccelerometers
+
+int const accNubmberOfChannels = 6;			//number of accelerometr channels {gx, gy, gz, ax, ay, az}
+bool const accDriven[accNubmberOfChannels] = {true, true, false, false, false, false};		//configuration of channels driven by accelerometers stabilization
+int const accChannelsPosition[accNubmberOfChannels] = {2,3,4,5,6,7};					//configuration of accelerotmeter channels and transmitter channels
+int accReverzCorrection[accNubmberOfChannels] = {1,1,1,1,1,1};					//set reverz and multiplied correction for transmitter channels
+int32_t wantAcc[accNubmberOfChannels];
 
 int32_t accData[8];	//saved accelerometers data
-int32_t computeAcc[8];	//integration of accData for detecting absolute position
-int32_t staticErrorsAcc[8];	//detected deviation after first calibration
+
 
 void accInit()
 {
 	rs2321.init(115200);
 }
 
+
 bool accUpdate()
 {
 	bool captured = false;
 	return captured;
 }
 
+/*int32_t computeAcc[8];	//integration of accData for detecting absolute position
+int32_t accStaticErrors[8];	//detected errors after first calibration
 
-/*void firstAccCalibration(int cycles = 1000)	//this function takes long time (a few seconds)
+void firstAccCalibration(int cycles = 1000)	//this function takes long time (a few seconds)
 {
 	for(int i=2;i<8;i++)
 	{
 
 	for(int i=2;i<8;i++)
 	{
-		staticErrorsAcc[i] = sumAcc[i] / cycles;
+		accStaticErrors[i] = sumAcc[i] / cycles;
 	}
 }*/
+
+
+#endif

firmware/YuniflyLibraries/basic.hpp

 #include <avr/io.h>
 #include <avr/interrupt.h>
 #include <util/delay.h>
+
+#include "uart.hpp"
+
+
+bool getBit(char value, int index)
+{
+	return value & (1<<index);
+}
+
+
+void init()
+{
+	sei();
+	rs232.init(38400);
+
+	_delay_ms(10);
+	debug << endl << "ok..." << endl;
+	debug.wait();
+}
+
+
+void run();
+
+
+int main()
+{
+	init();
+	run();
+	return 0;
+}

firmware/YuniflyLibraries/fastPWM.hpp

 //#include "basic.hpp"
 
-int const minPWMvalue = -64;	//min is -127, set -32 for debug
-int const maxPWMvalue = 64;		//max is 127, set 32 for debug
+#ifndef YuniflyFastPWM
+#define YuniflyFastPWM
+
+int const minServoValue = -64;	//min is -127, set -32 for debug
+int const maxServoValue = 64;		//max is 127, set 32 for debug
+
 
 int omezeni(int value)
 {
-	if(value > maxPWMvalue)
-		value = maxPWMvalue;
-	else if(value < minPWMvalue)
-		value = minPWMvalue;
+	if(value > maxServoValue)
+		value = maxServoValue;
+	else if(value < minServoValue)
+		value = minServoValue;
 	return value;
 }
 
-int convertPWMValue(int value)
+
+int convertServoValue(int value)
 {
 	return ((value+128)<<3)+500;
 }
 
+
 void setFastPWM(int id, int value)	//value -127; +127
 {
-	value = omezeni(value);
 	if(id == 0)
-		OCR1A = convertPWMValue(value);
+		OCR1A = value;
 	else if(id == 1)
-		OCR1B = convertPWMValue(value);
+		OCR1B = value;
 	else if(id == 2)
-		OCR1C = convertPWMValue(value);
+		OCR1C = value;
 	else if(id == 3)
-		OCR3A = convertPWMValue(value);
+		OCR3A = value;
 	else if(id == 4)
-		OCR3B = convertPWMValue(value);
+		OCR3B = value;
 	else if(id == 5)
-		OCR3C = convertPWMValue(value);
+		OCR3C = value;
 }
 
 
-void initFastPWM(uint32_t overflowValue = 20000)
+void setFastPWMServo(int id, int value)	//value -127; +127
+{
+	value = omezeni(value);
+	setFastPWM( id, convertServoValue(value) );
+}
+
+
+void initFastPWM(uint32_t overflowValue = 20000, int initValue = 0)
 {	
 	ICR1 = overflowValue;
 	ICR3 = overflowValue;
 
 	for(int i=0;i<6;i++)	//only 6 PWMs (constant)
 	{
-		setFastPWM( i, 0 );
+		setFastPWM( i, initValue );
 	}
 }
 
 
-void setAllPWMs(int v1, int v2, int v3, int v4, int v5, int v6)
+void initFastPWMServo(uint32_t overflowValue = 20000, int initValue = 0)
+{	
+	initFastPWM( overflowValue, convertServoValue(initValue) );
+}
+
+
+void setAllServos(int v1, int v2, int v3, int v4, int v5, int v6)
 {
 	v1 = omezeni(v1);
 	v2 = omezeni(v2);
 	v4 = omezeni(v4);
 	v5 = omezeni(v5);
 	v6 = omezeni(v6);
-	OCR1A = convertPWMValue(v1);
-	OCR1B = convertPWMValue(v2);
-	OCR1C = convertPWMValue(v3);
-	OCR3A = convertPWMValue(v4);
-	OCR3B = convertPWMValue(v5);
-	OCR3C = convertPWMValue(v6);
+	OCR1A = convertServoValue(v1);
+	OCR1B = convertServoValue(v2);
+	OCR1C = convertServoValue(v3);
+	OCR3A = convertServoValue(v4);
+	OCR3B = convertServoValue(v5);
+	OCR3C = convertServoValue(v6);
 }
 
+
 void testRangePWM()		//must not test motor range!
 {
-	for(int i=minPWMvalue;i<=maxPWMvalue;i++)
+	for(int i=minServoValue;i<=maxServoValue;i++)
 	{
-		setAllPWMs(i,i,i,i,i,i);
+		setAllServos(i,i,i,i,i,i);
 		_delay_ms(10);	//todo: time is not constant
 	}
-	for(int i=maxPWMvalue;i>=minPWMvalue;i--)
+	for(int i=maxServoValue;i>=minServoValue;i--)
 	{
-		setAllPWMs(i,i,i,i,i,i);
+		setAllServos(i,i,i,i,i,i);
 		_delay_ms(10);	//todo: time is not constant
 	}
 }
+
+
+#endif

firmware/YuniflyLibraries/firmware.aws

-<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA128"/><Files><File00000 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\YuniflyLibraries\firmware.c" Position="178 443 1274 741" LineCol="48 59"/><File00001 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\YuniflyLibraries\uart.hpp" Position="126 124 1214 392" LineCol="6 0"/><File00002 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\YuniflyLibraries\accelerometer.hpp" Position="261 761 421 788" LineCol="76 3"/><File00003 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\YuniflyLibraries\paralTransmitter.hpp" Position="176 174 1264 442" LineCol="6 74"/><File00004 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\YuniflyLibraries\fastPWM.hpp" Position="421 761 581 788" LineCol="62 3"/><File00005 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\YuniflyLibraries\led.hpp" Position="226 224 1314 492" LineCol="48 0"/></Files></AVRWorkspace>
+<AVRWorkspace><IOSettings><CurrentRegisters><AD_CONVERTER><register register="ADC" group="AD_CONVERTER" display="1" locked="0"/></AD_CONVERTER><AD_CONVERTER><register register="ADCSRA" group="AD_CONVERTER" display="1" locked="0"/></AD_CONVERTER><AD_CONVERTER><register register="ADMUX" group="AD_CONVERTER" display="1" locked="0"/></AD_CONVERTER></CurrentRegisters></IOSettings><part name="ATMEGA128"/><Files><File00000 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\YuniflyLibraries\firmware.c" Position="186 76 984 722" LineCol="62 0"/><File00001 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\YuniflyLibraries\uart.hpp" Position="506 787 666 814" LineCol="0 0"/><File00002 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\YuniflyLibraries\accelerometer.hpp" Position="281 179 1071 795" LineCol="7 0"/><File00003 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\YuniflyLibraries\paralTransmitter.hpp" Position="330 167 1120 783" LineCol="18 0"/><File00004 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\YuniflyLibraries\fastPWM.hpp" Position="346 787 506 814" LineCol="102 1"/><File00005 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\YuniflyLibraries\led.hpp" Position="186 787 346 814" LineCol="0 0"/></Files></AVRWorkspace>

firmware/YuniflyLibraries/firmware.c

 #include "basic.hpp"
 #include "led.hpp"
 #include "uart.hpp"
-using namespace kubas;	//todo: move or delete this
-kubas::format_t debug;
 #include "fastPWM.hpp"
 #include "accelerometer.hpp"
 #include "paralTransmitter.hpp"
 
+#include "stabilization.hpp"
 
-int main()
+
+void run()
 {
 	rs232.init(38400);
 	rs2321.init(115200);
-	sei();	//todo: move to correct library
-	initLEDs();
-	initFastPWM();
 
 	_delay_ms(10);
 	debug << endl << "ok..." << endl;
 	debug.wait();
 	
 	blink();
+
+	for(;;)
+	{
+	}
+	//initLEDs();
+	//initFastPWM();
 	//firstAccCalibration();
 	//blink();
 	//testRangePWM();
 
 	//BTRCinit();	//todo: uncomment or delete with declaration; set concurent access
 	//accInit();	//todo: uncomment or delete with declaration; set concurent access
-	int accPropConst = 200;
+	/*int accPropConst = 200;
 	
 	for(;;)
 	{
 			setLed();
 
 		//toggleLed();
-		/*debug.wait();
-		for(int j=2;j<8;j++)
-			debug << sumAcc[j] << "     |     ";
-			//debug << accData[j]/100 << "     |     ";
-		debug << "\r";*/
-	}
-
-	return 0;
+	}*/
 }

firmware/YuniflyLibraries/led.hpp

-//todo: need debug
 //#include "basic.hpp"
 
+#ifndef YuniflyLEDs
+#define YuniflyLEDs
 
 void initLEDs()
 {
-	DDRB = 0xF7;
-	PORTB = 0xF7;
+	DDRB = 0xF7;	//todo: set correct values
+	PORTB = 0xF7;	//todo: define LED ports externally
 	DDRE = 0xFF;
 	PORTE = 0xFF;
 }
 
 void blink(int waitTime_ms = 500)
 {
-	//PORTD |= (1<<5);
-	//PORTD |= (1<<7);
 	setLed();
 	_delay_ms(waitTime_ms);
 	clearLed();
 	}
 	led++;
 }
+
+#endif

firmware/YuniflyLibraries/paralTransmitter.hpp

 //todo: include libraries
+#ifndef paralTransmitterParser
+#define paralTransmitterParser
 
-int const channels = 6;		//todo: only 6 PWMs and 4 channels on transmitter, use 8 for AVR232client displaying
-int const startByte = 0xFF;
+int const BTRCnumberOfChannels = 8;		//only 6 PWMs and 4 channels on transmitter, use 8 for AVR232client displaying
+int const BTRCstartByte = 0xFF;
+int const BTRCservosPosition[BTRCnumberOfChannels] = {0,1,2,3,4,5};		//configuration of PWMs and transmitter channels
 
-int const servosPosition[channels] = {0,1,2,3,4,5};		//configuration of PWMs and transmitter channels
-bool const drivenByAcc[channels] = {true, true, false, false, false, false};		//configuration of channels driven by accelerometers stabilization
-int const accChannelsPosition[channels] = {2,3,4,5,6,7};					//configuration of accelerotmeter channels and transmitter channels
-
-int accReverzCorrection[channels] = {1,1,1,1,1,1};					//set reverz and multiplied correction for transmitter channels
-int32_t RCchannels[channels];
-int32_t wantAcc[channels];
-bool buttons[2];
-
-bool getBit(char value, int poce)
-{
-	return value & (1<<poce);
-}
+int32_t BTRCchannels[BTRCnumberOfChannels];
+bool BTRCbuttons[2];
 
 
 void BTRCinit()
 	char firstCaptured;
 	if(!rs232.peek(firstCaptured))
 		return true;
-	if(firstCaptured == startByte)
+	if(firstCaptured == BTRCstartByte)
 	{
 		int addr = rs232.get();	//adresa
 		int len = rs232.get();	//delka v bytech
 		{
 			for(int i=0;i<(len-1)/2;i++)	//kazdy kanal - 16bit, potom jeden byte na prikaz, proto (len-1)/2
 			{
-				RCchannels[i] = rs232.get()*256 + rs232.get();
-				if(RCchannels[i] > 32768)
-					RCchannels[i] -= 65535;
+				BTRCchannels[i] = rs232.get()*256 + rs232.get();
+				if(BTRCchannels[i] > 32768)
+					BTRCchannels[i] -= 65535;
 			}
 		}
 		if(cmd == 1)
 		{
 			if(rs232.get() == 1)
-				buttons[0] = false;
+				BTRCbuttons[0] = false;
 			else
-				buttons[0] = true;
+				BTRCbuttons[0] = true;
 			if(rs232.get() == 1)
-				buttons[1] = false;
+				BTRCbuttons[1] = false;
 			else
-				buttons[1] = true;
+				BTRCbuttons[1] = true;
 		}
 		return true;
 	}
 		error++;
 		if(error == 100)
 		{
-			for(int i=0;i<channels;i++)
+			for(int i=0;i<BTRCnumberOfChannels;i++)
 			{
-				RCchannels[i] = 0;
+				BTRCchannels[i] = 0;
 			}
 			error = 0;
 		}
 }
 
 
+#endif
+
 //parser for JUNIOR bluetooth transmitter
 /*int const startByte = 0x80;
 

firmware/YuniflyLibraries/softPWM.hpp

 //#include "basic.hpp"
+#ifndef YuniflySoftPWM
+#define YuniflySoftPWM
 
 volatile uint16_t servo[10];
 
 {
 	servo[id] = 12000 + value * 12;
 }
+
+
+#endif

firmware/YuniflyLibraries/stabilization.hpp

+//#include "basic.hpp"
+
+#define accNumberOfChannels 8
+#define historyLength 5
+
+class TaccHistory
+{
+	int history[historyLength][accNumberOfChannels];
+	int position;
+
+public:
+
+	TaccHistory()
+	{
+		position = 0;
+	}	
+
+	int limited(int value, int min = 0, int max = historyLength)
+	{
+		value -= min;
+		value = value % (max-min);
+		value += min;
+		return value;
+	}
+
+	void push(int32_t data[accNumberOfChannels])
+	{
+		for(int i=0;i<accNumberOfChannels;i++)
+		{
+			history[position][i] = data[i];
+		}
+		position = limited(position+1);
+	}
+
+	int getValue(int stepsAgo, int index)
+	{
+		return history[limited(position-stepsAgo)][index];
+	}
+};
+
+
+class Tstabilization
+{
+	TaccHistory history;
+	int lastDifference[accNumberOfChannels];
+
+public:
+
+	void calibration()
+	{
+		//todo
+	}
+	
+	void update()
+	{
+		history.push(accData);	//todo: global accelerometers variables
+		for(int i=0;i<accNumberOfChannels;i++)
+		{
+			lastDifference[i] = history.getValue(0,i) - history.getValue(1,i);	//todo: maybe set to 1 and 2 steps ago
+		}
+	}
+};

firmware/YuniflyLibraries/uart.hpp

-//#include "basic.hpp"
+#ifndef YuniflyUSART
+#define YuniflyUSART
 
 #define BOOTLOADER_PORT 0
 #define BOOTLOADER_WDT
 #include "kubas_avrlib/queue.h"
 #include "kubas_avrlib/rs232new-basic.h"
 #include "kubas_avrlib/format_rs232.h"
+
+using namespace kubas;	//todo: do not use "using namespace"
+kubas::format_t debug;
+
+#endif

firmware/stare/ServaICP/power_unit.c

-#define BOOTLOADER_PORT 0
-#define BOOTLOADER_WDT
-//#include"../headers/stdinc.h"
-#include<avr/io.h>
-#include<avr/interrupt.h>
-#include<util/delay.h>
-#include"../kubas_avrlib/queue.h"
-#include"../kubas_avrlib/rs232new-basic.h"
-#include"../kubas_avrlib/format_rs232.h"
-#include"../avrlib/portb.hpp"
-#include"../avrlib/portd.hpp"
-#include"../avrlib/porte.hpp"
-#include"../avrlib/portf.hpp"
-#include"../avrlib/pin.hpp"
-
-using namespace avrlib;
-using namespace kubas;
-
-format_t debug;
-
-void setMotorSpeed(int16_t l = 0, int16_t r = 0)
-{
-	if(l < 0)
-	{
-		PORTD |= (1<<6);
-		OCR1BL = 255 - ((-l)>>2);
-	}
-	else
-	{
-		PORTD &= ~(1<<6);
-		OCR1BL = 255 - (l>>2);
-	}
-	if(r < 0)
-	{
-		PORTD |= (1<<7);
-		OCR1CL = 255 - ((-r)>>2);
-	}
-	else
-	{
-		PORTD &= ~(1<<7);
-		OCR1CL = 255 - (r>>2);
-	}
-}
-
-volatile uint16_t servo[10];
-
-ISR(TIMER3_COMPA_vect)
-{
-	static int8_t state = 0;
-	static const uint8_t alignTable[10] = {5, 2, 4, 1, 3, 0, 9, 7, 8, 6};
-	OCR3A = servo[alignTable[state]];
-	if(state < 6)
-	{
-		
-		PORTB &= 0xF0;
-		PORTE = ((PORTE & 0x03) | (1<<(state + 2)));
-	}
-	else if(state != 10)
-	{
-		PORTE &= 0x03;
-		PORTB = ((PORTB & 0xF0) | (1<<(state - 6)));
-	}
-	else
-	{
-		state = -1;
-	}
-	++state;
-}
-
-void test()
-{
-	char ch;
-	if(!debug.peek(ch))
-		return;
-	debug<<"testing mode"<<endl;
-	int16_t l = 0;
-	int16_t r = 0;
-	int16_t k = 0;
-	for(;;)
-	{
-		if(debug.peek(ch))
-		{
-			switch(ch)
-			{
-				case 'w':
-					if(l>-1000)
-						l+=10;
-					debug<<"l = "<<l<<endl;
-					setMotorSpeed(l, r);
-					break;
-
-				case 's':
-					if(l<1000)
-						l-=10;
-					debug<<"l = "<<l<<endl;
-					setMotorSpeed(l, r);
-					break;
-
-				case 'e':
-					if(r>-1000)
-						r+=10;
-					debug<<"r = "<<r<<endl;
-					setMotorSpeed(l, r);
-					break;
-
-				case 'd':
-					if(r<1000)
-						r-=10;
-					debug<<"r = "<<r<<endl;
-					setMotorSpeed(l, r);
-					break;
-
-				case 'r':
-					if(k>-255)
-						--k;
-					debug<<"k = "<<k<<endl;
-					if(k<0)
-					{
-						OCR0 = 255 + k;
-						PORTD |= (1<<PD4);
-					}
-					else
-					{
-						OCR0 = 255 - k;
-						PORTD &= ~(1<<PD4);
-					}
-					break;
-
-				case 'f':
-					if(k<255)
-						++k;
-					debug<<"k = "<<k<<endl;
-					if(k<0)
-					{
-						OCR0 = 255 + k;
-						PORTD |= (1<<PD4);
-					}
-					else
-					{
-						OCR0 = 255 - k;
-						PORTD &= ~(1<<PD4);
-					}
-					break;
-
-				case 'W':
-					l = 0;
-					debug<<"l = "<<l<<endl;
-					setMotorSpeed(l, r);
-					break;
-
-				case 'E':
-					r = 0;
-					debug<<"r = "<<r<<endl;
-					setMotorSpeed(l, r);
-					break;
-
-				case 'R':
-					k = 0;
-					debug<<"k = "<<k<<endl;
-					OCR0 = 255;
-					break;
-
-				case 'z':
-					PORTD |= (1<<4);
-					_delay_ms(10);
-					debug<<"PD = "<<(PIND & 0xF0)<<endl;
-					break;
-				
-				case 'Z':
-					PORTD &= ~(1<<4);
-					_delay_ms(10);
-					debug<<"PD = "<<(PIND & 0xF0)<<endl;
-					break;
-				
-				case 'x':
-					PORTD |= (1<<5);
-					_delay_ms(10);
-					debug<<"PD = "<<(PIND & 0xF0)<<endl;
-					break;
-				
-				case 'X':
-					PORTD &= ~(1<<5);
-					_delay_ms(10);
-					debug<<"PD = "<<(PIND & 0xF0)<<endl;
-					break;
-				
-				case 'c':
-					PORTD |= (1<<6);
-					_delay_ms(10);
-					debug<<"PD = "<<(PIND & 0xF0)<<endl;
-					break;
-				
-				case 'C':
-					PORTD &= ~(1<<6);
-					_delay_ms(10);
-					debug<<"PD = "<<(PIND & 0xF0)<<endl;
-					break;
-				
-				case 'v':
-					PORTD |= (1<<7);
-					_delay_ms(10);
-					debug<<"PD = "<<(PIND & 0xF0)<<endl;
-					break;
-				
-				case 'V':
-					PORTD &= ~(1<<7);
-					_delay_ms(10);
-					debug<<"PD = "<<(PIND & 0xF0)<<endl;
-					break;
-				
-			}
-		}
-	}
-}
-
-int main()
-{
-	rs232.init(38400);
-	rs2321.init(38400);
-	_delay_us(1000);
-	sei();
-	debug<<endl<<endl<<" ok "<<endl;
-	debug.align(6);
-	DDRB = 0xFF;
-	DDRD = (1<<4)|(1<<5)|(1<<6)|(1<<7);
-	DDRE = (1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7);
-	OCR0 = 0xFF;
-	OCR1AL = 0xFF;
-	OCR1BL = 0xFF;
-	OCR1CL = 0xFF;
-	TCCR0 = (1<<WGM00)|(1<<WGM01)|(1<<COM00)|(1<<COM01)|(1<<CS01);
-	TCCR1A = (1<<COM1A1)|(1<<COM1A0)|(1<<COM1B1)|(1<<COM1B0)|(1<<COM1C1)|(1<<COM1C0)|(1<<WGM10);
-	TCCR1B = (1<<WGM12)|(1<<CS11);
-	OCR3A = 24000;
-	TCCR3B = (1<<CS30)|(1<<WGM32);
-	ETIMSK = (1<<OCIE3A);
-	for(uint8_t i = 0; i != 10; ++i)
-		servo[i] = 24000;
-	char ch = 0;
-	int16_t channels [4];
-	uint8_t buttons = 0;
-	int16_t l = 0;
-	int16_t r = 0;
-	for(;;)
-	{
-		while(ch != 0x80)
-		{
-			rs2321.peek(ch);
-			test();
-		}
-		while(ch != 0x19)
-		{
-			rs2321.peek(ch);
-			test();
-		}
-		for(uint8_t i = 0; i != 4; ++i)
-		{
-			while(!rs2321.peek(ch)){ test(); }
-			channels[i] = ch;
-			while(!rs2321.peek(ch)){ test(); }
-			channels[i] += (ch<<8);
-		}
-		while(!rs2321.peek(ch)){ test(); }
-		buttons = ch;
-		
-		for(uint8_t i = 0; i != 4; ++i)
-			debug<<channels[i];
-		debug<<buttons<<OCR1BL<<OCR1CL;
-		debug.wait();
-		l = channels[1] + channels[0];
-		r = channels[1] - channels[0];
-		if(l>1023)
-			l = 1023;
-		else if(l<-1023)
-			l = -1023;
-		if(r>1023)
-			r = 1023;
-		else if(r<-1023)
-			r = -1023;
-		//setMotorSpeed(l ,r);
-		if((buttons & 3) == 0)
-		{
-			setMotorSpeed(l ,r);
-			if((buttons & 4) != 0)
-			{
-				PORTD |= (1<<4);
-				OCR0 = 255 - (channels[3]>>2);
-			}
-			else if((buttons & 8) != 0)
-			{
-				OCR0 = 255 - (channels[3]>>2);
-			}
-			else
-			{
-				OCR0 = 255;
-				PORTD &= ~(1<<4);
-			}
-			//debug<<"   ";
-		}
-		else
-		{
-			servo[0+3*((buttons & 3)-1)] = 24000 + (channels[0] * 12);
-			servo[1+3*((buttons & 3)-1)] = 24000 + (channels[1] * 12);
-			servo[2+3*((buttons & 3)-1)] = 12000 + (channels[3] * 24);
-			//debug<<" s ";
-		}
-		/*for(uint8_t i = 0; i != 4; ++i)
-			debug<<((uint16_t)servo[i]);
-		debug<<"\r";
-		debug.wait();*/
-		/*setMotorSpeed(channels[0], channels[1]);
-		PORTD = (PORTD & 0x0F) | ((buttons & 0x0F)<<4);
-		if((buttons & 0x10) != 0)
-			OCR1AL = (channels[2]>>2);
-		else
-			OCR1AL = 255;
-		if((buttons & 0x20) != 0)
-			OCR1BL = (channels[2]>>2);
-		else
-			OCR1BL = 255;
-		if((buttons & 0x40) != 0)
-			OCR1CL = (channels[2]>>2);
-		else
-			OCR1CL = 255;
-		if((buttons & 0x80) != 0)
-			OCR0   = (channels[2]>>2);
-		else
-			OCR0   = 255;*/
-	}
-}

firmware/stare/ServaICP/testICP.aps

-<AVRStudio><MANAGEMENT><ProjectName>testICP</ProjectName><Created>16-May-2011 18:41:53</Created><LastEdit>21-Jun-2011 17:01:54</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>16-May-2011 18:41:53</Created><Version>4</Version><Build>4, 17, 0, 655</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\testICP.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>C:\Users\Admin\Desktop\Yunifly\ServaICP\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATmega128.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>testICP.c</SOURCEFILE><OTHERFILE>default\testICP.lss</OTHERFILE><OTHERFILE>default\testICP.map</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>atmega128</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>testICP.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>1</ISDIRTY><OPTIONS><OPTION><FILE>testICP.c</FILE><OPTIONLIST></OPTIONLIST></OPTION></OPTIONS><INCDIRS/><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2   -x c++   -DF_CPU=8000000UL -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-20100110\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\WinAVR-20100110\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><IOView><usergroups/><sort sorted="0" column="0" ordername="1" orderaddress="1" ordergroup="1"/></IOView><Files><File00000><FileId>00000</FileId><FileName>testICP.c</FileName><Status>1</Status></File00000><File00001><FileId>00001</FileId><FileName>power_unit.c</FileName><Status>1</Status></File00001></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>

firmware/stare/ServaICP/testICP.c

-
-
-int main()
-{
-	for(;;)
-	{
-		//to do
-	}
-	return 0;
-}

firmware/stare/ServaICP/testicp.aws

-<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA128"/><Files><File00000 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\ServaICP\testICP.c" Position="268 99 1345 593" LineCol="0 0"/></Files></AVRWorkspace>

firmware/stare/ServaICP/timer1.hpp

-#ifndef AVRLIB_TIMER1_HPP
-#define AVRLIB_TIMER1_HPP
-
-#include <avr/io.h>
-#include "timer_base.hpp"
-
-#ifndef TIFR1
-# define TIFR1 TIFR
-#endif
-
-#ifndef TIMSK1
-# define TIMSK1 TIMSK
-#endif
-
-#ifndef ICIE1
-# define ICIE1 TICIE1
-#endif
-
-namespace avrlib {
-
-struct timer1
-{
-	typedef uint16_t value_type;
-	typedef uint16_t time_type;
-	static const uint8_t value_bits = 16;
-
-	static value_type value()
-	{
-		value_type res = TCNT1L;
-		res |= TCNT1H << 8;
-		return res;
-	}
-
-	static void value(value_type v)
-	{
-		TCNT1H = v >> 8;
-		TCNT1L = v;
-	}
-
-	static void clock_source(timer_clock_source v)
-	{
-		TCCR1B = (TCCR1B & 0xf8) | v;
-	}
-
-	static void mode(timer_mode v)
-	{
-		TCCR1A = (TCCR1A & ~0x03) | (v & 0x03);
-		TCCR1B = (TCCR1B & ~0x18) | ((v & 0x0c) << 1);
-	}
-
-	struct ocra
-	{
-		static void mode(timer_ocr_mode v) { TCCR1A = (TCCR1A & 0x3f) | (v << 6); }
-		static void value(value_type v) { OCR1A = v; }
-		static value_type value() { return OCR1A; }
-		static void interrupt(bool enable)
-		{
-			if (enable)
-			{
-				TIFR1 = (1<<OCF1A);
-				TIMSK1 |= (1<<OCIE1A);
-			}
-			else
-				TIMSK1 &= (1<<OCIE1A);
-		}
-	};
-
-	struct ocrb
-	{
-		static void mode(timer_ocr_mode v) { TCCR1A = (TCCR1A & 0xcf) | (v << 4); }
-		static void value(value_type v) { OCR1B = v; }
-		static value_type value() { return OCR1B; }
-		static void interrupt(bool enable)
-		{
-			if (enable)
-			{
-				TIFR1 = (1<<OCF1B);
-				TIMSK1 |= (1<<OCIE1B);
-			}
-			else
-				TIMSK1 &= (1<<OCIE1B);
-		}
-	};
-
-#ifdef OCR1C
-	struct ocrc
-	{
-		static void mode(timer_ocr_mode v) { TCCR1A = (TCCR1A & 0xf3) | (v << 2); }
-		static void value(value_type v) { OCR1C = v; }
-		static value_type value() { return OCR1C; }
-		static void interrupt(bool enable)
-		{
-			if (enable)
-			{
-				TIFR1 = (1<<OCF1C);
-				TIMSK1 |= (1<<OCIE1C);
-			}
-			else
-				TIMSK1 &= (1<<OCIE1C);
-		}
-	};
-#endif
-
-	struct icr
-	{
-		static void value(value_type v) { ICR1 = v; }
-		static value_type value() { return ICR1; }
-
-		static void rising_edge(bool enable)
-		{
-			TCCR1B = (TCCR1B & ~(1<<ICES1)) | (enable? (1<<ICES1): 0);
-		}
-
-		static void noise_canceler(bool enable)
-		{
-			TCCR1B = (TCCR1B & ~(1<<ICNC1)) | (enable? (1<<ICNC1): 0);
-		}
-
-		static void interrupt(bool enable)
-		{
-			if (enable)
-			{
-				TIFR1 = (1<<ICF1);
-				TIMSK1 |= (1<<ICIE1);
-			}
-			else
-				TIMSK1 &= (1<<ICIE1);
-		}
-
-		static bool captured()
-		{
-			return TIFR1 & (1<<ICF1);
-		}
-
-		static void clear_captured()
-		{
-			TIFR1 = (1<<ICF1);
-		}
-	};
-
-	static void tov_interrupt(bool v)
-	{
-		if (v)
-		{
-			TIFR1 = (1<<TOV1);
-			TIMSK1 |= (1<<TOIE1);
-		}
-		else
-			TIMSK1 &= ~(1<<TOIE1);
-	}
-
-	static bool overflow()
-	{
-		return TIFR1 & (1<<TOV1);
-	}
-
-	static void clear_overflow()
-	{
-		TIFR1 = (1<<TOV1);
-	}
-};
-
-}
-
-#endif

firmware/stare/ServaICP/timer3.hpp

-#ifndef AVRLIB_TIMER3_HPP
-#define AVRLIB_TIMER3_HPP
-
-#include <avr/io.h>
-#include "timer_base.hpp"
-
-namespace avrlib {
-
-struct timer3
-{
-	typedef uint16_t value_type;
-	static const uint8_t value_bits = 16;
-
-	static value_type value()
-	{
-		value_type res = TCNT3L;
-		res |= TCNT3H << 8;
-		return res;
-	}
-
-	static void value(value_type v)
-	{
-		TCNT3H = v >> 8;
-		TCNT3L = v;
-	}
-
-	static void clock_source(timer_clock_source v)
-	{
-		TCCR3B = (TCCR3B & 0xf8) | v;
-	}
-
-	static void mode(timer_mode v)
-	{
-		TCCR3A = (TCCR3A & ~0x03) | (v & 0x03);
-		TCCR3B = (TCCR3B & ~0x18) | ((v & 0x0c) << 1);
-	}
-
-	struct ocra
-	{
-		typedef uint16_t value_type;
-		static void mode(timer_ocr_mode v) { TCCR3A = (TCCR3A & 0x3f) | (v << 6); }
-		static void value(value_type v) { OCR3A = v; }
-		static value_type value() { return OCR3A; }
-		static void interrupt(bool enable)
-		{
-			if (enable)
-			{
-				TIFR3 = (1<<OCF3A);
-				TIMSK3 |= (1<<OCIE3A);
-			}
-			else
-				TIMSK3 &= (1<<OCIE3A);
-		}
-	};
-
-	struct ocrb
-	{
-		typedef uint16_t value_type;
-		static void mode(timer_ocr_mode v) { TCCR3A = (TCCR3A & 0xcf) | (v << 4); }
-		static void value(value_type v) { OCR3B = v; }
-		static value_type value() { return OCR3B; }
-		static void interrupt(bool enable)
-		{
-			if (enable)
-			{
-				TIFR3 = (1<<OCF3B);
-				TIMSK3 |= (1<<OCIE3B);
-			}
-			else
-				TIMSK3 &= (1<<OCIE3B);
-		}
-	};
-
-	struct ocrc
-	{
-		typedef uint16_t value_type;
-		static void mode(timer_ocr_mode v) { TCCR3A = (TCCR3A & 0xf3) | (v << 2); }
-		static void value(value_type v) { OCR3C = v; }
-		static value_type value() { return OCR3C; }
-		static void interrupt(bool enable)
-		{
-			if (enable)
-			{
-				TIFR3 = (1<<OCF3C);
-				TIMSK3 |= (1<<OCIE3C);
-			}
-			else
-				TIMSK3 &= (1<<OCIE3C);
-		}
-	};
-
-	static uint8_t tov_interrupt(bool v)
-	{
-		if (v)
-		{
-			TIFR3 = (1<<TOV3);
-			TIMSK3 |= (1<<TOIE3);
-		}
-		else
-			TIMSK3 &= ~(1<<TOIE3);
-	}
-
-	static bool overflow()
-	{
-		return TIFR3 & (1<<TOV3);
-	}
-
-	static void clear_overflow()
-	{
-		TIFR3 = (1<<TOV3);
-	}
-};
-
-}
-
-#endif

firmware/stare/ServaICP/timer_base.hpp

-#ifndef AVRLIB_TIMER_BASE_HPP
-#define AVRLIB_TIMER_BASE_HPP
-
-namespace avrlib {
-
-enum timer_clock_source
-{
-	timer_no_clock = 0,
-	timer_fosc_1 = 1,
-	timer_fosc_8 = 2,
-	timer_fosc_64 = 3,
-	timer_fosc_256 = 4,
-	timer_fosc_1024 = 5,
-	timer_ext_falling = 6,
-	timer_ext_rising = 7,
-};
-
-enum timer_mode
-{
-	timer_mode_normal,
-	timer_mode_pwmp_8,
-	timer_mode_pwmp_9,
-	timer_mode_pwmp_10,
-	timer_mode_ctc_ocra,
-	timer_mode_pwm_8,
-	timer_mode_pwm_9,
-	timer_mode_pwm_10,
-	timer_mode_pwmpf_icr,
-	timer_mode_pwmpf_ocra,
-	timer_mode_pwmp_icr,
-	timer_mode_pwmp_ocra,
-	timer_mode_ctc_icr,
-	timer_mode_13,
-	timer_mode_pwm_icr,
-	timer_mode_pwm_ocra,
-};
-
-enum timer_ocr_mode
-{
-	timer_ocr_mode_disconnected = 0,
-	timer_ocr_mode_toggle = 1,
-	timer_ocr_mode_positive = 2,
-	timer_ocr_mode_negative = 3,
-};
-
-}
-
-#endif

firmware/stare/testICP/testICP.aps

-<AVRStudio><MANAGEMENT><ProjectName>testICP</ProjectName><Created>16-May-2011 18:41:53</Created><LastEdit>20-Jun-2011 18:22:57</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>16-May-2011 18:41:53</Created><Version>4</Version><Build>4, 17, 0, 655</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\testICP.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>C:\Documents and Settings\said\Desktop\Yunifly\testICP\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATmega128.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>testICP.c</SOURCEFILE><OTHERFILE>default\testICP.lss</OTHERFILE><OTHERFILE>default\testICP.map</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>atmega128</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>testICP.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>1</ISDIRTY><OPTIONS><OPTION><FILE>testICP.c</FILE><OPTIONLIST></OPTIONLIST></OPTION></OPTIONS><INCDIRS/><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2  -x c++  -DF_CPU=8000000UL -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-20090313\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\WinAVR-20090313\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><IOView><usergroups/><sort sorted="0" column="0" ordername="0" orderaddress="0" ordergroup="0"/></IOView><Files><File00000><FileId>00000</FileId><FileName>testICP.c</FileName><Status>1</Status></File00000></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>

firmware/stare/testICP/testICP.c

-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-
-#define BOOTLOADER_WDT
-
-#include "../kubas_avrlib/queue.h"
-#include "../kubas_avrlib/rs232new-basic.h"
-#include "../kubas_avrlib/format_rs232.h"
-
-using namespace kubas;
-
-format_t dataOut;
-
-int timeCapture = 0;
-
-SIGNAL (SIG_INPUT_CAPTURE1)
-{
-	timeCapture = TCNT1;
-}
-
-void initialize(void)
-{
-	DDRD = 0x80; //set input pins
-	TCCR1A = 0x00;
-	TCCR1B = 0x03;
-	OCR2 = 200;
-	sei();
-}
-
-//This is the routine which is waiting for interrupts
-
-void record(void)
-{
-	unsigned char sreg;
-
-	/* Save global interrupt flag */
-	sreg = SREG;
-
-	TCNT1 = 0; // Reset the clock here
-	int timeframe = -1; // Initialize our timeframe variable
-
-	TIMSK = 0x20; // Enable the ICP interrupt and disable all other interrupts
-	TIFR = 0x20;
-
-	if ((PIND & 0x10)==0x10) //if(ICP)
-	{
-		TCCR1B = TCCR1B & 0xBF; // Interrupt trigger on a falling edge
-	}
-	else
-	{
-		TCCR1B = TCCR1B | 0x40; // Interrupt trigger on a rising edge
-	}
-
-	/* Restore global interrupt flag */
-	SREG = sreg;
-	timeframe = 0; // Reset this variable
-	TIMSK = 0x02; // Turn all other interrupts on and turn the input capture ISR off
-	dataOut << timeCapture << "   " << TCNT1 << endl;
-	dataOut.wait();
-} 
-
-int main()
-{
-	rs232.init(38400);
-	sei();
-	dataOut<<endl<<endl<<" ok "<<endl;
-	dataOut.wait();
-	initialize();
-	for(;;)
-	{
-		record();
-	}
-}

firmware/stare/testICP/testicp.aws

-<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA128"/><Files><File00000 Name="C:\Documents and Settings\said\Desktop\Yunifly\testICP\testICP.c" Position="262 71 1328 774" LineCol="21 21" State="Maximized"/></Files></AVRWorkspace>

firmware/testy/SDmega128/SD_Card.aps

-<AVRStudio><MANAGEMENT><ProjectName>SD_Card</ProjectName><Created>08-Feb-2009 12:32:42</Created><LastEdit>23-Jun-2011 14:05:17</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>08-Feb-2009 12:32:42</Created><Version>4</Version><Build>4, 14, 0, 589</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\SD_Card.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>C:\Users\Admin\Desktop\Yunifly\SDmega128\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATmega8.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><Variables>option</Variables></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><modules><module></module></modules><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>FAT32.c</SOURCEFILE><SOURCEFILE>SD_main.c</SOURCEFILE><SOURCEFILE>SD_routines.c</SOURCEFILE><SOURCEFILE>SPI_routines.c</SOURCEFILE><SOURCEFILE>UART_routines.c</SOURCEFILE><SOURCEFILE>RTC_routines.c</SOURCEFILE><SOURCEFILE>i2c_routines.c</SOURCEFILE><HEADERFILE>FAT32.h</HEADERFILE><HEADERFILE>SD_routines.h</HEADERFILE><HEADERFILE>SPI_routines.h</HEADERFILE><HEADERFILE>UART_routines.h</HEADERFILE><HEADERFILE>i2c_routines.h</HEADERFILE><HEADERFILE>RTC_routines.h</HEADERFILE><OTHERFILE>default\SD_Card.lss</OTHERFILE><OTHERFILE>default\SD_Card.map</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>atmega128</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>SD_Card.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>0</ISDIRTY><OPTIONS><OPTION><FILE>FAT32.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>RTC_routines.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>SD_main.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>SD_routines.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>SPI_routines.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>UART_routines.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>i2c_routines.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  -x c++ </OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\WinAVR-20100110\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\WinAVR-20100110\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><IOView><usergroups/><sort sorted="0" column="0" ordername="1" orderaddress="1" ordergroup="1"/></IOView><Files><File00000><FileId>00000</FileId><FileName>FAT32.c</FileName><Status>257</Status></File00000><File00001><FileId>00001</FileId><FileName>SD_main.c</FileName><Status>257</Status></File00001><File00002><FileId>00002</FileId><FileName>FAT32.h</FileName><Status>1</Status></File00002><File00003><FileId>00003</FileId><FileName>SD_routines.c</FileName><Status>1</Status></File00003><File00004><FileId>00004</FileId><FileName>sd_routines.h</FileName><Status>1</Status></File00004><File00005><FileId>00005</FileId><FileName>UART_routines.c</FileName><Status>1</Status></File00005><File00006><FileId>00006</FileId><FileName>SPI_routines.h</FileName><Status>1</Status></File00006><File00007><FileId>00007</FileId><FileName>UART_routines.h</FileName><Status>1</Status></File00007><File00008><FileId>00008</FileId><FileName>RTC_routines.c</FileName><Status>1</Status></File00008><File00009><FileId>00009</FileId><FileName>i2c_routines.c</FileName><Status>1</Status></File00009><File00010><FileId>00010</FileId><FileName>i2c_routines.h</FileName><Status>1</Status></File00010><File00011><FileId>00011</FileId><FileName>RTC_routines.h</FileName><Status>1</Status></File00011><File00012><FileId>00012</FileId><FileName>SPI_routines.c</FileName><Status>1</Status></File00012><File00013><FileId>00013</FileId><FileName>kubas_avrlib\queue.h</FileName><Status>1</Status></File00013><File00014><FileId>00014</FileId><FileName>kubas_avrlib\rs232new-basic.h</FileName><Status>1</Status></File00014></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>
+<AVRStudio><MANAGEMENT><ProjectName>SD_Card</ProjectName><Created>08-Feb-2009 12:32:42</Created><LastEdit>06-Oct-2011 16:11:25</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>08-Feb-2009 12:32:42</Created><Version>4</Version><Build>4, 14, 0, 589</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\SD_Card.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATmega8.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><Variables>option</Variables></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><modules><module></module></modules><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>FAT32.c</SOURCEFILE><SOURCEFILE>SD_main.c</SOURCEFILE><SOURCEFILE>SD_routines.c</SOURCEFILE><SOURCEFILE>SPI_routines.c</SOURCEFILE><SOURCEFILE>UART_routines.c</SOURCEFILE><SOURCEFILE>RTC_routines.c</SOURCEFILE><SOURCEFILE>i2c_routines.c</SOURCEFILE><HEADERFILE>FAT32.h</HEADERFILE><HEADERFILE>SD_routines.h</HEADERFILE><HEADERFILE>SPI_routines.h</HEADERFILE><HEADERFILE>UART_routines.h</HEADERFILE><HEADERFILE>i2c_routines.h</HEADERFILE><HEADERFILE>RTC_routines.h</HEADERFILE><OTHERFILE>default\SD_Card.lss</OTHERFILE><OTHERFILE>default\SD_Card.map</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>atmega128</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>SD_Card.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>0</ISDIRTY><OPTIONS><OPTION><FILE>FAT32.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>RTC_routines.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>SD_main.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>SD_routines.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>SPI_routines.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>UART_routines.c</FILE><OPTIONLIST></OPTIONLIST></OPTION><OPTION><FILE>i2c_routines.c</FILE><OPTIONLIST></OPTIONLIST></OPTION></OPTIONS><INCDIRS/><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums  -x c++ </OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\WinAVR-20100110\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\WinAVR-20100110\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><ProjectFiles><Files><Name>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\FAT32.h</Name><Name>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\SD_routines.h</Name><Name>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\SPI_routines.h</Name><Name>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\UART_routines.h</Name><Name>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\i2c_routines.h</Name><Name>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\RTC_routines.h</Name><Name>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\FAT32.c</Name><Name>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\SD_main.c</Name><Name>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\SD_routines.c</Name><Name>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\SPI_routines.c</Name><Name>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\UART_routines.c</Name><Name>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\RTC_routines.c</Name><Name>D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\i2c_routines.c</Name></Files></ProjectFiles><IOView><usergroups/><sort sorted="0" column="0" ordername="0" orderaddress="0" ordergroup="0"/></IOView><Files><File00000><FileId>00000</FileId><FileName>FAT32.c</FileName><Status>257</Status></File00000><File00001><FileId>00001</FileId><FileName>SD_main.c</FileName><Status>257</Status></File00001><File00002><FileId>00002</FileId><FileName>FAT32.h</FileName><Status>1</Status></File00002><File00003><FileId>00003</FileId><FileName>SD_routines.c</FileName><Status>1</Status></File00003><File00004><FileId>00004</FileId><FileName>sd_routines.h</FileName><Status>1</Status></File00004><File00005><FileId>00005</FileId><FileName>UART_routines.c</FileName><Status>1</Status></File00005><File00006><FileId>00006</FileId><FileName>SPI_routines.h</FileName><Status>1</Status></File00006><File00007><FileId>00007</FileId><FileName>UART_routines.h</FileName><Status>1</Status></File00007><File00008><FileId>00008</FileId><FileName>RTC_routines.c</FileName><Status>1</Status></File00008><File00009><FileId>00009</FileId><FileName>i2c_routines.c</FileName><Status>1</Status></File00009><File00010><FileId>00010</FileId><FileName>i2c_routines.h</FileName><Status>1</Status></File00010><File00011><FileId>00011</FileId><FileName>RTC_routines.h</FileName><Status>1</Status></File00011><File00012><FileId>00012</FileId><FileName>SPI_routines.c</FileName><Status>1</Status></File00012><File00013><FileId>00013</FileId><FileName>kubas_avrlib\queue.h</FileName><Status>1</Status></File00013><File00014><FileId>00014</FileId><FileName>kubas_avrlib\rs232new-basic.h</FileName><Status>1</Status></File00014></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>

firmware/testy/SDmega128/sd_card.aws

-<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA8"/><Files><File00000 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\FAT32.c" Position="268 99 1345 593" LineCol="236 0"/><File00001 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\SD_main.c" Position="293 124 1362 588" LineCol="37 0"/><File00002 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\FAT32.h" Position="318 149 1387 613" LineCol="109 0"/><File00003 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\SD_routines.c" Position="343 174 1412 638" LineCol="8 0"/><File00004 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\sd_routines.h" Position="368 199 1437 663" LineCol="8 0"/><File00005 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\UART_routines.c" Position="393 224 1462 688" LineCol="122 0"/><File00006 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\SPI_routines.h" Position="418 249 1487 713" LineCol="8 0"/><File00007 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\UART_routines.h" Position="443 274 1512 738" LineCol="8 0"/><File00008 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\RTC_routines.c" Position="468 299 1537 763" LineCol="528 0"/><File00009 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\i2c_routines.c" Position="493 324 1562 788" LineCol="8 0"/><File00010 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\i2c_routines.h" Position="588 761 748 788" LineCol="8 0"/><File00011 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\RTC_routines.h" Position="428 761 588 788" LineCol="8 0"/><File00012 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\SPI_routines.c" Position="268 761 428 788" LineCol="25 0"/><File00013 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\kubas_avrlib\queue.h" Position="343 174 1412 638" LineCol="5 36"/><File00014 Name="C:\Users\Admin\Desktop\Yunifly\SDmega128\kubas_avrlib\rs232new-basic.h" Position="368 199 1437 663" LineCol="288 0"/></Files></AVRWorkspace>
+<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA8"/><Files><File00000 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\FAT32.c" Position="268 99 1399 593" LineCol="283 0"/><File00001 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\SD_main.c" Position="293 124 1416 588" LineCol="308 0"/><File00002 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\FAT32.h" Position="318 149 1441 613" LineCol="109 0"/><File00003 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\SD_routines.c" Position="343 174 1466 638" LineCol="8 0"/><File00004 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\sd_routines.h" Position="368 199 1491 663" LineCol="8 0"/><File00005 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\UART_routines.c" Position="428 761 588 788" LineCol="119 19"/><File00006 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\SPI_routines.h" Position="418 249 1541 713" LineCol="8 0"/><File00007 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\UART_routines.h" Position="443 274 1566 738" LineCol="8 0"/><File00008 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\RTC_routines.c" Position="468 299 1591 763" LineCol="528 0"/><File00009 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\i2c_routines.c" Position="493 324 1616 788" LineCol="5 0"/><File00010 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\i2c_routines.h" Position="268 99 1391 563" LineCol="8 0"/><File00011 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\RTC_routines.h" Position="293 124 1416 588" LineCol="8 0"/><File00012 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\SPI_routines.c" Position="318 149 1441 613" LineCol="25 0"/><File00013 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\kubas_avrlib\queue.h" Position="343 174 1466 638" LineCol="25 0"/><File00014 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\SDmega128\kubas_avrlib\rs232new-basic.h" Position="268 761 428 788" LineCol="288 0"/></Files></AVRWorkspace>

firmware/testy/TheFirstICR/thefirsticr.aws

-<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA128"/><Files><File00000 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\TheFirstICR\TheFirstICR.c" Position="258 67 1757 798" LineCol="29 3" State="Maximized"/></Files></AVRWorkspace>
+<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA128"/><Files><File00000 Name="D:\Beda\Aktualni data\Yunifly\Yunifly\testy\TheFirstICR\TheFirstICR.c" Position="101 99 1210 722" LineCol="30 0"/></Files></AVRWorkspace>

firmware/testy/avrlib/adc.hpp

+#ifndef AVRLIB_ADC_HPP
+#define AVRLIB_ADC_HPP
+
+#include <avr/io.h>
+
+namespace avrlib {
+
+class sync_adc
+{
+public:
+	explicit sync_adc(uint8_t channel, bool reverse = false)
+		: m_channel(channel), m_reverse(reverse)
+	{
+	}
+
+	void start()
+	{
+		ADCSRA |= (1<<ADSC);
+	}
+
+	bool running() const
+	{
+		return (ADCSRA & (1<<ADSC)) != 0;
+	}
+
+	uint16_t value() const
+	{
+		uint16_t res = ADCL;
+		res |= ADCH << 8;
+		return res;
+	}
+
+	uint16_t operator()()
+	{
+		ADMUX = (1<<ADLAR) | m_channel;
+		ADCSRA |= (1<<ADSC);
+		while ((ADCSRA & (1<<ADIF)) == 0)
+		{
+		}
+		/*ADCSRA |= (1<<ADSC);
+		while ((ADCSRA & (1<<ADIF)) == 0)
+		{
+		}*/
+
+		uint16_t res = ADCL;
+		res |= ADCH << 8;
+
+		if (m_reverse)
+			res = -res;
+
+		return res;
+	}
+
+private:
+	uint8_t m_channel;
+	bool m_reverse;
+};
+
+
+class async_adc
+{
+public:
+	explicit async_adc(uint8_t channel, bool reverse = false)
+		: m_channel(channel), m_reverse(reverse), m_value(0)
+	{
+	}
+
+	void start()
+	{
+		ADMUX = (1<<ADLAR) | m_channel;
+		ADCSRA |= (1<<ADSC);
+	}
+
+	bool process()
+	{
+		if ((ADCSRA & (1<<ADSC)) != 0)
+			return false;
+
+		m_value = ADCL;
+		m_value |= ADCH << 8;
+
+		if (m_reverse)
+			m_value = -m_value;
+
+		return true;
+	}
+
+	uint16_t value() const
+	{
+		return m_value;
+	}
+
+private:
+	uint8_t m_channel;
+	bool m_reverse;
+	uint16_t m_value;
+};
+
+}
+
+#endif

firmware/testy/avrlib/assert.hpp

+#ifndef AVRLIB_ASSERT_HPP
+#define AVRLIB_ASSERT_HPP
+
+#include <avr/interrupt.h>
+
+namespace avrlib {
+
+void assertion_failed(char const * message, char const * file, int line);
+
+class trace_mask_t
+{
+public:
+	trace_mask_t()
+		: m_mask(0)
+	{
+	}
+
+	void clear()
+	{
+		m_mask = 0;
+	}
+
+	void set(uint32_t mask = 0xffffffff)
+	{
+		m_mask = mask;
+	}
+
+	uint32_t get() const { return m_mask; }
+
+private:
+	uint32_t m_mask;
+};
+
+extern trace_mask_t trace_mask;
+void trace_triggered(uint8_t const * value, uint8_t len, char const * message, char const * file, int line);
+
+template <typename T>
+inline void trace_triggered(T value, char const * message, char const * file, int line)
+{
+	trace_triggered((uint8_t const *)&value, sizeof(T), message, file, line);
+}
+
+namespace detail {
+
+template <typename Usart>
+void trace_assert_common_main(char const * header, Usart & usart, uint8_t const * value, uint8_t len, char const * message, char const * file, int line)
+{
+	cli();
+
+	send(usart, header);
+	send(usart, file);
+	send(usart, "(");
+	send_int(usart, line);
+	send(usart, "): ");
+	send(usart, message);
+	send(usart, " = ");
+	for (uint8_t i = 0; i < len; ++i)
+	{
+		send_hex(usart, value[i], 2);
+		usart.write(' ');
+	}
+	send(usart, "\r\n");
+
+	for (;;)
+	{
+		usart.process_rx();
+		usart.process_tx();
+
+		if (usart.empty())
+			continue;
+
+		switch (usart.read())
+		{
+		case '?':
+			send(usart, header);
+			send(usart, file);
+			send(usart, "(");
+			send_int(usart, line);
+			send(usart, "): ");
+			send(usart, message);
+			send(usart, " = ");
+			for (uint8_t i = 0; i < len; ++i)
+			{
+				send_hex(usart, value[i], 2);
+				usart.write(' ');
+			}
+			send(usart, "\r\n");
+			break;
+#if 0
+		case 'q':
+			force_wd_reset();
+			break;
+#endif
+		case 't':
+			trace_mask.set();
+			break;
+		case 'C':
+			trace_mask.clear();
+			// fall through
+		case 'c':
+			sei();
+			return;
+		}
+	}
+}
+
+}
+
+template <typename Usart>
+void trace_main(Usart & usart, uint8_t const * value, uint8_t len, char const * message, char const * file, int line)
+{
+	detail::trace_assert_common_main("trace: ", usart, value, len, message, file, line);
+}
+
+template <typename Usart>
+void assert_main(Usart & usart, char const * message, char const * file, int line)
+{
+	trace_mask.set();
+	detail::trace_assert_common_main("assertion failed: ", usart, 0, 0, message, file, line);
+}
+
+}
+
+#ifndef NDEBUG
+#define AVRLIB_ASSERT(x) do { if(!(x)) ::avrlib::assertion_failed(#x, __FILE__, __LINE__); } while(0)
+#define AVRLIB_VERIFY(x) AVRLIB_ASSERT(x)
+#else
+#define AVRLIB_ASSERT(x) (void)0
+#define AVRLIB_VERIFY(x) (void)(x)
+#endif
+
+#ifndef NDEBUG
+#define AVRLIB_TRACE(mask, value) do { if (::avrlib::trace_mask.get() & (mask)) ::avrlib::trace_triggered((value), #value, __FILE__, __LINE__); } while(0)
+#define AVRLIB_TRACE_BIN(mask, value, len) do { if (::avrlib::trace_mask.get() & (mask)) ::avrlib::trace_triggered((value), (len), #value, __FILE__, __LINE__); } while(0)
+#else
+#define AVRLIB_TRACE(mask, value) (void)0
+#define AVRLIB_TRACE_BIN(mask, value, len) (void)0
+#endif
+
+#ifndef NDEBUG
+#define AVRLIB_ASSERT_TRACE(x, value) do { if(!(x)) { ::avrlib::trace_triggered((value), #value, __FILE__, __LINE__); ::avrlib::assertion_failed(#x, __FILE__, __LINE__); } } while(0)
+#define AVRLIB_VERIFY_TRACE(x, value) AVRLIB_ASSERT_TRACE(x, value)
+#else
+#define AVRLIB_ASSERT_TRACE(x, value) (void)0
+#define AVRLIB_VERIFY_TRACE(x, value) (void)(x)
+#endif
+
+#endif

firmware/testy/avrlib/async_usart.hpp

+#ifndef AVRLIB_ASYNC_USART_HPP
+#define AVRLIB_ASYNC_USART_HPP
+
+#include <stdint.h>
+#include "usart_base.hpp"
+#include "nobootseq.hpp"
+#include "buffer.hpp"
+
+namespace avrlib {
+
+template <typename Usart, int RxBufferSize, int TxBufferSize, typename Bootseq = nobootseq, typename Overflow = uint32_t>
+class async_usart
+{
+public:
+	typedef Usart usart_type;
+	typedef Overflow overflow_type;
+	typedef typename usart_type::value_type value_type;
+
+	typedef Bootseq bootseq_type;
+
+	async_usart()
+		: m_overflows(0)
+	{
+	}
+
+	bool empty() const
+	{
+		return m_rx_buffer.empty();
+	}
+
+	bool tx_empty() const
+	{
+		return m_tx_buffer.empty();
+	}
+
+	bool tx_ready() const
+	{
+		return !m_tx_buffer.full();
+	}
+
+	value_type read()
+	{
+		while (m_rx_buffer.empty())
+		{
+			cli();
+			this->process_rx();
+			sei();
+		}
+		
+		value_type res = m_rx_buffer.top();
+		m_rx_buffer.pop();
+		return res;
+	}
+
+	uint8_t read_size() const
+	{
+		return m_rx_buffer.size();
+	}
+
+	void write(value_type v)
+	{
+		while (m_tx_buffer.full())
+		{
+			cli();
+			this->process_tx();
+			sei();
+		}
+
+		m_tx_buffer.push(v);
+	}
+	
+	void flush()
+	{
+		bool tx_empty = false;
+		while (!tx_empty)
+		{
+			cli();
+			this->process_tx();
+			tx_empty = m_tx_buffer.empty();
+			sei();
+		}
+	}
+
+	void process_rx()
+	{
+		if (m_usart.rx_empty())
+			return;
+
+		if (m_usart.overflow())
+			++m_overflows;
+		value_type v = m_bootseq.check(m_usart.recv());
+		if (!m_rx_buffer.full())
+			m_rx_buffer.push(v);
+	}
+
+	void process_tx()
+	{
+		if (!m_tx_buffer.empty() && m_usart.tx_empty())
+		{
+			m_usart.send(m_tx_buffer.top());
+			m_tx_buffer.pop();
+		}
+
+		// TODO: flush the underlying port
+	}
+
+	typedef buffer<value_type, RxBufferSize> rx_buffer_type;
+	rx_buffer_type & rx_buffer() { return m_rx_buffer; }
+
+	overflow_type overflows() const { return m_overflows; }
+
+	usart_type & usart() { return m_usart; }
+	usart_type const & usart() const { return m_usart; }
+
+private:
+	usart_type m_usart;
+	buffer<value_type, RxBufferSize> m_rx_buffer;
+	buffer<value_type, TxBufferSize> m_tx_buffer;
+	bootseq_type m_bootseq;
+
+	overflow_type m_overflows;
+};
+
+}
+
+#endif

firmware/testy/avrlib/atomic.hpp

+#ifndef AVRLIB_ATOMIC_HPP
+#define AVRLIB_ATOMIC_HPP
+
+namespace avrlib {
+
+template <typename T>
+class atomic
+{
+public:
+	typedef T value_type;
+
+	atomic()
+	{
+	}
+
+	explicit atomic(value_type value)
+		: m_value(value)
+	{
+	}
+
+	value_type load() const volatile
+	{
+		return m_value;
+	}
+
+	value_type load_consume() const
+	{
+		return m_value;
+	}
+
+	operator value_type() const volatile
+	{
+		return m_value;
+	}
+
+	void store(value_type value) volatile
+	{
+		m_value = value;
+	}
+
+	value_type operator=(value_type value) volatile
+	{
+		m_value = value;
+	}
+
+private:
+	value_type m_value;
+
+	atomic(atomic const &);
+	atomic & operator=(atomic const &);
+};
+
+}
+
+#endif

firmware/testy/avrlib/bootseq.hpp

+#ifndef AVRLIB_BOOTSEQ_HPP
+#define AVRLIB_BOOTSEQ_HPP
+
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include "nobootseq.hpp"
+
+namespace avrlib {
+
+inline void bootseq_reset()
+{
+	cli();
+#if defined(WDTCR)
+# if defined(WDCE)
+	WDTCR = (1<<WDCE)|(1<<WDE);
+# else
+	WDTCR = (1<<WDTOE)|(1<<WDE);
+# endif
+	WDTCR = (1<<WDE);
+#elif defined(WDTCSR)
+	WDTCSR = (1<<WDCE)|(1<<WDE);
+	WDTCSR = (1<<WDE);
+#elif __AVR_ARCH__ >= 100 /*xmega*/
+	CCP = CCP_IOREG_gc;
+	RST.CTRL = RST_SWRST_bm;
+#else
+# error Unsupported Watchdog timer interface.
+#endif
+	for (;;)
+	{
+	}
+}
+
+class zigbit_bootseq
+{
+public:
+	zigbit_bootseq()
+		: m_state(0)
+	{
+	}
+
+	uint8_t check(uint8_t v)
+	{
+		static uint8_t const seq[] = { 0xB2, 0xA5, 0x65, 0x4B };
+
+		if (seq[m_state++] != v)
+			m_state = 0;
+
+		if (m_state == 4)
+			bootseq_reset();
+
+		return v;
+	}
+
+private:
+	uint8_t m_state;
+};
+
+class bootseq
+{
+public:
+	bootseq()
+		: m_state(0)
+	{
+	}
+
+	uint8_t check(uint8_t v)
+	{
+		static uint8_t const seq[] = { 0x74, 0x7E, 0x7A, 0x33 };
+
+		if (seq[m_state++] != v)
+			m_state = 0;
+
+		if (m_state == 4)
+			bootseq_reset();
+
+		return v;
+	}
+
+private:
+	uint8_t m_state;
+};
+
+template <uint16_t boot_entry_address>
+class legacy_bootseq
+{
+public:
+	legacy_bootseq()
+		: m_state(0)
+	{
+	}
+
+	uint8_t check(uint8_t v)
+	{
+		static uint8_t const seq[] = { 0x74, 0x7E, 0x7A, 0x33 };
+
+		if (seq[m_state++] != v)
+			m_state = 0;
+
+		if (m_state == 4)
+		{
+			void clean();
+			clean();
+
+			((void (*)())(void *)boot_entry_address)();
+		}
+
+		return v;
+	}
+
+private:
+	uint8_t m_state;
+};
+
+}
+
+#endif

firmware/testy/avrlib/buffer.hpp

+#ifndef AVRLIB_BUFFER_HPP
+#define AVRLIB_BUFFER_HPP
+
+#include "numeric.hpp"
+#include "assert.hpp"
+
+namespace avrlib {
+
+template <typename T, uint_max_t Capacity>
+class buffer
+{
+public:
+	typedef typename least_uint<Capacity + 1>::type index_type;
+	typedef T value_type;
+	static const index_type capacity = Capacity;
+
+	buffer()
+		: m_wptr(0), m_rptr(0)
+	{
+	}
+
+	void clear()
+	{
+		m_rptr = m_wptr;
+	}
+
+	bool empty() const
+	{
+		return m_wptr == m_rptr;
+	}
+
+	bool full() const
+	{
+		return next(m_wptr) == m_rptr;
+	}
+
+	void push(value_type v)
+	{
+		m_buffer[m_wptr] = v;
+		m_wptr = next(m_wptr);
+	}
+
+	value_type top() const
+	{
+		return m_buffer[m_rptr];
+	}
+
+	index_type size() const
+	{
+		return dist(m_wptr, m_rptr);
+	}
+
+	value_type operator[](index_type i) const
+	{
+		return m_buffer[next(m_rptr, i)];
+	}
+
+	template <typename Writer>
+	void copy_to(Writer & writer, index_type len, index_type offset = 0) const
+	{
+		AVRLIB_ASSERT(len + offset <= this->size());
+		uint8_t rptr = next(m_rptr, offset);
+
+		if (next(rptr, len) < rptr)
+		{
+			writer.write(m_buffer + rptr, capacity - rptr);
+			writer.write(m_buffer, len - (capacity - rptr));
+		}
+		else
+		{
+			writer.write(m_buffer + rptr, len);
+		}
+	}
+
+	template <typename Reader>
+	index_type append(Reader & reader, index_type len)
+	{
+		index_type wptr = m_wptr;
+
+		index_type free = capacity - this->size();
+		if (free < len)
+			len = free;
+
+		if (wptr > next(wptr, len))
+		{
+			reader.read(m_buffer + wptr, capacity - wptr);
+			reader.read(m_buffer, len - (capacity - wptr));
+		}
+		else
+		{
+			reader.read(m_buffer + wptr, len);
+		}
+
+		m_wptr = next(wptr, len);
+		return len;
+	}
+
+	void pop()
+	{
+		m_rptr = next(m_rptr);
+	}
+
+	void pop(index_type len)
+	{
+		m_rptr = next(m_rptr, len);
+	}
+
+private:
+	volatile value_type m_buffer[capacity];
+	volatile index_type m_wptr;
+	volatile index_type m_rptr;
+
+	static index_type next(index_type v)
+	{
+		index_type res = v + 1;
+		if (res == capacity)
+			res = 0;
+		return res;
+	}
+
+	static index_type next(index_type v, index_type len)
+	{
+		return index_type(capacity - v) <= len? len - index_type(capacity - v): v + len;
+	}
+
+	static index_type dist(index_type ptr, index_type base)
+	{
+		return ptr >= base? ptr - base: ptr + index_type(capacity - base);
+	}
+};