startup_samd21.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) 2016, Alex Taradov <alex@taradov.com>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  20. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. * POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. //-----------------------------------------------------------------------------
  29. #define DUMMY __attribute__ ((weak, alias ("irq_handler_dummy")))
  30. //-----------------------------------------------------------------------------
  31. void irq_handler_reset(void);
  32. DUMMY void irq_handler_nmi(void);
  33. DUMMY void irq_handler_hard_fault(void);
  34. DUMMY void irq_handler_sv_call(void);
  35. DUMMY void irq_handler_pend_sv(void);
  36. DUMMY void irq_handler_sys_tick(void);
  37. DUMMY void irq_handler_pm(void);
  38. DUMMY void irq_handler_sysctrl(void);
  39. DUMMY void irq_handler_wdt(void);
  40. DUMMY void irq_handler_rtc(void);
  41. DUMMY void irq_handler_eic(void);
  42. DUMMY void irq_handler_nvmctrl(void);
  43. DUMMY void irq_handler_dmac(void);
  44. DUMMY void irq_handler_usb(void);
  45. DUMMY void irq_handler_evsys(void);
  46. DUMMY void irq_handler_sercom0(void);
  47. DUMMY void irq_handler_sercom1(void);
  48. DUMMY void irq_handler_sercom2(void);
  49. DUMMY void irq_handler_sercom3(void);
  50. DUMMY void irq_handler_sercom4(void);
  51. DUMMY void irq_handler_sercom5(void);
  52. DUMMY void irq_handler_tcc0(void);
  53. DUMMY void irq_handler_tcc1(void);
  54. DUMMY void irq_handler_tcc2(void);
  55. DUMMY void irq_handler_tc3(void);
  56. DUMMY void irq_handler_tc4(void);
  57. DUMMY void irq_handler_tc5(void);
  58. DUMMY void irq_handler_tc6(void);
  59. DUMMY void irq_handler_tc7(void);
  60. DUMMY void irq_handler_adc(void);
  61. DUMMY void irq_handler_ac(void);
  62. DUMMY void irq_handler_dac(void);
  63. DUMMY void irq_handler_ptc(void);
  64. DUMMY void irq_handler_i2s(void);
  65. extern int main(void);
  66. extern void _stack_top(void);
  67. extern unsigned int _etext;
  68. extern unsigned int _data;
  69. extern unsigned int _edata;
  70. extern unsigned int _bss;
  71. extern unsigned int _ebss;
  72. //-----------------------------------------------------------------------------
  73. __attribute__ ((used, section(".vectors")))
  74. void (* const vectors[])(void) =
  75. {
  76. &_stack_top, // 0 - Initial Stack Pointer Value
  77. // Cortex-M0+ handlers
  78. irq_handler_reset, // 1 - Reset
  79. irq_handler_nmi, // 2 - NMI
  80. irq_handler_hard_fault, // 3 - Hard Fault
  81. 0, // 4 - Reserved
  82. 0, // 5 - Reserved
  83. 0, // 6 - Reserved
  84. 0, // 7 - Reserved
  85. 0, // 8 - Reserved
  86. 0, // 9 - Reserved
  87. 0, // 10 - Reserved
  88. irq_handler_sv_call, // 11 - SVCall
  89. 0, // 12 - Reserved
  90. 0, // 13 - Reserved
  91. irq_handler_pend_sv, // 14 - PendSV
  92. irq_handler_sys_tick, // 15 - SysTick
  93. // Peripheral handlers
  94. irq_handler_pm, // 0 - Power Manager
  95. irq_handler_sysctrl, // 1 - System Controller
  96. irq_handler_wdt, // 2 - Watchdog Timer
  97. irq_handler_rtc, // 3 - Real Time Counter
  98. irq_handler_eic, // 4 - External Interrupt Controller
  99. irq_handler_nvmctrl, // 5 - Non-Volatile Memory Controller
  100. irq_handler_dmac, // 6 - Direct Memory Access Controller
  101. irq_handler_usb, // 7 - Universal Serial Bus Controller
  102. irq_handler_evsys, // 8 - Event System
  103. irq_handler_sercom0, // 9 - Serial Communication Interface 0
  104. irq_handler_sercom1, // 10 - Serial Communication Interface 1
  105. irq_handler_sercom2, // 11 - Serial Communication Interface 2
  106. irq_handler_sercom3, // 12 - Serial Communication Interface 3
  107. irq_handler_sercom4, // 13 - Serial Communication Interface 4
  108. irq_handler_sercom5, // 14 - Serial Communication Interface 5
  109. irq_handler_tcc0, // 15 - Timer/Counter for Control 0
  110. irq_handler_tcc1, // 16 - Timer/Counter for Control 1
  111. irq_handler_tcc2, // 17 - Timer/Counter for Control 2
  112. irq_handler_tc3, // 18 - Timer/Counter 3
  113. irq_handler_tc4, // 19 - Timer/Counter 4
  114. irq_handler_tc5, // 20 - Timer/Counter 5
  115. irq_handler_tc6, // 21 - Timer/Counter 6
  116. irq_handler_tc7, // 22 - Timer/Counter 7
  117. irq_handler_adc, // 23 - Analog-to-Digital Converter
  118. irq_handler_ac, // 24 - Analog Comparator
  119. irq_handler_dac, // 25 - Digital-to-Analog Converter
  120. irq_handler_ptc, // 26 - Peripheral Touch Controller
  121. irq_handler_i2s, // 27 - Inter-IC Sound Interface
  122. };
  123. //-----------------------------------------------------------------------------
  124. void irq_handler_reset(void)
  125. {
  126. unsigned int *src, *dst;
  127. src = &_etext;
  128. dst = &_data;
  129. while (dst < &_edata)
  130. *dst++ = *src++;
  131. dst = &_bss;
  132. while (dst < &_ebss)
  133. *dst++ = 0;
  134. main();
  135. while (1);
  136. }
  137. //-----------------------------------------------------------------------------
  138. void irq_handler_dummy(void)
  139. {
  140. while (1);
  141. }
  142. //-----------------------------------------------------------------------------
  143. void _exit(int status)
  144. {
  145. (void)status;
  146. while (1);
  147. }