📄 illumination.c
字号:
}
else /* if the lamp failed to ignite */
{
dbmsg_trace( DBM_ALWAYS, "Can't transition to operating mode because...\r\n" );
dbmsg_trace( DBM_ALWAYS, " Lamp will not ignite\r\n" );
return EXEC_CC_FAIL; /* fail causes sysmon transition to standby */
}
/****************************************************/
/* Lamp is now lit */
/****************************************************/
if( gpConfiguration -> Illum.LampStrikeResetEnable )
{
/****************************************************/
/* If a lamp strike reset is expected, delay for an */
/* interval longer than lamp strike time. If the */
/* lamp strikes, there is no return from the delay. */
/* In normal circumstances, this code will not even */
/* be reached before the reset occurs. */
/* */
/* A lamp strike reset is expected on the first */
/* strike after power is applied (reset cause not */
/* lamp strike reset) or if reStrike is TRUE on the */
/* second lamp enable. Note that the second lamp */
/* strike reset causes reStrike to be set back to */
/* FALSE during application initialization, thus */
/* restarting the entire process. */
/* */
/* If the delay does return, the reset did not */
/* occur, so CW/lamp are set back to a stable state.*/
/****************************************************/
if( !illum_isLampStrikeReset() )
{
dbmsg_trace( DBM_ILLUM, "Wait for lamp strike reset\r\n");
RTA_TaskDelay( TMR_ConvertMSToTicks( 2000 ));
dbmsg_trace( DBM_ALWAYS, "Lamp strike reset did not occur as expected\r\n");
return EXEC_CC_FAIL;/* fail causes sysmon transition to standby */
}
reStrike = TRUE;
}
if( gpConfiguration -> Illum.UartBallastEnable )
{
GPIO_EnableAlternativeFunction( GPIO_UART1_TXD_RXD, TRUE );
RTA_TaskDelay( TMR_ConvertMSToTicks( gpConfiguration -> Illum.UartBallastCommEMIDelay ) );
if( LMP_BLST_EnableCommunication(TRUE)== PASS )
{
dbmsg_trace( DBM_ILLUM, "\r\nLAMP: Lamp ballast communication has been enabled.\r\n" );
}
else
{
dbmsg_trace( DBM_ILLUM, "\r\nLAMP: Failed to enable lamp ballast communication.\r\n" );
}
}
/****************************************************/
/* Unpark the DMD and start lamp syncs */
/****************************************************/
if( EXEC_CC_PASS != datapath_okToUnpark())
{
dbmsg_trace( DBM_ALWAYS, "Illumination: Datapath not ready.\r\n" );
dbmsg_trace( DBM_ALWAYS, "Illumination:Continue...\r\n" );
}
if( PASS != DMD_Unpark())
dbmsg_trace( DBM_ALWAYS, "Can't unpark DMD\r\n" );
if( gpConfiguration -> Illum.EnableLampSyncs )
{
RTA_TaskDelay( TMR_ConvertMSToTicks(
gpConfiguration -> Illum.LampSyncEnableDelay ));
LMP_SetLampSyncType(
gpConfiguration -> Illum.LampSyncType, FALSE, TRUE );
dbmsg_trace( DBM_ILLUM, "Lamp syncs enabled\r\n");
}
return EXEC_CC_PASS;
}
/****************************************************************************/
/* Periodic polling callback function. */
/* */
/* Increment the lamp usage counter every 0.1 hour when the lamp is lit. */
/* */
/* The lamp usage counter is four 16-bit counters in EEPROM. One counter is */
/* incremented each 0.1 hour; total lamp usage time is the sum of the four */
/* counters. The EEPROM rewrite count is specified as 100000 writes, min. */
/* Thus the four counters will accumulate a minimum of 100000 * 4 * 0.1 = */
/* 40000 hours. */
/****************************************************************************/
int16 illum_poll( uint16 tick )
{
int i; /* lamp usage array index */
uint32 hours = 0;
if( LMP_IsLampLit() && ( ++lampUseCount >= LAMPUSE_COUNT ))
{
for( i = 3; i > 0; i-- ) /* locate member to update */
if( lampOnTime[ i ] < lampOnTime[ i - 1 ] )
break;
lampOnTime[i]++; /* bump value */
EE_PUTVAR( UserSystem.LampTime[i], lampOnTime[i] ); /* update */
lampUseCount -= LAMPUSE_COUNT; /* restart */
for( i = 0; i < 4; i++ ) hours += lampOnTime[ i ];
dbmsg_ftrace( DBM_ILLUM, "Update lamp on-time: %d.%d hours\r\n",
hours / 10, hours % 10 );
}
return LAMP_PERIOD / RTOS_MS_PER_TICK;
}
/****************************************************************************/
/* Return number of hours lamp usage. */
/****************************************************************************/
uint32 illum_lampHoursGet( void )
{
int lc; /* loop counter */
uint32 hours = 0;
for( lc = 0; lc < 4; lc++ ) hours += lampOnTime[ lc ];
return ( hours + 5 ) / 10; /* round off */
}
/****************************************************************************/
/* Reset lamp hours. */
/****************************************************************************/
void illum_lampHoursReset( void )
{
int lc; /* loop counter */
for( lc = 0; lc < 4; lc++ ) lampOnTime[ lc ] = 0;
EE_PUTVAR( UserSystem.LampTime, lampOnTime ); /* update */
}
/****************************************************************************/
/* Return lamp overtemperature indication. */
/****************************************************************************/
BOOL illum_lampOvertemp( void )
{
BOOL isOvertemp;
GPIO_GetPin( GIO_LAMP_HOT, &isOvertemp );
return isOvertemp;
}
/****************************************************************************/
/* Return true if the system is powering up from a lamp strike reset */
/****************************************************************************/
BOOL illum_isLampStrikeReset( void )
{
if( (!reStrike) && (DDP_LAMPSTRIKE_RESET == DDP_GetResetCause()) )
return TRUE;
else
return FALSE;
}
/****************************************************************************/
/* Conversions between delay times and milliseconds. */
/* */
/* Some API calls use unusual bitweights for delay times. These functions */
/* convert between those bitweights and user-friendly terms. */
/* */
/* Lamp enable delay: lsb = 163.84 uSec. */
/* Lamp strike reset delay: lsb = 250 uSec. */
/****************************************************************************/
static uint16 _millisecToLampEnable( uint16 delay )
{
return (uint16)( ((uint32)delay * 1000 ) / 164 );
}
/****************************************************************************/
static uint16 _millisecToLampStrikeReset( uint16 delay )
{
return (uint16)( ((uint32)delay * 1000 ) / 250 );
}
/****************************************************************************/
/* Strike the lamp. */
/****************************************************************************/
static BOOL _strikeLamp( void )
{
int lc; /* loop counter */
uint16 delay;
/****************************************************/
/* Configure lamp strike reset if enabled by the */
/* application. */
/****************************************************/
if( gpConfiguration -> Illum.LampStrikeResetEnable )
{
dbmsg_trace( DBM_ILLUM, "Set up for lamp strike reset\r\n" );
LMP_EnableLampStrikeReset( LMP_ASIC_CW );
delay = _millisecToLampEnable( gpConfiguration -> Illum.LampEnableDelay );
LMP_SetLampEnableDelay( delay );
delay = _millisecToLampStrikeReset( gpConfiguration -> Illum.LampStrikeResetDelay );
LMP_SetLampStrikeResetDelay( delay );
}
/****************************************************/
/* Check if the lamp extinguished during */
/* lamp strike reset and fail if necessary */
/****************************************************/
if( illum_isLampStrikeReset() == TRUE && LMP_IsLampLit() == FALSE )
{
dbmsg_trace( DBM_ILLUM, "Lamp extinguished during lamp strike reset -- lamp enable delay set too short?\r\n");
return FALSE;
}
/****************************************************/
/* Enable the lamp strike and examine the result: */
/****************************************************/
if( PASS == LMP_Enable( TRUE ))
{
dbmsg_trace( DBM_ILLUM, "Enable lamp strike\r\n");
/****************************************************/
/* Delay for lamp lit and stable. */
/****************************************************/
if( gpConfiguration -> Illum.EnableWaitLampLitStable )
{
dbmsg_trace( DBM_ILLUM, "Wait for lamp lit and stable\r\n");
for( lc = 0; lc < 100; lc++ )
{
if( LMP_IsLampLit() && LMP_IsLampLitStable())
{
dbmsg_trace( DBM_ILLUM, "Lamp lit and stable\r\n");
return TRUE; /* lamp struck successfully */
}
RTA_TaskDelay( TMR_ConvertMSToTicks( 100 ));
}
/****************************************************/
/* Either "lit" or "stable" did not occur. */
/****************************************************/
dbmsg_trace( DBM_ALWAYS, "Lamp did not strike\r\n");
return FALSE;
}
else
{
RTA_TaskDelay( TMR_ConvertMSToTicks( 1000 ));
return TRUE; /* assume lamp struck successfully */
}
}
else
{
dbmsg_trace( DBM_ALWAYS, "Can't enable lamp strike\r\n");
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -