This commit is contained in:
Tristan Krause 2019-04-01 15:16:47 +02:00
parent 949591a50d
commit b6d0b4c8f5
29 changed files with 0 additions and 0 deletions

1
firmware/B15F.aps Normal file

File diff suppressed because one or more lines are too long

BIN
firmware/B15F.elf Normal file

Binary file not shown.

192
firmware/B15F.hex Normal file
View file

@ -0,0 +1,192 @@
:100000000C9453000C947D000C947D000C947D00A6
:100010000C947D000C947D000C947D000C947D006C
:100020000C947D000C947D000C947D000C947D005C
:100030000C947D000C947D000C947D000C947D004C
:100040000C947D000C947D000C947D000C947D003C
:100050000C947D000C947D000C947D000C947D002C
:100060000C947D000C947D000C947D000C947D001C
:100070000C947D000C947D000C947D000C947D000C
:100080000C947D000C947D000C947D00EC00EF003E
:10009000F200E300F500F800FB00FE00010104019E
:1000A000E9000701AA0511241FBECFEFD0E4DEBF8F
:1000B000CDBF11E0A0E0B1E0E8EBFBE000E00BBF5A
:1000C00002C007900D92A232B107D9F721E0A2E257
:1000D000B1E001C01D92A433B207E1F710E0C3E51F
:1000E000D0E004C02197FE010E94D105C235D1079E
:1000F000C9F70E947A050C94DA050C94000083E39A
:1001000091E00E940B0160E080E391E00E944E01CB
:100110006FEF80E391E00E946F0160E08DE291E07B
:100120000E944E016FEF8DE291E00E946F016FEF30
:100130008AE291E00E946F0183E291E00E94460210
:1001400082E291E00E943E03789484B7877F84BF67
:10015000109260000FB6F894A895809160008861B5
:1001600080936000109260000FBE0895CF930FB689
:10017000F894A89580916000886180936000109247
:1001800060000FBE6FEF8DE291E00E94900182E26D
:1001900091E00E94EC03C82F60E08DE291E00E94A4
:1001A000900198E088E10FB6F894A89580936000DC
:1001B0000FBE90936000A8958C2F90E0FC013197C2
:1001C000EC30F10510F0CF910895EA5BFF4F0C94ED
:1001D000D105CF910C940605CF910C947F04CF915B
:1001E0000C949004CF910C94AF04CF910C94BC0468
:1001F000CF910C94CA04CF910C94D804CF910C9455
:10020000E104CF910C94EA04CF910C94F804CF91BF
:100210000C941405089584B1806B84B926988AB132
:100220008C618AB980E58CBD81E08DBD8BB1837E08
:100230008BB95A9A5B9A5C9A08958BB1837E8BB97D
:100240008BB160FD10C090E0892B8BB98BB161FD43
:1002500010C090E0892B8BB98BB162FD10C090E08B
:10026000892B8BB9089594E0892B8BB98BB161FFF1
:10027000F0CF98E0892B8BB98BB162FFF0CF90E182
:10028000892B8BB908956EBD0DB407FEFDCF8EB5D9
:100290000895FC0171836083428308951F93CF9377
:1002A000DF93EC01162F6A81888199810E941D01DC
:1002B00060E4888199810E94430160E0888199818E
:1002C0000E944301612F888199810E94430167E068
:1002D00088819981DF91CF911F910C941D011F930B
:1002E000CF93DF93EC01162F6A81888199810E9458
:1002F0001D0160E4888199810E94430161E0888149
:1003000099810E944301612F888199810E94430154
:1003100067E088819981DF91CF911F910C941D0135
:100320001F93CF93DF93EC01162F6A818881998107
:100330000E941D0160E4888199810E94430162E16D
:10034000888199810E944301612F888199810E944F
:10035000430167E088819981DF91CF911F910C94CF
:100360001D011F93CF93DF93EC01162F6A818881C3
:1003700099810E941D0160E4888199810E94430156
:1003800063E1888199810E944301612F888199816D
:100390000E94430167E088819981DF91CF911F918D
:1003A0000C941D011F93CF93DF93EC016A81888128
:1003B00099810E941D0161E4888199810E94430115
:1003C00062E1888199810E94430160E0888199817E
:1003D0000E944301182F67E0888199810E941D01C6
:1003E000812FDF91CF911F9108951F93CF93DF93BA
:1003F000EC016A81888199810E941D0161E48881F4
:1004000099810E94430163E1888199810E9443019F
:1004100060E0888199810E944301182F67E08881FC
:1004200099810E941D01812FDF91CF911F91089525
:10043000FC0171836083428308950F931F93CF93D0
:10044000DF93EC018B016A81888199810E941D01F3
:10045000B8010024660F771F001C660F771F001C71
:10046000672F702D888199810E944301602F660F4C
:10047000660F888199810E94430167E08881998194
:10048000DF91CF911F910F910C941D0110927C0070
:1004900087E880937A00089580917C00807E682BA5
:1004A00060937C0080917A00806480937A0083EA74
:1004B00091E00197F1F700C0000080917A0086FD7D
:1004C000FCCF809178009091790008950F931F934D
:1004D000CF93DF9361E080E391E00E949001C1E05F
:1004E000D0E001E010E02FEF84E39CE02150804059
:1004F0009040E1F700C00000B8010C2E01C0660F6B
:100500000A94EAF780E391E00E9490012196C930B5
:10051000D10549F7DF91CF911F910F9108950F9366
:100520001F93CF93DF9361E08DE291E00E949001F1
:10053000C1E0D0E001E010E02FEF84E39CE0215027
:1005400080409040E1F700C00000B8010C2E01C0CF
:10055000660F0A94EAF78DE291E00E9490012196DD
:10056000C930D10549F7DF91CF911F910F910895BF
:10057000CF93DF93C0E0D0E0BE0187E291E00E941C
:100580001D0287E893E10197F1F700C00000219672
:10059000C11594E0D90781F72FE78AE196E0215051
:1005A00080409040E1F700C0000060E070E087E22A
:1005B00091E0DF91CF910C941D02CF93DF93C0E0C7
:1005C000D0E0BE0184E291E00E941D0287E893E141
:1005D0000197F1F700C000002196C11594E0D907FA
:1005E00081F72FE78AE196E0215080409040E1F7C3
:1005F00000C0000060E070E084E291E0DF91CF9104
:100600000C941D020FB6F894A89580916000886143
:1006100080936000109260000FBE60E083E291E082
:100620000E944C02BC0187E291E00E941D0261E041
:1006300083E291E00E944C02BC0184E291E00E94BE
:100640001D0280E391E00E94F501682F80E391E0B4
:100650000E9490018AE291E00E94F501682F8DE2EC
:1006600091E00E949001D9CF0E9466020E948F0201
:100670000E94B8020E94DD020E94020382E0809381
:10068000C00088E18093C10086E08093C200109290
:10069000C50084E18093C40008958091C6008FE76F
:1006A00092E00197F1F700C000008091C00087FD43
:1006B000F4CF08958091C00085FFFCCF6093C60001
:1006C00008958091C00085FFFCCF6093C6008091A3
:1006D000C00085FFFCCF7093C60008958091C000D4
:1006E00085FFFCCF4093C6009FEF940F442351F049
:1006F000FB0121918091C00085FFFCCF2093C600B3
:100700009150B8F708958091C00085FFFCCF4093C9
:10071000C6005FEF540F442309F45CC0FB0120E0E6
:1007200041E9DF0190818091C00085FFFCCF90936B
:10073000C60031969C91822F892780FD842790E006
:1007400095958795282F80FF02C0242F2827822F78
:1007500090E095958795282F80FF02C0242F2827A9
:1007600030E035952795822F20FF02C0842F822705
:1007700090E095958795282F80FF02C0242F282789
:1007800030E035952795822F20FF02C0842F8227E5
:1007900090E095958795282F80FF02C0242F282769
:1007A00030E035952795822F20FF02C0842F8227C5
:1007B000282F2695515008F0B4CF8091C00085FFB6
:1007C000FCCF2093C6008091C00087FFFCCF8091B2
:1007D000C600089520E0F1CF8091C00087FFFCCFD4
:1007E0008091C60008958091C00087FFFCCF2091C2
:1007F000C60030E09091C00097FFFCCF8091C6000A
:10080000A901582BCA010895CB0171E99C01240F5D
:10081000311DA9018091C00087FFFCCFE091C60087
:10082000E13108F0E0E060E090E08091C00087FFF7
:10083000FCCFF091C6008F2F892780FD872790E09D
:1008400095958795282F80FF02C0272F2827822F74
:1008500090E095958795282F80FF02C0272F2827A5
:1008600030E035952795822F20FF02C0872F822701
:1008700090E095958795282F80FF02C0272F282785
:1008800030E035952795822F20FF02C0872F8227E1
:1008900090E095958795282F80FF02C0272F282765
:1008A00030E035952795822F20FF02C0872F8227C1
:1008B000982F96956E17F0F06F5FE61708F0B5CF9A
:1008C0008091C600EFE7F2E03197F1F700C0000039
:1008D0008091C00087FDF4CF992351F02EEF8091D5
:1008E000C00085FFFCCF2093C600911193CF0895DF
:1008F0002FEFF5CFDA01A60FB11DFC93DDCFCF931B
:1009000082E291E00E94EC03C82F6FEF82E291E057
:100910000E945A036C2F82E291E0CF910C945A030B
:1009200063E082E291E00E945A034CE065E171E0ED
:1009300082E291E00E946E0349E06CE071E082E2A5
:1009400091E00E946E034CE060E071E082E291E091
:100950000E946E036FEF82E291E00C945A0382E2F0
:1009600091E00E94F303BC01660F771F680F791FA7
:1009700082E291E00C94610382E291E00E94EC0338
:10098000682F80E391E00E9490016FEF82E291E096
:100990000C945A0382E291E00E94EC03682F8DE2EE
:1009A00091E00E9490016FEF82E291E00C945A0373
:1009B00080E391E00E94F501682F82E291E00C94BF
:1009C0005A038DE291E00E94F501682F82E291E0E6
:1009D0000C945A0382E291E00E94F303BC0187E287
:1009E00091E00E941D026FEF82E291E00C945A03A5
:1009F00082E291E00E94F303BC0184E291E00E9454
:100A00001D026FEF82E291E00C945A0382E291E0C2
:100A10000E94EC03682F83E291E00E944C02BC012B
:100A200082E291E00C9461038F929F92AF92BF9209
:100A3000CF92DF92EF92FF920F931F93CF93DF93AA
:100A400082E291E00E94EC03882E82E291E00E9413
:100A5000EC03982E82E291E00E94F303EC0182E223
:100A600091E00E94F3035C0182E291E00E94F303B3
:100A70008C016FEF82E291E00E945A03A09E600118
:100A8000A19ED00CB09ED00C1124CC15DD050CF528
:100A9000BE0187E291E00E941D02A895682D83E2C5
:100AA00091E00E944C027C01692D83E291E00E945A
:100AB0004C028C01B70182E291E00E946103B8010F
:100AC00082E291E00E946103CA0DDB1DCC15DD05B9
:100AD000FCF26FEF82E291E0DF91CF911F910F91D5
:100AE000FF90EF90DF90CF90BF90AF909F908F904E
:100AF0000C945A03CF93DF93CDB7DEB760970FB650
:100B0000F894DEBF0FBECDBF0E947F006FEF80E381
:100B100091E00E9490012FE78AE196E02150804009
:100B20009040E1F700C0000060E080E391E00E94A7
:100B3000900160E011E0160F80E391E00E949001C7
:100B400040E0BE016F5F7F4F82E291E00E940404AB
:100B5000612FF0CF83E391E00E940A0142E063E35A
:100B600071E080E391E00E94490143E063E371E0BA
:100B70008DE291E00E94490145E063E371E08AE281
:100B800091E00E94490140E063E371E087E291E077
:100B90000E94180241E063E371E084E291E00C946A
:100BA0001802EE0FFF1F0024001C0BBE0790F691E9
:080BB000E02D0994F894FFCF39
:100BB800626F617264696E666F2E680030383A3110
:100BC800363A3531004170722020312032303139C7
:020BD80000001B
:00000001FF

36
firmware/Makefile Normal file
View file

@ -0,0 +1,36 @@
# Name: Makefile
# Project: B15F (board15 Famulus Edition)
# Author: Tristan Krause
# Creation Date: 2019-03-22
# Umgebungseinstellungen
COMPILER_PATH = C:\avr8-gnu-toolchain-win32_x86\bin\avr-g++.exe
OBJCOPY_PATH = C:\avr8-gnu-toolchain-win32_x86\bin\avr-objcopy.exe
OUTPUT = B15F.elf
HEX = B15F.hex
CFLAGS = -Wall -Wextra -std=c++14 -O3 -mmcu=atmega1284 -DF_CPU=20000000
LDFLAGS =
OBJECTS = main.o spi.o mcp23s17.o tlc5615.o adu.o selftest.o global_vars.o usart.o requests.o
COMPILE = $(COMPILER_PATH) $(CFLAGS)
B15F: $(OBJECTS)
@echo "Linking..."
$(COMPILE) $(OBJECTS) -o $(OUTPUT) $(LDFLAGS)
$(OBJCOPY_PATH) -O ihex -R .eeprom -R .fuse -R .lock -R .signature $(OUTPUT) $(HEX)
help:
@echo "This Makefile has the following rules:"
@echo "make B15F .... to compile (default)"
@echo "make clean ... to delete objects, elf and hex file"
clean:
@echo "Cleaning..."
rm -f $(OBJECTS) $(OUTPUT) $(HEX)
.cpp.o:
$(COMPILE) -c $< -o $@

13
firmware/TLC5615.cpp Normal file
View file

@ -0,0 +1,13 @@
#include "TLC5615.h"
TLC5615::TLC5615(SPI& spi, uint8_t adr) : spi(spi), adr(adr)
{
}
void TLC5615::setValue(uint16_t val) const
{
spi.setAdr(adr);
spi.pushByte(val >> 6);
spi.pushByte(val << 2);
spi.setAdr(SPIADR::NONE);
}

18
firmware/TLC5615.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef TLC5615_H
#define TLC5615_H
#include "spi.h"
class TLC5615
{
public:
TLC5615(SPI&, uint8_t);
void setValue(uint16_t) const;
private:
SPI& spi;
const uint8_t adr;
};
#endif // TLC5615_H

27
firmware/adu.cpp Normal file
View file

@ -0,0 +1,27 @@
#include "adu.h"
void ADU::init()
{
// externe Referenz an AREF
ADMUX = 0;
// ADC aktiviert, prescaler = 128
ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
}
uint16_t ADU::getValue(uint8_t channel)
{
// lege Kanal fest
ADMUX = (ADMUX & 0xE0) | channel;
// starte Konvertierung
ADCSRA |= _BV(ADSC);
// warte Konvertierungszeit ab
_delay_us(13 * 1000000 * 128 / F_CPU + 1);
// warte auf Ende
while(ADCSRA & _BV(ADSC));
return ADCW;
}

15
firmware/adu.h Normal file
View file

@ -0,0 +1,15 @@
#ifndef ADC_H
#define ADC_H
#include <avr/io.h>
#include <util/delay.h>
#include <stdint.h>
class ADU
{
public:
void init(void);
uint16_t getValue(uint8_t);
};
#endif // ADC_H

1
firmware/b15f.aws Normal file
View file

@ -0,0 +1 @@
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA1284"/><Files><File00000 Name="E:\main.cpp" Position="289 130 1383 493" LineCol="57 2" State="Maximized"/><File00001 Name="E:\requests.h" Position="311 159 1405 522" LineCol="0 0" State="Maximized"/><File00002 Name="E:\requests.cpp" Position="263 71 1501 646" LineCol="97 14" State="Maximized"/><File00003 Name="E:\usart.cpp" Position="355 217 1449 580" LineCol="47 7" State="Maximized"/><File00004 Name="E:\global_vars.cpp" Position="377 246 1471 609" LineCol="0 0" State="Maximized"/><File00005 Name="E:\global_vars.h" Position="399 275 1493 638" LineCol="0 0" State="Maximized"/><File00006 Name="E:\adu.h" Position="267 101 1361 464" LineCol="14 15" State="Maximized"/><File00007 Name="E:\usart.h" Position="289 130 1387 497" LineCol="19 8" State="Maximized"/></Files></AVRWorkspace>

8
firmware/boardinfo.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef BOARDINFO_H
#define BOARDINFO_H
const char DATE[] = __DATE__;
const char TIME[] = __TIME__;
const char FSRC[] = __FILE__;
#endif // BOARDINFO_H

View file

@ -0,0 +1 @@
:00000001FF

BIN
firmware/default/B15F.elf Normal file

Binary file not shown.

12
firmware/default/B15F.hex Normal file
View file

@ -0,0 +1,12 @@
:100000000C9446000C9450000C9450000C9450003A
:100010000C9450000C9450000C9450000C94500020
:100020000C9450000C9450000C9450000C94500010
:100030000C9450000C9450000C9450000C94500000
:100040000C9450000C9450000C9450000C945000F0
:100050000C9450000C9450000C9450000C945000E0
:100060000C9450000C9450000C9450000C945000D0
:100070000C9450000C9450000C9450000C945000C0
:100080000C9450000C9450000C94500011241FBE8E
:10009000CFEFD0E4DEBFCDBF0E9452000C945500DC
:0E00A0000C94000080E090E00895F894FFCFEB
:00000001FF

96
firmware/default/B15F.lss Normal file
View file

@ -0,0 +1,96 @@
B15F.elf: file format elf32-avr
Sections:
Idx Name Size VMA LMA File off Algn
0 .data 00000000 00800100 000000ae 00000122 2**0
CONTENTS, ALLOC, LOAD, DATA
1 .text 000000ae 00000000 00000000 00000074 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .comment 00000030 00000000 00000000 00000122 2**0
CONTENTS, READONLY
3 .note.gnu.avr.deviceinfo 00000040 00000000 00000000 00000154 2**2
CONTENTS, READONLY
4 .debug_aranges 00000020 00000000 00000000 00000194 2**0
CONTENTS, READONLY, DEBUGGING
5 .debug_info 00000833 00000000 00000000 000001b4 2**0
CONTENTS, READONLY, DEBUGGING
6 .debug_abbrev 0000079a 00000000 00000000 000009e7 2**0
CONTENTS, READONLY, DEBUGGING
7 .debug_line 00000061 00000000 00000000 00001181 2**0
CONTENTS, READONLY, DEBUGGING
8 .debug_frame 00000024 00000000 00000000 000011e4 2**2
CONTENTS, READONLY, DEBUGGING
9 .debug_str 000003b8 00000000 00000000 00001208 2**0
CONTENTS, READONLY, DEBUGGING
10 .debug_ranges 00000010 00000000 00000000 000015c0 2**0
CONTENTS, READONLY, DEBUGGING
Disassembly of section .text:
00000000 <__vectors>:
0: 0c 94 46 00 jmp 0x8c ; 0x8c <__ctors_end>
4: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
8: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
c: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
10: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
14: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
18: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
1c: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
20: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
24: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
28: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
2c: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
30: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
34: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
38: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
3c: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
40: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
44: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
48: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
4c: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
50: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
54: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
58: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
5c: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
60: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
64: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
68: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
6c: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
70: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
74: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
78: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
7c: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
80: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
84: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
88: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__bad_interrupt>
0000008c <__ctors_end>:
8c: 11 24 eor r1, r1
8e: 1f be out 0x3f, r1 ; 63
90: cf ef ldi r28, 0xFF ; 255
92: d0 e4 ldi r29, 0x40 ; 64
94: de bf out 0x3e, r29 ; 62
96: cd bf out 0x3d, r28 ; 61
98: 0e 94 52 00 call 0xa4 ; 0xa4 <main>
9c: 0c 94 55 00 jmp 0xaa ; 0xaa <_exit>
000000a0 <__bad_interrupt>:
a0: 0c 94 00 00 jmp 0 ; 0x0 <__vectors>
000000a4 <main>:
int main() {
SPI spi_master;
return 0;
}
a4: 80 e0 ldi r24, 0x00 ; 0
a6: 90 e0 ldi r25, 0x00 ; 0
a8: 08 95 ret
000000aa <_exit>:
aa: f8 94 cli
000000ac <__stop_program>:
ac: ff cf rjmp .-2 ; 0xac <__stop_program>

431
firmware/default/B15F.map Normal file
View file

@ -0,0 +1,431 @@
Archive member included to satisfy reference by file (symbol)
c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a(_exit.o)
c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o (exit)
Memory Configuration
Name Origin Length Attributes
text 0x00000000 0x00020000 xr
data 0x00800100 0x0000ff00 rw !x
eeprom 0x00810000 0x00010000 rw !x
fuse 0x00820000 0x00000003 rw !x
lock 0x00830000 0x00000400 rw !x
signature 0x00840000 0x00000400 rw !x
user_signatures 0x00850000 0x00000400 rw !x
*default* 0x00000000 0xffffffff
Linker script and memory map
Address of section .data set to 0x800100
LOAD c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o
LOAD main.o
LOAD spi.o
LOAD c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a
LOAD c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51\libm.a
LOAD c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51\libc.a
START GROUP
LOAD c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a
LOAD c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51\libm.a
LOAD c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51\libc.a
LOAD c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51\libatmega1284.a
END GROUP
0x00020000 __TEXT_REGION_LENGTH__ = DEFINED (__TEXT_REGION_LENGTH__)?__TEXT_REGION_LENGTH__:0x20000
0x0000ff00 __DATA_REGION_LENGTH__ = DEFINED (__DATA_REGION_LENGTH__)?__DATA_REGION_LENGTH__:0xff00
0x00010000 __EEPROM_REGION_LENGTH__ = DEFINED (__EEPROM_REGION_LENGTH__)?__EEPROM_REGION_LENGTH__:0x10000
[0x00000003] __FUSE_REGION_LENGTH__ = DEFINED (__FUSE_REGION_LENGTH__)?__FUSE_REGION_LENGTH__:0x400
0x00000400 __LOCK_REGION_LENGTH__ = DEFINED (__LOCK_REGION_LENGTH__)?__LOCK_REGION_LENGTH__:0x400
0x00000400 __SIGNATURE_REGION_LENGTH__ = DEFINED (__SIGNATURE_REGION_LENGTH__)?__SIGNATURE_REGION_LENGTH__:0x400
0x00000400 __USER_SIGNATURE_REGION_LENGTH__ = DEFINED (__USER_SIGNATURE_REGION_LENGTH__)?__USER_SIGNATURE_REGION_LENGTH__:0x400
.hash
*(.hash)
.dynsym
*(.dynsym)
.dynstr
*(.dynstr)
.gnu.version
*(.gnu.version)
.gnu.version_d
*(.gnu.version_d)
.gnu.version_r
*(.gnu.version_r)
.rel.init
*(.rel.init)
.rela.init
*(.rela.init)
.rel.text
*(.rel.text)
*(.rel.text.*)
*(.rel.gnu.linkonce.t*)
.rela.text
*(.rela.text)
*(.rela.text.*)
*(.rela.gnu.linkonce.t*)
.rel.fini
*(.rel.fini)
.rela.fini
*(.rela.fini)
.rel.rodata
*(.rel.rodata)
*(.rel.rodata.*)
*(.rel.gnu.linkonce.r*)
.rela.rodata
*(.rela.rodata)
*(.rela.rodata.*)
*(.rela.gnu.linkonce.r*)
.rel.data
*(.rel.data)
*(.rel.data.*)
*(.rel.gnu.linkonce.d*)
.rela.data
*(.rela.data)
*(.rela.data.*)
*(.rela.gnu.linkonce.d*)
.rel.ctors
*(.rel.ctors)
.rela.ctors
*(.rela.ctors)
.rel.dtors
*(.rel.dtors)
.rela.dtors
*(.rela.dtors)
.rel.got
*(.rel.got)
.rela.got
*(.rela.got)
.rel.bss
*(.rel.bss)
.rela.bss
*(.rela.bss)
.rel.plt
*(.rel.plt)
.rela.plt
*(.rela.plt)
.text 0x00000000 0xae
*(.vectors)
.vectors 0x00000000 0x8c c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o
0x00000000 __vector_default
0x00000000 __vectors
*(.vectors)
*(.progmem.gcc*)
0x0000008c . = ALIGN (0x2)
0x0000008c __trampolines_start = .
*(.trampolines)
.trampolines 0x0000008c 0x0 linker stubs
*(.trampolines*)
0x0000008c __trampolines_end = .
*libprintf_flt.a:*(.progmem.data)
*libc.a:*(.progmem.data)
*(.progmem*)
0x0000008c . = ALIGN (0x2)
*(.jumptables)
*(.jumptables*)
*(.lowtext)
*(.lowtext*)
0x0000008c __ctors_start = .
*(.ctors)
0x0000008c __ctors_end = .
0x0000008c __dtors_start = .
*(.dtors)
0x0000008c __dtors_end = .
SORT(*)(.ctors)
SORT(*)(.dtors)
*(.init0)
.init0 0x0000008c 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o
0x0000008c __init
*(.init0)
*(.init1)
*(.init1)
*(.init2)
.init2 0x0000008c 0xc c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o
*(.init2)
*(.init3)
*(.init3)
*(.init4)
*(.init4)
*(.init5)
*(.init5)
*(.init6)
*(.init6)
*(.init7)
*(.init7)
*(.init8)
*(.init8)
*(.init9)
.init9 0x00000098 0x8 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o
*(.init9)
*(.text)
.text 0x000000a0 0x4 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o
0x000000a0 __vector_22
0x000000a0 __vector_28
0x000000a0 __vector_1
0x000000a0 __vector_32
0x000000a0 __vector_34
0x000000a0 __vector_24
0x000000a0 __vector_12
0x000000a0 __bad_interrupt
0x000000a0 __vector_6
0x000000a0 __vector_31
0x000000a0 __vector_3
0x000000a0 __vector_23
0x000000a0 __vector_30
0x000000a0 __vector_25
0x000000a0 __vector_11
0x000000a0 __vector_13
0x000000a0 __vector_17
0x000000a0 __vector_19
0x000000a0 __vector_7
0x000000a0 __vector_27
0x000000a0 __vector_5
0x000000a0 __vector_33
0x000000a0 __vector_4
0x000000a0 __vector_9
0x000000a0 __vector_2
0x000000a0 __vector_21
0x000000a0 __vector_15
0x000000a0 __vector_29
0x000000a0 __vector_8
0x000000a0 __vector_26
0x000000a0 __vector_14
0x000000a0 __vector_10
0x000000a0 __vector_16
0x000000a0 __vector_18
0x000000a0 __vector_20
.text 0x000000a4 0x0 main.o
.text 0x000000a4 0x0 spi.o
.text 0x000000a4 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a(_exit.o)
0x000000a4 . = ALIGN (0x2)
*(.text.*)
.text.startup 0x000000a4 0x6 main.o
0x000000a4 main
.text.libgcc.mul
0x000000aa 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a(_exit.o)
.text.libgcc.div
0x000000aa 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a(_exit.o)
.text.libgcc 0x000000aa 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a(_exit.o)
.text.libgcc.prologue
0x000000aa 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a(_exit.o)
.text.libgcc.builtins
0x000000aa 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a(_exit.o)
.text.libgcc.fmul
0x000000aa 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a(_exit.o)
.text.libgcc.fixed
0x000000aa 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a(_exit.o)
0x000000aa . = ALIGN (0x2)
*(.fini9)
.fini9 0x000000aa 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a(_exit.o)
0x000000aa _exit
0x000000aa exit
*(.fini9)
*(.fini8)
*(.fini8)
*(.fini7)
*(.fini7)
*(.fini6)
*(.fini6)
*(.fini5)
*(.fini5)
*(.fini4)
*(.fini4)
*(.fini3)
*(.fini3)
*(.fini2)
*(.fini2)
*(.fini1)
*(.fini1)
*(.fini0)
.fini0 0x000000aa 0x4 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a(_exit.o)
*(.fini0)
0x000000ae _etext = .
.data 0x00800100 0x0 load address 0x000000ae
[!provide] PROVIDE (__data_start, .)
*(.data)
.data 0x00800100 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o
.data 0x00800100 0x0 main.o
.data 0x00800100 0x0 spi.o
.data 0x00800100 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a(_exit.o)
*(.data*)
*(.gnu.linkonce.d*)
*(.rodata)
*(.rodata*)
*(.gnu.linkonce.r*)
0x00800100 . = ALIGN (0x2)
0x00800100 _edata = .
[!provide] PROVIDE (__data_end, .)
.bss 0x00800100 0x0
[!provide] PROVIDE (__bss_start, .)
*(.bss)
.bss 0x00800100 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o
.bss 0x00800100 0x0 main.o
.bss 0x00800100 0x0 spi.o
.bss 0x00800100 0x0 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/avr51\libgcc.a(_exit.o)
*(.bss*)
*(COMMON)
[!provide] PROVIDE (__bss_end, .)
0x000000ae __data_load_start = LOADADDR (.data)
0x000000ae __data_load_end = (__data_load_start + SIZEOF (.data))
.noinit 0x00800100 0x0
[!provide] PROVIDE (__noinit_start, .)
*(.noinit*)
[!provide] PROVIDE (__noinit_end, .)
0x00800100 _end = .
[!provide] PROVIDE (__heap_start, .)
.eeprom 0x00810000 0x0
*(.eeprom*)
0x00810000 __eeprom_end = .
.fuse
*(.fuse)
*(.lfuse)
*(.hfuse)
*(.efuse)
.lock
*(.lock*)
.signature
*(.signature*)
.user_signatures
*(.user_signatures*)
.stab
*(.stab)
.stabstr
*(.stabstr)
.stab.excl
*(.stab.excl)
.stab.exclstr
*(.stab.exclstr)
.stab.index
*(.stab.index)
.stab.indexstr
*(.stab.indexstr)
.comment 0x00000000 0x30
*(.comment)
.comment 0x00000000 0x30 main.o
0x31 (size before relaxing)
.comment 0x00000030 0x31 spi.o
.note.gnu.avr.deviceinfo
0x00000000 0x40
.note.gnu.avr.deviceinfo
0x00000000 0x40 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o
.note.gnu.build-id
*(.note.gnu.build-id)
.debug
*(.debug)
.line
*(.line)
.debug_srcinfo
*(.debug_srcinfo)
.debug_sfnames
*(.debug_sfnames)
.debug_aranges 0x00000000 0x20
*(.debug_aranges)
.debug_aranges
0x00000000 0x20 main.o
.debug_pubnames
*(.debug_pubnames)
.debug_info 0x00000000 0x833
*(.debug_info .gnu.linkonce.wi.*)
.debug_info 0x00000000 0x792 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o
.debug_info 0x00000792 0xa1 main.o
.debug_abbrev 0x00000000 0x79a
*(.debug_abbrev)
.debug_abbrev 0x00000000 0x729 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o
.debug_abbrev 0x00000729 0x71 main.o
.debug_line 0x00000000 0x61
*(.debug_line .debug_line.* .debug_line_end)
.debug_line 0x00000000 0x1a c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o
.debug_line 0x0000001a 0x47 main.o
.debug_line 0x00000061 0x0 spi.o
.debug_frame 0x00000000 0x24
*(.debug_frame)
.debug_frame 0x00000000 0x24 main.o
.debug_str 0x00000000 0x3b8
*(.debug_str)
.debug_str 0x00000000 0x296 c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr51/crtatmega1284.o
.debug_str 0x00000296 0x117 main.o
0x14b (size before relaxing)
.debug_str 0x000003ad 0xb spi.o
0xd5 (size before relaxing)
.debug_loc
*(.debug_loc)
.debug_macinfo
*(.debug_macinfo)
.debug_weaknames
*(.debug_weaknames)
.debug_funcnames
*(.debug_funcnames)
.debug_typenames
*(.debug_typenames)
.debug_varnames
*(.debug_varnames)
.debug_pubtypes
*(.debug_pubtypes)
.debug_ranges 0x00000000 0x10
*(.debug_ranges)
.debug_ranges 0x00000000 0x10 main.o
.debug_macro
*(.debug_macro)
OUTPUT(B15F.elf elf32-avr)
LOAD linker stubs

83
firmware/default/Makefile Normal file
View file

@ -0,0 +1,83 @@
###############################################################################
# Makefile for the project B15F
###############################################################################
## General Flags
PROJECT = B15F
MCU = atmega1284
TARGET = B15F.elf
CC = avr-g++
CPP = avr-g++
## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
## Compile options common for all C compilation units.
CFLAGS = $(COMMON)
CFLAGS += -Wall -gdwarf-2 -DF_CPU=20000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d
## Assembly specific flags
ASMFLAGS = $(COMMON)
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS += -Wl,-Map=B15F.map
## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature
HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
## Include Directories
INCLUDES = -I"C:\avr8-gnu-toolchain-win32_x86\avr\include"
## Library Directories
LIBDIRS = -L"C:\avr8-gnu-toolchain-win32_x86\avr\lib"
## Libraries
LIBS = -lc
## Objects that must be built in order to link
OBJECTS = main.o spi.o
## Objects explicitly added by the user
LINKONLYOBJECTS =
## Build
all: $(TARGET) B15F.hex B15F.eep B15F.lss## Compile
main.o: ../main.c
$(CPP) $(INCLUDES) $(CFLAGS) -c $<
spi.o: ../spi.cpp
$(CPP) $(INCLUDES) $(CFLAGS) -c $<
##Link
$(TARGET): $(OBJECTS)
$(CPP) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)
%.hex: $(TARGET)
avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
%.eep: $(TARGET)
-avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
%.lss: $(TARGET)
avr-objdump -h -S $< > $@
## Clean target
.PHONY: clean
clean:
-rm -rf $(OBJECTS) B15F.elf dep/* B15F.hex B15F.eep B15F.lss B15F.map
## Other dependencies
-include $(shell mkdir dep 2>NUL) $(wildcard dep/*)

11
firmware/global_vars.cpp Normal file
View file

@ -0,0 +1,11 @@
#include "global_vars.h"
SPI spi;
MCP23S17 beba0(spi, SPIADR::BEBA0);
MCP23S17 beba1(spi, SPIADR::BEBA1);
MCP23S17 sw(spi, SPIADR::SWITCH);
TLC5615 dac0(spi, SPIADR::AA0);
TLC5615 dac1(spi, SPIADR::AA1);
ADU adu;
USART usart;

18
firmware/global_vars.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef GLOBAL_VARS_H
#define GLOBAL_VARS_H
#include "mcp23s17.h"
#include "tlc5615.h"
#include "adu.h"
#include "usart.h"
extern SPI spi;
extern MCP23S17 beba0;
extern MCP23S17 beba1;
extern MCP23S17 sw;
extern TLC5615 dac0;
extern TLC5615 dac1;
extern ADU adu;
extern USART usart;
#endif // GLOBAL_VARS_H

125
firmware/main.cpp Normal file
View file

@ -0,0 +1,125 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/wdt.h>
#include "global_vars.h"
#include "selftest.h"
#include "requests.h"
#define WDT_TIMEOUT WDTO_15MS
void initAll()
{
spi.init();
beba0.setDirA(0x00); // alle Ausgang
beba0.setDirB(0xFF); // alle Eingang
beba1.setDirA(0x00); // alle Ausgang
beba1.setDirB(0xFF); // alle Eingang
sw.setDirB(0xFF); // alle Eingang
adu.init();
usart.init();
// aktiviere Interrupts
sei();
// deaktiviere WDT VOLLSTAENDIG
MCUSR &= ~_BV(WDRF);
WDTCSR = 0;
wdt_disable();
}
void handleRequest()
{
wdt_disable();
beba1.writePortA(0xFF);
const uint8_t req = usart.readByte();
beba1.writePortA(0x00);
// starte WDT
wdt_enable(WDT_TIMEOUT);
wdt_reset();
switch(req)
{
case RQ_DISC:
break;
case RQ_TEST:
rqTestConnection();
break;
case RQ_INFO:
rqBoardInfo();
break;
case RQ_INT:
rqTestIntConv();
break;
case RQ_BA0:
rqDigitalWrite0();
break;
case RQ_BA1:
rqDigitalWrite1();
break;
case RQ_BE0:
rqDigitalRead0();
break;
case RQ_BE1:
rqDigitalRead1();
break;
case RQ_AA0:
rqAnalogWrite0();
break;
case RQ_AA1:
rqAnalogWrite1();
break;
case RQ_ADC:
rqAnalogRead();
break;
case RQ_ADC_DAC_STROKE:
rqAdcDacStroke();
break;
default:
break;
}
}
int main()
{
initAll();
// Reset anzeigen
beba0.writePortA(0xFF);
_delay_ms(100);
beba0.writePortA(0x00);
uint8_t n = 0;
uint8_t block[16];
while(1)
{
beba0.writePortA(n++ & 0xFF);
usart.readBlock(&block[0], 0);
}
while(1)
{
handleRequest();
}
return 0;
}

61
firmware/mcp23s17.cpp Normal file
View file

@ -0,0 +1,61 @@
#include "mcp23s17.h"
MCP23S17::MCP23S17(SPI& spi, uint8_t adr) : spi(spi), adr(adr)
{
}
void MCP23S17::setDirA(uint8_t dir) const
{
spi.setAdr(adr);
spi.pushByte(MCP23S17_OPCODE | MCP23S17_WRITE);
spi.pushByte(MCP23S17_DIRA);
spi.pushByte(dir);
spi.setAdr(SPIADR::NONE);
}
void MCP23S17::setDirB(uint8_t dir) const
{
spi.setAdr(adr);
spi.pushByte(MCP23S17_OPCODE | MCP23S17_WRITE);
spi.pushByte(MCP23S17_DIRB);
spi.pushByte(dir);
spi.setAdr(SPIADR::NONE);
}
void MCP23S17::writePortA(uint8_t port) const
{
spi.setAdr(adr);
spi.pushByte(MCP23S17_OPCODE | MCP23S17_WRITE);
spi.pushByte(MCP23S17_PORTA);
spi.pushByte(port);
spi.setAdr(SPIADR::NONE);
}
void MCP23S17::writePortB(uint8_t port) const
{
spi.setAdr(adr);
spi.pushByte(MCP23S17_OPCODE | MCP23S17_WRITE);
spi.pushByte(MCP23S17_PORTB);
spi.pushByte(port);
spi.setAdr(SPIADR::NONE);
}
uint8_t MCP23S17::readPortA(void) const
{
spi.setAdr(adr);
spi.pushByte(MCP23S17_OPCODE | MCP23S17_READ);
spi.pushByte(MCP23S17_PORTA);
uint8_t port = spi.pushByte(0);
spi.setAdr(SPIADR::NONE);
return port;
}
uint8_t MCP23S17::readPortB(void) const
{
spi.setAdr(adr);
spi.pushByte(MCP23S17_OPCODE | MCP23S17_READ);
spi.pushByte(MCP23S17_PORTB);
uint8_t port = spi.pushByte(0);
spi.setAdr(SPIADR::NONE);
return port;
}

30
firmware/mcp23s17.h Normal file
View file

@ -0,0 +1,30 @@
#ifndef MCP23S17_H
#define MCP23S17_H
#include "spi.h"
constexpr uint8_t MCP23S17_DIRA = 0x00;
constexpr uint8_t MCP23S17_DIRB = 0x01;
constexpr uint8_t MCP23S17_PORTA = 0x12;
constexpr uint8_t MCP23S17_PORTB = 0x13;
constexpr uint8_t MCP23S17_READ = 0x01;
constexpr uint8_t MCP23S17_WRITE = 0x00;
constexpr uint8_t MCP23S17_OPCODE = 0x40;
class MCP23S17
{
public:
MCP23S17(SPI&, uint8_t);
void setDirA(uint8_t dir) const;
void setDirB(uint8_t dir) const;
void writePortA(uint8_t) const;
void writePortB(uint8_t) const;
uint8_t readPortA(void) const;
uint8_t readPortB(void) const;
private:
SPI& spi;
const uint8_t adr;
};
#endif // MCP23S17_H

121
firmware/requests.cpp Normal file
View file

@ -0,0 +1,121 @@
#include "requests.h"
void rqTestConnection()
{
uint8_t dummy = usart.readByte();
usart.writeByte(USART::MSG_OK);
usart.writeByte(dummy);
}
void rqBoardInfo()
{
usart.writeByte(3); // Anzahl an Strings
usart.writeStr(DATE, sizeof(DATE));
usart.writeStr(TIME, sizeof(TIME));
usart.writeStr(FSRC, sizeof(FSRC));
usart.writeByte(USART::MSG_OK);
}
void rqTestIntConv()
{
usart.writeInt(usart.readInt() * 3);
}
void rqDigitalWrite0()
{
uint8_t port = usart.readByte();
beba0.writePortA(port);
usart.writeByte(USART::MSG_OK);
}
void rqDigitalWrite1()
{
uint8_t port = usart.readByte();
beba1.writePortA(port);
usart.writeByte(USART::MSG_OK);
}
void rqDigitalRead0()
{
uint8_t port = beba0.readPortB();
usart.writeByte(port);
}
void rqDigitalRead1()
{
uint8_t port = beba1.readPortB();
usart.writeByte(port);
}
void rqAnalogWrite0()
{
uint16_t value = usart.readInt();
dac0.setValue(value);
usart.writeByte(USART::MSG_OK);
}
void rqAnalogWrite1()
{
uint16_t value = usart.readInt();
dac1.setValue(value);
usart.writeByte(USART::MSG_OK);
}
void rqAnalogRead()
{
uint8_t channel = usart.readByte();
uint16_t value = adu.getValue(channel);
usart.writeInt(value);
}
void rqAdcDacStroke()
{
uint8_t channel_a = usart.readByte();
uint8_t channel_b = usart.readByte();
int16_t start = static_cast<int16_t>(usart.readInt());
int16_t delta = static_cast<int16_t>(usart.readInt());
int16_t count = static_cast<int16_t>(usart.readInt());
usart.writeByte(USART::MSG_OK);
count *= delta;
for(int16_t i = start; i < count; i += delta)
{
dac0.setValue(i);
wdt_reset();
uint16_t val_a = adu.getValue(channel_a);
uint16_t val_b = adu.getValue(channel_b);
usart.writeInt(val_a);
usart.writeInt(val_b);
/*union doubleword
{
uint16_t word[2];
uint8_t byte[4];
};
union doubleword dw;
dw.word[0] = adu.getValue(channel_a);
dw.word[1] = adu.getValue(channel_b);
uint8_t ret = 0;
do
{
wdt_reset();
ret = usart.writeBlock(&(dw.byte[0]), 4);
if(ret == 0)
return;
} while(ret != USART::MSG_OK);*/
}
usart.writeByte(USART::MSG_OK);
}

34
firmware/requests.h Normal file
View file

@ -0,0 +1,34 @@
#ifndef REQUESTS_H
#define REQUESTS_H
#include <avr/wdt.h>
#include "global_vars.h"
#include "boardinfo.h"
constexpr static uint8_t RQ_DISC = 0;
constexpr static uint8_t RQ_TEST = 1;
constexpr static uint8_t RQ_INFO = 2;
constexpr static uint8_t RQ_INT = 3;
constexpr static uint8_t RQ_BA0 = 5;
constexpr static uint8_t RQ_BA1 = 6;
constexpr static uint8_t RQ_BE0 = 7;
constexpr static uint8_t RQ_BE1 = 8;
constexpr static uint8_t RQ_AA0 = 9;
constexpr static uint8_t RQ_AA1 = 10;
constexpr static uint8_t RQ_ADC = 11;
constexpr static uint8_t RQ_ADC_DAC_STROKE = 12;
void rqTestConnection(void);
void rqBoardInfo(void);
void rqTestIntConv(void);
void rqTestLongConv(void);
void rqDigitalWrite0(void);
void rqDigitalWrite1(void);
void rqDigitalRead0(void);
void rqDigitalRead1(void);
void rqAnalogWrite0(void);
void rqAnalogWrite1(void);
void rqAnalogRead(void);
void rqAdcDacStroke(void);
#endif // REQUESTS_H

69
firmware/selftest.cpp Normal file
View file

@ -0,0 +1,69 @@
#include "selftest.h"
void testAll(void)
{
testBEBA0();
testBEBA1();
testDAC0();
testDAC1();
testMirror();
}
void testBEBA0(void)
{
for(uint8_t i = 0; i < 9; i++)
{
beba0.writePortA(_BV(i));
if(i < 8)
_delay_ms(200);
}
}
void testBEBA1(void)
{
for(uint8_t i = 0; i < 9; i++)
{
beba1.writePortA(_BV(i));
if(i < 8)
_delay_ms(200);
}
}
void testDAC0(void)
{
for(uint16_t i = 0; i < 1024; i++)
{
dac0.setValue(i);
_delay_ms(1);
}
_delay_ms(100);
dac0.setValue(0);
}
void testDAC1(void)
{
for(uint16_t i = 0; i < 1024; i++)
{
dac1.setValue(i);
_delay_ms(1);
}
_delay_ms(100);
dac1.setValue(0);
}
void testMirror()
{
// deaktiviere WDT
wdt_disable();
// Endlosschleife
while(1)
{
dac0.setValue(adu.getValue(0));
dac1.setValue(adu.getValue(1));
beba0.writePortA(beba0.readPortB());
beba1.writePortA(sw.readPortB());
}
}

14
firmware/selftest.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef SELFTEST_H
#define SELFTEST_H
#include <avr/wdt.h>
#include "global_vars.h"
void testAll(void);
void testBEBA0(void);
void testBEBA1(void);
void testDAC0(void);
void testDAC1(void);
void testMirror(void);
#endif // SELFTEST_H

39
firmware/spi.cpp Normal file
View file

@ -0,0 +1,39 @@
#include "spi.h"
SPI::SPI(void)
{
}
void SPI::init(void) const
{
// Konfiguriere SPI DDRs
DDRB |= _BV(SLSL) | _BV(MOSI) | _BV(SCLK);
DDRB &= ~_BV(MISO);
// Konfiguriere DMUX DDRs
DDRD |= _BV(DMUX1) | _BV(DMUX2) | _BV(DMUX3);
// aktiviere SPI, Master Modus, SPI Modus 0
// F_SPI = F_CPU / 2 (prescaler 2)
SPCR = _BV(SPE) | _BV(MSTR);
SPSR = _BV(SPI2X);
// waehle keinen SPI Slave aus
setAdr(SPIADR::NONE);
}
void SPI::setAdr(uint8_t adr) const
{
PORTD &= ~(_BV(DMUX1) | _BV(DMUX2) | _BV(DMUX3));
PORTD |= (adr & 0x01) ? _BV(DMUX1) : 0;
PORTD |= (adr & 0x02) ? _BV(DMUX2) : 0;
PORTD |= (adr & 0x04) ? _BV(DMUX3) : 0;
}
uint8_t SPI::pushByte(uint8_t b) const
{
SPDR = b;
while(!(SPSR & _BV(SPIF)));
return SPDR;
}

37
firmware/spi.h Normal file
View file

@ -0,0 +1,37 @@
#ifndef SPI_H
#define SPI_H
#include <util/delay.h>
#include <avr/io.h>
#include <stdint.h>
#define SLSL PB4
#define MOSI PB5
#define MISO PB6
#define SCLK PB7
#define DMUX1 PD2
#define DMUX2 PD3
#define DMUX3 PD4
enum SPIADR {
AA0 = 0,
AA1 = 1,
BEBA0 = 2,
BEBA1 = 3,
EXT = 4,
SWITCH = 5,
NONE = 7,
};
class SPI
{
public:
SPI(void);
void init(void) const;
void setAdr(uint8_t) const;
uint8_t pushByte(uint8_t) const;
};
#endif // SPI_H

130
firmware/usart.cpp Normal file
View file

@ -0,0 +1,130 @@
#include "usart.h"
void USART::init()
{
UCSR0A = _BV(U2X0);
UCSR0B = _BV(RXEN0) | _BV(TXEN0);
// Einstellen des Datenformats: 8 Datenbits, 1 Stoppbit
UCSR0C = _BV(UCSZ00) |_BV(UCSZ01);// (1<<URSEL0)|(1<<UCSZ10)|(1<<UCSZ00);
// setze Baudrate
UBRR0H = (((F_CPU / (8UL * BAUDRATE))-1) >> 8) & 0xFF;
UBRR0L = ((F_CPU / (8UL * BAUDRATE))-1) & 0xFF;
}
void USART::flush()
{
uint8_t dummy;
do
{
dummy = UDR0;
_delay_us((1000000 / BAUDRATE) * 16); // Warte Übertragungszeit von 16 Bit ab
}
while (UCSR0A & (1<<RXC0));
if(dummy) // taeusche dummy Verwendung vor
return;
}
void USART::writeByte(uint8_t b)
{
while (!(UCSR0A & (1<<UDRE0)));
UDR0 = b;
//while(!(UCSR0A & _BV(TXC0)));
}
void USART::writeInt(uint16_t v)
{
while (!(UCSR0A & (1<<UDRE0)));
UDR0 = v & 0xFF;
v >>= 8;
while (!(UCSR0A & (1<<UDRE0)));
UDR0 = v & 0xFF;
//while(!(UCSR0A & _BV(TXC0)));
}
void USART::writeStr(const char* str, uint8_t len)
{
writeByte(len);
while(len--)
writeByte(*str++);
}
uint8_t USART::writeBlock(uint8_t* ptr, uint8_t len)
{
writeByte(len);
uint8_t crc = 0;
while(len--)
{
writeByte(*ptr);
crc ^= *ptr++;
for (uint8_t i = 0; i < 8; i++)
{
if (crc & 1)
crc ^= CRC7_POLY;
crc >>= 1;
}
}
writeByte(crc);
return readByte();
}
uint8_t USART::readByte()
{
while (!(UCSR0A & (1<<RXC0)));
return UDR0;
}
uint16_t USART::readInt()
{
uint16_t v = readByte();
v |= readByte() << 8;
return v;
}
void USART::readBlock(uint8_t* ptr, uint8_t offset)
{
ptr += offset;
uint8_t crc;
do
{
crc = 0;
uint8_t len = readByte();
if(len > MAX_BLOCK_SIZE)
len = 0;
for(uint8_t k = 0; k <= len; k++) // len + 1 Durchgänge (+ crc)
{
uint8_t next = readByte();
crc ^= next;
for (uint8_t i = 0; i < 8; i++)
{
if (crc & 1)
crc ^= CRC7_POLY;
crc >>= 1;
}
if(k < len)
ptr[k] = next;
}
flush(); // leere Eingangspuffer
writeByte(crc == 0 ? MSG_OK : MSG_FAIL);
}
while(crc != 0);
}

32
firmware/usart.h Normal file
View file

@ -0,0 +1,32 @@
#ifndef USART_H
#define USART_H
#include <avr/io.h>
#include <util/delay.h>
#include <stdint.h>
constexpr uint32_t BAUDRATE = 115200; // 38400
constexpr uint8_t CRC7_POLY = 0x91;
constexpr uint8_t MAX_BLOCK_SIZE = 16;
class USART
{
public:
void init(void);
void flush(void);
void writeByte(uint8_t);
void writeInt(uint16_t);
void writeLong(uint32_t);
void writeStr(const char*, uint8_t);
uint8_t writeBlock(uint8_t*, uint8_t);
uint8_t readByte(void);
uint16_t readInt(void);
uint32_t readLong(void);
void readBlock(uint8_t*, uint8_t);
constexpr static uint8_t MSG_OK = 0xFF;
constexpr static uint8_t MSG_FAIL = 0xFE;
};
#endif // USART_H