?? lmp_blst.c
字號:
error = URT_Write (LMP_BLST_PortNum, 2, &write_buffer[0], LMP_BLST_UART_DELAY, &numBytesWritten);
if (error == PASS)
{
/* Check response for "Waveform Programming Mailbox" command */
error = URT_Read (LMP_BLST_PortNum, 2, &read_buffer[0], LMP_BLST_UART_DELAY, &numBytesRead);
if (error == PASS)
{
if (read_buffer[0] == 0x73)
{
if ((LMP_BLST_CurrERR != LMP_BLST_NOSEQMATCH) && (LMP_BLST_CurrERR != LMP_BLST_WAVEFORM_OOR))
LMP_BLST_SetLampStatus (FALSE, PASS);
}
else
{
error = LMP_BLST_BALLASTERR;
LMP_BLST_SetLampStatus (TRUE, error);
}
}
else
{
if (error == URT_TIMEOUT)
error = LMP_BLST_TIMEOUT;
else
error = LMP_BLST_URTERR;
LMP_BLST_SetLampStatus (TRUE, error);
}
}
else
{
if (error == URT_TIMEOUT)
error = LMP_BLST_TIMEOUT;
else
error = LMP_BLST_URTERR;
LMP_BLST_SetLampStatus (TRUE, error);
}
RTA_SemRelease(LMP_BLST_Sem);
return error;
}
/****************************************************************************/
/* This function reads the mailbox with address startingat the StartAddr */
/* with LMP_BLST_OpenMailBox API call, consecutive call to */
/* LMP_BLST_ReadMailBox API will cause the next byte to be read. */
/* */
/* param Data - O - Data read from the mailbox */
/* */
/* return PASS = Successful */
/* FAIL = Unsuccessful */
/* LMP_BLST_INUSEERR = Lamp UART is in use */
/* LMP_BLST_TIMEOUT = UART Timeout */
/* LMP_BLST_URTERR = UART all other Errors */
/* LMP_BLST_BALLASTERR = Ballast returned error */
/****************************************************************************/
int08 LMP_BLST_ReadMailBox (uint08 *Data)
{
int08 error = FAIL;
if(RTA_SemReserve(LMP_BLST_Sem, TMR_ConvertMSToTicks(LMP_BLST_SEM_DELAY)) != RTA_SUCCESS)
return LMP_BLST_INUSEERR;
URT_FlushReadFIFO(LMP_BLST_PortNum); /* Discard any spurious data */
/* Read Byte Mailbox */
write_buffer[0] = 0xF9;
error = URT_Write (LMP_BLST_PortNum, 1, &write_buffer[0], LMP_BLST_UART_DELAY, &numBytesWritten);
if (error == PASS)
{
/* Check response for "Read Byte Mailbox" command */
error = URT_Read (LMP_BLST_PortNum, 2, &read_buffer[0], LMP_BLST_UART_DELAY, &numBytesRead);
if (error == PASS)
{
if (read_buffer[0] == 0xF9)
{
if ((LMP_BLST_CurrERR != LMP_BLST_NOSEQMATCH) && (LMP_BLST_CurrERR != LMP_BLST_WAVEFORM_OOR))
LMP_BLST_SetLampStatus (FALSE, PASS);
*Data = read_buffer[1];
}
else
{
error = LMP_BLST_BALLASTERR;
LMP_BLST_SetLampStatus (TRUE, error);
}
}
else
{
if (error == URT_TIMEOUT)
error = LMP_BLST_TIMEOUT;
else
error = LMP_BLST_URTERR;
LMP_BLST_SetLampStatus (TRUE, error);
}
}
else
{
if (error == URT_TIMEOUT)
error = LMP_BLST_TIMEOUT;
else
error = LMP_BLST_URTERR;
LMP_BLST_SetLampStatus (TRUE, error);
}
RTA_SemRelease(LMP_BLST_Sem);
return error;
}
/****************************************************************************/
/* This function closes the mailbox. */
/* */
/* return PASS = Successful */
/* FAIL = Unsuccessful */
/* LMP_BLST_INUSEERR = Lamp UART is in use */
/* LMP_BLST_TIMEOUT = UART Timeout */
/* LMP_BLST_URTERR = UART all other Errors */
/* LMP_BLST_BALLASTERR = Ballast returned error */
/****************************************************************************/
int08 LMP_BLST_CloseMailBox (void)
{
int08 error = FAIL;
if(RTA_SemReserve(LMP_BLST_Sem, TMR_ConvertMSToTicks(LMP_BLST_SEM_DELAY)) != RTA_SUCCESS)
return LMP_BLST_INUSEERR;
URT_FlushReadFIFO(LMP_BLST_PortNum); /* Discard any spurious data */
/* Waveform Mailbox Control */
write_buffer[0] = 0x74;
write_buffer[1] = 0x00; /* clear up the address fields */
write_buffer[2] = 0x00;
write_buffer[3] = FALSE; /* disable access */
error = URT_Write (LMP_BLST_PortNum, 4, &write_buffer[0], LMP_BLST_UART_DELAY, &numBytesWritten);
error = URT_Read (LMP_BLST_PortNum, 4, &read_buffer[0], LMP_BLST_UART_DELAY, &numBytesRead);
if (read_buffer[0] == 0x74)
{
if ((LMP_BLST_CurrERR != LMP_BLST_NOSEQMATCH) && (LMP_BLST_CurrERR != LMP_BLST_WAVEFORM_OOR))
LMP_BLST_SetLampStatus (FALSE, PASS);
}
else
{
error = LMP_BLST_BALLASTERR;
LMP_BLST_SetLampStatus (TRUE, error);
}
RTA_SemRelease(LMP_BLST_Sem);
return error;
}
/****************************************************************************/
/* This function returns the mailbox status. */
/* */
/* param StartAddr - O - Current address of the mailbox. */
/* MailboxAccess - O - TRUE - Write enabled. FALSE - Write Disabled.*/
/* */
/* */
/* return PASS = Successful */
/* FAIL = Unsuccessful */
/* LMP_BLST_INUSEERR = Lamp UART is in use */
/* LMP_BLST_TIMEOUT = UART Timeout */
/* LMP_BLST_URTERR = UART all other Errors */
/* LMP_BLST_BALLASTERR = Ballast returned error */
/****************************************************************************/
int08 LMP_BLST_GetMailboxStatus (uint16 *StartAddr, uint08 *MailboxAccess)
{
int08 error = FAIL;
if(RTA_SemReserve(LMP_BLST_Sem, TMR_ConvertMSToTicks(LMP_BLST_SEM_DELAY)) != RTA_SUCCESS)
return LMP_BLST_INUSEERR;
URT_FlushReadFIFO(LMP_BLST_PortNum); /* Discard any spurious data */
/* Mailbox Status Readback */
write_buffer[0] = 0xF7;
error = URT_Write (LMP_BLST_PortNum, 1, &write_buffer[0], LMP_BLST_UART_DELAY, &numBytesWritten);
error = URT_Read (LMP_BLST_PortNum, 4, &read_buffer[0], LMP_BLST_UART_DELAY, &numBytesRead); /* echo + address bytes + control byte */
/* Philips ballast only returns the echo + two bytes of address */
/* Currently this logic won't work with Philips' ballast */
if (read_buffer[0] == 0xF7)
{
*StartAddr = ((read_buffer[1] << 8) | read_buffer[2]);
*MailboxAccess = read_buffer[3];
}
else
{
error = LMP_BLST_BALLASTERR;
LMP_BLST_SetLampStatus (TRUE, error);
}
RTA_SemRelease(LMP_BLST_Sem);
return error;
}
/****************************************************************************/
/* This function returns the Ballast Manufacturer ID. */
/* */
/* return Ballast Manufacture ID. */
/****************************************************************************/
uint08 LMP_BLST_GetManufacturerID (void)
{
return LMP_BLST_BallastMfgID;
}
/****************************************************************************/
/* This function returns the hardware and software Ballast IDs. */
/* Byte 1 is the hardware ID and byte 2 is the software ID. */
/* */
/* return Ballast ID. */
/****************************************************************************/
uint16 LMP_BLST_GetBallastID (void)
{
return LMP_BLST_BallastID;
}
/****************************************************************************/
/* This function returns the current ballast status. */
/* ------------------------------------------------------------- */
/* | Reserved for future status | Reserved | Lamp On | */
/* ------------------------------------------------------------- */
/* -------- bit7 through bit2 -------- bit1 ------- bit0 --- */
/* */
/* param BallastStatus - O - Ballast status */
/* */
/* return PASS = Successful */
/* FAIL = Unsuccessful */
/* LMP_BLST_INUSEERR = Lamp UART is in use */
/* LMP_BLST_TIMEOUT = UART Timeout */
/* LMP_BLST_URTERR = UART all other Errors */
/* LMP_BLST_BALLASTERR = Ballast returned error */
/****************************************************************************/
int08 LMP_BLST_GetBallastStatus (uint08 *BallastStatus)
{
int08 error = FAIL;
LMP_BLST_CurrLmpLit = FALSE;
if(RTA_SemReserve(LMP_BLST_Sem, TMR_ConvertMSToTicks(LMP_BLST_SEM_DELAY)) != RTA_SUCCESS)
return LMP_BLST_INUSEERR;
URT_FlushReadFIFO(LMP_BLST_PortNum); /* Discard any spurious data */
/* Ballast Status */
write_buffer[0] = 0xF5;
error = URT_FlushFIFOs (LMP_BLST_PortNum);
error = URT_Write (LMP_BLST_PortNum, 1, &write_buffer[0], LMP_BLST_UART_DELAY, &numBytesWritten);
error = URT_Read (LMP_BLST_PortNum, 2, &read_buffer[0], LMP_BLST_UART_DELAY, &numBytesRead);
if (error == PASS)
{
if (read_buffer[0] == 0xF5)
{
*BallastStatus = read_buffer[1];
LMP_BLST_CurrLmpLit = ((*BallastStatus & LMP_BLST_LAMPON) != 0);
}
else
error = LMP_BLST_BALLASTERR;
}
else
{
if (error == URT_TIMEOUT)
error = LMP_BLST_TIMEOUT;
else
error = LMP_BLST_URTERR;
}
RTA_SemRelease(LMP_BLST_Sem);
return error;
}
/****************************************************************************/
/* This function sets the Lamp Status. */
/* which includes the flag whether in the lamp sync off safe mode and */
/* the err code that cause the lamp error (see LMP_BLST.h for return codes) */
/* */
/* param LampSafeMode - I - TRUE/FALSE to set lamp in safe mode */
/* LampERRCode - I - error code that cause the lamp error and */
/* switch to safe mode; LMP_BLST_NOSEQMATCH, */
/* LMP_BLST_WAVEFORM_OOR, or LMP_BLST_TIMEOUT */
/* */
/* return PASS */
/****************************************************************************/
int08 LMP_BLST_SetLampStatus (BOOL LampSafeMode, int08 LampERRCode)
{
/* save the safe mode flag and error code */
LMP_BLST_SafeMode = LampSafeMode;
LMP_BLST_CurrERR = LampERRCode;
if (LMP_BLST_CurrERR == PASS)
{
// if UART lamp OKAY, then enable lamp sync
LMP_SetLampSyncType( gpConfiguration->Illum.LampSyncType, FALSE, TRUE );
}
else
{
// if UART Lamp error occurred (OOR or no match), then disable lamp sync
LMP_SetLampSyncType(LMP_SYNC_OFF, 0, 0);
}
return PASS;
}
/****************************************************************************/
/* This function returns the current Lamp Status, which includes byte for */
/* UART is in "SAFE" mode and UART Mode Error code (see LMP_BLST.h for */
/* return codes). */
/* */
/* param LampSafeMode - O - TRUE - Lamp is in safe mode. FALSE - Lamp is */
/* in normal mode. */
/* */
/* param LampERRCode - O - Error code that cause the lamp error and */
/* switch to safe mode */
/* */
/* return PASS. */
/****************************************************************************/
int08 LMP_BLST_GetLampStatus (BOOL *LampSafeMode, int08 *LampERRCode)
{
*LampSafeMode = LMP_BLST_SafeMode;
*LampERRCode = LMP_BLST_CurrERR;
return PASS;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -