Revision 200
| trunk/bootloader/bootloader.c (revision 200) | ||
|---|---|---|
| 58 | 58 |
uint8_t i; |
| 59 | 59 |
uint8_t retries; |
| 60 | 60 |
uint8_t addr; |
| 61 |
uint8_t boot; |
|
| 61 | 62 |
|
| 62 | 63 |
retry_jpnt: |
| 63 | 64 |
iteration = 0; |
| 64 | 65 |
retries = 0; |
| 66 |
boot = 0; |
|
| 65 | 67 |
addr = eeprom_read_byte(EEPROM_ADDR); |
| 68 |
//set LED pins as output |
|
| 69 |
LED_DDR = 0x07; |
|
| 70 |
PORTB = 0x00; |
|
| 71 |
|
|
| 66 | 72 |
|
| 67 | 73 |
// Clear the watchdog timer |
| 68 |
MCUSR &= ~_BV(WDRF); |
|
| 69 |
wdt_disable(); |
|
| 70 |
WDTCSR = 0; |
|
| 74 |
if (MCUSR & _BV(WDRF)) {
|
|
| 75 |
MCUSR &= ~_BV(WDRF); |
|
| 76 |
wdt_disable(); |
|
| 77 |
WDTCSR = 0; |
|
| 78 |
boot = 1; |
|
| 79 |
} |
|
| 71 | 80 |
|
| 81 |
if (!(PINB & (_BV(PINB3) | _BV(PINB4)))) {
|
|
| 82 |
PORTB |= 0x01; |
|
| 83 |
boot = 1; |
|
| 84 |
} |
|
| 85 |
|
|
| 72 | 86 |
rs485_init(BAUD9600); |
| 73 | 87 |
|
| 74 |
//set LED pin as output |
|
| 75 |
LED_DDR |= 0x07; |
|
| 76 |
PORTB = 0x07; |
|
| 88 |
//Start bootloading process |
|
| 89 |
if (boot == 0) {
|
|
| 90 |
PORTB |= 0x07; |
|
| 91 |
main_start(); |
|
| 92 |
} |
|
| 77 | 93 |
|
| 78 |
//Start bootloading process |
|
| 79 | 94 |
send_packet(TT_BOOT, addr); |
| 80 |
|
|
| 81 | 95 |
resp = parse_packet(mbuf, addr); |
| 82 | 96 |
|
| 83 | 97 |
// Enter programming mode |
| ... | ... | |
| 94 | 108 |
|
| 95 | 109 |
// Run user code |
| 96 | 110 |
} else {
|
| 111 |
PORTB = 0x07; |
|
| 97 | 112 |
main_start(); |
| 98 | 113 |
} |
| 99 | 114 |
|
| ... | ... | |
| 151 | 166 |
mbuf[PROGD_PACKET_SIZE-1] = jbuf.bytes[1]; |
| 152 | 167 |
|
| 153 | 168 |
onboard_program_write(BOOT_START - SPM_PAGESIZE, mbuf); |
| 154 |
|
|
| 169 |
|
|
| 170 |
PORTB = 0x07; |
|
| 155 | 171 |
main_start(); |
| 156 | 172 |
} else {
|
| 157 | 173 |
prog_len -= PROGD_PACKET_SIZE; |
Also available in: Unified diff