山东群英会开奖结果

(玩电子) 电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

TMS320F2812外设例程系列之SysCtrl

作者:佚名   来源:不详   点击数:x  更新时间:2014年08月17日   【字体:

 

 
//#####################################################################
//文件:  DSP281x_SysCtrl.c
//说明:  初始化系统控制
//#####################################################################
#include "DSP281x_Device.h"     
#include "DSP281x_Examples.h"  
#pragma CODE_SECTION(InitFlash, "ramfuncs");  //将InitFlash函数存在ramfuncs中
//InitSysCtrl:初始化系统控制
void InitSysCtrl(void)
{
   DisableDog();               //关看门狗
   InitPll(0xA);               //初始化PLL,用户要根据外部晶振的大小来改变实参
   InitPeripheralClocks();   //初始化外设时钟
}
//喂狗子程序,如果用户使用看门狗,就可以调用该子程序
void KickDog(void)
{
EALLOW;
    SysCtrlRegs.WDKEY = 0x0055;
    SysCtrlRegs.WDKEY = 0x00AA;
EDIS;
}
//关闭看门狗子程序,在初始系统时,或者用户不想使用看门狗,可以调用该程序
void DisableDog(void)
{
    EALLOW;
    SysCtrlRegs.WDCR= 0x0068;
    EDIS;
}
//初始化PLL
void InitPll(Uint16 val)
{
   volatile Uint16 iVol;
   if (SysCtrlRegs.PLLCR.bit.DIV != val)
   {
      EALLOW;
      SysCtrlRegs.PLLCR.bit.DIV = val;
      EDIS;
      DisableDog();                   //确保在进入下面循环前关闭看门狗
      for(iVol= 0; iVol< ( (131072/2)/12 ); iVol++)
      {
      }                             //等待周期
   }
}
//初始化外设时钟
void InitPeripheralClocks(void)
{
EALLOW;
   SysCtrlRegs.HISPCP.all = 0x0001;     //设定高速外设时钟预分频值
   SysCtrlRegs.LOSPCP.all = 0x0002;     //设定低速外设时钟预分频值 
   //对选定的外设进行外设时钟使能设置
   SysCtrlRegs.PCLKCR.bit.EVAENCLK=1;
   SysCtrlRegs.PCLKCR.bit.EVBENCLK=1;
   SysCtrlRegs.PCLKCR.bit.SCIAENCLK=1;
   SysCtrlRegs.PCLKCR.bit.SCIBENCLK=1;
   SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=1;
   SysCtrlRegs.PCLKCR.bit.SPIENCLK=1;
   SysCtrlRegs.PCLKCR.bit.ECANENCLK=1;
   SysCtrlRegs.PCLKCR.bit.ADCENCLK=1;
EDIS;
}
//=====================================================================
//本文件内还有一些与flash和CSM相关的子程序,不予列举,有兴趣的读者可以参考TI
//文献sprc097(可以到www.ti.com免费下载)。
//=====================================================================
 
 
//---------------------------------------------------------------------------
// Example: InitFlash:
//---------------------------------------------------------------------------
// This function initializes the Flash Control registers
 
//                   CAUTION
// This function MUST be executed out of RAM. Executing it
// out of OTP/Flash will yield unpredictable results
 
void InitFlash(void)
{
   EALLOW;
   //Enable Flash Pipeline mode to improve performance
   //of code executed from Flash.
   FlashRegs.FOPT.bit.ENPIPE = 1;
 
   //                CAUTION
   //Minimum waitstates required for the flash operating
   //at a given CPU rate must be characterized by TI.
   //Refer to the datasheet for the latest information.
 
   //Set the Random Waitstate for the Flash
   FlashRegs.FBANKWAIT.bit.RANDWAIT = 5;
 
   //Set the Paged Waitstate for the Flash
   FlashRegs.FBANKWAIT.bit.PAGEWAIT = 5;
 
   //                CAUTION
   //Minimum cycles required to move between power states
   //at a given CPU rate must be characterized by TI.
   //Refer to the datasheet for the latest information.
 
   //For now use the default count
   //Set number of cycles to transition from sleep to standby
   FlashRegs.FSTDBYWAIT.bit.STDBYWAIT = 0x01FF;
 
   //Set number of cycles to transition from standby to active
   FlashRegs.FACTIVEWAIT.bit.ACTIVEWAIT = 0x01FF;
   EDIS;
 
   //Force a pipeline flush to ensure that the write to
   //the last register configured occurs before returning.
 
   asm(" RPT #7 || NOP");
}
 
//---------------------------------------------------------------------------
// Example: CsmUnlock:
//---------------------------------------------------------------------------
// This function unlocks the CSM. User must replace 0xFFFF's with current
// password for the DSP. Returns 1 if unlock is successful.
#define STATUS_FAIL          0
#define STATUS_SUCCESS       1
 
Uint16 CsmUnlock()
{
    volatile Uint16 temp;
 
    // Load the key registers with the current password. The 0xFFFF's are dummy
// passwords.  User should replace them with the correct password for the DSP.
 
    EALLOW;
    CsmRegs.KEY0 = 0xFFFF;
    CsmRegs.KEY1 = 0xFFFF;
    CsmRegs.KEY2 = 0xFFFF;
    CsmRegs.KEY3 = 0xFFFF;
    CsmRegs.KEY4 = 0xFFFF;
    CsmRegs.KEY5 = 0xFFFF;
    CsmRegs.KEY6 = 0xFFFF;
    CsmRegs.KEY7 = 0xFFFF;
    EDIS;
 
    // Perform a dummy read of the password locations
    // if they match the key values, the CSM will unlock
 
    temp = CsmPwl.PSWD0;
    temp = CsmPwl.PSWD1;
    temp = CsmPwl.PSWD2;
    temp = CsmPwl.PSWD3;
    temp = CsmPwl.PSWD4;
    temp = CsmPwl.PSWD5;
    temp = CsmPwl.PSWD6;
    temp = CsmPwl.PSWD7;
 
    // If the CSM unlocked, return succes, otherwise return
    // failure.
    if (CsmRegs.CSMSCR.bit.SECURE == 0) return STATUS_SUCCESS;
    else return STATUS_FAIL;
 
}
 
//===========================================================================
// No more.
//===========================================================================
 

文章评论

北京赛车pk10玩法 秒速时时彩 青海快3 pk10怎么玩 天津快乐十分 555彩注册 南方彩票注册 海南4+1走势图 福建11选5官网 赖子棋牌