1 # 1 "added/bootload.S" 1 /* 1 ... 0 0 22 .list 23 24 /* 25 atmel_def.h contains some definitions taken from the Atmel's def 26 file (which one is defined in the Makefile). Always keep in mind 27 that flash addresses taken from there are word addresses. 28 */ 29 #undef FLASHEND 30 #include "atmel_def.h" 1 #define SIGNATURE_000 0x1e 2 #define SIGNATURE_001 0x93 3 #define SIGNATURE_002 0x0a 4 #define BOOTRST 0 // Select reset vector 5 #define BOOTSZ0 1 // Select boot size 6 #define BOOTSZ1 2 // Select boot size 7 #define FLASHEND 0x0fff // Note: Word address 8 #define SRAM_START 0x0100 9 #define SRAM_SIZE 1024 10 ; ***** BOOTLOADER DECLARATIONS ****************************************** 11 #define PAGESIZE 32 31 32 #define byte3(x) ((x)>>16) 33 #define byte2(x) ((x & 0xff00)>>8) 34 #define byte1(x) (x & 0xff) 35 36 37 /* 38 Atmel's AVR assembler is case insensitive, gcc is not. 39 mangled_case.h covers the cases where the representations in the 40 program mix case. 41 */ 42 #include "mangled_case.h" 1 /* 43 44 /* 45 This includes the program: 46 */ 47 #include "bootload.asm" 1 ;************************************************************************* 2 ;* * 3 ;* Generic AVR Bootloader * 4 ;* * 5 ;* Author: Peter Dannegger * 6 ;* * 7 ;************************************************************************* 8 ; select the appropriate include file: 9 ;.include "tn13def.inc" 10 ;.include "tn2313def.inc" 11 ;.include "tn25def.inc" 12 ;.include "tn261def.inc" 13 ;.include "tn44def.inc" 14 ;.include "tn45def.inc" 15 ;.include "tn461def.inc" 16 ;.include "m48def.inc" 17 ;.include "tn84def.inc" 18 ;.include "tn85def.inc" 19 ;.include "tn861def.inc" 20 21 ; set the SecondBootStart fuse on these AVRs: 22 ;.include "m8def.inc" 23 ;.include "m8515def.inc" 24 ;.include "m8535def.inc" 25 ;.include "m88def.inc" 26 ;.include "m16def.inc" 27 ;.include "m162def.inc" 28 ;.include "m168def.inc" 29 30 ; set the FirstBootStart fuse on these AVRs: 31 ;.include "m32def.inc" 32 ;.include "m64def.inc" 33 ;.include "m644def.inc" 34 ;.include "m128def.inc" 35 ;.include "m1281def.inc" 36 ;.include "m2561def.inc" 37 38 39 ; remove comment sign to exclude API-Call: 40 ; only on ATmega >= 8kB supported 41 // #define APICALL 0 42 43 ; remove comment sign to exclude Watchdog trigger: 44 // #define WDTRIGGER 0 45 46 ; remove comment sign to exclude CRC: 47 // #define CRC 0 48 49 ; remove comment sign to exclude Verify: 50 // #define VERIFY 0 51 52 ;------------------------------------------------------------------------- 53 ; Port definitions 54 ;------------------------------------------------------------------------- 55 56 ;------------------------------------------------------------------------- 57 #include "fastload.inc" 1 /* 2 3 fastload.inc 4 5 Written by Peter Dannegger, modified by H. C. Zimmerer 6 7 Time-stamp: <2010-01-14 21:16:21 hcz> 8 9 You may use my modifications here and in the accompanying files of 10 this project for whatever you want to do with them provided you 11 don't remove this copyright notice. 12 13 14 */ 15 ;************************************************************************* 16 ;* * 17 ;* AVR universal Bootloader * 18 ;* * 19 ;* Author: Peter Dannegger * 20 ;* * 21 ;************************************************************************* 22 #include "fastload.h" 1 /* 2 fastload.h 3 4 Written by Peter Dannegger, modified by H. C. Zimmerer 5 6 Time-stamp: <2010-01-14 21:58:08 hcz> 7 8 You may use my modifications here and in the accompanying files of 9 this project for whatever you want to do with them provided you 10 don't remove this copyright notice. 11 12 */ 13 14 ;************************************************************************* 15 #include "compat.h" // compatibility definitions 1 /* 2 3 compat.h 4 5 Written by Peter Dannegger, modified by H. C. Zimmerer 6 7 Time-stamp: <2009-07-18 13:14:35 hcz> 8 9 You may use my modifications here and in the accompanying files of 10 this project for whatever you want to do with them provided you 11 don't remove this copyright notice. 12 13 14 */ 15 ;------------------------------------------------------------------------ 16 ; redefinitions for compatibility 17 ;------------------------------------------------------------------------ 18 #ifndef WDTCSR 19 #define WDTCSR WDTCR 20 #define wdtcsr WDTCR 21 #endif 22 ;--------------------------- 23 #ifndef WDCE 24 #define WDCE WDTOE 25 #define wdce WDTOE 26 #endif 27 ;--------------------------- 28 #ifndef SPMCSR 29 #define SPMCSR SPMCR 30 #define spmcsr SPMCR 31 #endif 32 ;--------------------------- 33 #ifndef RWWSRE 34 #ifdef ASRE 35 #define RWWSRE ASRE 36 #define rwwsre ASRE 37 #endif 38 #endif 39 ;--------------------------- 40 #ifndef SPMEN 41 #define SPMEN SELFPRGEN 42 #define spmen SELFPRGEN 43 #endif 44 ;---------------------- macros for extended IO access ------------------- 45 .macro xout arg0, arg1 46 .if \arg0 > 0x3F 47 sts \arg0, \arg1 48 .else 49 out \arg0, \arg1 50 .endif 51 .endm 52 ;--------------------------- 53 .macro xin arg0, arg1 54 .if \arg1 > 0x3F 55 lds \arg0, \arg1 56 .else 57 in \arg0, \arg1 58 .endif 59 .endm 60 ;--------------------------- 61 .macro xlpm arg0, arg1 62 .if FLASHEND > 0x7FFF 63 elpm \arg0, \arg1 64 .else 65 lpm \arg0, \arg1 66 .endif 67 .endm 68 ;------------------------------------------------------------------------ 69 ... 16 #include "protocol.h" 1 //************************************************************************* 17 ;------------------------------------------------------------------------- 18 ; Constant definitions 19 ;------------------------------------------------------------------------- 20 #define VERSION 0x0201 21 22 #define XTAL F_CPU // 8MHz, not critical 23 #define BootDelay XTAL / 3 // 0.33s 24 #define BOOTDELAY XTAL / 3 25 26 ;------------------------------ select UART mode ------------------------- 27 #if SRX == STX && SRX_PORT == STX_PORT 28 #define ONEWIRE 3 29 #else 30 #define ONEWIRE 0 31 #endif 32 33 #define SRX_PIN SRX_PORT - 2 34 #define STX_DDR STX_PORT - 1 35 36 ;------------------------------ select bootloader size ------------------- 37 38 #ifndef APICALL 39 #ifndef FirstBootStart 40 #define APICALL 0 41 #else 42 #define APICALL 2*12 43 #endif 44 #endif 45 46 #ifndef CRC 47 #define CRC 2*15 48 #endif 49 50 #ifndef VERIFY 51 #define VERIFY 2*14 52 #endif 53 54 #ifndef WDTRIGGER 55 #define WDTRIGGER 2*9 56 #endif 57 58 #ifndef SPH 59 #define MinSize 2*198 60 #define MINSIZE 2*198 61 #else 62 #define MinSize 2*203 63 #define MINSIZE 2*203 64 #endif 65 66 #define BootSize CRC + VERIFY + ONEWIRE + WDTRIGGER + MinSize 67 #define BOOTSIZE CRC + VERIFY + ONEWIRE + WDTRIGGER + MinSize 68 69 ;------------------------------ UART delay loop value -------------------- 70 #if CRC 71 #define UartLoop 28 // UART loop time 72 #define UARTLOOP 28 73 #else 74 #define UartLoop 24 75 #define UARTLOOP 24 76 #endif 77 78 ;------------------------------ Bootloader fuse setting ------------------ 79 #ifdef FIRSTBOOTSTART 80 # if (FlashEnd - FirstBootStart) >= 256 // 256 Words needed 81 # define BootStart FirstBootStart 82 # define BOOTSTART FirstBootStart 83 # else 84 # define BootStart SecondBootStart 85 # define BOOTSTART SecondBootStart 86 # endif 87 ;---------------------------- max possible buffer size ----------------- 88 89 .equ BufferSize,((SRAM_SIZE / 2) - PAGESIZE) 90 .macro testpage 91 .if BootStart % BufferSize 92 .set BufferSize, BufferSize - PAGESIZE 93 .if BootStart % BufferSize 94 .set Buffersize, BufferSize - PAGESIZE 95 testpage 96 .endif 97 .endif 98 .endm 99 testpage ; calculate Buffersize to fit into BootStart 100 101 ;----------------------------------------------------------------------- 102 # define UserFlash (2*BootStart) 103 # define USERFLASH (2*BootStart) 104 #else /* FirstBootStart not defined */ 105 # ifndef FLASHEND 106 # define FLASHEND FlashEnd 107 # endif 108 # define BootStart (FLASHEND - 255) 109 # define BOOTSTART (FLASHEND - 255) 110 # define BufferSize PageSize 111 # define BUFFERSIZE PageSize 112 # define UserFlash (2 * BootStart - 2) 113 # define USERFLASH (2 * BootStart - 2) 114 #endif 115 ;------------------------------------------------------------------------- 116 ; Using register 117 ;------------------------------------------------------------------------- 118 #define zerol r2 119 #define ZEROL r2 120 #define zeroh r3 121 #define ZEROH r3 122 #define baudl r4 // baud divider 123 #define BAUDL r4 124 #define baudh r5 125 #define BAUDH r5 126 #define crcl r6 127 #define CRCL r6 128 #define crch r7 129 #define CRCH r7 130 131 ;------------------------------------------------------------------------- 132 #define appl r16 // rjmp to application 133 #define APPL r16 134 #define apph r17 135 #define APPH r17 136 #define polynoml r18 // CRC polynom 0xA001 137 #define POLYNOML r18 138 #define polynomh r19 139 #define POLYNOMH r19 140 141 #define zx r21 // 3 byte Z pointer 142 #define ZX r21 143 #define a0 r22 // working registers 144 #define A0 r22 145 #define a1 r23 146 #define A1 r23 147 #define twl r24 // wait time 148 #define TWL r24 149 #define twh r25 150 #define TWH r25 151 ;------------------------------------------------------------------------- 152 ; Using SRAM 153 ;------------------------------------------------------------------------- 154 .section .bss 155 .global PROGBUFF,PROGBUFFEND 156 0000 0000 0000 PROGBUFF: .space 2*BufferSize 156 0000 0000 156 0000 0000 156 0000 0000 156 0000 0000 157 PROGBUFFEND: 158 ProgBuffEnd: 159 .section .text 160 ;------------------------------------------------------------------------- 161 ; Macros 162 ;------------------------------------------------------------------------- 163 #if ONEWIRE 164 .macro IOPortInit 165 sbi STX_PORT, SRX ; weak pullup on 166 cbi STX_DDR, SRX ; as input 167 .endm 168 .macro TXD_0 169 sbi STX_DDR, SRX ; strong pullup = 0 170 .endm 171 .macro TXD_1 172 cbi STX_DDR, SRX ; weak pullup = 1 173 .endm 174 .macro SKIP_RXD_0 175 sbis SRX_PIN, SRX ; low = 1 176 .endm 177 .macro SKIP_RXD_1 178 sbic SRX_PIN, SRX ; high = 0 179 .endm 180 #else 181 .macro IOPortInit 182 sbi SRX_PORT, SRX 183 sbi STX_PORT, STX 184 sbi STX_DDR, STX 185 .endm 186 .macro TXD_0 187 cbi STX_PORT, STX 188 .endm 189 .macro TXD_1 190 sbi STX_PORT, STX 191 .endm 192 .macro SKIP_RXD_0 193 sbic SRX_PIN, SRX 194 .endm 195 .macro SKIP_RXD_1 196 sbis SRX_PIN, SRX 197 .endm 198 #endif 199 ;------------------------------------------------------------------------- 200 ... 23 .list 24 init: 25 #ifndef FIRSTBOOTSTART 26 ; .equ Application,init-2 27 #endif 28 0000 F894 cli ; no interrupts allowed 29 0002 6FEF ldi a0, lo8(RamEnd) ; initialize stack 30 0004 6DBF out SPL, a0 31 #ifdef SPH 32 0006 64E0 ldi a0, hi8(RamEnd) 33 0008 6EBF out SPH, a0 34 #endif 35 000a 2224 clr zerol ; for faster clear 36 000c 3324 clr zeroh 37 38 #if WDTRIGGER 39 #include "watchdog.inc" 1 ;------------------------------ check, if watchdog active ---------------- 2 000e A895 wdr 3 0010 6091 6000 xin a0, WDTCSR 4 0014 6061 ori a0, 1< 0x7FFF 6 ldi a0, hh8(/* 2* */Password) 7 out RAMPZ, a0 8 #endif 9 checkpwd: 10 0066 E0E0 ldi zl, lo8(/* 2* */Password) 11 0068 F0E0 ldi zh, hi8(/* 2* */Password) 12 _cpw2: 13 006a 0590 XLPM r0, z+ 14 006c 0020 tst r0 15 006e 01F0 breq _cpw3 ; end if zero byte 16 0070 00D0 rcall getchar 17 0072 0616 cp r0, a0 18 0074 01F0 breq _cpw2 ; compare next byte 19 0076 CA95 dec yl ; count down wrong compares 20 0078 01F0 breq timeout 21 007a 00C0 rjmp checkpwd ; try again 22 _cpw3: 23 ;------------------------------------------------------------------------- 24 ... 50 ;------------------------------------------------------------------------- 51 connected: 52 007c 66EA ldi a0, CONNECT ; password recognized 53 #if ONEWIRE 54 rcall syncputchar ; avoid message garbage 55 #else 56 007e 00D0 rcall putchar 57 #endif 58 0080 00D0 rcall getchar 59 0082 01F4 brne connected ; until COMMAND received 60 ;------------------------------------------------------------------------- 61 #include "command.inc" // execute commands 1 ;------------------------------------------------------------------------- 2 ; Receive commands 3 ;------------------------------------------------------------------------- 4 ;00 get bootloader revision 5 ;01 get buffer size 6 ;02 get target signature 7 ;03 get user flash size 8 ;04 program flash 9 ;05 start application 10 ;06 check crc 11 ;07 verify flash 12 ;------------------------------------------------------------------------- 13 main_ok: 14 0084 6AEA ldi a0, SUCCESS 15 _cex1: 16 0086 00D0 rcall putchar 17 _cex2: 18 0088 00D0 rcall getchar 19 008a 01F4 brne _cex2 ; ignore until COMMAND 20 _cex3: 21 008c 00D0 rcall getchar 22 008e 01F0 breq _cex3 ; ignore further COMMAND 23 #if FLASHEND > 0x7FFF 24 ldi zx, 0 25 #endif 26 0090 F101 movw zl, zerol ; Z = 0x0000, 27 0092 E894 clt ; T = 0 (for program, verify) 28 0094 6430 cpi a0, 4 29 0096 00F0 brcs SendMessage ; command 0 ... 3 30 0098 01F0 breq program ; command 4 31 009a 6530 cpi a0, 5 32 009c 01F0 breq timeout ; command 5 33 009e 6730 cpi a0, 7 34 #if VERIFY 35 00a0 01F0 breq VerifyFlash ; command 7 36 #endif 37 00a2 67EA ldi a0, BADCOMMAND 38 ;------------------------------------------------------------------------- 39 #if CRC 40 00a4 00F4 brcc _cex1 ; command >7 41 ;------------------------------------------------------------------------- 42 CheckCRC: ; command 6 43 00a6 00D0 rcall getchar ; read CRC low 44 00a8 00D0 rcall getchar ; read CRC high 45 00aa 6728 or crcl, crch ; now CRC = 0x0000 ? 46 00ac 01F0 breq main_ok ; yes 47 00ae 3101 movw crcl, zerol ; clear CRC 48 #else 49 rjmp _cex1 50 #endif 51 ;------------------------------------------------------------------------- 52 main_error: 53 00b0 6BEA ldi a0, FAIL 54 00b2 00C0 rjmp _cex1 55 ;------------------------------------------------------------------------- 56 timeout: ; command 5 57 00b4 2AB8 out STX_DDR, zerol 58 00b6 2BB8 out STX_PORT, zerol 59 #if SRX_PORT != STX_PORT 60 out SRX_PORT, zerol 61 #endif 62 #if FlashEnd > 0x0fff 63 jmp Application 64 #else 65 00b8 00C0 rjmp Application ; run application 66 #endif 67 ;------------------------------------------------------------------------- 68 #include "message.inc" // command 0 ... 3 1 ;------------------------------------------------------------------------- 2 ; Send Messages 3 ;------------------------------------------------------------------------- 4 ;input: a0 = number of message 0 .. 3 5 ; 6 SendMessage: 7 #if FLASHEND > 0x7FFF 8 ldi zx, hh8(/* 2* */Messages) 9 out RAMPZ, zx 10 #endif 11 00ba E0E0 ldi zl, lo8(/* 2* */Messages) 12 00bc F0E0 ldi zh, hi8(/* 2* */Messages) 13 00be C0E0 ldi yl, 0 14 _sme1: 15 00c0 EC0F add zl, yl ; add offset to next message 16 00c2 F21D adc zh, zerol 17 00c4 C491 XLPM yl, z 18 00c6 6150 subi a0, 1 ; count down until message found 19 00c8 00F4 brcc _sme1 20 00ca 68EA ldi a0, ANSWER ; first byte of message 21 _sme2: 22 00cc 00D0 rcall putchar 23 00ce 6591 XLPM a0, z+ 24 00d0 C150 subi yl, 1 25 00d2 00F4 brcc _sme2 26 00d4 00C0 rjmp main_ok 27 ;------------------------------------------------------------------------- 28 ... 69 ;------------------------------------------------------------------------- 70 #if VERIFY 71 #include "verify.inc" // command 7 1 ;------------------------------------------------------------------------- 2 ; Verify User Flash 3 ;------------------------------------------------------------------------- 4 ; 5 _ver1: 6 #if FLASHEND > 0x7FFF 7 out RAMPZ, zx 8 elpm r0, z 9 adiw zl, 1 10 adc zx, zerol ; 24 bit addition 11 #else 12 00d6 0590 lpm r0, z+ 13 #endif 14 #ifndef FirstBootStart 15 cpi zl, 3 16 cpc zh, zerol 17 brcs VerifyFlash ; exclude jump to bootloader 18 #endif 19 00d8 0612 cpse r0, a0 20 00da 6894 set 21 VerifyFlash: 22 00dc 00D0 rcall getchar 23 00de 01F4 brne _ver1 ; not COMMAND ? 24 00e0 00D0 rcall getchar 25 00e2 6058 subi a0, ESC_SHIFT 26 00e4 01F4 brne _ver1 ; COMMMAND + not COMMAND = End 27 00e6 06F0 brts main_error ; error, Flash not equal 28 00e8 00C0 rjmp main_ok 29 ;------------------------------------------------------------------------- 30 ... 72 #endif 73 ;------------------------------------------------------------------------- 74 #ifdef FirstBootStart 75 #include "progmega.inc" // mega with bootstart fuse set 1 ;------------------------------------------------------------------------- 2 ; Program User Flash 3 ;------------------------------------------------------------------------- 4 _pro1: 5 00ea 69EA ldi a0, CONTINUE 6 00ec 00D0 rcall putchar 7 program: 8 00ee 6894 set 9 00f0 A0E0 ldi xl, lo8(ProgBuff) 10 00f2 B0E0 ldi xh, hi8(ProgBuff) 11 00f4 D0E0 ldi yh, hi8(ProgBuffEnd) 12 ;------------------------------ Receive data into buffer ----------------- 13 _pro2: 14 00f6 00D0 rcall getchar 15 00f8 01F4 brne _pro3 16 00fa 00D0 rcall getchar 17 00fc 6058 subi a0, ESC_SHIFT 18 00fe 01F4 brne _pro3 ; A5,80 = end mark 19 0100 06F0 brts _pro6 20 0102 6894 set 21 0104 00C0 rjmp _pro4 22 _pro3: 23 0106 E894 clt 24 0108 6D93 st x+, a0 25 010a A030 cpi xl, lo8(ProgBuffEnd) 26 010c BD07 cpc xh, yh 27 010e 01F4 brne _pro2 28 ;------------------------------------------------------------------------- 29 _pro4: 30 0110 A0E0 ldi xl, lo8(ProgBuff) 31 0112 B0E0 ldi xh, hi8(ProgBuff) 32 _pro5: 33 0114 00D0 rcall prog_page ; CY = 1: o.k 34 0116 00F4 brcc main_error ; error, bootloader reached 35 0118 E05C subi zl, lo8(-2*PageSize) 36 011a FF4F sbci zh, hi8(-2*PageSize) ; point to next page 37 #if FLASHEND > 0x7FFF 38 sbci zx, hh8(-/* 2* */BufferSize) 39 #endif 40 011c A030 cpi xl, lo8(ProgBuffEnd) 41 011e BD07 cpc xh, yh 42 0120 01F4 brne _pro5 ; until buffer end 43 0122 06F4 brtc _pro1 44 ;------------------------------------------------------------------------- 45 _pro6: 46 0124 00C0 rjmp main_ok 47 ;------------------------------------------------------------------------- 48 ; Program page in Flash 49 ;------------------------------------------------------------------------- 50 ;use: r0, r1, a0, xl, xh, zl, zh 51 ; 52 ;input: X = buffer to RAM 53 ; Z = page to program 54 ;output: CY = 0: error, attempt to overwrite itself 55 ; 56 #define PAGEMASK (PageSize *2 - 1) & ~1 57 58 prog_page: 59 ;------------------------------ Avoid self destruction ! ----------------- 60 0126 E030 cpi zl, (2*BOOTSTART)&0xff 61 0128 6EE1 ldi a0, (BOOTSTART&0x7fff)>>7 62 012a F607 cpc zh, a0 ; below bootloader ? 63 #if FLASHEND > 0x7FFF 64 ldi a0, hh8(2*BootStart) 65 cpc zx, a0 66 #endif 67 012c 00F4 brcc _prp3 ; CY = 0: error 68 ;------------------------------ Fill page buffer ------------------------- 69 012e 0D90 _prp1: ld r0, x+ 70 0130 1D90 ld r1, x+ 71 0132 61E0 ldi a0, 1< 0x7FFF 89 out RAMPZ, zx ; 3 byte Z pointer 90 xout SPMCSR, a0 91 #endif 92 014e E895 spm 93 _prp2: 94 0150 67B7 xin a0, SPMCSR 95 0152 60FD sbrc a0, SPMEN 96 0154 00C0 rjmp _prp2 97 0156 0894 sec ; CY = 1: successful 98 _prp3: 99 0158 0895 ret 100 ;------------------------------------------------------------------------- 101 ... 76 #else 77 #include "progtiny.inc" // tiny, mega without RWW section 78 #endif 79 ;------------------------------------------------------------------------- 80 ... 62 #include "uart.inc" // UART subroutines 1 ;------------------------------------------------------------------------- 2 ; Receive Byte 3 ;------------------------------------------------------------------------- 4 ;output: a0 = byte 5 ;used: a1 6 ; 7 getchar: 8 #if WDTRIGGER 9 015a A895 wdr 10 #endif 11 015c 489B SKIP_RXD_1 ; wait for RXD = 1 12 015e 00C0 rjmp getchar 13 _rx1: 14 0160 4899 SKIP_RXD_0 ; wait for RXD = 0 (start bit) 15 0162 00C0 rjmp _rx1 16 0164 78E0 ldi a1, 8 17 0166 C201 movw twl, baudl 18 0168 9695 lsr twh 19 016a 8795 ror twl 20 016c 00D0 rcall wait_time ; middle of start bit 21 _rx2: 22 016e 00D0 rcall wait_bit_time ;14 + tw 23 0170 6695 lsr a0 ;1 24 0172 4899 SKIP_RXD_0 ;1/2 25 0174 6068 ori a0, 0x80 ;1 26 #if CRC 27 ;------------------------------ CRC -------------------------------------- 28 0176 67FD sbrc a0, 7 ;1 29 0178 6226 eor crcl, polynoml ;1 crcl.0 ^= a0.7 30 017a 7694 lsr crch ;1 31 017c 6794 ror crcl ;1 32 017e 00F4 brcc _rx5 ;1 33 0180 6226 eor crcl, polynoml ;1 ^0x01 34 _rx5: 35 0182 00F4 brcc _rx6 ;1 36 0184 7326 eor crch, polynomh ;1 ^0xA0 37 _rx6: 38 ;------------------------------------------------------------------------- 39 #else 40 rjmp . ;2 41 rjmp . ;2 42 #endif 43 0186 7A95 dec a1 ;1 44 0188 01F4 brne _rx2 ;2 = 24 + tw 45 018a 653A cpi a0, COMMAND ; needed several times 46 018c 0895 ret 47 ;------------------------------------------------------------------------- 48 ; transmit byte 49 ;------------------------------------------------------------------------- 50 ;input: a0 = byte 51 ;used: a1 52 ; 53 putchar: 54 018e 00D0 rcall wait_bit_time 55 0190 5998 TXD_0 56 #if ONEWIRE 57 rjmp _tx2 58 syncputchar: ; start with 1->0 from master 59 SKIP_RXD_1 60 rjmp syncputchar 61 _tx1: 62 SKIP_RXD_0 63 rjmp _tx1 64 _tx2: 65 #else 66 0192 7491 lpm a1, z ;3 67 #endif 68 0194 79E0 ldi a1, 9 ;1 69 0196 6095 com a0 ;1 = 5 70 _tx3: 71 #if CRC 72 0198 00C0 rjmp . ;2 73 019a 00C0 rjmp . ;2 74 #endif 75 019c 00D0 rcall wait_bit_time ;14 + tw 76 019e 6695 lsr a0 ;1 77 01a0 00F4 brcc _tx4 ;1/2 78 01a2 0000 nop ;1 79 01a4 5998 TXD_0 ;2 80 01a6 00C0 rjmp _tx5 ;2 81 _tx4: 82 01a8 599A TXD_1 ;2 83 01aa 00C0 rjmp _tx5 ;2 84 _tx5: 85 01ac 7A95 dec a1 ;1 86 01ae 01F4 brne _tx3 ;2 = 24 + tw 87 01b0 0895 ret 88 ;------------------------------------------------------------------------- 89 ; Wait 14 cycle + tw 90 ; 91 wait_bit_time: 92 01b2 C201 movw twl, baudl ;1 93 wait_time: 94 01b4 0497 sbiw twl, 4 ;2 95 01b6 00F4 brcc wait_time ;2/1 96 01b8 8D3F cpi twl, 0xFD ;1 97 01ba 00F0 brcs _wt1 ;2/1 (2) 98 01bc 01F0 breq _wt1 ;2/1 (3) 99 01be 8F3F cpi twl, 0xFF ;1 100 01c0 01F0 breq _wt1 ;2/1 (4/5) 101 _wt1: 102 01c2 0895 ret ;4 + 3 (rcall) = 14 103 ;------------------------------------------------------------------------- 104 ... 63 ;------------------------------------------------------------------------- 64 Password: 65 01c4 5065 6461 .ascii "Peda", "\0", "\0" ; 'a' was recognized by ABAUD 65 0000 66 67 .list 68 Messages: 69 01ca 03 .byte 3 70 01cb 02 .byte VERSION>>8 71 01cc 01 .byte VERSION&0xff 72 01cd 03 .byte 3 73 01ce 03 .byte ((2*BufferSize)>>8) 74 01cf C0 .byte ((2*BufferSize) & 0xff) 75 01d0 04 .byte 4 76 01d1 1E .byte SIGNATURE_000 77 01d2 93 .byte SIGNATURE_001 78 01d3 0A .byte SIGNATURE_002 79 01d4 04 .byte 4 80 01d5 00 .byte UserFlash>>16 81 01d6 1E .byte (UserFlash>>8) & 0xff 82 01d7 00 .byte UserFlash & 0xff 83 .align 1 84 ;------------------------------------------------------------------------- 85 #if APICALL 86 #include "apicall.inc" // program Flash from application 1 ;------------------------------------------------------------------------ 2 ; API-Call to program Flash from application 3 ;------------------------------------------------------------------------ 4 ; 5 ;input: R22 = command a0 = r22 6 ; X = source 7 ; R21, Z = destination zx = r21 8 ;output: R22 = return code 9 ;use: R0, R1, R21, R22, R23, X, Z 10 ; 11 api_call: 12 01d8 7FB7 in a1, SREG 13 01da F894 cli 14 01dc 6138 cpi a0, API_PROG_PAGE 15 01de 60EF ldi a0, API_ERR_FUNC 16 01e0 01F4 brne _apc1 17 01e2 00D0 rcall prog_page 18 01e4 60E8 ldi a0, API_SUCCESS 19 01e6 00F0 brcs _apc1 ; CY = 1: o.k. 20 01e8 61EF ldi a0, API_ERR_RANGE 21 _apc1: 22 01ea 7FBF out SREG, a1 23 01ec 0895 ret 24 ;------------------------------------------------------------------------- 25 /* .org Flashend */ ; removed by _conv.awk 26 /* rjmp api_call */ ; removed by _conv.awk 27 ;------------------------------------------------------------------------- 28 87 #endif 88 ;------------------------------------------------------------------------- 89 ... 58 ;------------------------------------------------------------------------- 59 ... 48 49 50 .global api_call DEFINED SYMBOLS ./added/fastload.h:89 *ABS*:000001e0 BufferSize ./added/fastload.h:156 .bss:00000000 PROGBUFF ./added/fastload.h:157 .bss:000003c0 PROGBUFFEND ./added/fastload.h:158 .bss:000003c0 ProgBuffEnd ./added/fastload.inc:24 .text:00000000 init ./converted/abaud.inc:15 .text:0000002c abaud ./converted/abaud.inc:17 .text:0000002e _aba1 ./converted/abaud.inc:19 .text:00000030 _aba2 ./converted/abaud.inc:22 .text:00000034 _aba3 ./converted/command.inc:56 .text:000000b4 timeout ./converted/abaud.inc:28 .text:0000003e _aba4 ./converted/abaud.inc:36 .text:0000004a _aba5 ./converted/password.inc:9 .text:00000066 checkpwd ./added/fastload.inc:64 .text:000001c4 Password ./converted/password.inc:12 .text:0000006a _cpw2 ./converted/password.inc:22 .text:0000007c _cpw3 ./converted/uart.inc:7 .text:0000015a getchar ./added/fastload.inc:51 .text:0000007c connected ./converted/uart.inc:53 .text:0000018e putchar ./converted/command.inc:13 .text:00000084 main_ok ./converted/command.inc:15 .text:00000086 _cex1 ./converted/command.inc:17 .text:00000088 _cex2 ./converted/command.inc:20 .text:0000008c _cex3 ./converted/message.inc:6 .text:000000ba SendMessage ./converted/progmega.inc:7 .text:000000ee Program ./converted/verify.inc:21 .text:000000dc VerifyFlash ./converted/command.inc:42 .text:000000a6 CheckCRC ./converted/command.inc:52 .text:000000b0 main_error ./added/fastload.inc:68 .text:000001ca Messages ./converted/message.inc:14 .text:000000c0 _sme1 ./converted/message.inc:21 .text:000000cc _sme2 ./converted/verify.inc:5 .text:000000d6 _ver1 ./converted/progmega.inc:4 .text:000000ea _pro1 ./converted/progmega.inc:13 .text:000000f6 _pro2 ./converted/progmega.inc:22 .text:00000106 _pro3 ./converted/progmega.inc:45 .text:00000124 _pro6 ./converted/progmega.inc:29 .text:00000110 _pro4 ./converted/progmega.inc:32 .text:00000114 _pro5 ./converted/progmega.inc:58 .text:00000126 prog_page ./converted/progmega.inc:98 .text:00000158 _prp3 ./converted/progmega.inc:69 .text:0000012e _prp1 ./converted/progmega.inc:86 .text:0000014c do_spm ./converted/progmega.inc:93 .text:00000150 _prp2 ./converted/uart.inc:13 .text:00000160 _rx1 ./converted/uart.inc:93 .text:000001b4 wait_time ./converted/uart.inc:21 .text:0000016e _rx2 ./converted/uart.inc:91 .text:000001b2 wait_bit_time ./converted/uart.inc:34 .text:00000182 _rx5 ./converted/uart.inc:37 .text:00000186 _rx6 ./converted/uart.inc:70 .text:00000198 _tx3 ./converted/uart.inc:81 .text:000001a8 _tx4 ./converted/uart.inc:84 .text:000001ac _tx5 ./converted/uart.inc:101 .text:000001c2 _wt1 ./converted/apicall.inc:11 .text:000001d8 api_call ./converted/apicall.inc:21 .text:000001ea _apc1 UNDEFINED SYMBOLS Application