Skip to content

Commit 46f7592

Browse files
committed
LiftDriver bootloder format
1 parent 845afe1 commit 46f7592

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

bootloaders/atmega/ATmegaBOOT_168.c

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
#define BL_PIN PINF
114114
#define BL0 PINF7
115115
#define BL1 PINF6
116-
#elif defined __AVR_ATmega1280__
116+
#elif defined __AVR_ATmega1280__
117117
/* we just don't do anything for the MEGA and enter bootloader on reset anyway*/
118118
#else
119119
/* other ATmegas have only one UART, so only one pin is defined to enter bootloader */
@@ -133,7 +133,7 @@
133133
#define LED_PIN PINB
134134
#define LED PINB7
135135
#else
136-
/* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duomilanuove */
136+
/* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duomilanuove */
137137
/* other boards like e.g. Crumb8, Crumb168 are using PB2 */
138138
#define LED_DDR DDRB
139139
#define LED_PORT PORTB
@@ -142,6 +142,7 @@
142142
#endif
143143

144144

145+
145146
/* monitor functions will only be compiled when using ATmega128, due to bootblock size constraints */
146147
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
147148
#define MONITOR 1
@@ -343,7 +344,7 @@ int main(void)
343344
#endif
344345
}
345346

346-
#ifdef __AVR_ATmega128__
347+
#ifdef __AVR_ATmega128__
347348
/* no bootuart was selected, default to uart 0 */
348349
if(!bootuart) {
349350
bootuart = 1;
@@ -371,7 +372,7 @@ int main(void)
371372
UBRR = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
372373
UBRRHI = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
373374
UCSRA = 0x00;
374-
UCSRB = _BV(TXEN)|_BV(RXEN);
375+
UCSRB = _BV(TXEN)|_BV(RXEN);
375376
#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined (__AVR_ATmega328__)
376377

377378
#ifdef DOUBLE_SPEED
@@ -440,7 +441,7 @@ int main(void)
440441

441442
/* A bunch of if...else if... gives smaller code than switch...case ! */
442443

443-
/* Hello is anyone home ? */
444+
/* Hello is anyone home ? */
444445
if(ch=='0') {
445446
nothing_response();
446447
}
@@ -537,10 +538,10 @@ int main(void)
537538
if (ch == 0) {
538539
byte_response(SIG1);
539540
} else if (ch == 1) {
540-
byte_response(SIG2);
541+
byte_response(SIG2);
541542
} else {
542543
byte_response(SIG3);
543-
}
544+
}
544545
} else {
545546
getNch(3);
546547
byte_response(0x00);
@@ -571,7 +572,7 @@ int main(void)
571572
eeprom_write_byte((void *)address.word,buff[w]);
572573
#endif
573574
address.word++;
574-
}
575+
}
575576
}
576577
else { //Write to FLASH one page at a time
577578
if (address.byte[1]>127) address_high = 0x01; //Only possible with m128, m256 will need 3rd address byte. FIXME
@@ -596,17 +597,17 @@ int main(void)
596597
"ldi r29,hi8(buff) \n\t"
597598
"lds r24,length \n\t" //Length of data to be written (in bytes)
598599
"lds r25,length+1 \n\t"
599-
"length_loop: \n\t" //Main loop, repeat for number of words in block
600+
"length_loop: \n\t" //Main loop, repeat for number of words in block
600601
"cpi r17,0x00 \n\t" //If page_word_count=0 then erase page
601-
"brne no_page_erase \n\t"
602+
"brne no_page_erase \n\t"
602603
"wait_spm1: \n\t"
603604
"lds r16,%0 \n\t" //Wait for previous spm to complete
604605
"andi r16,1 \n\t"
605606
"cpi r16,1 \n\t"
606607
"breq wait_spm1 \n\t"
607608
"ldi r16,0x03 \n\t" //Erase page pointed to by Z
608609
"sts %0,r16 \n\t"
609-
"spm \n\t"
610+
"spm \n\t"
610611
#ifdef __AVR_ATmega163__
611612
".word 0xFFFF \n\t"
612613
"nop \n\t"
@@ -615,19 +616,19 @@ int main(void)
615616
"lds r16,%0 \n\t" //Wait for previous spm to complete
616617
"andi r16,1 \n\t"
617618
"cpi r16,1 \n\t"
618-
"breq wait_spm2 \n\t"
619+
"breq wait_spm2 \n\t"
619620

620621
"ldi r16,0x11 \n\t" //Re-enable RWW section
621-
"sts %0,r16 \n\t"
622+
"sts %0,r16 \n\t"
622623
"spm \n\t"
623624
#ifdef __AVR_ATmega163__
624625
".word 0xFFFF \n\t"
625626
"nop \n\t"
626627
#endif
627-
"no_page_erase: \n\t"
628+
"no_page_erase: \n\t"
628629
"ld r0,Y+ \n\t" //Write 2 bytes into page buffer
629-
"ld r1,Y+ \n\t"
630-
630+
"ld r1,Y+ \n\t"
631+
631632
"wait_spm3: \n\t"
632633
"lds r16,%0 \n\t" //Wait for previous spm to complete
633634
"andi r16,1 \n\t"
@@ -636,7 +637,7 @@ int main(void)
636637
"ldi r16,0x01 \n\t" //Load r0,r1 into FLASH page buffer
637638
"sts %0,r16 \n\t"
638639
"spm \n\t"
639-
640+
640641
"inc r17 \n\t" //page_word_count++
641642
"cpi r17,%1 \n\t"
642643
"brlo same_page \n\t" //Still same page in FLASH
@@ -649,7 +650,7 @@ int main(void)
649650
"breq wait_spm4 \n\t"
650651
#ifdef __AVR_ATmega163__
651652
"andi r30,0x80 \n\t" // m163 requires Z6:Z1 to be zero during page write
652-
#endif
653+
#endif
653654
"ldi r16,0x05 \n\t" //Write page pointed to by Z
654655
"sts %0,r16 \n\t"
655656
"spm \n\t"
@@ -662,15 +663,15 @@ int main(void)
662663
"lds r16,%0 \n\t" //Wait for previous spm to complete
663664
"andi r16,1 \n\t"
664665
"cpi r16,1 \n\t"
665-
"breq wait_spm5 \n\t"
666+
"breq wait_spm5 \n\t"
666667
"ldi r16,0x11 \n\t" //Re-enable RWW section
667-
"sts %0,r16 \n\t"
668-
"spm \n\t"
668+
"sts %0,r16 \n\t"
669+
"spm \n\t"
669670
#ifdef __AVR_ATmega163__
670671
".word 0xFFFF \n\t"
671672
"nop \n\t"
672673
#endif
673-
"same_page: \n\t"
674+
"same_page: \n\t"
674675
"adiw r30,2 \n\t" //Next word in FLASH
675676
"sbiw r24,2 \n\t" //length-2
676677
"breq final_write \n\t" //Finished
@@ -696,7 +697,7 @@ int main(void)
696697
} else {
697698
if (++error_count == MAX_ERROR_COUNT)
698699
app_start();
699-
}
700+
}
700701
}
701702

702703

@@ -761,7 +762,7 @@ int main(void)
761762
}
762763

763764

764-
#if defined MONITOR
765+
#if defined MONITOR
765766

766767
/* here come the extended monitor commands by Erik Lins */
767768

@@ -783,7 +784,7 @@ int main(void)
783784
welcome = "ATmegaBOOT / PROBOmega128 - (C) J.P.Kyle, E.Lins - 050815\n\r";
784785
#elif defined SAVVY128
785786
welcome = "ATmegaBOOT / Savvy128 - (C) J.P.Kyle, E.Lins - 050815\n\r";
786-
#elif defined __AVR_ATmega1280__
787+
#elif defined __AVR_ATmega1280__
787788
welcome = "ATmegaBOOT / Arduino Mega - (C) Arduino LLC - 090930\n\r";
788789
#endif
789790

@@ -815,7 +816,7 @@ int main(void)
815816
LED_PORT |= _BV(LED);
816817
putch('0');
817818
}
818-
}
819+
}
819820

820821
/* read byte from address */
821822
else if(ch == 'r') {
@@ -907,14 +908,14 @@ void puthex(char ch) {
907908
} else {
908909
ah += '0';
909910
}
910-
911+
911912
ch &= 0x0f;
912913
if(ch >= 0x0a) {
913914
ch = ch - 0x0a + 'a';
914915
} else {
915916
ch += '0';
916917
}
917-
918+
918919
putch(ah);
919920
putch(ch);
920921
}
@@ -948,7 +949,7 @@ char getch(void)
948949
uint32_t count = 0;
949950
if(bootuart == 1) {
950951
while(!(UCSR0A & _BV(RXC0))) {
951-
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
952+
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
952953
/* HACKME:: here is a good place to count times*/
953954
count++;
954955
if (count > MAX_TIME_COUNT)
@@ -959,7 +960,7 @@ char getch(void)
959960
}
960961
else if(bootuart == 2) {
961962
while(!(UCSR1A & _BV(RXC1))) {
962-
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
963+
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
963964
/* HACKME:: here is a good place to count times*/
964965
count++;
965966
if (count > MAX_TIME_COUNT)
@@ -972,7 +973,7 @@ char getch(void)
972973
#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined (__AVR_ATmega328__)
973974
uint32_t count = 0;
974975
while(!(UCSR0A & _BV(RXC0))){
975-
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
976+
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
976977
/* HACKME:: here is a good place to count times*/
977978
count++;
978979
if (count > MAX_TIME_COUNT)
@@ -983,7 +984,7 @@ char getch(void)
983984
/* m8,16,32,169,8515,8535,163 */
984985
uint32_t count = 0;
985986
while(!(UCSRA & _BV(RXC))){
986-
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
987+
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
987988
/* HACKME:: here is a good place to count times*/
988989
count++;
989990
if (count > MAX_TIME_COUNT)
@@ -1001,7 +1002,7 @@ void getNch(uint8_t count)
10011002
if(bootuart == 1) {
10021003
while(!(UCSR0A & _BV(RXC0)));
10031004
UDR0;
1004-
}
1005+
}
10051006
else if(bootuart == 2) {
10061007
while(!(UCSR1A & _BV(RXC1)));
10071008
UDR1;
@@ -1010,11 +1011,11 @@ void getNch(uint8_t count)
10101011
getch();
10111012
#else
10121013
/* m8,16,32,169,8515,8535,163 */
1013-
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
1014+
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
10141015
//while(!(UCSRA & _BV(RXC)));
10151016
//UDR;
10161017
getch(); // need to handle time out
1017-
#endif
1018+
#endif
10181019
}
10191020
}
10201021

0 commit comments

Comments
 (0)