bootapp.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //bootapp.c
  2. #include "bootapp.h"
  3. #include <avr/pgmspace.h>
  4. #include <avr/wdt.h>
  5. #include <avr/interrupt.h>
  6. /*
  7. void bootapp_print_vars()
  8. {
  9. printf_P(_n("boot_src_addr =0x%08lx\n"), boot_src_addr);
  10. printf_P(_n("boot_dst_addr =0x%08lx\n"), boot_dst_addr);
  11. printf_P(_n("boot_copy_size =0x%04x\n"), boot_copy_size);
  12. printf_P(_n("boot_reserved =0x%02x\n"), boot_reserved);
  13. printf_P(_n("boot_app_flags =0x%02x\n"), boot_app_flags);
  14. printf_P(_n("boot_app_magic =0x%08lx\n"), boot_app_magic);
  15. }
  16. */
  17. void bootapp_ram2flash(uint16_t rptr, uint16_t fptr, uint16_t size)
  18. {
  19. cli();
  20. boot_app_magic = BOOT_APP_MAGIC;
  21. boot_app_flags |= BOOT_APP_FLG_COPY;
  22. boot_app_flags |= BOOT_APP_FLG_ERASE;
  23. /* uint16_t ui; for (ui = 0; ui < size; ui++)
  24. {
  25. uint8_t uc = ram_array[ui+rptr];
  26. if (pgm_read_byte(ui+fptr) & uc != uc)
  27. {
  28. boot_app_flags |= BOOT_APP_FLG_ERASE;
  29. break;
  30. }
  31. }*/
  32. boot_copy_size = (uint16_t)size;
  33. boot_src_addr = (uint32_t)rptr;
  34. boot_dst_addr = (uint32_t)fptr;
  35. wdt_enable(WDTO_15MS);
  36. while(1);
  37. }
  38. void bootapp_reboot_user0(uint8_t reserved)
  39. {
  40. cli();
  41. boot_app_magic = BOOT_APP_MAGIC;
  42. boot_app_flags = BOOT_APP_FLG_USER0;
  43. boot_reserved = reserved;
  44. wdt_enable(WDTO_15MS);
  45. while(1);
  46. }