|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: MIT |
| 3 | + * SPDX-FileCopyrightText: 2021 Rafael Silva <perigoso@riseup.net> |
| 4 | + */ |
| 5 | + |
| 6 | +#include <sam.h> |
| 7 | + |
| 8 | +#include "util/types.h" |
| 9 | + |
| 10 | +/* Stack pointer */ |
| 11 | +extern void _estack(); /* Not a function, just to be compatible with the vector table array */ |
| 12 | + |
| 13 | +/* Variables */ |
| 14 | +extern u32 _svect; /* ISR Vectors */ |
| 15 | +extern u32 _evect; |
| 16 | + |
| 17 | +extern u32 _stext; /* Main program */ |
| 18 | +extern u32 _etext; |
| 19 | + |
| 20 | +extern u32 _sidata; /* Data source */ |
| 21 | +extern u32 _sdata; /* Data destination */ |
| 22 | +extern u32 _edata; |
| 23 | + |
| 24 | +extern u32 _sbss; /* BSS destination */ |
| 25 | +extern u32 _ebss; |
| 26 | + |
| 27 | +extern u32 _end; |
| 28 | + |
| 29 | +/* Functions */ |
| 30 | +void _default_isr() |
| 31 | +{ |
| 32 | + while (1) continue; |
| 33 | +} |
| 34 | + |
| 35 | +void __attribute__((weak)) __libc_init_array() |
| 36 | +{ |
| 37 | +} |
| 38 | + |
| 39 | +extern void __attribute__((noreturn)) main(); |
| 40 | + |
| 41 | +#define DEFAULT_ISR "_default_isr" |
| 42 | + |
| 43 | +void _reset_isr() |
| 44 | +{ |
| 45 | + u32 *src, *dst; |
| 46 | + |
| 47 | + src = &_sidata; |
| 48 | + dst = &_sdata; |
| 49 | + |
| 50 | + while (dst < &_edata) /* Copy data */ |
| 51 | + *(dst++) = *(src++); |
| 52 | + |
| 53 | + src = 0; |
| 54 | + dst = &_sbss; |
| 55 | + |
| 56 | + while (dst < &_ebss) /* Zero BSS */ |
| 57 | + *(dst++) = 0; |
| 58 | + |
| 59 | + __libc_init_array(); |
| 60 | + |
| 61 | + SCB->VTOR = (u32) &_svect; /* ISR Vectors offset */ |
| 62 | + SCB->AIRCR = 0x05FA0000 | (4 << 8); /* Interrupt priority - 3 bits Group, 1 bit Sub-group */ |
| 63 | + SCB->SHCSR = SCB_SHCSR_USGFAULTENA_Msk | SCB_SHCSR_BUSFAULTENA_Msk | |
| 64 | + SCB_SHCSR_MEMFAULTENA_Msk; /* Enable separate fault handlers */ |
| 65 | + |
| 66 | + main(); |
| 67 | + |
| 68 | + __disable_irq(); |
| 69 | + while (1) continue; |
| 70 | +} |
| 71 | + |
| 72 | +/* Cortex-M Exception Handlers */ |
| 73 | +void _nmi_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 74 | +void _hardfault_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 75 | +void _memmanage_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 76 | +void _busfault_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 77 | +void _usagefault_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 78 | +void _svc_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 79 | +void _debugmon_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 80 | +void _pendsv_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 81 | +void _systick_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 82 | +/* External interrupts */ |
| 83 | +void _supc_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 84 | +void _rstc_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 85 | +void _rtc_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 86 | +void _rtt_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 87 | +void _wdt_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 88 | +void _pmc_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 89 | +void _efc0_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 90 | +#ifdef _SAM3U_EFC1_INSTANCE_ |
| 91 | +void _efc1_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 92 | +#endif /* _SAM3U_EFC1_INSTANCE_ */ |
| 93 | +void _uart_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 94 | +void _pioa_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 95 | +void _piob_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 96 | +#ifdef _SAM3U_PIOC_INSTANCE_ |
| 97 | +void _pioc_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 98 | +#endif /* _SAM3U_PIOC_INSTANCE_ */ |
| 99 | +void _usart0_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 100 | +void _usart1_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 101 | +void _usart2_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 102 | +#ifdef _SAM3U_USART3_INSTANCE_ |
| 103 | +void _usart3_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 104 | +#endif /* _SAM3U_USART3_INSTANCE_ */ |
| 105 | +void _hsmci_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 106 | +void _twi0_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 107 | +void _twi1_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 108 | +void _spi_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 109 | +void _ssc_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 110 | +void _tc0_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 111 | +void _tc1_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 112 | +void _tc2_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 113 | +void _pwm_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 114 | +void _adc12b_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 115 | +void _adc_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 116 | +void _dmac_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 117 | +void _udphs_isr() __attribute__((weak, alias(DEFAULT_ISR))); |
| 118 | + |
| 119 | +/* Vector table */ |
| 120 | +__attribute__((section(".isr_vector"), used)) void (*const g_pfnVectors[])() = { |
| 121 | + /* Cortex-M Exception Handlers */ |
| 122 | + _estack, |
| 123 | + _reset_isr, |
| 124 | + _nmi_isr, |
| 125 | + _hardfault_isr, |
| 126 | + _memmanage_isr, |
| 127 | + _busfault_isr, |
| 128 | + _usagefault_isr, |
| 129 | + 0, /* Reserved */ |
| 130 | + 0, /* Reserved */ |
| 131 | + 0, /* Reserved */ |
| 132 | + 0, /* Reserved */ |
| 133 | + _svc_isr, |
| 134 | + _debugmon_isr, |
| 135 | + 0, /* Reserved */ |
| 136 | + _pendsv_isr, |
| 137 | + _systick_isr, |
| 138 | + /* External interrupts */ |
| 139 | + _supc_isr, /* 0 Supply Controller */ |
| 140 | + _rstc_isr, /* 1 Reset Controller */ |
| 141 | + _rtc_isr, /* 2 Real Time Clock */ |
| 142 | + _rtt_isr, /* 3 Real Time Timer */ |
| 143 | + _wdt_isr, /* 4 Watchdog Timer */ |
| 144 | + _pmc_isr, /* 5 Power Management Controller */ |
| 145 | + _efc0_isr, /* 6 Enhanced Embedded Flash Controller 0 */ |
| 146 | +#ifdef _SAM3U_EFC1_INSTANCE_ |
| 147 | + _efc1_isr, /* 7 Enhanced Embedded Flash Controller 1 */ |
| 148 | +#else |
| 149 | + 0, /* 7 Reserved */ |
| 150 | +#endif /* _SAM3U_EFC1_INSTANCE_ */ |
| 151 | + _uart_isr, /* 8 Universal Asynchronous Receiver Transmitter */ |
| 152 | + 0, /* 9 Reserved */ |
| 153 | + _pioa_isr, /* 10 Parallel I/O Controller A, */ |
| 154 | + _piob_isr, /* 11 Parallel I/O Controller B */ |
| 155 | +#ifdef _SAM3U_PIOC_INSTANCE_ |
| 156 | + _pioc_isr, /* 12 Parallel I/O Controller C */ |
| 157 | +#else |
| 158 | + 0, /* 12 Reserved */ |
| 159 | +#endif /* _SAM3U_PIOC_INSTANCE_ */ |
| 160 | + _usart0_isr, /* 13 USART 0 */ |
| 161 | + _usart1_isr, /* 14 USART 1 */ |
| 162 | + _usart2_isr, /* 15 USART 2 */ |
| 163 | +#ifdef _SAM3U_USART3_INSTANCE_ |
| 164 | + _usart3_isr, /* 16 USART 3 */ |
| 165 | +#else |
| 166 | + 0, /* 16 Reserved */ |
| 167 | +#endif /* _SAM3U_USART3_INSTANCE_ */ |
| 168 | + _hsmci_isr, /* 17 High Speed Multimedia Card Interface */ |
| 169 | + _twi0_isr, /* 18 Two-Wire Interface 0 */ |
| 170 | + _twi1_isr, /* 19 Two-Wire Interface 1 */ |
| 171 | + _spi_isr, /* 20 Serial Peripheral Interface */ |
| 172 | + _ssc_isr, /* 21 Synchronous Serial Controller */ |
| 173 | + _tc0_isr, /* 22 Timer Counter 0 */ |
| 174 | + _tc1_isr, /* 23 Timer Counter 1 */ |
| 175 | + _tc2_isr, /* 24 Timer Counter 2 */ |
| 176 | + _pwm_isr, /* 25 Pulse Width Modulation Controller */ |
| 177 | + _adc12b_isr, /* 26 12-bit ADC Controller */ |
| 178 | + _adc_isr, /* 27 10-bit ADC Controller */ |
| 179 | + _dmac_isr, /* 28 DMA Controller */ |
| 180 | + _udphs_isr, /* 29 USB Device High Speed */ |
| 181 | +}; |
0 commit comments