Some optimizations to run on AVR-GCC 4.9

This commit is contained in:
Thomas Kopp 2014-09-22 23:24:05 +02:00
parent b08051ee5f
commit 3f66aeeca1
4 changed files with 207 additions and 212 deletions

View file

@ -11,100 +11,98 @@
#include "main.h"
volatile uint8_t timer_tick = false;
/*! \brief Initialize the AVR.
*/
static inline void init(void)
{
// Init ports
DDRB = 0xFF; // PB0-PB7: LED 1-8 (Kathode)
PORTB = 0xFF; // HIGH
DDRD = 0x78; // PD6: LED 9 (Kathode); PD5-PD3: A-C (Anode)
PORTD = 0x40;
// Setup Timer-Interrupt "TIMER1" compare match
// Refresh-rate is 100Hz of the whole LEDCube.
// The timer fires at 300Hz.
// Set the compare value to
// 625d = 0x271
OCR1A = 0x271;
// Set prescaler to 64 and CTC mode
TCCR1B = (1 << CS11) | (1 << CS10) | (1 << WGM12);
sei(); // Enable interrupts global
}
/*! \brief Main loop
*/
int __attribute__((OS_main)) main()
{
uint8_t level;
uint8_t frmnum;
uint8_t delay;
// Initialize the AVR and the USB connection.
init();
init_usb();
// Hauptschleife
for (;;)
{
// main loop
for (;;) {
usbPoll(); // keep connected
}
}
/*! \brief Initialize the AVR.
*/
void init()
{
// Init ports
DDRB = 0b11111111; // PB0-PB7: LED 1-8 (Kathode)
PORTB = 0b11111111; // HIGH
if (TIFR & (1 << OCF1A)) {
TIFR = (1 << OCF1A);
cli();
DDRD = 0b01111000; // PD6: LED 9 (Kathode); PD5-PD3: A-C (Anode)
PORTD = 0b01000000;
// Setup Timer-Interrupt "TIMER1" compare match interrupt
TIMSK = (1 << OCIE1A);
// Refreshrate is 100Hz of the whole LEDCube.
// The ISR comes up at 300Hz.
// Set the compare value to
// 625d = 0x271 = 0b00000010, 0b01110001
OCR1AH = 0b00000010;
OCR1AL = 0b01110001;
// Set prescale to 64 and clear the counter on compare match.
TCCR1B = (1 << CS11) | (1 << CS10) | (1 << WGM12);
sei(); // Enable interrupts global
}
/*! \brief TIMER1 interruptvector, called in a frequency of 300Hz.
*/
ISR (TIMER1_COMPA_vect)
{
if (!(--delay)) // decrease the counter and check if we are done with waiting
{
if (frmnum == MAX_EEPROM_FRAMES)
{
if (mode == MODE_ANIMATION_SINGLE)
if (!(--delay)) { // decrease the counter and check if we are done with waiting
if (frmnum == MAX_EEPROM_FRAMES) {
if (mode == MODE_ANIMATION_SINGLE) {
mode = MODE_ANIMATION_STOP; // stop the animation after we have reached the 31th frame
}
frmnum = 0; // always start at the first frame
} else {
if (mode)
{
if (mode) {
// if we are in an animation mode we have to load a frame out of the eeprom
// and increase the counter
frame = eeprom_read_dword( &eep_anim[frmnum] );
frame = eeprom_read_dword(&eep_anim[frmnum]);
frmnum++;
}
}
// Just shift right by 24 instead of 27 to multiply the delay by 8.
// Possible delays are 8 16 24 32 and so on. A zero delay isn't possible.
// Zero means that a delay of 255 happens because the delay variable was decreased first before testing
// it's is zero value.
// it's zero value.
delay = (frame >> 24) & 0xf8;
}
// !!!Don't touch the 6th bit (9th LED wire)!!!
// PORTD = __, 9, C, B, A, D+, D-, __
PORTD &= 0b11000111; // delete bit 3 to 6 (bit 3 to 5 = layer 0 to 2
PORTD &= ~((1 << 5) | (1 << 4) | (1 << 3) | (1 << 2));; // delete bit 3 to 6 (bit 3 to 5 = layer 0 to 2
uint8_t tmp = level * 9; // calculate the position in the frame
// PORTB = 1..8
// 0 = led is on, 1 = led is off
PORTB = ~((frame >> tmp) & 0xff);
if ((((frame >> tmp) >> 8) & 0x01))
if ((((frame >> tmp) >> 8) & 0x01)) {
PORTD &= ~(1 << 6); // turn the 9th LED on
else
} else {
PORTD |= (1 << 6); // turn the 9th LED off
}
// set the current level to high
// at this point the LED pins are up to date so it's
// safe to reenable the level wire (A/B/C)
// this prevents wierd LED flashing which is not defined
// safe to re-enable the level wire (A/B/C)
// this prevents weird LED flashing which is not defined
// in the animation frame
PORTD |= ((1 << level) << 3);
PORTD |= ((1 << level) << 3); // set the current level
// rotate through the 3 level
level++;
if (level > 2)
level = 0;
if (level > 2) {
level = 0;
}
sei();
}
}
}

View file

@ -15,6 +15,8 @@
// Includes
#include "globals.h"
#include <stdbool.h>
#include <stdint.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/eeprom.h>
@ -27,20 +29,18 @@
* the next frame will be shown (load from the EEPROM)
*/
uint32_t frame;
uint8_t level; // current layer
uint8_t mode = MODE_ANIMATION_LOOP; // firmware mode
uint8_t frmnum; // frame nummber in the animation loop
uint8_t delay; // delay in ISR calls between changing to the next animation frame
// uint8_t level; // current layer
// uint8_t frmnum; // frame nummber in the animation loop
// uint8_t delay; // delay in ISR calls between changing to the next animation frame
// eeprom array of the animation
uint32_t eep_anim[MAX_EEPROM_FRAMES] EEMEM;
// function prototypes
void init(void);
extern void init_usb(void);
extern void usbPoll(void);
#endif // __main_h__

View file

@ -1,128 +1,127 @@
:1000000083C111C09AC199C1C9C197C196C195C197
:1000100094C193C192C191C190C18FC18EC18DC154
:100020008CC18BC18AC1CF93CFB7CF93C395819B2E
:10003000E9F7819B09C0819B07C0819B05C0819B1B
:1000400003C0819B01C0A3C0DF93C0918400DD2762
:10005000C557DF4F819B02C0DF91EBCF2F930F93EA
:100060001F9300B32FEF01FB20F94F933F9310B381
:100070004FEF012701FB21F93BE031C04E7F012FFB
:1000800010B3216028C0102F4D7F2260000000B304
:1000900029C04B7F2460012F000010B32BC010B388
:1000A000477F28602AC04F7E00B320612CC04F7D5F
:1000B00010B320622FC04F7B00B3206432C04227B0
:1000C00000B349934FEF0000102711FB20F910B344
:1000D0001670C9F1297F91F2012701FB21F900B3C4
:1000E000237F89F2315058F1102711FB22F910B308
:1000F000277E79F2012701FB23F92F7C81F200B3DF
:10010000102711FB24F92F7971F200C010B30127D9
:1001100001FB25F92F7359F200C000B3102711FB22
:1001200026F9223040F200C010B3012701FB27F965
:10013000243028F64F77206810B30000F9CF10E480
:100140001ABF002719C03B503195C31BD04010E4A3
:100150001ABF0881033CF9F00B34E9F020918200CA
:100160001981110F1213EDCF4A81441F093641F155
:100170000D3211F0013E29F7009389003F914F9114
:100180001F910F912F91DF91CAB7C6FD4FCFCF912D
:10019000CFBFCF91189520918900222379F3109138
:1001A0008700112369F534306AF13093870020937A
:1001B0008300109184003BE0311B3093840022C007
:1001C000009187000130E4F40AE54F7049F4309162
:1001D000610034FD19C000936100CBE6D0E018C087
:1001E0003091760034FD10C000937600C7E7D0E070
:1001F0000FC02795A8F45150A9F4220F0000F9CFA1
:100200004AE503C042ED01C0432FC4E1D0E032E033
:1002100011B31660919A11BB02B320E416E05F930C
:10022000012756E002BB279520F4515021F4220FFC
:10023000F9CF012756E000003B5A02BBD0F22795C8
:1002400028F4515029F4220F0000F9CF012756E07D
:10025000279502BB20F4515021F4220FF9CF01273A
:1002600056E02991332302BB21F6097F10918800C3
:10027000110FC651D04002BB11F01093820010E460
:100280001ABF026011B3197F402F497F5F9100C0F0
:1002900000C002BB11BB42BB71CF040309041003B1
:1002A0004300540048004E002E0064006500100317
:1002B0004C004500440043007500620065001201D7
:1002C000100100000008C016DF0500010102000156
:1002D00009022200010100807D09040000010300E1
:1002E0000000092101010001221600070581030811
:1002F000000A0600FF0901A101150026FF0075088C
:1003000095010900B20201C011241FBECFEDCDBF7F
:1003100010E0A0E6B0E0E8EDF7E002C005900D9235
:10032000A436B107D9F710E0A4E6B0E001C01D92F1
:10033000A13AB107E1F72ED04DC262CEA82FB92F56
:1003400080E090E041E050EA609530E009C02D91F6
:1003500082279795879510F084279527305EC8F3FC
:100360006F5FA8F30895EADF8D939D9308958FEF53
:1003700087BB88BB88E781BB80E482BB89B7806488
:1003800089BF82E08BBD81E78ABD8EB58B608EBD53
:1003900078940895ECDFDAD184D0FECF1F920F92CB
:1003A0000FB60F9211241F932F933F934F935F9398
:1003B0006F937F938F939F93AF93BF93EF93FF932D
:1003C00080916500815080936500882341F51091EC
:1003D0006A0080916000103239F4813011F410927B
:1003E000600010926A0016C08823A1F0812F90E06F
:1003F000880F991F880F991F80509040C3D1609338
:1004000066007093670080936800909369001F5F97
:1004100010936A0080916900887F8093650082B3A1
:10042000877882BB92B390648091640028E030E0CA
:10043000082E02C0220F331F0A94E2F7922B92BBC0
:1004400069E097D120916600309167004091680083
:100450005091690004C056954795379527958A9520
:10046000D2F7822F809588BB30FD969880916400EA
:100470008F5F80936400833010F010926400FF91CE
:10048000EF91BF91AF919F918F917F916F915F910C
:100490004F913F912F911F910F900FBE0F901F9082
:1004A00018951F93CF93DF9380918700835087FD2A
:1004B000A1C090918400209183002D3209F098C052
:1004C000883009F095C0CCE0D0E0C91BD109C557F0
:1004D000DF4F83EC80936B008AE58093610013BA51
:1004E0008881807619F0CE01DBD079C09A81109294
:1004F00074008981882331F41092750024E730E07C
:1005000082E069C0853019F49093880061C086301C
:1005100009F048C08B81813041F48EEB92E09093DA
:1005200086008093850082E13AC0823041F480EDFC
:1005300092E0909386008093850082E230C0833001
:10054000C9F4992341F48AE992E09093860080935C
:10055000850084E024C0913019F48EE992E004C053
:100560009230E1F48EEA92E09093860080938500C9
:1005700080E115C0813241F482EE92E090938600D2
:100580008093850089E00BC0823241F482EF92E0D3
:10059000909386008093850086E101C080E090E41E
:1005A00093BB1DC0883069F0893019F490938A009C
:1005B0000FC08A3049F08B3059F48BE48093770078
:1005C00007C02AE830E002C024E730E081E003C041
:1005D00024E730E080E030938600209385009F81FF
:1005E000992321F49E81981708F4892F8093620043
:1005F000109287008091610084FF44C08091620066
:100600008F3F09F43FC0182F893008F018E0811B94
:100610008093620080916B0098E8892780936B003B
:10062000112321F1E0918500F0918600812F815006
:100630009E9B0CC090E083599F4FACE6B0E02491A4
:100640002D933196A817B907D1F70CC0EF0190E0B0
:1006500083599F4FACE6B0E029912D93FE01A81776
:10066000B907D1F7F0938600E09385008CE690E01F
:10067000612F79DE1C5F1C3019F08FEF80936200D0
:100680001093610084E190B3967031F48150D9F7F2
:100690001092880010928200DF91CF911F910895EF
:1006A000FC0180818076803409F04EC081818130E8
:1006B00091F5848173816281209166003091670099
:1006C0004091680050916900882359F4972F80E089
:1006D000860F911DAA2797FDA095BA2F2070307024
:1006E0000DC0972F80E0860F911DAA2797FDA0953A
:1006F000BA2FDC019927882740705070822B932BEA
:10070000A42BB52B8093660090936700A09368009C
:10071000B093690019C0823091F4848190E0880F11
:10072000991F880F991F4091660050916700609152
:100730006800709169008050904027D005C08330D8
:1007400019F482818093600080E0089585B782600B
:1007500085BF8BB780648BBF8BE4809377008AE57D
:1007600080937600899A01C000009150E9F789983A
:100770000895002480FD060E660F11F08695D1F7CE
:10078000802D0895A6E144E00AC0242F16D0252F1D
:1007900014D000C011D0272F10C0A82F862FE82F0B
:1007A000E199FECF1FBA05C0EEBBE09AE3950DB20A
:1007B0000D924150C8F70895262FE199FECF1CBA3B
:1007C0001FBA8EBB2DBB0FB6F894E29AE19A0FBE0A
:0807D00001960895F894FFCF93
:0407D800025AFF00C2
:1000000049C07BC060C05FC05EC05DC05CC05BC0FB
:100010005AC059C058C057C056C055C054C053C02C
:1000200052C051C050C009022200010100807D0968
:100030000400000103000000092101010001221653
:10004000000705810308000A1201100100000008E2
:10005000C016DF0500010102000110034C0045003D
:100060004400430075006200650010034300540023
:1000700048004E002E0064006500040309040600D9
:10008000FF0901A101150026FF007508950109006F
:10009000B20201C011241FBECFEDCDBF10E0A0E61B
:1000A000B0E0E2ECF7E002C005900D92A436B10793
:1000B000D9F710E0A4E6B0E001C01D92AF39B10756
:1000C000E1F755D17CC39CCFA82FB92F80E090E0F9
:1000D00041E050EA609530E009C02D918227979564
:1000E000879510F084279527305EC8F36F5FA8F3DB
:1000F0000895EADF8D939D930895CF93CFB7CF9363
:10010000C395819BE9F7819B09C0819B07C0819BB7
:1001100005C0819B03C0819B01C0A3C0DF93C09138
:100120008200DD27C757DF4F819B02C0DF91EBCFF5
:100130002F930F931F9300B32FEF01FB20F94F93E1
:100140003F9310B34FEF012701FB21F93BE031C092
:100150004E7F012F10B3216028C0102F4D7F2260E9
:10016000000000B329C04B7F2460012F000010B3B2
:100170002BC010B3477F28602AC04F7E00B3206198
:100180002CC04F7D10B320622FC04F7B00B3206482
:1001900032C0422700B349934FEF0000102711FBF4
:1001A00020F910B31670C9F1297F91F2012701FBE4
:1001B00021F900B3237F89F2315058F1102711FB48
:1001C00022F910B3277E79F2012701FB23F92F7C56
:1001D00081F200B3102711FB24F92F7971F200C0CE
:1001E00010B3012701FB25F92F7359F200C000B3AA
:1001F000102711FB26F9223040F200C010B301276E
:1002000001FB27F9243028F64F77206810B300004F
:10021000F9CF10E41ABF002719C03B503195C31B1A
:10022000D04010E41ABF0881033CF9F00B34E9F028
:10023000209180001981110F1213EDCF4A81441FC4
:10024000093641F10D3211F0013E29F70093870084
:100250003F914F911F910F912F91DF91CAB7C6FD2A
:100260004FCFCF91CFBFCF911895209187002223F8
:1002700079F310918500112369F534306AF13093D8
:10028000850020938100109182003BE0311B309368
:10029000820022C0009185000130E4F40AE54F702D
:1002A00049F43091620034FD19C000936200C9E640
:1002B000D0E018C03091740034FD10C00093740079
:1002C000C5E7D0E00FC02795A8F45150A9F4220F3C
:1002D0000000F9CF4AE503C042ED01C0432FC4E15D
:1002E000D0E032E011B31660919A11BB02B320E462
:1002F00016E05F93012756E002BB279520F451508A
:1003000021F4220FF9CF012756E000003B5A02BB2F
:10031000D0F2279528F4515029F4220F0000F9CF8C
:10032000012756E0279502BB20F4515021F4220FFB
:10033000F9CF012756E02991332302BB21F6097F2B
:1003400010918600110FC651D04002BB11F01093DE
:10035000800010E41ABF026011B3197F402F497F5B
:100360005F9100C000C002BB11BB42BB71CF8FEFD9
:1003700087BB88BB88E781BB80E482BB81E792E0D2
:100380009BBD8ABD8BE08EBD7894DED166D008B669
:1003900006FEFCCF80E488BFF894115011F58091DF
:1003A0006000D03229F48130C1F41092600015C091
:1003B0008823A1F08D2F90E0880F991F880F991F37
:1003C00080509040D4D16093650070936600809314
:1003D000670090936800DF5F01C0D0E01091680073
:1003E000187F82B3837C82BB8C2F69E0B7D1282F22
:1003F00040916500509166006091670070916800BF
:1004000004C076956795579547958A95D2F740959C
:1004100048BB8091650090916600A0916700B09103
:10042000680004C0B695A795979587952A95D2F749
:1004300090FF02C0969801C0969A22B388E090E09F
:100440000C2E01C0880F0A94EAF7822B82BBCF5F83
:10045000C33009F4C0E0789499CFCF93DF938091B3
:100460008500835087FDA3C0909182002091810078
:100470002D3209F09AC0883009F097C0CCE0D0E066
:10048000C91BD109C757DF4F83EC809369008AE508
:1004900080936200109264008881807619F0CE010A
:1004A000E7D07AC09A81109272008981811106C0CA
:1004B0001092730022E730E082E06AC0853019F4C0
:1004C0009093860062C0863009F049C08B818130EC
:1004D00041F488E490E0909384008093830082E16B
:1004E0003AC0823041F486E290E090938400809399
:1004F000830082E230C08330C9F4911108C08AE7DA
:1005000090E0909384008093830084E024C0913035
:1005100019F48AE690E004C09230E1F48AE590E0B4
:10052000909384008093830080E115C0813241F470
:1005300088E390E0909384008093830089E00BC06F
:10054000823241F48EE790E09093840080938300A0
:1005500086E101C080E090E4909364001DC0883083
:1005600069F0893019F4909388000FC08A3049F0FF
:100570008B3059F48BE48093750007C028E830E095
:1005800002C022E730E081E003C022E730E080E0F3
:1005900030938400209383009F81911104C09E8139
:1005A000981708F4892F809361001092850080913C
:1005B000620084FF43C0809161008F3F09F43EC018
:1005C000C82F893008F0C8E08C1B8093610090919F
:1005D000690088E8892780936900CC2319F180910C
:1005E000830040918400209164009C2F980F26FF87
:1005F0000AC0AAE6B0E0E82FF42F84918D933196DB
:100600009E13FBCF0BC02AE630E0A82FB42F8D91AC
:10061000F90181939F01FD019A13F9CFF0938400B2
:10062000E09383006C2F8AE690E063DDCC5FCC30F2
:1006300019F08FEF80936100C093620084E190B362
:10064000967031F48150D9F7109286001092800094
:10065000DF91CF91089585B7826085BF8BB78064A5
:100660008BBFE4E7F0E08BE481838AE58083089523
:100670000F931F93FC0180818076803409F060C065
:100680008181813009F043C084814091650050919F
:100690006600609167007091680081111AC08281C4
:1006A000038110E0102F0027080F111D222717FDCE
:1006B0002095322F44275527042B152B262B372B1B
:1006C00000936500109366002093670030936800E4
:1006D00037C022819381892F90E0982F8827820F3D
:1006E000911DAA2797FDA095BA2FDC01992788278D
:1006F00066277727842B952BA62BB72B8093650035
:1007000090936600A0936700B093680019C0823090
:1007100091F440916500509166006091670070917E
:100720006800848190E0880F991F880F991F80507E
:10073000904020D005C0833019F4828180936000FE
:1007400080E01F910F910895CF9385DF899AC15062
:1007500011F00000FCCF8998CF910895002480FD0E
:10076000060E660F11F08695D1F7802D0895A6E14B
:1007700044E00AC0242F16D0252F14D000C011D079
:10078000272F10C0A82F862FE82FE199FECF1FBA80
:1007900005C0EEBBE09AE3950DB20D924150C8F74B
:1007A0000895262FE199FECF1CBA1FBA8EBB2DBB30
:1007B0000FB6F894E29AE19A0FBE01960895F89464
:0207C000FFCF69
:0407C20002FF5A00D8
:00000001FF

View file

@ -40,7 +40,6 @@ PROGMEM const char usbHidReportDescriptor[22] = { /* USB report descriptor */
void init_usb(void);
//extern uint8_t eep_delay_max EEMEM;
extern uint32_t eep_anim[MAX_EEPROM_FRAMES] EEMEM;
// usb buffer
@ -48,4 +47,3 @@ extern uint32_t frame; // Framebuffer
extern uint8_t mode; // FW mode
#endif // __usb_h__