|
-
-
- #include "kinetis.h"
- #include "core_pins.h"
- #include "ser_print.h"
- #include <errno.h>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #define FSEC 0xDE
-
-
- #define FOPT 0xF9
-
-
- 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) __attribute__((noinline));
- void __libc_init_array(void);
-
-
- void fault_isr(void)
- {
- #if 0
- uint32_t addr;
-
- SIM_SCGC4 |= 0x00000400;
- UART0_BDH = 0;
- UART0_BDL = 26;
- UART0_C2 = UART_C2_TE;
- PORTB_PCR17 = PORT_PCR_MUX(3);
- ser_print("\nfault: \n??: ");
- asm("ldr %0, [sp, #52]" : "=r" (addr) ::);
- ser_print_hex32(addr);
- ser_print("\n??: ");
- asm("ldr %0, [sp, #48]" : "=r" (addr) ::);
- ser_print_hex32(addr);
- ser_print("\n??: ");
- asm("ldr %0, [sp, #44]" : "=r" (addr) ::);
- ser_print_hex32(addr);
- ser_print("\npsr:");
- asm("ldr %0, [sp, #40]" : "=r" (addr) ::);
- ser_print_hex32(addr);
- ser_print("\nadr:");
- asm("ldr %0, [sp, #36]" : "=r" (addr) ::);
- ser_print_hex32(addr);
- ser_print("\nlr: ");
- asm("ldr %0, [sp, #32]" : "=r" (addr) ::);
- ser_print_hex32(addr);
- ser_print("\nr12:");
- asm("ldr %0, [sp, #28]" : "=r" (addr) ::);
- ser_print_hex32(addr);
- ser_print("\nr3: ");
- asm("ldr %0, [sp, #24]" : "=r" (addr) ::);
- ser_print_hex32(addr);
- ser_print("\nr2: ");
- asm("ldr %0, [sp, #20]" : "=r" (addr) ::);
- ser_print_hex32(addr);
- ser_print("\nr1: ");
- asm("ldr %0, [sp, #16]" : "=r" (addr) ::);
- ser_print_hex32(addr);
- ser_print("\nr0: ");
- asm("ldr %0, [sp, #12]" : "=r" (addr) ::);
- ser_print_hex32(addr);
- ser_print("\nr4: ");
- asm("ldr %0, [sp, #8]" : "=r" (addr) ::);
- ser_print_hex32(addr);
- ser_print("\nlr: ");
- asm("ldr %0, [sp, #4]" : "=r" (addr) ::);
- ser_print_hex32(addr);
- ser_print("\n");
- asm("ldr %0, [sp, #0]" : "=r" (addr) ::);
- #endif
- 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();
- }
-
- void nmi_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void hard_fault_isr(void) __attribute__ ((weak, alias("fault_isr")));
- void memmanage_fault_isr(void) __attribute__ ((weak, alias("fault_isr")));
- void bus_fault_isr(void) __attribute__ ((weak, alias("fault_isr")));
- void usage_fault_isr(void) __attribute__ ((weak, alias("fault_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);
-
- 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_ch4_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch5_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch6_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch7_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch8_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch9_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch10_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch11_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch12_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch13_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch14_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_ch15_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dma_error_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void mcm_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void randnum_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 i2c1_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void i2c2_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void i2c3_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void spi0_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void spi1_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void spi2_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void sdhc_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void enet_timer_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void enet_tx_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void enet_rx_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void enet_error_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void can0_message_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void can0_bus_off_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void can0_error_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void can0_tx_warn_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void can0_rx_warn_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void can0_wakeup_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void can1_message_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void can1_bus_off_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void can1_error_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void can1_tx_warn_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void can1_rx_warn_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void can1_wakeup_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 i2s0_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 uart3_status_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void uart3_error_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void uart4_status_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void uart4_error_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void uart5_status_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void uart5_error_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void lpuart0_status_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void adc0_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void adc1_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 cmp2_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void cmp3_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 ftm2_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void ftm3_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void tpm0_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void tpm1_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void tpm2_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 pit_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 usbhs_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void usbhs_phy_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dac0_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void dac1_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 portcd_isr(void) __attribute__ ((weak, alias("unused_isr")));
- void software_isr(void) __attribute__ ((weak, alias("unused_isr")));
-
- #if defined(__MK20DX128__)
- __attribute__ ((section(".dmabuffers"), used, aligned(256)))
- #elif defined(__MK20DX256__)
- __attribute__ ((section(".dmabuffers"), used, aligned(512)))
- #elif defined(__MKL26Z64__)
- __attribute__ ((section(".dmabuffers"), used, aligned(256)))
- #elif defined(__MK64FX512__)
- __attribute__ ((section(".dmabuffers"), used, aligned(512)))
- #elif defined(__MK66FX1M0__)
- __attribute__ ((section(".dmabuffers"), used, aligned(512)))
- #endif
- void (* _VectorsRam[NVIC_NUM_INTERRUPTS+16])(void);
-
- __attribute__ ((section(".vectors"), used))
- void (* const _VectorsFlash[NVIC_NUM_INTERRUPTS+16])(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,
- #if defined(__MK20DX128__)
- 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,
- #elif defined(__MK20DX256__)
- dma_ch0_isr,
- dma_ch1_isr,
- dma_ch2_isr,
- dma_ch3_isr,
- dma_ch4_isr,
- dma_ch5_isr,
- dma_ch6_isr,
- dma_ch7_isr,
- dma_ch8_isr,
- dma_ch9_isr,
- dma_ch10_isr,
- dma_ch11_isr,
- dma_ch12_isr,
- dma_ch13_isr,
- dma_ch14_isr,
- dma_ch15_isr,
- dma_error_isr,
- unused_isr,
- flash_cmd_isr,
- flash_error_isr,
- low_voltage_isr,
- wakeup_isr,
- watchdog_isr,
- unused_isr,
- i2c0_isr,
- i2c1_isr,
- spi0_isr,
- spi1_isr,
- unused_isr,
- can0_message_isr,
- can0_bus_off_isr,
- can0_error_isr,
- can0_tx_warn_isr,
- can0_rx_warn_isr,
- can0_wakeup_isr,
- i2s0_tx_isr,
- i2s0_rx_isr,
- unused_isr,
- unused_isr,
- unused_isr,
- unused_isr,
- unused_isr,
- unused_isr,
- unused_isr,
- uart0_lon_isr,
- uart0_status_isr,
- uart0_error_isr,
- uart1_status_isr,
- uart1_error_isr,
- uart2_status_isr,
- uart2_error_isr,
- unused_isr,
- unused_isr,
- unused_isr,
- unused_isr,
- unused_isr,
- unused_isr,
- adc0_isr,
- adc1_isr,
- cmp0_isr,
- cmp1_isr,
- cmp2_isr,
- ftm0_isr,
- ftm1_isr,
- ftm2_isr,
- cmt_isr,
- rtc_alarm_isr,
- rtc_seconds_isr,
- pit0_isr,
- pit1_isr,
- pit2_isr,
- pit3_isr,
- pdb_isr,
- usb_isr,
- usb_charge_isr,
- unused_isr,
- unused_isr,
- unused_isr,
- unused_isr,
- unused_isr,
- unused_isr,
- dac0_isr,
- unused_isr,
- tsi0_isr,
- mcg_isr,
- lptmr_isr,
- unused_isr,
- porta_isr,
- portb_isr,
- portc_isr,
- portd_isr,
- porte_isr,
- unused_isr,
- unused_isr,
- software_isr,
- #elif defined(__MKL26Z64__)
- dma_ch0_isr,
- dma_ch1_isr,
- dma_ch2_isr,
- dma_ch3_isr,
- unused_isr,
- flash_cmd_isr,
- low_voltage_isr,
- wakeup_isr,
- i2c0_isr,
- i2c1_isr,
- spi0_isr,
- spi1_isr,
- uart0_status_isr,
- uart1_status_isr,
- uart2_status_isr,
- adc0_isr,
- cmp0_isr,
- ftm0_isr,
- ftm1_isr,
- ftm2_isr,
- rtc_alarm_isr,
- rtc_seconds_isr,
- pit_isr,
- i2s0_isr,
- usb_isr,
- dac0_isr,
- tsi0_isr,
- mcg_isr,
- lptmr_isr,
- software_isr,
- porta_isr,
- portcd_isr,
- #elif defined(__MK64FX512__)
- dma_ch0_isr,
- dma_ch1_isr,
- dma_ch2_isr,
- dma_ch3_isr,
- dma_ch4_isr,
- dma_ch5_isr,
- dma_ch6_isr,
- dma_ch7_isr,
- dma_ch8_isr,
- dma_ch9_isr,
- dma_ch10_isr,
- dma_ch11_isr,
- dma_ch12_isr,
- dma_ch13_isr,
- dma_ch14_isr,
- dma_ch15_isr,
- dma_error_isr,
- mcm_isr,
- flash_cmd_isr,
- flash_error_isr,
- low_voltage_isr,
- wakeup_isr,
- watchdog_isr,
- randnum_isr,
- i2c0_isr,
- i2c1_isr,
- spi0_isr,
- spi1_isr,
- i2s0_tx_isr,
- i2s0_rx_isr,
- unused_isr,
- uart0_status_isr,
- uart0_error_isr,
- uart1_status_isr,
- uart1_error_isr,
- uart2_status_isr,
- uart2_error_isr,
- uart3_status_isr,
- uart3_error_isr,
- adc0_isr,
- cmp0_isr,
- cmp1_isr,
- ftm0_isr,
- ftm1_isr,
- ftm2_isr,
- cmt_isr,
- rtc_alarm_isr,
- rtc_seconds_isr,
- pit0_isr,
- pit1_isr,
- pit2_isr,
- pit3_isr,
- pdb_isr,
- usb_isr,
- usb_charge_isr,
- unused_isr,
- dac0_isr,
- mcg_isr,
- lptmr_isr,
- porta_isr,
- portb_isr,
- portc_isr,
- portd_isr,
- porte_isr,
- software_isr,
- spi2_isr,
- uart4_status_isr,
- uart4_error_isr,
- uart5_status_isr,
- uart5_error_isr,
- cmp2_isr,
- ftm3_isr,
- dac1_isr,
- adc1_isr,
- i2c2_isr,
- can0_message_isr,
- can0_bus_off_isr,
- can0_error_isr,
- can0_tx_warn_isr,
- can0_rx_warn_isr,
- can0_wakeup_isr,
- sdhc_isr,
- enet_timer_isr,
- enet_tx_isr,
- enet_rx_isr,
- enet_error_isr,
- #elif defined(__MK66FX1M0__)
- dma_ch0_isr,
- dma_ch1_isr,
- dma_ch2_isr,
- dma_ch3_isr,
- dma_ch4_isr,
- dma_ch5_isr,
- dma_ch6_isr,
- dma_ch7_isr,
- dma_ch8_isr,
- dma_ch9_isr,
- dma_ch10_isr,
- dma_ch11_isr,
- dma_ch12_isr,
- dma_ch13_isr,
- dma_ch14_isr,
- dma_ch15_isr,
- dma_error_isr,
- mcm_isr,
- flash_cmd_isr,
- flash_error_isr,
- low_voltage_isr,
- wakeup_isr,
- watchdog_isr,
- randnum_isr,
- i2c0_isr,
- i2c1_isr,
- spi0_isr,
- spi1_isr,
- i2s0_tx_isr,
- i2s0_rx_isr,
- unused_isr,
- uart0_status_isr,
- uart0_error_isr,
- uart1_status_isr,
- uart1_error_isr,
- uart2_status_isr,
- uart2_error_isr,
- uart3_status_isr,
- uart3_error_isr,
- adc0_isr,
- cmp0_isr,
- cmp1_isr,
- ftm0_isr,
- ftm1_isr,
- ftm2_isr,
- cmt_isr,
- rtc_alarm_isr,
- rtc_seconds_isr,
- pit0_isr,
- pit1_isr,
- pit2_isr,
- pit3_isr,
- pdb_isr,
- usb_isr,
- usb_charge_isr,
- unused_isr,
- dac0_isr,
- mcg_isr,
- lptmr_isr,
- porta_isr,
- portb_isr,
- portc_isr,
- portd_isr,
- porte_isr,
- software_isr,
- spi2_isr,
- uart4_status_isr,
- uart4_error_isr,
- unused_isr,
- unused_isr,
- cmp2_isr,
- ftm3_isr,
- dac1_isr,
- adc1_isr,
- i2c2_isr,
- can0_message_isr,
- can0_bus_off_isr,
- can0_error_isr,
- can0_tx_warn_isr,
- can0_rx_warn_isr,
- can0_wakeup_isr,
- sdhc_isr,
- enet_timer_isr,
- enet_tx_isr,
- enet_rx_isr,
- enet_error_isr,
- lpuart0_status_isr,
- tsi0_isr,
- tpm1_isr,
- tpm2_isr,
- usbhs_phy_isr,
- i2c3_isr,
- cmp3_isr,
- usbhs_isr,
- can1_message_isr,
- can1_bus_off_isr,
- can1_error_isr,
- can1_tx_warn_isr,
- can1_rx_warn_isr,
- can1_wakeup_isr,
- #endif
- };
-
-
- __attribute__ ((section(".flashconfig"), used))
- const uint8_t flashconfigbytes[16] = {
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, FSEC, FOPT, 0xFF, 0xFF
- };
-
-
-
-
-
- #ifndef TIME_T
- #define TIME_T 1349049600
- #endif
- extern void *__rtc_localtime;
- extern void rtc_set(unsigned long t);
-
-
- static void startup_default_early_hook(void) {
- #if defined(KINETISK)
- WDOG_STCTRLH = WDOG_STCTRLH_ALLOWUPDATE;
- #elif defined(KINETISL)
- SIM_COPC = 0;
- #endif
- }
- static void startup_default_late_hook(void) {}
- void startup_early_hook(void) __attribute__ ((weak, alias("startup_default_early_hook")));
- void startup_late_hook(void) __attribute__ ((weak, alias("startup_default_late_hook")));
-
-
- #if defined(__PURE_CODE__) || !defined(__OPTIMIZE__) || defined(__clang__)
-
- __attribute__ ((optimize("-Os")))
- #else
-
- __attribute__ ((section(".startup"),optimize("-Os")))
- #endif
- void ResetHandler(void)
- {
- uint32_t *src = &_etext;
- uint32_t *dest = &_sdata;
- unsigned int i;
- #if F_CPU <= 2000000
- volatile int n;
- #endif
-
-
- #ifdef KINETISK
- WDOG_UNLOCK = WDOG_UNLOCK_SEQ1;
- WDOG_UNLOCK = WDOG_UNLOCK_SEQ2;
- __asm__ volatile ("nop");
- __asm__ volatile ("nop");
- #endif
-
-
- startup_early_hook();
-
-
- #if defined(__MK20DX128__)
- SIM_SCGC5 = 0x00043F82;
- SIM_SCGC6 = SIM_SCGC6_RTC | SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTFL;
- #elif defined(__MK20DX256__)
- SIM_SCGC3 = SIM_SCGC3_ADC1 | SIM_SCGC3_FTM2;
- SIM_SCGC5 = 0x00043F82;
- SIM_SCGC6 = SIM_SCGC6_RTC | SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTFL;
- #elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
- SIM_SCGC3 = SIM_SCGC3_ADC1 | SIM_SCGC3_FTM2 | SIM_SCGC3_FTM3;
- SIM_SCGC5 = 0x00043F82;
- SIM_SCGC6 = SIM_SCGC6_RTC | SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTFL;
-
-
-
-
- #elif defined(__MKL26Z64__)
- SIM_SCGC4 = SIM_SCGC4_USBOTG | 0xF0000030;
- SIM_SCGC5 = 0x00003F82;
- SIM_SCGC6 = SIM_SCGC6_ADC0 | SIM_SCGC6_TPM0 | SIM_SCGC6_TPM1 | SIM_SCGC6_TPM2 | SIM_SCGC6_FTFL;
- #endif
- #if defined(__MK64FX512__) || defined(__MK66FX1M0__)
- SCB_CPACR = 0x00F00000;
- #endif
- #if defined(__MK66FX1M0__)
- LMEM_PCCCR = 0x85000003;
- #endif
- #if 0
-
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV4(1);
- MCG_C4 |= MCG_C4_DMX32 | MCG_C4_DRST_DRS(1);
- SIM_SOPT2 = SIM_SOPT2_UART0SRC(1) | SIM_SOPT2_TPMSRC(1);
- SIM_SCGC4 |= 0x00000400;
- UART0_BDH = 0;
- UART0_BDL = 26;
- UART0_C2 = UART_C2_TE;
- PORTB_PCR17 = PORT_PCR_MUX(3);
- #endif
- #if defined(KINETISK) && !defined(__MK66FX1M0__)
-
-
-
- if (!(RTC_CR & RTC_CR_OSCE)) {
- RTC_SR = 0;
- RTC_CR = RTC_CR_SC16P | RTC_CR_SC4P | RTC_CR_OSCE;
- }
- #endif
-
- if (PMC_REGSC & PMC_REGSC_ACKISO) PMC_REGSC |= PMC_REGSC_ACKISO;
-
-
-
- #if defined(__MK66FX1M0__)
- SMC_PMPROT = SMC_PMPROT_AHSRUN | SMC_PMPROT_AVLP | SMC_PMPROT_ALLS | SMC_PMPROT_AVLLS;
- #else
- SMC_PMPROT = SMC_PMPROT_AVLP | SMC_PMPROT_ALLS | SMC_PMPROT_AVLLS;
- #endif
-
-
- while (dest < &_edata) *dest++ = *src++;
- dest = &_sbss;
- while (dest < &_ebss) *dest++ = 0;
-
-
- for (i=0; i < NVIC_NUM_INTERRUPTS + 16; i++) _VectorsRam[i] = _VectorsFlash[i];
- for (i=0; i < NVIC_NUM_INTERRUPTS; i++) NVIC_SET_PRIORITY(i, 128);
- SCB_VTOR = (uint32_t)_VectorsRam;
-
-
-
-
-
-
-
- #if F_CPU <= 2000000
- #if defined(KINETISK)
- MCG_C1 = MCG_C1_CLKS(1) | MCG_C1_IREFS;
- #elif defined(KINETISL)
-
- MCG_C1 = MCG_C1_CLKS(1) | MCG_C1_IREFS | MCG_C1_IRCLKEN;
- #endif
-
- while ((MCG_S & MCG_S_CLKST_MASK) != MCG_S_CLKST(1)) ;
- for (n=0; n<10; n++) ;
- MCG_C2 = MCG_C2_IRCS;
- while (!(MCG_S & MCG_S_IRCST)) ;
-
-
-
-
-
- MCG_C2 = MCG_C2_IRCS | MCG_C2_LP;
-
-
-
-
-
- #else
- #if defined(KINETISK)
-
- OSC0_CR = OSC_SC8P | OSC_SC2P | OSC_ERCLKEN;
- #elif defined(KINETISL)
-
- OSC0_CR = OSC_SC8P | OSC_SC2P | OSC_ERCLKEN;
- #endif
-
- 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)) ;
-
-
-
-
-
-
-
- #if F_CPU <= 16000000
-
- MCG_C2 = MCG_C2_RANGE0(2) | MCG_C2_EREFS | MCG_C2_LP;
-
-
-
-
- #else
-
- #if defined(__MK66FX1M0__)
- #if F_CPU > 120000000
- SMC_PMCTRL = SMC_PMCTRL_RUNM(3);
- while (SMC_PMSTAT != SMC_PMSTAT_HSRUN) ;
- #endif
- #if F_CPU == 256000000
-
-
- MCG_C5 = MCG_C5_PRDIV0(0);
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(16);
- #elif F_CPU == 240000000
- MCG_C5 = MCG_C5_PRDIV0(0);
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(14);
- #elif F_CPU == 216000000
- MCG_C5 = MCG_C5_PRDIV0(0);
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(11);
- #elif F_CPU == 192000000
- MCG_C5 = MCG_C5_PRDIV0(0);
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(8);
- #elif F_CPU == 180000000
- MCG_C5 = MCG_C5_PRDIV0(1);
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(29);
- #elif F_CPU == 168000000
- MCG_C5 = MCG_C5_PRDIV0(0);
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(5);
- #elif F_CPU == 144000000
- MCG_C5 = MCG_C5_PRDIV0(0);
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(2);
- #elif F_CPU == 120000000
- MCG_C5 = MCG_C5_PRDIV0(1);
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(14);
- #elif F_CPU == 96000000 || F_CPU == 48000000 || F_CPU == 24000000
- MCG_C5 = MCG_C5_PRDIV0(1);
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(8);
- #elif F_CPU == 72000000
- MCG_C5 = MCG_C5_PRDIV0(1);
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(2);
- #elif F_CPU > 16000000
- #error "MK66FX1M0 does not support this clock speed yet...."
- #endif
- #else
- #if F_CPU == 72000000
- MCG_C5 = MCG_C5_PRDIV0(5);
- #else
- MCG_C5 = MCG_C5_PRDIV0(3);
- #endif
- #if F_CPU == 168000000
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(18);
- #elif F_CPU == 144000000
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(12);
- #elif F_CPU == 120000000
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(6);
- #elif F_CPU == 72000000
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(3);
- #elif F_CPU == 96000000 || F_CPU == 48000000 || F_CPU == 24000000
- MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(0);
- #elif F_CPU > 16000000
- #error "This clock speed isn't supported..."
- #endif
- #endif
-
-
- while (!(MCG_S & MCG_S_PLLST)) ;
-
- while (!(MCG_S & MCG_S_LOCK0)) ;
-
- #endif
- #endif
-
- #if F_CPU == 256000000
-
-
- #if F_BUS == 64000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(3) | SIM_CLKDIV1_OUTDIV4(7);
- #elif F_BUS == 128000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV4(7);
- #else
- #error "This F_CPU & F_BUS combination is not supported"
- #endif
- SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(0);
- #elif F_CPU == 240000000
-
-
- #if F_BUS == 60000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(3) | SIM_CLKDIV1_OUTDIV4(7);
- #elif F_BUS == 80000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(2) | SIM_CLKDIV1_OUTDIV4(7);
- #elif F_BUS == 120000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV4(7);
- #else
- #error "This F_CPU & F_BUS combination is not supported"
- #endif
- SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(4);
- #elif F_CPU == 216000000
-
-
- #if F_BUS == 54000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(3) | SIM_CLKDIV1_OUTDIV4(7);
- #elif F_BUS == 72000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(2) | SIM_CLKDIV1_OUTDIV4(7);
- #elif F_BUS == 108000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV4(7);
-
- #else
- #error "This F_CPU & F_BUS combination is not supported"
- #endif
- SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(0);
- #elif F_CPU == 192000000
-
-
- #if F_BUS == 48000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(3) | SIM_CLKDIV1_OUTDIV4(6);
- #elif F_BUS == 64000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(2) | SIM_CLKDIV1_OUTDIV4(6);
- #elif F_BUS == 96000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV4(6);
- #else
- #error "This F_CPU & F_BUS combination is not supported"
- #endif
- SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(3);
- #elif F_CPU == 180000000
-
- #if F_BUS == 60000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(2) | SIM_CLKDIV1_OUTDIV4(6);
- #elif F_BUS == 90000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV4(6);
- #else
- #error "This F_CPU & F_BUS combination is not supported"
- #endif
- SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(0);
- #elif F_CPU == 168000000
-
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(2) | SIM_CLKDIV1_OUTDIV4(5);
- SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(6) | SIM_CLKDIV2_USBFRAC;
- #elif F_CPU == 144000000
-
- #if F_BUS == 48000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(2) | SIM_CLKDIV1_OUTDIV4(4);
- #elif F_BUS == 72000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV4(4);
- #else
- #error "This F_CPU & F_BUS combination is not supported"
- #endif
- SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(2);
- #elif F_CPU == 120000000
-
- #if F_BUS == 60000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV4(4);
- #elif F_BUS == 120000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) | SIM_CLKDIV1_OUTDIV4(4);
- #else
- #error "This F_CPU & F_BUS combination is not supported"
- #endif
- SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(4) | SIM_CLKDIV2_USBFRAC;
- #elif F_CPU == 96000000
-
- #if F_BUS == 48000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV4(3);
- #elif F_BUS == 96000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) | SIM_CLKDIV1_OUTDIV4(3);
- #else
- #error "This F_CPU & F_BUS combination is not supported"
- #endif
- SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(1);
- #elif F_CPU == 72000000
-
- #if F_BUS == 36000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV4(2);
- #elif F_BUS == 72000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) | SIM_CLKDIV1_OUTDIV4(2);
- #else
- #error "This F_CPU & F_BUS combination is not supported"
- #endif
- SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(2) | SIM_CLKDIV2_USBFRAC;
- #elif F_CPU == 48000000
-
- #if defined(KINETISK)
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(1) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV3(1) | SIM_CLKDIV1_OUTDIV4(3);
- SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(1);
- #elif defined(KINETISL)
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(1) | SIM_CLKDIV1_OUTDIV4(1);
- #endif
- #elif F_CPU == 24000000
-
- #if defined(KINETISK)
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(3) | SIM_CLKDIV1_OUTDIV2(3) | SIM_CLKDIV1_OUTDIV3(3) | SIM_CLKDIV1_OUTDIV4(3);
- SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(1);
- #elif defined(KINETISL)
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(3) | SIM_CLKDIV1_OUTDIV4(0);
- #endif
- #elif F_CPU == 16000000
-
- #if defined(KINETISK)
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) | SIM_CLKDIV1_OUTDIV3(0) | SIM_CLKDIV1_OUTDIV4(0);
- #elif defined(KINETISL)
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV4(0);
- #endif
- #elif F_CPU == 8000000
-
- #if defined(KINETISK)
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(1) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV3(1) | SIM_CLKDIV1_OUTDIV4(1);
- #elif defined(KINETISL)
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(1) | SIM_CLKDIV1_OUTDIV4(0);
- #endif
- #elif F_CPU == 4000000
-
-
-
-
-
- #if defined(KINETISK)
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(3) | SIM_CLKDIV1_OUTDIV2(3) | SIM_CLKDIV1_OUTDIV3(3) | SIM_CLKDIV1_OUTDIV4(3);
- #elif defined(KINETISL)
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(3) | SIM_CLKDIV1_OUTDIV4(0);
- #endif
- #elif F_CPU == 2000000
-
-
-
-
- #if defined(KINETISK)
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) | SIM_CLKDIV1_OUTDIV4(1);
- #elif defined(KINETISL)
-
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV4(1);
- #endif
- #else
- #error "Error, F_CPU must be 256, 240, 216, 192, 180, 168, 144, 120, 96, 72, 48, 24, 16, 8, 4, or 2 MHz"
- #endif
-
- #if F_CPU > 16000000
-
- MCG_C1 = MCG_C1_CLKS(0) | MCG_C1_FRDIV(4);
-
- while ((MCG_S & MCG_S_CLKST_MASK) != MCG_S_CLKST(3)) ;
-
-
- #if defined(KINETISK)
- #if F_CPU == 256000000 || F_CPU == 216000000 || F_CPU == 180000000
-
- SIM_SOPT2 = SIM_SOPT2_USBSRC | SIM_SOPT2_IRC48SEL | SIM_SOPT2_TRACECLKSEL | SIM_SOPT2_CLKOUTSEL(6);
- #else
-
- SIM_SOPT2 = SIM_SOPT2_USBSRC | SIM_SOPT2_PLLFLLSEL | SIM_SOPT2_TRACECLKSEL | SIM_SOPT2_CLKOUTSEL(6);
- #endif
- #elif defined(KINETISL)
- SIM_SOPT2 = SIM_SOPT2_USBSRC | SIM_SOPT2_PLLFLLSEL | SIM_SOPT2_CLKOUTSEL(6)
- | SIM_SOPT2_UART0SRC(1) | SIM_SOPT2_TPMSRC(1);
- #endif
- #else
-
- #if F_CPU == 2000000
- SIM_SOPT2 = SIM_SOPT2_TRACECLKSEL | SIM_SOPT2_CLKOUTSEL(4) | SIM_SOPT2_UART0SRC(3);
- #else
- SIM_SOPT2 = SIM_SOPT2_TRACECLKSEL | SIM_SOPT2_CLKOUTSEL(6) | SIM_SOPT2_UART0SRC(2);
- #endif
-
- #endif
-
- #if F_CPU <= 2000000
-
- SMC_PMCTRL = SMC_PMCTRL_RUNM(2);
- #endif
-
- #if defined(__MK66FX1M0__)
-
-
- if (!(RTC_CR & RTC_CR_OSCE)) {
- RTC_SR = 0;
- RTC_CR = RTC_CR_SC16P | RTC_CR_SC4P | RTC_CR_OSCE;
- }
- #endif
-
-
- SYST_RVR = (F_CPU / 1000) - 1;
- SYST_CVR = 0;
- SYST_CSR = SYST_CSR_CLKSOURCE | SYST_CSR_TICKINT | SYST_CSR_ENABLE;
- SCB_SHPR3 = 0x20200000;
-
-
- __enable_irq();
-
- _init_Teensyduino_internal_();
-
- #if defined(KINETISK)
-
- if (RTC_SR & RTC_SR_TIF) {
-
-
-
-
-
-
- #if ARDUINO >= 10600
- rtc_set((uint32_t)&__rtc_localtime);
- #else
- rtc_set(TIME_T);
- #endif
- *(uint32_t *)0x4003E01C = 0x5A94C3A5;
- }
- if ((RCM_SRS0 & RCM_SRS0_PIN) && (*(uint32_t *)0x4003E01C == 0x5A94C3A5)) {
-
-
-
-
-
-
- #if ARDUINO >= 10600
- rtc_set((uint32_t)&__rtc_localtime);
- #else
- rtc_set(TIME_T);
- #endif
- *(uint32_t *)0x4003E01C = 0;
- }
- #endif
-
- __libc_init_array();
-
- startup_late_hook();
- main();
-
- while (1) ;
- }
-
- char *__brkval = (char *)&_ebss;
-
- #ifndef STACK_MARGIN
- #if defined(__MKL26Z64__)
- #define STACK_MARGIN 512
- #elif defined(__MK20DX128__)
- #define STACK_MARGIN 1024
- #elif defined(__MK20DX256__)
- #define STACK_MARGIN 4096
- #elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
- #define STACK_MARGIN 8192
- #endif
- #endif
-
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wunused-parameter"
-
- void * _sbrk(int incr)
- {
- char *prev, *stack;
-
- prev = __brkval;
- if (incr != 0) {
- __asm__ volatile("mov %0, sp" : "=r" (stack) ::);
- if (prev + incr >= stack - STACK_MARGIN) {
- errno = ENOMEM;
- return (void *)-1;
- }
- __brkval = prev + incr;
- }
- return prev;
- }
-
- __attribute__((weak))
- int _read(int file, char *ptr, int len)
- {
- return 0;
- }
-
- __attribute__((weak))
- int _close(int fd)
- {
- return -1;
- }
-
- #include <sys/stat.h>
-
- __attribute__((weak))
- int _fstat(int fd, struct stat *st)
- {
- st->st_mode = S_IFCHR;
- return 0;
- }
-
- __attribute__((weak))
- int _isatty(int fd)
- {
- return 1;
- }
-
- __attribute__((weak))
- int _lseek(int fd, long long offset, int whence)
- {
- return -1;
- }
-
- __attribute__((weak))
- void _exit(int status)
- {
- while (1);
- }
-
- __attribute__((weak))
- void __cxa_pure_virtual()
- {
- while (1);
- }
-
- __attribute__((weak))
- int __cxa_guard_acquire (char *g)
- {
- return !(*g);
- }
-
- __attribute__((weak))
- void __cxa_guard_release(char *g)
- {
- *g = 1;
- }
-
- __attribute__((weak))
- void abort(void)
- {
- while (1) ;
- }
-
- #pragma GCC diagnostic pop
-
- int nvic_execution_priority(void)
- {
- uint32_t priority=256;
- uint32_t primask, faultmask, basepri, ipsr;
-
-
-
- __asm__ volatile("mrs %0, faultmask\n" : "=r" (faultmask)::);
- if (faultmask) return -1;
- __asm__ volatile("mrs %0, primask\n" : "=r" (primask)::);
- if (primask) return 0;
- __asm__ volatile("mrs %0, ipsr\n" : "=r" (ipsr)::);
- if (ipsr) {
- if (ipsr < 16) priority = 0;
- else priority = NVIC_GET_PRIORITY(ipsr - 16);
- }
- __asm__ volatile("mrs %0, basepri\n" : "=r" (basepri)::);
- if (basepri > 0 && basepri < priority) priority = basepri;
- return priority;
- }
-
-
- #if defined(HAS_KINETIS_HSRUN) && F_CPU > 120000000
- int kinetis_hsrun_disable(void)
- {
- if (SMC_PMSTAT == SMC_PMSTAT_HSRUN) {
-
-
-
-
- #if F_CPU == 256000000 && F_BUS == 64000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(1, 3, 1, 7);
- #elif F_CPU == 256000000 && F_BUS == 128000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(1, 1, 1, 7);
- #elif F_CPU == 240000000 && F_BUS == 60000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(1, 3, 1, 7);
- #elif F_CPU == 240000000 && F_BUS == 80000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(2, 2, 2, 8);
- #elif F_CPU == 240000000 && F_BUS == 120000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(1, 1, 1, 7);
- #elif F_CPU == 216000000 && F_BUS == 54000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(1, 3, 1, 7);
- #elif F_CPU == 216000000 && F_BUS == 72000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(2, 2, 2, 8);
- #elif F_CPU == 216000000 && F_BUS == 108000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(1, 1, 1, 7);
- #elif F_CPU == 192000000 && F_BUS == 48000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(1, 3, 1, 7);
- #elif F_CPU == 192000000 && F_BUS == 64000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(2, 2, 2, 8);
- #elif F_CPU == 192000000 && F_BUS == 96000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(1, 1, 1, 7);
- #elif F_CPU == 180000000 && F_BUS == 60000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(2, 2, 2, 8);
- #elif F_CPU == 180000000 && F_BUS == 90000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(1, 1, 1, 7);
- #elif F_CPU == 168000000 && F_BUS == 56000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(2, 2, 2, 5);
- #elif F_CPU == 144000000 && F_BUS == 48000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(2, 2, 2, 5);
- #elif F_CPU == 144000000 && F_BUS == 72000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(1, 1, 1, 5);
- #else
- return 0;
- #endif
-
- SMC_PMCTRL = SMC_PMCTRL_RUNM(0);
- while (SMC_PMSTAT == SMC_PMSTAT_HSRUN) ;
- return 1;
- }
- return 0;
- }
-
- int kinetis_hsrun_enable(void)
- {
- if (SMC_PMSTAT == SMC_PMSTAT_RUN) {
-
- SMC_PMCTRL = SMC_PMCTRL_RUNM(3);
- while (SMC_PMSTAT != SMC_PMSTAT_HSRUN) {;}
-
- #if F_CPU == 256000000 && F_BUS == 64000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 3, 0, 7);
- #elif F_CPU == 256000000 && F_BUS == 128000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 1, 0, 7);
- #elif F_CPU == 240000000 && F_BUS == 60000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 3, 0, 7);
- #elif F_CPU == 240000000 && F_BUS == 80000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 2, 0, 7);
- #elif F_CPU == 240000000 && F_BUS == 120000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 1, 0, 7);
- #elif F_CPU == 216000000 && F_BUS == 54000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 3, 0, 7);
- #elif F_CPU == 216000000 && F_BUS == 72000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 2, 0, 7);
- #elif F_CPU == 216000000 && F_BUS == 108000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 1, 0, 7);
- #elif F_CPU == 192000000 && F_BUS == 48000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 3, 0, 6);
- #elif F_CPU == 192000000 && F_BUS == 64000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 2, 0, 6);
- #elif F_CPU == 192000000 && F_BUS == 96000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 1, 0, 6);
- #elif F_CPU == 180000000 && F_BUS == 60000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 2, 0, 6);
- #elif F_CPU == 180000000 && F_BUS == 90000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 1, 0, 6);
- #elif F_CPU == 168000000 && F_BUS == 56000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 2, 0, 5);
- #elif F_CPU == 144000000 && F_BUS == 48000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 2, 0, 4);
- #elif F_CPU == 144000000 && F_BUS == 72000000
- SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIVS(0, 1, 0, 4);
- #else
- return 0;
- #endif
- return 1;
- }
- return 0;
- }
- #endif
|