irq.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * =====================================================================================
  3. *
  4. * ________ .__ __ ________ ____ ________
  5. * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
  6. * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
  7. * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
  8. * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
  9. * \__> \/ \/ \/ \/ \/
  10. *
  11. * www.optixx.org
  12. *
  13. *
  14. * Version: 1.0
  15. * Created: 07/21/2009 03:32:16 PM
  16. * Author: david@optixx.org
  17. *
  18. * =====================================================================================
  19. */
  20. #include <stdint.h>
  21. #include <stdio.h>
  22. #include <avr/io.h>
  23. #include <avr/interrupt.h> /* for sei() */
  24. #include <avr/wdt.h>
  25. #include "usbdrv.h"
  26. #include "oddebug.h" /* This is also an example for using debug macros */
  27. #include "debug.h"
  28. #include "info.h"
  29. #include "sram.h"
  30. #include "system.h"
  31. extern system_t system;
  32. void (*jump_to_app) (void) = 0x0000;
  33. void irq_init()
  34. {
  35. cli();
  36. PCMSK3 |= (1 << PCINT27);
  37. PCICR |= (1 << PCIE3);
  38. sei();
  39. system.reset_irq = RESET_IRQ_ON;
  40. }
  41. void irq_stop()
  42. {
  43. cli();
  44. PCMSK3 &= ~(1 << PCINT27);
  45. sei();
  46. system.reset_irq = RESET_IRQ_OFF;
  47. }
  48. void leave_application(void)
  49. {
  50. cli();
  51. usbDeviceDisconnect();
  52. system.avr_reset_count++;
  53. wdt_enable(WDTO_15MS);
  54. while (1);
  55. }
  56. ISR(SIG_PIN_CHANGE3)
  57. {
  58. if (snes_reset_test()) {
  59. info_P(PSTR("Catch SNES reset button\n"));
  60. info_P(PSTR("Set watchdog...\n"));
  61. leave_application();
  62. }
  63. }