<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

        TMS320F2812外設例程系列之SysCtrl

        作者:佚名   來源:不詳   點擊數:  更新時間: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.
        //===========================================================================
         
        關閉窗口
        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮