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.

58 lines
1.5 KiB

  1. /* gc_n64_usb : Gamecube or N64 controller to USB adapter firmware
  2. Copyright (C) 2007-2021 Raphael Assenat <raph@raphnet.net>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <avr/io.h>
  15. #include <avr/interrupt.h>
  16. #include <avr/wdt.h>
  17. #include <util/delay.h>
  18. #include "usb.h"
  19. void enterBootLoader(void)
  20. {
  21. cli();
  22. usb_shutdown();
  23. _delay_ms(10);
  24. #if defined(__AVR_ATmega32U2__)
  25. // ATmega32u2 : 0x3800
  26. asm volatile(
  27. "cli \n"
  28. "ldi r30, 0x00 \n" // ZL
  29. "ldi r31, 0x38 \n" // ZH
  30. "ijmp");
  31. #elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
  32. // AT90USB1287/1286 : 0xF000 (word address)
  33. asm volatile(
  34. "cli \n"
  35. "ldi r30, 0x00 \n" // ZL
  36. "ldi r31, 0xF0 \n" // ZH
  37. "ijmp");
  38. #else
  39. #error Bootloader address unknown for this CPU
  40. #endif
  41. }
  42. void resetFirmware(void)
  43. {
  44. usb_shutdown();
  45. // jump to the application reset vector
  46. asm volatile(
  47. "cli \n"
  48. "ldi r30, 0x00 \n" // ZL
  49. "ldi r31, 0x00 \n" // ZH
  50. "ijmp");
  51. }