|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
-
-
- #include "mk20dx128.h"
-
-
- extern unsigned long _stext;
- extern unsigned long _etext;
- extern unsigned long _sdata;
- extern unsigned long _edata;
- extern unsigned long _sbss;
- extern unsigned long _ebss;
- extern unsigned long _estack;
-
-
- extern int main (void);
- void ResetHandler(void);
- void _init_Teensyduino_internal_(void);
- void __libc_init_array(void);
-
-
- void fault_isr(void)
- {
- while (1) {
-
-
- if (SIM_SCGC4 & SIM_SCGC4_USBOTG) usb_isr();
- if (SIM_SCGC4 & SIM_SCGC4_UART0) uart0_status_isr();
- if (SIM_SCGC4 & SIM_SCGC4_UART1) uart1_status_isr();
- if (SIM_SCGC4 & SIM_SCGC4_UART2) uart2_status_isr();
- }
- }
-
- void unused_isr(void)
- {
- fault_isr();
- }
-
- extern volatile uint32_t systick_millis_count;
- void systick_default_isr(void)
- {
- systick_millis_count++;
- }
-
- void nmi_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void hard_fault_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void memmanage_fault_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void bus_fault_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void usage_fault_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void svcall_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void debugmonitor_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void pendablesrvreq_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void systick_isr(void) __attribute__ ((weak, alias("systick_default_isr")));
-
- void dma_ch0_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch1_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch2_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch3_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_error_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void flash_cmd_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void flash_error_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void low_voltage_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void wakeup_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void watchdog_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void i2c0_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void spi0_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void i2s0_tx_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void i2s0_rx_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void uart0_lon_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void uart0_status_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void uart0_error_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void uart1_status_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void uart1_error_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void uart2_status_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void uart2_error_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void adc0_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void cmp0_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void cmp1_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void ftm0_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void ftm1_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void cmt_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void rtc_alarm_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void rtc_seconds_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void pit0_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void pit1_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void pit2_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void pit3_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void pdb_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void usb_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void usb_charge_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void tsi0_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void mcg_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void lptmr_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void porta_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void portb_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void portc_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void portd_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void porte_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void software_isr(void) __attribute__ ((weak, alias("unused_isr")));
-
-
-
-
- __attribute__ ((section(".vectors"), used))
- void (* const gVectors[])(void) =
- {
- (void (*)(void))((unsigned long)&_estack),
- ResetHandler,
- nmi_isr,
- hard_fault_isr,
- memmanage_fault_isr,
- bus_fault_isr,
- usage_fault_isr,
- fault_isr,
- fault_isr,
- fault_isr,
- fault_isr,
- svcall_isr,
- debugmonitor_isr,
- fault_isr,
- pendablesrvreq_isr,
- systick_isr,
- dma_ch0_isr,
- dma_ch1_isr,
- dma_ch2_isr,
- dma_ch3_isr,
- dma_error_isr,
- unused_isr,
- flash_cmd_isr,
- flash_error_isr,
- low_voltage_isr,
- wakeup_isr,
- watchdog_isr,
- i2c0_isr,
- spi0_isr,
- i2s0_tx_isr,
- i2s0_rx_isr,
- uart0_lon_isr,
- uart0_status_isr,
- uart0_error_isr,
- uart1_status_isr,
- uart1_error_isr,
- uart2_status_isr,
- uart2_error_isr,
- adc0_isr,
- cmp0_isr,
- cmp1_isr,
- ftm0_isr,
- ftm1_isr,
- cmt_isr,
- rtc_alarm_isr,
- rtc_seconds_isr,
- pit0_isr,
- pit1_isr,
- pit2_isr,
- pit3_isr,
- pdb_isr,
- usb_isr,
- usb_charge_isr,
- tsi0_isr,
- mcg_isr,
- lptmr_isr,
- porta_isr,
- portb_isr,
- portc_isr,
- portd_isr,
- porte_isr,
- software_isr,
- };
-
-
-
-
-
- __attribute__ ((section(".flashconfig"), used))
- const uint8_t flashconfigbytes[16] = {
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF
- };
-
-
-
-
-
- #ifndef TIME_T
- #define TIME_T 1349049600
- #endif
- extern void rtc_set(unsigned long t);
-
-
-
- static void startup_unused_hook(void) {}
- void startup_early_hook(void) __attribute__ ((weak, alias("startup_unused_hook")));
- void startup_late_hook(void) __attribute__ ((weak, alias("startup_unused_hook")));
-
-
- __attribute__ ((section(".startup")))
- void ResetHandler(void)
- {
- uint32_t *src = &_etext;
- uint32_t *dest = &_sdata;
- unsigned int i;
-
- WDOG_UNLOCK = WDOG_UNLOCK_SEQ1;
- WDOG_UNLOCK = WDOG_UNLOCK_SEQ2;
- WDOG_STCTRLH = WDOG_STCTRLH_ALLOWUPDATE;
- startup_early_hook();
-
-
- SIM_SCGC5 = 0x00043F82;
- SIM_SCGC6 = SIM_SCGC6_RTC | SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTFL;
-
- if (!(RTC_CR & RTC_CR_OSCE)) {
- RTC_SR = 0;
- RTC_CR = RTC_CR_SC16P | RTC_CR_SC4P | RTC_CR_OSCE;
- }
-
-
- if (PMC_REGSC & PMC_REGSC_ACKISO) PMC_REGSC |= PMC_REGSC_ACKISO;
-
-
- while (dest < &_edata) *dest++ = *src++;
- dest = &_sbss;
- while (dest < &_ebss) *dest++ = 0;
- SCB_VTOR = 0;
-
-
- for (i=0; i < NVIC_NUM_INTERRUPTS; i++) NVIC_SET_PRIORITY(i, 128);
-
-
-
- OSC0_CR = OSC_SC8P | OSC_SC2P;
-
- MCG_C2 = MCG_C2_RANGE0(2) | MCG_C2_EREFS;
-
- MCG_C1 = MCG_C1_CLKS(2) | MCG_C1_FRDIV(4);
-
- while ((MCG_S & MCG_S_OSCINIT0) == 0) ;
-
- while ((MCG_S & MCG_S_IREFST) != 0) ;
-
- while ((MCG_S & MCG_S_CLKST_MASK) != MCG_S_CLKST(2)) ;
-
-
- MCG_C5 = MCG_C5_PRDIV0(3);
-
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(0);
-
- while (!(MCG_S & MCG_S_PLLST)) ;
-
- while (!(MCG_S & MCG_S_LOCK0)) ;
-
- #if F_CPU == 96000000
-
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV4(3);
- #elif F_CPU == 48000000
-
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(1) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV4(3);
- #elif F_CPU == 24000000
-
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(3) | SIM_CLKDIV1_OUTDIV2(3) | SIM_CLKDIV1_OUTDIV4(3);
- #else
- #error "Error, F_CPU must be 96000000, 48000000, or 24000000"
- #endif
-
- MCG_C1 = MCG_C1_CLKS(0) | MCG_C1_FRDIV(4);
-
- while ((MCG_S & MCG_S_CLKST_MASK) != MCG_S_CLKST(3)) ;
-
-
- SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(1);
-
- SIM_SOPT2 = SIM_SOPT2_USBSRC | SIM_SOPT2_PLLFLLSEL | SIM_SOPT2_TRACECLKSEL | SIM_SOPT2_CLKOUTSEL(6);
-
-
- SYST_RVR = (F_CPU / 1000) - 1;
- SYST_CSR = SYST_CSR_CLKSOURCE | SYST_CSR_TICKINT | SYST_CSR_ENABLE;
-
-
- __enable_irq();
-
- _init_Teensyduino_internal_();
- if (RTC_SR & RTC_SR_TIF) rtc_set(TIME_T);
-
- __libc_init_array();
-
-
- startup_late_hook();
- main();
- while (1) ;
- }
-
-
-
-
- char *__brkval = (char *)&_ebss;
-
- void * _sbrk(int incr)
- {
-
-
-
-
- char *prev = __brkval;
- __brkval += incr;
- return prev;
- }
-
- int _read(int file, char *ptr, int len)
- {
- return 0;
- }
-
- int _write(int file, char *ptr, int len)
- {
- return 0;
- }
-
- int _close(int fd)
- {
- return -1;
- }
-
- int _lseek(int fd, long long offset, int whence)
- {
- return -1;
- }
-
- void _exit(int status)
- {
- while (1);
- }
-
- void __cxa_pure_virtual()
- {
- while (1);
- }
-
- int __cxa_guard_acquire (int *g)
- {
- return 1;
- }
-
- void __cxa_guard_release(int *g)
- {
- }
-
|