?? lmp_blst.c
字號:
/* Set Waveform Index */
write_buffer[0] = 0x71;
write_buffer[1] = Waveform_Index;
error = URT_Write (LMP_BLST_PortNum, 2, &write_buffer[0], LMP_BLST_UART_DELAY, &numBytesWritten);
if (error == PASS)
{
/* Check response for "Waveform Selection" command */
error = URT_Read (LMP_BLST_PortNum, 2, &read_buffer[0], LMP_BLST_UART_DELAY, &numBytesRead);
if (error == PASS)
{
if (read_buffer [0] == 0x71)
{
if (LMP_BLST_CurrERR != LMP_BLST_NOSEQMATCH)
LMP_BLST_SetLampStatus (FALSE, PASS);
LMP_BLST_CurrWaveformIndex = Waveform_Index;
}
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 returns the number of waveforms stored in the ballast. */
/* */
/* return Number of Waveforms. */
/****************************************************************************/
uint08 LMP_BLST_GetNumWaveforms (void)
{
return LMP_BLST_NumWaveforms;
}
/****************************************************************************/
/* This function returns the current waveform selected. */
/* */
/* param WaveformID - O - Current waveform id */
/* */
/* 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_GetWaveformID (uint08 *WaveformID)
{
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 */
/* Get Waveform ID */
write_buffer[0] = 0xF2;
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] == 0xF2)
*WaveformID = read_buffer[1];
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 returns the currently selected waveform index. */
/* */
/* return Waveform Index, sets by the LMP_BLST_SetWaveform command or select*/
/* automatically by the Sequence. */
/****************************************************************************/
uint08 LMP_BLST_GetWaveformIndex (void)
{
return LMP_BLST_CurrWaveformIndex;
}
/****************************************************************************/
/* This function sets the output power level of the lamp. */
/* NOTE that some ballast manufacturers provide a command to lower the */
/* overall power of the lamp. This command (commonly known as DIM) must be */
/* entered via the waveform programming mailbox. */
/* */
/* param Waveform_Gain - I - Waveform Gain range 0x0 to 0xFF. This should */
/* be between (inclusive) minimum and maximum */
/* allowed limit. Refer LMP_BLST_GetMaxGain() */
/* and LMP_BLST_GetMinGain(). */
/* */
/* 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_SetWaveformGain (uint08 Waveform_Gain)
{
int08 error = FAIL;
/* Return if it is the same waveform gain */
if (Waveform_Gain == LMP_BLST_CurrWaveformGain)
return PASS;
/* Set the OOR flag if the gain is out of range */
if (!INRNG(LMP_BLST_MinGain, Waveform_Gain, LMP_BLST_MaxGain))
{
error = LMP_BLST_SetLampStatus (TRUE, LMP_BLST_WAVEFORMGAIN_OOR);
return LMP_BLST_WAVEFORMGAIN_OOR;
}
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 */
/* Set Waveform Gain */
write_buffer[0] = 0x72;
write_buffer[1] = Waveform_Gain; /* actual gain = gain value / 128 */
error = URT_Write (LMP_BLST_PortNum, 2, &write_buffer[0], LMP_BLST_UART_DELAY, &numBytesWritten);
if (error == PASS)
{
/* Check response for "Waveform Gain" command */
error = URT_Read (LMP_BLST_PortNum, 2, &read_buffer[0], LMP_BLST_UART_DELAY, &numBytesRead);
if (error == PASS)
{
if (read_buffer[0] == 0x72)
{
if ((LMP_BLST_CurrERR != LMP_BLST_NOSEQMATCH) && (LMP_BLST_CurrERR != LMP_BLST_WAVEFORM_OOR))
LMP_BLST_SetLampStatus (FALSE, PASS);
LMP_BLST_CurrWaveformGain = read_buffer [1]; /* set to what we read back */
}
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 returns the current waveform gain value. */
/* */
/* return Waveform Gain = sets by the LMP_BLST_Set_Waveform_Gain command */
/****************************************************************************/
uint08 LMP_BLST_GetWaveformGain (void)
{
return LMP_BLST_CurrWaveformGain;
}
/****************************************************************************/
/* This function returns the minimum value allowable for the waveform gain */
/* command. */
/* */
/* return Minimum Gain value. */
/****************************************************************************/
uint08 LMP_BLST_GetMinGain (void)
{
return LMP_BLST_MinGain;
}
/****************************************************************************/
/* This function returns the maximum value allowable for the waveform gain */
/* command. */
/* */
/* return Maximum Gain Value. */
/****************************************************************************/
uint08 LMP_BLST_GetMaxGain (void)
{
return LMP_BLST_MaxGain;
}
/****************************************************************************/
/* This function opens the mailbox with the StartAddr specified. The address*/
/* will be automatically incremented upon mailbox read/ write. */
/* */
/* param StartAddr - I - Start address. */
/* */
/* 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_OpenMailBox (uint16 StartAddr)
{
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] = (StartAddr & 0xFF00) >> 8; /* High Byte */
write_buffer[2] = (StartAddr & 0xFF); /* Low Byte */
write_buffer[3] = TRUE; /* enable access */
error = URT_Write (LMP_BLST_PortNum, 4, &write_buffer[0], LMP_BLST_UART_DELAY, &numBytesWritten);
if (error == PASS)
{
error = URT_Read (LMP_BLST_PortNum, 4, &read_buffer[0], LMP_BLST_UART_DELAY, &numBytesRead);
if (error == PASS)
{
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);
}
}
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 writes to the mailbox starting at the StartAddr with */
/* LMP_BLST_OpenMailBox API call, consecutive call to LMP_BLST_WriteMailBox */
/* API will cause the next byte to be written. */
/* */
/* param Data - I - Data to be written to 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_WriteMailBox (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 */
/* Waveform Programming Mailbox */
write_buffer[0] = 0x73;
write_buffer[1] = Data;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -