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

📄 davincievm_psc.c

📁 开发环境CCS3.2,为TI最新处理器TMS320DM6446的网卡驱动程序源码
💻 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"

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_initPsc( )                                                   *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_initPsc( )
{
    return 0;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  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( )
{
    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;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  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( )
{
    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;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  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( )
{
    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;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_enablePowerModule( domain, id )                              *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_enablePowerModule( Uint32 domain, Uint32 id )
{
    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;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_disablePowerModule( domain, id )                             *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_disablePowerModule( Uint32 domain, Uint32 id )
{
    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;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_resetPowerModule( domain, id )                               *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_resetPowerModule( Uint32 domain, Uint32 id )
{
    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;
}

⌨️ 快捷键说明

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