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

📄 illumination.c

📁 IT projecotr reference design.
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************/
/*             TEXAS INSTRUMENTS PROPRIETARY INFORMATION                    */
/*                                                                          */
/*  (c) Copyright, Texas Instruments Incorporated, 2006.                    */
/*      All Rights Reserved.                                                */
/*                                                                          */
/*  Property of Texas Instruments Incorporated. Restricted Rights -         */
/*  Use, duplication, or disclosure is subject to restrictions set          */
/*  forth in TI's program license agreement and associated documentation.   */
/****************************************************************************/

/****************************************************************************/
/* illumination.c                                                           */
/*                                                                          */
/* Illumination manager: Incorporates control of lamp and related color     */
/* wheel functionality.                                                     */
/****************************************************************************/

#include "common.h"
#include "ddp2230_rtos_include.h"
#include "lmp.h"
#include "lmp_blst.h"
#include "cw.h"
#include "ddp.h"
#include "seq.h"
#include "dmd.h"
#include "pmd.h"
#include "tmr.h"
#include "frame.h"
#include "gpio.h"

#include "main.h"
#include "sysmon.h"
#include "eeprom.h"
#include "global.h"
#include "gpioFunction.h"
#include "dbmessage.h"
#include "illumination.h"
#include "environment.h"
#include "datapath.h"


/****************************************************************************/
/* Definitions and constants.                                               */
/****************************************************************************/

#define LAMPUSE_UPDATE      360000             /* 0.1 hour, in milliseconds */
#define LAMPUSE_COUNT     ( LAMPUSE_UPDATE / LAMP_PERIOD )  /* update count */



/****************************************************************************/
/* Local data.                                                              */
/****************************************************************************/

static uint16 lampOnTime[4];                             /* usage registers */
static uint16 lampUseCount;                                   /* lamp timer */
static BOOL   illumEnabled;                 /* illumination-is-enabled flag */

                        /****************************************************/
                        /* When any kind of reset occurs, reStrike is set   */
                        /* FALSE. It is set TRUE on the first lamp strike   */
                        /* reset after power up.                            */
                        /****************************************************/

static BOOL reStrike = FALSE;


/****************************************************************************/
/* Local functions.                                                         */
/****************************************************************************/

static BOOL _strikeLamp( void );

static uint16 _millisecToLampEnable( uint16 delay );
static uint16 _millisecToLampStrikeReset( uint16 delay );


/****************************************************************************/
/* Module reset function.                                                   */
/*                                                                          */
/* id:   reset type.                                                        */
/****************************************************************************/

EXEC_CC_ENUM illum_init( void )
{
    int08  cc;                                           /* completion code */
    uint16 delay;                                             /* delay time */

    illumEnabled = FALSE;                       /* illumination not enabled */

                        /****************************************************/
                        /* Initialize lamp.                                 */
                        /****************************************************/

    EE_GETVAR( UserSystem.LampTime, lampOnTime );    /* get usage registers */
    lampUseCount = LAMPUSE_COUNT >> 1; /* set midrange; implements roundoff */

    delay = _millisecToLampEnable( gpConfiguration -> Illum.LampEnableDelay );
    LMP_SetLampEnableDelay( delay );

    delay = _millisecToLampStrikeReset( gpConfiguration -> Illum.LampStrikeResetDelay );
    LMP_SetLampStrikeResetDelay( delay );

    GPIO_SetPinConfig( GIO_LAMP_HOT, GIOCFG_INPUT, FALSE, GIOCFG_ACTIVE );

                        /****************************************************/
                        /* Initialize DMD.                                  */
                        /****************************************************/

    if( PASS != ( cc = DMD_Init()))
        dbmsg_trace( DBM_ALWAYS, "Can't initialize DMD\r\n" );

    return ( cc == PASS ) ? EXEC_CC_PASS : EXEC_CC_FAIL;
}



/****************************************************************************/
/* Set illumination to standby mode.                                        */
/****************************************************************************/

EXEC_CC_ENUM illum_powerStandby( void )
{
    BOOL pass = TRUE;                /* assume all API operations will pass */

    dbmsg_trace( DBM_ILLUM, "Illumination: Transition to standby\r\n" );

    if( LMP_IsLampLit() || illumEnabled )       /* start cooldown if needed */
    {
        dbmsg_trace( DBM_ILLUM, "Start cooldown timer\r\n" );
        enviro_startCooldown();
    }

    illumEnabled = FALSE;                       /* illumination not enabled */

    if( LMP_BLST_IsCommunicationEnabled()== TRUE )
    {
        if( LMP_BLST_EnableCommunication( FALSE ) )
        {
            dbmsg_trace( DBM_ILLUM, "\r\nLAMP: Lamp ballast communication has been disabled.\r\n" );
        }
        else
        {
            dbmsg_trace( DBM_ILLUM, "\r\nLAMP: Failed to disable lamp ballast communication.\r\n" );
        }
    }

    pass = pass & ( PASS == LMP_Enable( FALSE ));
    pass = pass & ( PASS == DMD_Park());

    RTA_TaskDelay(TMR_ConvertMSToTicks( 500 ));    /* lamp turnoff settling */

    pass = pass & ( PASS == SEQ_Enable( FALSE ));
    pass = pass & ( PASS == LMP_SetLampSyncType( LMP_SYNC_OFF, FALSE, FALSE ));
    pass = pass & ( PASS == CW_Stop());
    pass = pass & ( PASS == CW_EnableClock( FALSE ));
    pass = pass & ( PASS == DMD_Power( FALSE ));

    enviro_enableLampCWInterlock( FALSE );

    if( !pass )
        dbmsg_trace( DBM_ALWAYS, "API error in illumination transition to standby\r\n" );

    return pass ? EXEC_CC_PASS : EXEC_CC_API;
}



/****************************************************************************/
/* Set illumination to normal operating mode.                               */
/****************************************************************************/

EXEC_CC_ENUM illum_powerNormal( void )
{
    CW_MODES cwMode;                              /* default CW spin factor */
    uint08 tryCount;                               /* startup retry counter */
    uint08 spinTry;                                     /* spin try counter */
    BOOL   cwStarted;                     /* flag if cw succesfully started */
    uint08 pmdStatus;                                         /* PMD status */
    BOOL pass = TRUE;                /* assume all API operations will pass */

    dbmsg_trace( DBM_ILLUM, "Illumination: Transition to operating mode\r\n" );

                        /****************************************************/
                        /* Initialize the PMD1000                           */
                        /****************************************************/

    pass &= ( PASS == PMD_Init());
    pass &= ( PASS == PMD_SetResetMask(PMD_MASK_FAN | PMD_MASK_PWRENA, 0 ));
    pass &= ( PASS == PMD_INT_ReadLatchedStatus( &pmdStatus, 0 ));
    pass &= ( PASS == PMD_INT_ClearLatchedStatus( pmdStatus, 0 ));

    if( !pass )
    {
        dbmsg_ftrace( DBM_ALWAYS, "Can't initialize PMD1000: cc= %d\r\n", pmdStatus );
        return EXEC_CC_API;
    }

                        /****************************************************/
                        /* Set up for color wheel start.                    */
                        /****************************************************/

    CW_Init();                           /* initialize before all CW starts */

    cwMode = CW_MODE_2_0X;               /* find a supported CW spin factor */
    while( CW_IsModeSupported( cwMode ) != TRUE )
    {
        cwMode ++;
        if( cwMode == CW_MODE_MAX )
        {
            dbmsg_trace( DBM_ALWAYS, "No supported color wheel spin factors\r\n" );
            return EXEC_CC_API;
        }
    }

    pass &= ( PASS == CW_SetMode( cwMode ));
    pass &= ( PASS == CW_SetExpectedVsync( 60<<1 ));
    pass &= ( PASS == CW_EnableClock( TRUE ));
    pass &= ( PASS == CW_SetIndexDelay( MIN( EE_GETCONST( UserSystem.CW_Calibration, uint32 ), 719 )));
    pass &= ( PASS == CW_SetCoast( FALSE ));

    if( !pass )
    {
        dbmsg_trace( DBM_ALWAYS, "Can't set up for color wheel start\r\n" );
        return EXEC_CC_API;
    }

                        /****************************************************/
                        /* Set up DMD and sequencer.                        */
                        /****************************************************/

    pass &= ( PASS == DMD_Init());
    pass &= ( PASS == DMD_SetBin( 3 ));
    pass &= ( PASS == DMD_Power( TRUE ));

    RTA_TaskDelay(TMR_ConvertMSToTicks( 100 ));           /* power settling */

    if( !pass )
    {
        dbmsg_trace( DBM_ALWAYS, "Can't set up DMD\r\n" );
        return EXEC_CC_API;
    }

    if( TRUE != (  pass &= ( PASS == SEQ_Enable( TRUE ))))
    {
        dbmsg_trace( DBM_ALWAYS, "Can't enable sequencer\r\n" );
        return EXEC_CC_API;
    }

                        /****************************************************/
                        /* Start the color wheel. When successful, strike   */
                        /* the lamp and set the lamp sync type.             */
                        /*                                                  */
                        /* If the wheel fails to start, try again.          */
                        /****************************************************/

    cwStarted = FALSE;

    for( tryCount = 0; tryCount < gpConfiguration -> Illum.CWMaxRetries && !cwStarted; tryCount++ )
    {
        dbmsg_trace( DBM_ILLUM, "Start the color wheel\r\n" );

        if( PASS != CW_Start())                    /* start the color wheel */
        {
            dbmsg_trace( DBM_ALWAYS, "Can't command CW_Start\r\n" );
            return EXEC_CC_API;
        }

        for( spinTry = 0; spinTry < 40 && !cwStarted; spinTry ++ )/* poll 2 sec */
        {
            RTA_TaskDelay( TMR_ConvertMSToTicks( 50 ));       /* wait 50 ms */

            if( CW_GetSpinning() )               /* break when wheel starts */
                cwStarted = TRUE;
        }

        if( FALSE == cwStarted )
        {
            CW_Stop();                          /* logically stop the wheel */
            RTA_TaskDelay( TMR_ConvertMSToTicks( 200 ));     /* wait 200 ms */
        }
    }
                        /****************************************************/
                        /* Report problem if CW did not start.              */
                        /****************************************************/

    if( cwStarted == FALSE )                  /* if the wheel did not start */
    {
        dbmsg_trace( DBM_ALWAYS, "Can't transition to operating mode because...\r\n" );
        dbmsg_trace( DBM_ALWAYS, "  Color wheel will not spin\r\n" );

        return EXEC_CC_FAIL;    /* fail causes sysmon transition to standby */
    }

    if( _strikeLamp() == PASS )                          /* if the lamp lit */
    {
        illumEnabled = TRUE;                     /* illumination is enabled */
        enviro_enableLampCWInterlock( TRUE );

⌨️ 快捷键说明

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