int main(int argc, char **argv) {
	_init_Teensyduino_internal_();
	setup();
	for (;;) {
		loop();
	}
	cleanup();
}
Example #2
0
//int main(void) __attribute__((noreturn));
int main(void)
{
	_init_Teensyduino_internal_();
    
	setup();
    
    for (;;)
        loop();
}
//int main(void) __attribute__((noreturn));
int main(void) {
	_init_Teensyduino_internal_();

	setup();

	while (1) {
		loop();
	}
}
Example #4
0
int main(void) {

#if defined(CORE_TEENSY)
        _init_Teensyduino_internal_();
#else
        init();
#if defined(USBCON)
        USBDevice.attach();
#endif
#endif

        xmem::begin(true, true);
        if(xmem::getTotalBanks() == 0) goto bad;
        if(XMEM_STACK_TOP == XRAMEND) goto bad;
        noInterrupts();
        // Save the original stack pointer, needed to switch banks.
        keepstack = SP;
        asm volatile ( "ldi     16, %0" ::"i" (XMEM_STACK_TOP >> 8));
        asm volatile ( "out     %0,16" ::"i" (AVR_STACK_POINTER_HI_ADDR));
        asm volatile ( "ldi     16, %0" ::"i" (XMEM_STACK_TOP & 0x0ff));
        asm volatile ( "out     %0,16" ::"i" (AVR_STACK_POINTER_LO_ADDR));
        interrupts();

        setup();
        xmem::MultitaskBegin();

        for(;;) {
                loop();
#if !defined(CORE_TEENSY)
                if(serialEventRun) serialEventRun();
#endif
        }

        return 0;

bad:
        //
        // NO external RAM.
        // Use hardware to quickly blink the LED (pin 13) to alert error.
        //
        DDRB |= _BV(PB7);
        // OC1C
        TCCR1A = _BV(COM1C0);
        TCCR1B = _BV(WGM12) | _BV(CS11);
        OCR1A = 0XDEAD;
        noInterrupts();
        for(;;);
}
Example #5
0
int main(void) {

#if defined(CORE_TEENSY)
        _init_Teensyduino_internal_();
#else
#if ARDUINO >= 106
        initVariant();
#endif
        init();
#if defined(USBCON)
        USBDevice.attach();
#endif
#endif


#if EXT_RAM
        xmem::begin(EXT_RAM_HEAP, EXT_RAM_STACK);
#if EXT_RAM_STACK
        if(xmem::getTotalBanks() == 0) goto no;
        if(XMEM_STACK_TOP == XRAMEND) goto no;
        noInterrupts();
        asm volatile ( "ldi     16, %0" ::"i" (XMEM_STACK_TOP >> 8));
        asm volatile ( "out     %0,16" ::"i" (AVR_STACK_POINTER_HI_ADDR));
        asm volatile ( "ldi     16, %0" ::"i" (XMEM_STACK_TOP & 0x0ff));
        asm volatile ( "out     %0,16" ::"i" (AVR_STACK_POINTER_LO_ADDR));
        interrupts();
#endif
no:
#endif
        setup();

        for(;;) {
                loop();
#if !defined(CORE_TEENSY)
                if(serialEventRun) serialEventRun();
#endif
        }

        return 0;
}
void ResetHandler(void)
{
        uint32_t *src = &_etext;
        uint32_t *dest = &_sdata;

	WDOG_UNLOCK = WDOG_UNLOCK_SEQ1;
	WDOG_UNLOCK = WDOG_UNLOCK_SEQ2;
	WDOG_STCTRLH = WDOG_STCTRLH_ALLOWUPDATE;
	startup_early_hook();

	// enable clocks to always-used peripherals
	SIM_SCGC5 = 0x00043F82;		// clocks active to all GPIO
	SIM_SCGC6 = SIM_SCGC6_RTC | SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTFL;
	// if the RTC oscillator isn't enabled, get it started early
	if (!(RTC_CR & RTC_CR_OSCE)) {
		RTC_SR = 0;
		RTC_CR = RTC_CR_SC16P | RTC_CR_SC4P | RTC_CR_OSCE;
	}

	// TODO: do this while the PLL is waiting to lock....
        while (dest < &_edata) *dest++ = *src++;
        dest = &_sbss;
        while (dest < &_ebss) *dest++ = 0;
	SCB_VTOR = 0;	// use vector table in flash

        // start in FEI mode
        // enable capacitors for crystal
        OSC0_CR = OSC_SC8P | OSC_SC2P;
        // enable osc, 8-32 MHz range, low power mode
        MCG_C2 = MCG_C2_RANGE0(2) | MCG_C2_EREFS;
        // switch to crystal as clock source, FLL input = 16 MHz / 512
        MCG_C1 =  MCG_C1_CLKS(2) | MCG_C1_FRDIV(4);
        // wait for crystal oscillator to begin
        while ((MCG_S & MCG_S_OSCINIT0) == 0) ;
        // wait for FLL to use oscillator
        while ((MCG_S & MCG_S_IREFST) != 0) ;
        // wait for MCGOUT to use oscillator
        while ((MCG_S & MCG_S_CLKST_MASK) != MCG_S_CLKST(2)) ;
        // now we're in FBE mode
        // config PLL input for 16 MHz Crystal / 4 = 4 MHz
        MCG_C5 = MCG_C5_PRDIV0(3);
        // config PLL for 96 MHz output
        MCG_C6 = MCG_C6_PLLS | MCG_C6_VDIV0(0);
        // wait for PLL to start using xtal as its input
        while (!(MCG_S & MCG_S_PLLST)) ;
        // wait for PLL to lock
        while (!(MCG_S & MCG_S_LOCK0)) ;
        // now we're in PBE mode
#if F_CPU == 96000000
        // config divisors: 96 MHz core, 48 MHz bus, 24 MHz flash
        SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1) |  SIM_CLKDIV1_OUTDIV4(3);
#elif F_CPU == 48000000
        // config divisors: 48 MHz core, 48 MHz bus, 24 MHz flash
        SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(1) | SIM_CLKDIV1_OUTDIV2(1) |  SIM_CLKDIV1_OUTDIV4(3);
#elif F_CPU == 24000000
        // config divisors: 24 MHz core, 24 MHz bus, 24 MHz flash
        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
        // switch to PLL as clock source, FLL input = 16 MHz / 512
        MCG_C1 = MCG_C1_CLKS(0) | MCG_C1_FRDIV(4);
        // wait for PLL clock to be used
        while ((MCG_S & MCG_S_CLKST_MASK) != MCG_S_CLKST(3)) ;
        // now we're in PEE mode
        // configure USB for 48 MHz clock
        SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(1); // USB = 96 MHz PLL / 2
        // USB uses PLL clock, trace is CPU clock, CLKOUT=OSCERCLK0
        SIM_SOPT2 = SIM_SOPT2_USBSRC | SIM_SOPT2_PLLFLLSEL | SIM_SOPT2_TRACECLKSEL | SIM_SOPT2_CLKOUTSEL(6);

        // initialize the SysTick counter
        SYST_RVR = (F_CPU / 1000) - 1;
        SYST_CSR = SYST_CSR_CLKSOURCE | SYST_CSR_TICKINT | SYST_CSR_ENABLE;

	//init_pins();
	__enable_irq();

	_init_Teensyduino_internal_();
	if (RTC_SR & RTC_SR_TIF) rtc_set(TIME_T);

	__libc_init_array();

/*
	for (ptr = &__init_array_start; ptr < &__init_array_end; ptr++) {
		(*ptr)();
	}
*/
	startup_late_hook();
        main();
        while (1) ;
}
Example #7
0
// Main
int main(void) {
    
    // Init
    
#if defined(ENERGIA) // LaunchPad, FraunchPad and StellarPad specific
#if defined(__LM4F120H5QR__) // StellarPad specific
    ROM_FPULazyStackingEnable();
    
    timerInit();
    
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
#else // LaunchPad and FraunchPad specific
    init();
#endif
    
#elif defined(CORE_TEENSY) // Teensy specific
    _init_Teensyduino_internal_();
    
#elif defined(WIRING) // Wiring specific
    boardInit();
    
#else // General case
    init();
    delay(1);
    
#if defined(ARDUINO) && (ARDUINO >= 100) // Arduino 1.0 + 1.5 specific
#if defined(USBCON) // Arduino 1.0 + 1.5 specific
    USBDevice.attach();
#endif
#endif
    
#endif
    
    // Setup
    
    setup();
    
    // Loop
    
    for (;;) {
        
        loop();
        
#if defined(ENERGIA)
#elif defined(MPIDE)
#elif defined(CORE_TEENSY)
#ifdef USB_SERIAL
        usb_serial_class Serial;
#endif
#elif defined(WIRING)
#elif defined(ARDUINO) && (ARDUINO >= 100) // Arduino 1.0 + 1.5 specific
        if (serialEventRun) serialEventRun();
#endif
    }
    
    return 0;
}