打印

(转)LPC2368一些基本测试程序2 TargetResetInit

[复制链接]
2275|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
txcy|  楼主 | 2009-10-14 16:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
void TargetResetInit(void)
{
#ifdef __DEBUG_RAM   
     MEMMAP = 0x2;                     // remap
#endif
#ifdef __DEBUG_FLASH   
     MEMMAP = 0x1;                    // remap
#endif
#ifdef __IN_CHIP   
     MEMMAP = 0x1;                    // remap
#endif

if ( PLLSTAT & (1 << 25) )    // if the PLL was connected
    {
  PLLCON  = 0x01;         
  PLLFEED = 0xAA;      // disconnect the PLL
  PLLFEED = 0x55;
  PLLCON  = 0x00;         
  PLLFEED = 0xAA;      // disable the PLL
  PLLFEED = 0x55;   
    }  
else if ( PLLSTAT & (1 << 24) )   // if the PLL was enabled                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   // 如果PLL已被使能,则先禁止PLL
    {
  PLLCON  = 0x00;         
  PLLFEED = 0xAA;      // disable the PLL
  PLLFEED = 0x55;
    }
      
SCS |= 0x20;       // Enable the main OSC,,1MHz~20MHz
    while( !(SCS & 0x40) );     // Wait until main OSC is usable
   
PLLCON = 1;        // Enable but disconnect the PLL
    CLKSRCSEL = 0x01;      // select main OSC as the PLL clock source
    PLLCFG  = ( ( (PLL_NValue-1) << 16)  | (PLL_MValue-1) );   // set the PLLCFG  
    PLLFEED = 0xAA;       // Enable PLL
    PLLFEED = 0x55;
    while (((PLLSTAT & (1 << 24)) == 0)); // Wait until the PLL is usable
    CCLKCFG = (Fcco/Fcclk - 1);    // set the CCLKCFG  
  PLLCON = 3;        // connect the PLL
    PLLFEED = 0xAA;
    PLLFEED = 0x55;      
while (((PLLSTAT & (3 << 25)) == 0)); // Wait until the PLL is connected and locked
    #if USE_USB
     PCONP |= 0x80000000;    // Turn On the USB PCLK
     USBCLKCFG = (Fcco/Fusbclk - 1);      
#endif
// Set system timers for each component
#if (Fpclk / (Fcclk / 4)) == 1
     PCLKSEL0 = 0x00000000;    // PCLK is 1/4 CCLK
     PCLKSEL1 = 0x00000000;
#endif
#if (Fpclk / (Fcclk / 4)) == 2
     PCLKSEL0 = 0xAAAAAAAA;    // PCLK is 1/2 CCLK
     PCLKSEL1 = 0xAAAAAAAA;  
#endif
#if (Fpclk / (Fcclk / 4)) == 4
     PCLKSEL0 = 0x55555555;    // PCLK is the same as CCLK
     PCLKSEL1 = 0x55555555;
#endif

    // Set memory accelerater module     
       MAMCR = 0;
#if Fcclk < 20000000
     MAMTIM = 1;
#else
#if Fcclk < 40000000
     MAMTIM = 2;
#else
     MAMTIM = 3;
#endif
#endif
     MAMCR = 2;      
/* Initialize VIC*/  
VICIntEnClr = 0xffffffff;
    VICVectAddr = 0;
   
   
    /* Add your codes here */
    return;
}

重点在于启动主晶振
SCS |= 0x20;       // Enable the main OSC,,1MHz~20MHz
    while( !(SCS & 0x40) );     // Wait until main OSC is usable

相关帖子

沙发
txcy|  楼主 | 2009-10-14 16:48 | 只看该作者
LPC2368一些基本测试程序1 IRQ.c
/*****************************************************************************************************
//函数名:uint32 install_irq( uint32 IntNumber, void *HandlerAddr, uint32 Priority )
//描述  :
//参数  :
//返回  :
//其他  :
********************************************************************************************************/
uint32 install_irq( uint32 IntNumber, void *HandlerAddr, uint32 Priority )
{
    uint32 *vect_addr;
    uint32 *vect_cntl;
      
    VICIntEnClr = 1 << IntNumber; /// Disable Interrupt
    if ( IntNumber >= VIC_SIZE )
    {
  return ( FALSE );
    }
    else
    {
  // find first un-assigned VIC address for the handler
  vect_addr = (uint32 *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + IntNumber*4);
  vect_cntl = (uint32 *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + IntNumber*4);
  *vect_addr = (uint32)HandlerAddr; // set interrupt vector
  *vect_cntl = Priority;
  VICIntEnable = 1 << IntNumber; // Enable Interrupt
  return( TRUE );
    }
}

和LPC21xx不同,LPC2368的vic的vect_addr 和中断号码是一样对应的。

使用特权

评论回复
板凳
华荣汇FAE3| | 2009-10-14 16:59 | 只看该作者
呵呵,谢谢楼上,辛苦了!:P

使用特权

评论回复
地板
hsbjb| | 2009-10-15 09:36 | 只看该作者
楼主辛苦了,不过程序的注释要是再详细点就更好了

使用特权

评论回复
5
无冕之王| | 2009-10-16 19:21 | 只看该作者
应该说明一下程序的作用。。。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

274

主题

2106

帖子

0

粉丝