bootapp.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. /* uint16_t ui; for (ui = 0; ui < size; ui++)
  26. {
  27. uint8_t uc = ram_array[ui+rptr];
  28. if (pgm_read_byte(ui+fptr) & uc != uc)
  29. {
  30. boot_app_flags |= BOOT_APP_FLG_ERASE;
  31. break;
  32. }
  33. }*/
  34. boot_copy_size = (uint16_t)size;
  35. boot_src_addr = (uint32_t)rptr;
  36. boot_dst_addr = (uint32_t)fptr;
  37. bootapp_print_vars();
  38. softReset();
  39. }
  40. void bootapp_reboot_user0(uint8_t reserved)
  41. {
  42. cli();
  43. boot_app_magic = BOOT_APP_MAGIC;
  44. boot_app_flags = BOOT_APP_FLG_USER0;
  45. boot_reserved = reserved;
  46. bootapp_print_vars();
  47. softReset();
  48. }