bootapp.c 1.4 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. void bootapp_print_vars(void)
  10. {
  11. fprintf_P(uartout, PSTR("boot_src_addr =0x%08lx\n"), boot_src_addr);
  12. fprintf_P(uartout, PSTR("boot_dst_addr =0x%08lx\n"), boot_dst_addr);
  13. fprintf_P(uartout, PSTR("boot_copy_size =0x%04x\n"), boot_copy_size);
  14. fprintf_P(uartout, PSTR("boot_reserved =0x%02x\n"), boot_reserved);
  15. fprintf_P(uartout, PSTR("boot_app_flags =0x%02x\n"), boot_app_flags);
  16. fprintf_P(uartout, PSTR("boot_app_magic =0x%08lx\n"), boot_app_magic);
  17. }
  18. void bootapp_ram2flash(uint16_t rptr, uint16_t fptr, uint16_t size)
  19. {
  20. cli();
  21. boot_app_magic = BOOT_APP_MAGIC;
  22. boot_app_flags |= BOOT_APP_FLG_COPY;
  23. boot_app_flags |= BOOT_APP_FLG_ERASE;
  24. /* uint16_t ui; for (ui = 0; ui < size; ui++)
  25. {
  26. uint8_t uc = ram_array[ui+rptr];
  27. if (pgm_read_byte(ui+fptr) & uc != uc)
  28. {
  29. boot_app_flags |= BOOT_APP_FLG_ERASE;
  30. break;
  31. }
  32. }*/
  33. boot_copy_size = (uint16_t)size;
  34. boot_src_addr = (uint32_t)rptr;
  35. boot_dst_addr = (uint32_t)fptr;
  36. bootapp_print_vars();
  37. wdt_enable(WDTO_15MS);
  38. while(1);
  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. wdt_enable(WDTO_15MS);
  48. while(1);
  49. }