bootapp.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //bootapp.c
  2. #include "bootapp.h"
  3. #include <avr/pgmspace.h>
  4. #include <avr/wdt.h>
  5. #include <avr/interrupt.h>
  6. #include <stdio.h>
  7. extern FILE _uartout;
  8. #define uartout (&_uartout)
  9. extern void softReset();
  10. void bootapp_print_vars(void)
  11. {
  12. fprintf_P(uartout, PSTR("boot_src_addr =0x%08lx\n"), boot_src_addr);
  13. fprintf_P(uartout, PSTR("boot_dst_addr =0x%08lx\n"), boot_dst_addr);
  14. fprintf_P(uartout, PSTR("boot_copy_size =0x%04x\n"), boot_copy_size);
  15. fprintf_P(uartout, PSTR("boot_reserved =0x%02x\n"), boot_reserved);
  16. fprintf_P(uartout, PSTR("boot_app_flags =0x%02x\n"), boot_app_flags);
  17. fprintf_P(uartout, PSTR("boot_app_magic =0x%08lx\n"), boot_app_magic);
  18. }
  19. void bootapp_ram2flash(uint16_t rptr, uint16_t fptr, uint16_t size)
  20. {
  21. cli();
  22. boot_app_magic = BOOT_APP_MAGIC;
  23. boot_app_flags |= BOOT_APP_FLG_COPY;
  24. boot_app_flags |= BOOT_APP_FLG_ERASE;
  25. boot_copy_size = (uint16_t)size;
  26. boot_src_addr = (uint32_t)rptr;
  27. boot_dst_addr = (uint32_t)fptr;
  28. bootapp_print_vars();
  29. softReset();
  30. }
  31. void bootapp_reboot_user0(uint8_t reserved)
  32. {
  33. cli();
  34. boot_app_magic = BOOT_APP_MAGIC;
  35. boot_app_flags = BOOT_APP_FLG_USER0;
  36. boot_reserved = reserved;
  37. bootapp_print_vars();
  38. softReset();
  39. }