You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.6 KiB

#include "config.h"
#include "System.h"
#include "boot.h"
#include "USART1.h"
#include "RSLink.h"
#include <avr/fuse.h>
#include <stdint.h>
#include "idibus_hw.h"
FUSES= { .extended=F_Ext, .high = F_High, .low = F_Low }; // Fuses + Lock programming
LOCKBITS=F_Lock;
int main(void)
{
cli();
// Not enough memory on 328pb
#ifdef _LONG_ADDR_SPACE_
//FUSE CHECK
asm volatile (
"ldi R31, 0x00 \n\t"
"ldi R30, 0x01 \n\t"
"ldi R16, 0x09 \n\t"
"out 0x37, R16 \n\t"
"lpm R17, Z \n\t"
"cpi R17, %0 \n\t"
"brne L_LOOP_%= \n\t"
// Fuse Extended
"ldi R30, 0x02 \n\t"
"out 0x37, R16 \n\t"
"lpm R17, Z \n\t"
"cpi R17, %1 \n\t"
"brne L_LOOP_%= \n\t"
// Fuse Low Byte
"ldi R30, 0x00 \n\t"
"out 0x37, R16 \n\t"
"lpm R17, Z \n\t"
"cpi R17, %2 \n\t"
"brne L_LOOP_%= \n\t"
// Fuse Hi Byte
"ldi R30, 0x03 \n\t"
"out 0x37, R16 \n\t"
"lpm R17, Z \n\t"
"cpi R17, %3 \n\t"
"breq L_EXIT_%= \n\t"
"L_LOOP_%=: \n\t"
"rjmp L_LOOP_%= \n\t"
"L_EXIT_%=: \n\t"
: //No output
: "M" (F_Lock),
"M" (F_Ext),
"M" (F_Low),
"M" (F_High)
);
#endif
wdt_enable(WDTO_2S);
wdt_reset();
//Move interrupt table
uint8_t temp = MCUCR;
MCUCR=temp|(1<<IVCE);
MCUCR=temp|(1<<IVSEL);
RSLink_StatusLedInit();
RSLink_StatusLedSetOn();
RSLink_DipsInit();
uint8_t Reason = FindBootloaderEnterReason(); //Do checks
wdt_reset();
//RSLink_StatusLedSetOff();
if (Reason == IDIFMW_REASON_NoReason) LaunchApplication();
USART1_Init();
RSLink_Init();
sei();
while (1)
{
RSLink_Handler();
wdt_reset();
}
}