⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 davincievm_psc.c

📁 TI的DM6446的硬件平台搭建的相关例子
💻 C
字号:
/*
 *  Copyright 2005 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 *
 *  Not for distribution.
 */

/*
 *  Board Setup ( for ARM and/or DSP )
 *
 */

#include "davincievm_psc.h"

#ifdef ARM_SIDE

    #include "csl_psc.h"
    CSL_PscHandle psc_handle;
    CSL_PscObj    psc_obj;

#elif DSP_SIDE
    
#endif

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_initPsc( )                                                   *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_initPsc( )
{
    #ifdef ARM_SIDE

        CSL_Status status;

        CSL_pscInit( );
        psc_handle = CSL_pscOpen( &psc_obj, 0, 0, &status );

        return 0;

    #elif DSP_SIDE

        return 0;

    #endif
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_enableDspPowerDomain( )                                      *
 *                                                                          *
 *      The "Power Domain" controls all the modules below it.  There are    *
 *      only 2 domains ALWAYSON and DSP.  This function will only be able   *
 *      to affect the DSP power domain.                                     *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_enableDspPowerDomain( )
{
    #ifdef ARM_SIDE

        if ( CSL_pscHwControl( psc_handle, CSL_PSC_CMD_DSP_PWR_ON, 0 ) == CSL_SOK )
            return 0;
        else
            return 1;

    #elif DSP_SIDE

        Uint32 dspdomainbit = 0x0002;

        while( ( PSC_PTSTAT & dspdomainbit ) != 0 );    // Wait for state transtion to finish
        PSC_PDCTL1 |= 0x0001;                           // Turn ON power domain
        PSC_PTCMD = dspdomainbit;                       // Start state transition
        while( ( PSC_EPCPR & dspdomainbit ) == 0 );     // Wait for external power request

        /*
         *  Apply External Power if needed.
         */

        PSC_PDCTL1 |= 0x0100;                           // Turn ON external power
        while( ( PSC_PTSTAT & dspdomainbit ) != 0 );    // Wait for state transtion to finish
        return 0;

    #endif
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_disableDspPowerDomain( )                                     *
 *                                                                          *
 *      The "Power Domain" controls all the modules below it.  There are    *
 *      only 2 domains ALWAYSON and DSP.  This function will only be able   *
 *      to affect the DSP power domain.                                     *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_disableDspPowerDomain( )
{
    #ifdef ARM_SIDE

        if ( CSL_pscHwControl( psc_handle, CSL_PSC_CMD_DSP_PWR_OFF, 0 ) == CSL_SOK )
            return 0;
        else
            return 1;

    #elif DSP_SIDE

        Uint32 dspdomainbit = 0x0002;

        while( ( PSC_PTSTAT & dspdomainbit ) != 0 );    // Wait for state transtion to finish
        PSC_PDCTL1 &= ~0x0001;                          // Turn OFF power domain
        PSC_PTCMD = dspdomainbit;                       // Start state transition
        while( ( PSC_EPCPR & dspdomainbit ) == 0 );     // Wait for external power request

        /*
         *  Remove External Power if needed ???
         */

        PSC_PDCTL1 &= ~0x0100;                          // Turn ON external power
        while( ( PSC_PTSTAT & dspdomainbit ) != 0 );    // Wait for state transtion to finish

        return 0;

    #endif
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_enableAllPowerModules( )                                     *
 *                                                                          *
 *      This turns on all clocks in ALWAYSON and DSP power domains.         *
 *      Note this function assumes that the Power Domains are already on.   *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_enableAllPowerModules( )
{
    #ifdef ARM_SIDE

        if ( CSL_pscHwControl( psc_handle, CSL_PSC_CMD_MD_STATE_ENABLE_ALL, 0 ) == CSL_SOK )
            return 0;
        else
            return 1;

    #elif DSP_SIDE

        Int16 i;
        volatile Uint32* mdctl = ( Uint32* )PSC_MDCTL_BASE;
        Uint8 module_intr_list[15] = { 1,5,6,7,9,10,11,12,13,14,15,16,17,26,40 } ;

        for ( i = 0 ; i < 41 ; i++ )                    // Enable all 41 power modules
            *mdctl++ |= 0x0003;

        for ( i = 0 ; i < 15 ; i++ )                    // Enable Interrupts for these modules
            *( Uint32* )( PSC_MDCTL_BASE + 4 * module_intr_list[i] ) |= 0x0200;

        *( Uint32* )( PSC_MDCTL_BASE + 4 * 8 ) = 0x000; // IEEE1394A - OFF

        PSC_PTCMD = 0x0001;                             // ALWAYSON domain state transition
        while( ( PSC_PTSTAT & 0x0001 ) != 0 );

        PSC_PTCMD = 0x0002;                             // DSP domain state transition
        while( ( PSC_PTSTAT & 0x0002 ) != 0 );

        for ( i = 0 ; i < 15 ; i++ )                    // Clear Interrupts for these modules
            *( Uint32* )( PSC_MDCTL_BASE + 4 * module_intr_list[i] ) &= 0xFDFF;

        return 0;

    #endif
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_enablePowerModule( domain, id )                              *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_enablePowerModule( Uint32 domain, Uint32 id )
{
    #ifdef ARM_SIDE    

        CSL_PscMdCfg psc_mdcfg;
        psc_mdcfg.mdId          = ( CSL_PscMdId* )&id;  // Module ID(s)
        psc_mdcfg.numMds        = 1;                    // # Modules
        psc_mdcfg.mdState       = 0;                    // Module State(s)
        psc_mdcfg.mdIntEnable   = 0;                    // Module Interrupt(s)
        psc_mdcfg.mdStateRecord = 0;                    // Current state

        if ( CSL_pscHwControl( psc_handle, CSL_PSC_CMD_MD_STATE_ENABLE, &psc_mdcfg ) == CSL_SOK )
            return 0;
        else
            return 1;

    #elif DSP_SIDE

        Uint32 domainbit = ( 1 << ( domain & 1 ) );

        Uint8 enableinterrupts = 0;
        volatile Uint32* mdstat = ( Uint32* )( PSC_MDSTAT_BASE + 4 * id );
        volatile Uint32* mdctl  = ( Uint32* )( PSC_MDCTL_BASE  + 4 * id );

        if ( domain == DSP_POWER_DOMAIN )               // Check if we are talking about DSP domain
            if ( ( PSC_PDSTAT1 & 0x0001F ) == 0 )       // No power to DSP domain
                DAVINCIEVM_enableDspPowerDomain( );     // Enable power

        /*
         *  Check for one of the following:
         *      VPSS, USB, ATA, VLYNQ, HPI, DDR, AEMIF,
         *      MMCSD, MemStk, ASP, GPIO, & IMCOP
         *
         *  Then set the EMURSTIE bit
         */

        if (   ( id == 1 )
            || ( ( id >= 5 ) && ( id <= 7 ) )
            || ( ( id >= 9 ) && ( id <= 17 ) )
            || ( id == 26 ) || ( id == 40 ) )
        {
            enableinterrupts = 1;
        }

        while( ( PSC_PTSTAT & domainbit ) != 0 );       // Wait for state transtion to finish
        *mdctl |= ~0x001F;                              // Clear next module state
        *mdctl |= 0x0003;                               // Set next module state to ENABLE

        if ( enableinterrupts )
           * mdctl |= 0x0200;                           // Enable interrupts

        PSC_PTCMD = domainbit;                          // Start power state transition
        while( ( PSC_PTSTAT & domainbit ) != 0 );       // Wait for power state transtion to finish
        while( ( *mdstat & 0x001F ) != 0x0003 );        // Wait for module state enable

        return 0;

    #endif
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_disablePowerModule( domain, id )                             *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_disablePowerModule( Uint32 domain, Uint32 id )
{
    #ifdef ARM_SIDE

        CSL_PscMdCfg psc_mdcfg;
        psc_mdcfg.mdId          = ( CSL_PscMdId* )&id;  // Module ID(s)
        psc_mdcfg.numMds        = 1;                    // # Modules
        psc_mdcfg.mdState       = 0;                    // Module State(s)
        psc_mdcfg.mdIntEnable   = 0;                    // Module Interrupt(s)
        psc_mdcfg.mdStateRecord = 0;                    // Current state

        if ( CSL_pscHwControl( psc_handle, CSL_PSC_CMD_MD_STATE_DISABLE, &psc_mdcfg ) == CSL_SOK )
            return 0;
        else
            return 1;

    #elif DSP_SIDE

        Uint32 domainbit = ( 1 << ( domain & 1 ) );

        Uint8 enableinterrupts = 0;
        volatile Uint32* mdstat = ( Uint32* )( PSC_MDSTAT_BASE + 4 * id );
        volatile Uint32* mdctl  = ( Uint32* )( PSC_MDCTL_BASE  + 4 * id );

        /*
         *  Check for one of the following:
         *      VPSS, USB, ATA, VLYNQ, HPI, DDR, AEMIF,
         *      MMCSD, MemStk, ASP, GPIO, & IMCOP
         *
         *  Then set the EMURSTIE bit
         */

        if (   ( id == 1 )  || ( ( id >= 9 ) && ( id <= 17 ) )
            || ( id == 26 ) || ( id == 40 ) )
        {
            enableinterrupts = 1;
        }

        while( ( PSC_PTSTAT & domainbit ) != 0 );       // Wait for state transtion to finish
        *mdctl |= ~0x001F;                              // Clear next module state
        *mdctl |= 0x0002;                               // Set next module state to DISABLE

        if ( enableinterrupts )
            *mdctl |= 0x0200;                           // Enable interrupts

        PSC_PTCMD = domainbit;                          // Start power state transition
        while( ( PSC_PTSTAT & domainbit ) != 0 );       // Wait for power state transtion to finish
        while( ( *mdstat & 0x001F ) != 0x0002 );        // Wait for module state enable

        return 0;

    #endif
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_resetPowerModule( domain, id )                               *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_resetPowerModule( Uint32 domain, Uint32 id )
{
    #ifdef ARM_SIDE

        CSL_PscMdState psc_mdstate  = CSL_PSC_MD_STATE_SYNCRST;
        CSL_PscMdCfg   psc_mdcfg;
        psc_mdcfg.mdId          = ( CSL_PscMdId* )&id;  // Module ID(s)
        psc_mdcfg.numMds        = 1;                    // # Modules
        psc_mdcfg.mdState       = &psc_mdstate;         // Module State(s)
        psc_mdcfg.mdIntEnable   = 0;                    // Module Interrupt(s)
        psc_mdcfg.mdStateRecord = 0;                    // Current state

        if ( CSL_pscHwControl( psc_handle, CSL_PSC_CMD_MD_STATE_CFG, &psc_mdcfg ) == CSL_SOK )
            return 0;
        else
            return 1;

    #elif DSP_SIDE

        Uint32 domainbit = ( 1 << ( domain & 1 ) );

        Uint8 enableinterrupts = 0;
        volatile Uint32* mdstat = ( Uint32* )( PSC_MDSTAT_BASE + 4 * id );
        volatile Uint32* mdctl  = ( Uint32* )( PSC_MDCTL_BASE  + 4 * id );

        /*
         *  Check for one of the following:
         *      VPSS, USB, ATA, VLYNQ, HPI, DDR, AEMIF,
         *      MMCSD, MemStk, ASP, GPIO, & IMCOP
         *
         *  Then set the EMURSTIE bit
         */

        if (   ( id == 1 )  || ( ( id >= 9 ) && ( id <= 17 ) )
            || ( id == 26 ) || ( id == 40 ) )
        {
            enableinterrupts = 1;
        }

        while( ( PSC_PTSTAT & domainbit ) != 0 );       // Wait for state transtion to finish
        *mdctl |= ~0x001F;                              // Clear next module state
        *mdctl |= 0x0001;                               // Set next module state to DISABLE

        if ( enableinterrupts )
            *mdctl |= 0x0200;                           // Enable interrupts

        PSC_PTCMD = domainbit;                          // Start power state transition
        while( ( PSC_PTSTAT & domainbit ) != 0 );       // Wait for power state transtion to finish
        while( ( *mdstat & 0x001F ) != 0x0001 );        // Wait for module state enable

        return 0;

    #endif
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -