IAR是5.30版本,从官网上下的基于UCOSII2.84版本的移植范例(LPC2378),用J-LINK V6调试,为了节省空间,优化选项选择最高程度的代码量优化(之前选不优化,结果也是跑飞),结果发现在这里会跑飞(在flash中调,开发板SmartARM2300) static void Tmr_TickInit (void) { CPU_INT32U pclk_freq; CPU_INT32U rld_cnts;
/* VIC timer #0 Initialization */ VICIntSelect &= ~(1 << VIC_TIMER0); /* Configure the timer interrupt as an IRQ source */ VICVectAddr4 = (CPU_INT32U)Tmr_TickISR_Handler; /* Set the vector address */ VICIntEnable = (1 << VIC_TIMER0); /* Enable the timer interrupt source */
pclk_freq = BSP_CPU_PclkFreq(PCLK_TIMER0); /* Get the peripheral clock frequency */
rld_cnts = pclk_freq / OS_TICKS_PER_SEC; /* Calculate the # of counts necessary for the OS ticker */
T0TCR = (1 << 1); /* Disable and reset counter 0 and the prescale counter 0 */ T0TCR = 0; /* Clear the reset bit */ T0PC = 0; /* Prescaler is set to no division */
T0MR0 = rld_cnts; T0MCR = 3; /* Interrupt on MR0 (reset TC), stop TC */
T0CCR = 0; /* Capture is disabled. */ T0EMR = 0; /* No external match output. */ T0TCR = 1; /* Enable timer 0 */ }
就是在上面这个函数的pclk_freq = BSP_CPU_PclkFreq(PCLK_TIMER0);这一行,并且按F11跟进去,发现这个函数: CPU_INT32U BSP_CPU_ClkFreq (void) { CPU_INT32U msel; CPU_INT32U nsel=0x10000000; CPU_INT32U fin; CPU_INT32U pll_clk_feq; /* When the PLL is enabled, this is Fcco */ CPU_INT32U clk_div; CPU_INT32U clk_freq;
switch (CLKSRCSEL & 0x03) { /* Determine the current clock source */ case 0: fin = IRC_OSC_FRQ; break;
case 1: fin = MAIN_OSC_FRQ; break;
case 2: fin = RTC_OSC_FRQ; break;
default: fin = IRC_OSC_FRQ; break; }
if ((PLLSTAT & (1 << 25)) > 0) { /* If the PLL is currently enabled and connected */ msel = (CPU_INT32U)(PLLSTAT & 0x3FFF) + 1; /* Obtain the PLL multiplier */ nsel = (CPU_INT32U)((PLLSTAT >> 16) & 0x0F) + 1; /* Obtain the PLL divider */ pll_clk_feq = (2 * msel * (fin / nsel)); /* Compute the PLL output frequency */ } else { pll_clk_feq = (fin); /* The PLL is bypassed */ }
clk_div = (CPU_INT32U)(CCLKCFG & 0xFF) + 1; /* Obtain the CPU core clock divider */ clk_freq = (CPU_INT32U)(pll_clk_feq / clk_div); /* Compute the ARM Core clock frequency */
return (clk_freq); } 跟踪到nsel = (CPU_INT32U)((PLLSTAT >> 16) & 0x0F) + 1;这一行时候,发现nsel为unavailable,即使在这之前已经给nsel取了0作为初值。在这一行再往下跟,就飞了。 |