Ejemplo n.º 1
0
/*!
 * \brief   Kinetis Start
 * \return  None
 *
 * This function calls all of the needed starup routines and then 
 * branches to the main process.
 */
void start(void)
{ 
	/* Disable the watchdog timer */
	wdog_disable();

	/* Copy any vector or data sections that need to be in RAM */
	common_startup();

	/* Perform processor initialization */
	sysinit();
        
        printf("\n\n");
        
	/* Determine the last cause(s) of reset */
        outSRS();

	/* Determine specific Kinetis device and revision */
	cpu_identify();
	
	/* Jump to main process */
	main();

	/* No actions to perform after this so wait forever */
	while(1);
}
Ejemplo n.º 2
0
void pre_reset_handler(void)
{
    /*
     * Important: Keep this function as simple as possible, we must not use any
     * stack space or we will crash, since we will overwrite all of the stack.
     */
    /* Disable watchdog first, it is necessary to do within 256 cycles.
     * After this we will completely overwrite the stack so all necessary
     * variables must be stored in registers or as immediate values in the
     * machine code. */
    wdog_disable();
    /*
     * The register keyword suggests to the compiler to place the variable in a
     * register instead of on the stack. Using the register keyword is not a
     * guarantee that the variable will be placed in a register. However, this
     * function has been verified manually by disassembling the GCC output to
     * ensure no stack is being used until after the write loop is finished.
     */
    register uint32_t *p;

    /* Fill stack space with canary values */
    for (p = (uint32_t *)_sstack; p < (uint32_t *)_estack; ++p) {
        *p = STACK_CANARY_WORD;
    }

    /* Now launch the real reset handler. */
    __ASM volatile("b reset_handler\n");

    /* reset_handler should never return */
    while (1);
}
Ejemplo n.º 3
0
/*!
 * \brief   Kinetis Start
 * \return  None
 *
 * This function calls all of the needed starup routines and then
 * branches to the main process.
 */
void start(void)
{
//#ifdef DEBUG
    /* 关闭看门狗 */
    wdog_disable();
//#endif

    /* 复制中断向量表、初始化数据、以__ramfunc声明的子函数复制到RAM区 */
    common_startup();

    /* CPU初始化,设置频率 */
    sysinit();

#if (defined(DEBUG) && defined(DEBUG_PRINT))

    printf("\n\n\t\t野火kinetis核心板测试程序\n");
    printf("内核频率:%dMHz\t总线频率 :%dMHz\nflex频率:%dMHz \tflash频率:%dMHz\n\n",\
           core_clk_mhz,core_clk_mhz/(mcg_div.bus_div+1),core_clk_mhz/(mcg_div.flex_div+1),core_clk_mhz/(mcg_div.flash_div+1));
    /* Determine the last cause(s) of reset */
    if (MC_SRSH & MC_SRSH_SW_MASK)
        printf("Software Reset\n");
    if (MC_SRSH & MC_SRSH_LOCKUP_MASK)
        printf("Core Lockup Event Reset\n");
    if (MC_SRSH & MC_SRSH_JTAG_MASK)
        printf("JTAG Reset\n");
    if (MC_SRSL & MC_SRSL_POR_MASK)
        printf("Power-on Reset\n");
    if (MC_SRSL & MC_SRSL_PIN_MASK)
        printf("External Pin Reset\n");
    if (MC_SRSL & MC_SRSL_COP_MASK)
        printf("Watchdog(COP) Reset\n");
    if (MC_SRSL & MC_SRSL_LOC_MASK)
        printf("Loss of Clock Reset\n");
    if (MC_SRSL & MC_SRSL_LVD_MASK)
        printf("Low-voltage Detect Reset\n");
    if (MC_SRSL & MC_SRSL_WAKEUP_MASK)
        printf("LLWU Reset\n");	

    /* 这两个数组的地址 在  链接器Linker文件,即ICF文件 定义 */
    extern uint32 __VECTOR_TABLE[];
    extern uint32 __VECTOR_RAM[];

    /* 检测是否需要 复制中断向量表,即可以知道是ROM启动还是RAM启动*/
    printf("\n野火Kinetis开发板启动方式:");
    if (__VECTOR_RAM != __VECTOR_TABLE)     printf("flash启动\n");
    else                                    printf("SRAM启动\n");

    /* Determine specific Kinetis device and revision */
    cpu_identify();

#endif  //DUBUG && DEBUG_PRINT

    /* 跳进main函数 */
    main();

    /* 保证CPU不会停止执行 */
    while(1);
}
Ejemplo n.º 4
0
Archivo: start.c Proyecto: MorS25/amcfc
//-------------------------------------------------------------------------*
//函数名: start                                                            *
//功  能: 系统启动                                                         * 
//参  数: 无								   *	
//说  明: 无                                                               *
//-------------------------------------------------------------------------*
void start(void)
{
    //关闭看门狗
    wdog_disable();		
    //复制中断向量表到RAM中
    common_startup();	
    //系统设置
    sysinit();			
    //进入主函数
    main();				
}
Ejemplo n.º 5
0
void pre_startup(void)
{
    /* disable the WDOG */
    wdog_disable();
#ifdef SIM_SCGC7_FLEXBUS_SHIFT
    /*
     * Workaround for hardware errata e4218: "SIM/FLEXBUS: SIM_SCGC7[FLEXBUS]
     * bit should be cleared when the FlexBus is not being used."
     */
    BITBAND_REG32(SIM->SCGC7, SIM_SCGC7_FLEXBUS_SHIFT) = 0;
#endif
}
Ejemplo n.º 6
0
/*!
 * \brief   Kinetis Start
 * \return  None
 *
 * This function calls all of the needed starup routines and then 
 * branches to the main process.
 */
void start(void)
{ 
	/* Disable the watchdog timer */
	wdog_disable();

	/* Copy any vector or data sections that need to be in RAM */
	common_startup();
	
	/* Jump to main process */
	main();

	/* No actions to perform after this so wait forever */
	while(1);
}
/*
 * 描述: Kinetis启动代码
 * 返回值: 无
 *
 * This function calls all of the needed starup routines and then 
 * branches to the main process.
 */
void start(void)
{
	/* 禁用看门狗定时器 */
	wdog_disable();

	/* 复制需要用到的中断向量表和数据段到RAM中 */
	common_startup();

	/* 执行处理器初始化 */
	sysinit();
        
#if(defined(DEBUG_PRINT))   

	if (MC_SRSH & MC_SRSH_SW_MASK)
		printf("Software Reset\r\n");
	if (MC_SRSH & MC_SRSH_LOCKUP_MASK)
		printf("Core Lockup Event Reset\r\n");
	if (MC_SRSH & MC_SRSH_JTAG_MASK)
		printf("JTAG Reset\r\n");
	
	if (MC_SRSL & MC_SRSL_POR_MASK)
		printf("Power-on Reset\r\n");
	if (MC_SRSL & MC_SRSL_PIN_MASK)
		printf("External Pin Reset\r\n");
	if (MC_SRSL & MC_SRSL_COP_MASK)
		printf("Watchdog(COP) Reset\r\n");
	if (MC_SRSL & MC_SRSL_LOC_MASK)
		printf("Loss of Clock Reset\r\n");
	if (MC_SRSL & MC_SRSL_LVD_MASK)
		printf("Low-voltage Detect Reset\r\n");
	if (MC_SRSL & MC_SRSL_WAKEUP_MASK)
		printf("LLWU Reset\r\n");	
	

	/* Determine specific Kinetis device and revision */
	cpu_identify();
#endif
	
	/* 执行main主函数 */
	main();

	/* 无限等待 */
	while(1);
}
Ejemplo n.º 8
0
/*!
 * \brief   Kinetis Start
 * \return  None
 *
 * This function calls all of the needed starup routines and then 
 * branches to the main process.
 */
void start(void)
{
	/* Disable the watchdog timer */
	wdog_disable();

	/* Copy any vector or data sections that need to be in RAM */
	common_startup();

	/* Perform processor initialization */
	sysinit();
        
    printf("\n\n");
	
	/* Determine the last cause(s) of reset */
	if (MC_SRSH & MC_SRSH_SW_MASK)
		printf("Software Reset\n");
	if (MC_SRSH & MC_SRSH_LOCKUP_MASK)
		printf("Core Lockup Event Reset\n");
	if (MC_SRSH & MC_SRSH_JTAG_MASK)
		printf("JTAG Reset\n");
	
	if (MC_SRSL & MC_SRSL_POR_MASK)
		printf("Power-on Reset\n");
	if (MC_SRSL & MC_SRSL_PIN_MASK)
		printf("External Pin Reset\n");
	if (MC_SRSL & MC_SRSL_COP_MASK)
		printf("Watchdog(COP) Reset\n");
	if (MC_SRSL & MC_SRSL_LOC_MASK)
		printf("Loss of Clock Reset\n");
	if (MC_SRSL & MC_SRSL_LVD_MASK)
		printf("Low-voltage Detect Reset\n");
	if (MC_SRSL & MC_SRSL_WAKEUP_MASK)
		printf("LLWU Reset\n");	
	

	/* Determine specific Kinetis device and revision */
	cpu_identify();
	
	/* Jump to main process */
	main();

	/* No actions to perform after this so wait forever */
	while(1);
}
/*!
 * \brief   Kinetis Start
 * \return  None
 *
 * This function calls all of the needed starup routines and then 
 * branches to the main process.
 */
void start(void)
{
	/* Disable the watchdog timer */
	wdog_disable();

	/* Copy any vector or data sections that need to be in RAM */
	common_startup();

	/* Perform processor initialization */
	sysinit();
        
    /* Determine the flash revision */
    flash_identify();    

	/* Jump to main process */
	main();

	/* No actions to perform after this so wait forever */
	while(1);
}
Ejemplo n.º 10
0
/*
 * Panic is called on unresolvable fatal errors.  It prints "panic: mesg",
 * and then reboots.  If we are called twice, then we avoid trying to sync
 * the disks as this often leads to recursive panics.
 */
void
panic(const char *fmt, ...)
{
	int bootopt, newpanic;
	globaldata_t gd = mycpu;
	thread_t td = gd->gd_curthread;
	__va_list ap;
	static char buf[256];

#ifdef SMP
	/*
	 * If a panic occurs on multiple cpus before the first is able to
	 * halt the other cpus, only one cpu is allowed to take the panic.
	 * Attempt to be verbose about this situation but if the kprintf() 
	 * itself panics don't let us overrun the kernel stack.
	 *
	 * Be very nasty about descheduling our thread at the lowest
	 * level possible in an attempt to freeze the thread without
	 * inducing further panics.
	 *
	 * Bumping gd_trap_nesting_level will also bypass assertions in
	 * lwkt_switch() and allow us to switch away even if we are a
	 * FAST interrupt or IPI.
	 *
	 * The setting of panic_cpu_gd also determines how kprintf()
	 * spin-locks itself.  DDB can set panic_cpu_gd as well.
	 */
	for (;;) {
		globaldata_t xgd = panic_cpu_gd;

		/*
		 * Someone else got the panic cpu
		 */
		if (xgd && xgd != gd) {
			crit_enter();
			++mycpu->gd_trap_nesting_level;
			if (mycpu->gd_trap_nesting_level < 25) {
				kprintf("SECONDARY PANIC ON CPU %d THREAD %p\n",
					mycpu->gd_cpuid, td);
			}
			td->td_release = NULL;	/* be a grinch */
			for (;;) {
				lwkt_deschedule_self(td);
				lwkt_switch();
			}
			/* NOT REACHED */
			/* --mycpu->gd_trap_nesting_level */
			/* crit_exit() */
		}

		/*
		 * Reentrant panic
		 */
		if (xgd && xgd == gd)
			break;

		/*
		 * We got it
		 */
		if (atomic_cmpset_ptr(&panic_cpu_gd, NULL, gd))
			break;
	}
#else
	panic_cpu_gd = gd;
#endif
	/*
	 * Try to get the system into a working state.  Save information
	 * we are about to destroy.
	 */
	kvcreinitspin();
	if (panicstr == NULL) {
		bcopy(td->td_toks_array, panic_tokens, sizeof(panic_tokens));
		panic_tokens_count = td->td_toks_stop - &td->td_toks_base;
	}
	lwkt_relalltokens(td);
	td->td_toks_stop = &td->td_toks_base;

	/*
	 * Setup
	 */
	bootopt = RB_AUTOBOOT | RB_DUMP;
	if (sync_on_panic == 0)
		bootopt |= RB_NOSYNC;
	newpanic = 0;
	if (panicstr) {
		bootopt |= RB_NOSYNC;
	} else {
		panicstr = fmt;
		newpanic = 1;
	}

	/*
	 * Format the panic string.
	 */
	__va_start(ap, fmt);
	kvsnprintf(buf, sizeof(buf), fmt, ap);
	if (panicstr == fmt)
		panicstr = buf;
	__va_end(ap);
	kprintf("panic: %s\n", buf);
#ifdef SMP
	/* two separate prints in case of an unmapped page and trap */
	kprintf("cpuid = %d\n", mycpu->gd_cpuid);
#endif

#if (NGPIO > 0) && defined(ERROR_LED_ON_PANIC)
	led_switch("error", 1);
#endif

#if defined(WDOG_DISABLE_ON_PANIC) && defined(WATCHDOG_ENABLE)
	wdog_disable();
#endif

	/*
	 * Enter the debugger or fall through & dump.  Entering the
	 * debugger will stop cpus.  If not entering the debugger stop
	 * cpus here.
	 */
#if defined(DDB)
	if (newpanic && trace_on_panic)
		print_backtrace(-1);
	if (debugger_on_panic)
		Debugger("panic");
	else
#endif
#ifdef SMP
	if (newpanic)
		stop_cpus(mycpu->gd_other_cpus);
#else
	;
#endif
	boot(bootopt);
}
Ejemplo n.º 11
0
void pre_startup(void)
{
    /* disable the WDOG */
    wdog_disable();
    cpu_errata_fixes();
}