📄 l2_global.c
字号:
iday = iday+366; //whole days sicne 2000/1/1
lday = iday/1461; //quadyr = 4 yr period = 1461 days
qday = iday%1461; //days since current quadyr begin
if(qday>=60) lday++; //if past 2/29 then add this quadyr's leap day
iyrs = (iday-lday)/365; //whole years since 2001/1/1
jday = iday-(iyrs*365)-lday; //days since 1/1 of current year
if((qday<=365) && (qday>=60)) jday++; //if past 2/29 and a leap year then add a leap day
DatePt->Year = iyrs;
mon = 13;
mday = 366;
while(jday<mday)
{
mon--;
mday = DMonth[mon];
if((mon>2) && ((iyrs%4)==0)) mday++; //if past 2/29 and leap year then add leap day
}
DatePt->Month = mon;
DatePt->Day = jday-mday+1;
// return
//PRINT_L2(" L3_BinToDate: Exit\n");
return(status);
}
UCHAR L2_ReadRTC(PDATE DatePt) USING_0
{
struct DATESTC Bin;
UCHAR first0, first1, first2, first3, first4, first5;
UCHAR last0, last1, last2, last3, last4, last5;
USHORT first10,last10;
BIT retry;
UCHAR status;
status = L2K_SUCCESS;
//body
//PRINT_L2(" L2_ReadRTC: Enter\n");
L3_ReadRTCData(0xA0, &first0);
L3_ReadRTCData(0xA1, &first1);
L3_ReadRTCData(0xA2, &first2);
L3_ReadRTCData(0xA3, &first3);
L3_ReadRTCData(0xA4, &first4);
L3_ReadRTCData(0xA5, &first5);
first10 = ((USHORT)first1<<8)|(USHORT)first0;
do
{
L3_ReadRTCData(0xA0, &last0);
L3_ReadRTCData(0xA1, &last1);
L3_ReadRTCData(0xA2, &last2);
L3_ReadRTCData(0xA3, &last3);
L3_ReadRTCData(0xA4, &last4);
L3_ReadRTCData(0xA5, &last5);
last10 = ((USHORT)last1<<8)|(USHORT)last0;
retry = (last5!=first5) || (last4!=first4) ||
(last3!=first3) || (last3!=first3) ||
(last10<first10);
first0 = last0;
first1 = last1;
first2 = last2;
first3 = last3;
first4 = last4;
first5 = last5;
} while(retry);
Bin.Second = first0;
Bin.Minute = first1;
Bin.Hour = first2;
Bin.Day = first3;
Bin.Month = first4;
Bin.Year = first5;
L3_BinToDate(&Bin, DatePt); //translate binary count to date
//PRINT_GLOBAL(" L2_ReadRTC: Second = %bu\n", DatePt->Second);
//PRINT_GLOBAL(" L2_ReadRTC: Minute = %bu\n", DatePt->Minute);
//PRINT_GLOBAL(" L2_ReadRTC: Hour = %bu\n", DatePt->Hour);
//PRINT_GLOBAL(" L2_ReadRTC: Day = %bu\n", DatePt->Day);
//PRINT_GLOBAL(" L2_ReadRTC: Month = %bu\n", DatePt->Month);
//PRINT_GLOBAL(" L2_ReadRTC: Year = %bu\n", DatePt->Year);
// return
//PRINT_L2(" L2_ReadRTC: Exit\n");
return(status);
}
////*/
//patch4.5@cytsai@fix RTC problem end
//-----------------------------------------------------------------------------
//L2_WriteAlarm
//-----------------------------------------------------------------------------
/*
routine description:
Read the value of the date structure, translate them to 48-bit binary
count and then program the binary count to the alarm register.
arguments:
*DatePt: the value of the date structure that is composed of the data defined as follows:
UCHAR Year,
UCHAR Month,
UCHAR Day,
UCHAR Hour,
UCHAR Minute,
UCHAR Second.
return value:
0x00 - success
0x01 - general error
0x02 - parameter error
others - error
*/
UCHAR L2_WriteAlarm(PDATE DatePt) USING_0
{
struct DATESTC Bin;
UCHAR status0, status1, status2, status3, status4, status5, status6;
UCHAR status;
//body
//PRINT_L2(" L2_WriteAlarm: Enter\n");
status0 = L3_DateToBin(DatePt, &Bin); //translate the date to binary count
status1 = L3_WriteRTCData(0x20, Bin.Second);
status2 = L3_WriteRTCData(0x21, Bin.Minute);
status3 = L3_WriteRTCData(0x22, Bin.Hour);
status4 = L3_WriteRTCData(0x23, Bin.Day);
status5 = L3_WriteRTCData(0x24, Bin.Month);
status6 = L3_WriteRTCData(0x25, Bin.Year);
status = status0|status1|status2|status3|status4|status5|status6;
// return
//PRINT_L2(" L2_WriteAlarm: Exit\n");
return(status);
}
//-----------------------------------------------------------------------------
//L2_ReadAlarm
//-----------------------------------------------------------------------------
/*
routine description:
Read the value of alarm register and translate them to the value of Year,
Month, Date, Hour, Minute and Second.
arguments:
*DatePt: the value of the date structure
return value:
0x00 - success
0x01 - general error
0x02 - parameter error
others - error
*/
UCHAR L2_ReadAlarm(PDATE DatePt) USING_0
{
struct DATESTC Bin;
UCHAR status0, status1, status2, status3, status4, status5, status6;
UCHAR status;
//body
//PRINT_L2(" L2_ReadAlarm: Enter\n");
status0 = L3_ReadRTCData(0x20, &(Bin.Second));
status1 = L3_ReadRTCData(0x21, &(Bin.Minute));
status2 = L3_ReadRTCData(0x22, &(Bin.Hour));
status3 = L3_ReadRTCData(0x23, &(Bin.Day));
status4 = L3_ReadRTCData(0x24, &(Bin.Month));
status5 = L3_ReadRTCData(0x25, &(Bin.Year));
status6 = L3_BinToDate(&Bin, DatePt); //translate binary count to date
status = status0|status1|status2|status3|status4|status5|status6;
/*
//PRINT_L2(" L2_ReadAlarm: Second = %bu\n", DatePt->Second);
//PRINT_L2(" L2_ReadAlarm: Minute = %bu\n", DatePt->Minute);
//PRINT_L2(" L2_ReadAlarm: Hour = %bu\n", DatePt->Hour);
//PRINT_L2(" L2_ReadAlarm: Day = %bu\n", DatePt->Day);
//PRINT_L2(" L2_ReadAlarm: Month = %bu\n", DatePt->Month);
//PRINT_L2(" L2_ReadAlarm: Year = %bu\n", DatePt->Year);
*/
// return
//PRINT_L2(" L2_ReadAlarm: Exit\n");
return(status);
}
//-----------------------------------------------------------------------------
//L2_ConfigPG
//-----------------------------------------------------------------------------
/*
routine description:
Set the parameters of pattern generator
arguments:
TimeBase: Time base, 20ns*(TimeBase+1)
TrigMode: Trigger mode
0: software trigger one
1: mechanical shutter control signal
2: always trigger (repeat foverver)
RptCnt: Repeat count
When the value of "RptCnt" is zero, the repeat count is 256;
otherwise the repeat count is the value of "RptCnt"
AtvCnt: Active count
When the value of "AtvCnt" is zero, the active count is 65536;
otherwise the active count is the value of "AtvCnt".
InAtvCnt: Inactive count
The inactive count is the value of "InAtvCnt".
InAtvLev: Inactive level
The pattern level in the inactive period.
Bit 0: the pattern generator 0
Bit 1: the pattern generator 1
Bit 2: the pattern generator 2
Bit 3: the pattern generator 3
Micro pattern: the basic pattern in the active period
Pg0pattern for the pattern generator 0
Pg1pattern for the pattern generator 1
Pg2pattern for the pattern generator 2
Pg3pattern for the pattern generator 3
SelectPG: Select pattern generator
Bit 0: when set, select the normal form of pattern generator 0
Bit 1: when set, select the inverse form of pattern generator 0
Bit 2: when set, select the normal form of pattern generator 1
Bit 3: when set, select the inverse form of pattern generator 1
Bit 4: when set, select the normal form of pattern generator 2
Bit 5: when set, select the inverse form of pattern generator 2
Bit 6: when set, select the normal form of pattern generator 3
Bit 7: when set, select the inverse form of pattern generator 3
return value:
0x00 - success
0x01 - general error
0x02 - parameter error
others - error
*/
UCHAR L2_ConfigPG(ULONG TimeBase, UCHAR TrigMode, UCHAR RptCnt, USHORT AtvCnt,
USHORT InAtvCnt, UCHAR InAtvLev, UCHAR PG0Pattern,
UCHAR PG1Pattern, UCHAR PG2Pattern, UCHAR PG3Pattern,
UCHAR SelectPG) USING_0
{
UCHAR status;
status = L2K_SUCCESS;
//body
//PRINT_L2(" L2_ConfigPG: Enter\n");
//time base
XBYTE[0x2090] = M_LoByteOfDword(TimeBase);
XBYTE[0x2091] = M_MidLoByteOfDword(TimeBase);
XBYTE[0x2092] = M_MidHiByteOfDword(TimeBase);
//trigger mode
if(TrigMode==1)
{
XBYTE[0x209E] = 0x01;
}
else if(TrigMode==2)
{
XBYTE[0x20E8] = 0x01;
}
else
{
XBYTE[0x209E] = 0x00;
XBYTE[0x20E8] = 0x00;
}
//repeat count
XBYTE[0x2093] = RptCnt;
//active count
XBYTE[0x2094] = M_LoByteOfWord(AtvCnt);
XBYTE[0x2095] = M_HiByteOfWord(AtvCnt);
//inactive count
XBYTE[0x2096] = M_LoByteOfWord(InAtvCnt);
XBYTE[0x2097] = M_HiByteOfWord(InAtvCnt);
//inactive level
XBYTE[0x209D] = InAtvLev;
//micro pattern
XBYTE[0x2098] = PG0Pattern;
XBYTE[0x2099] = PG1Pattern;
XBYTE[0x209a] = PG2Pattern;
XBYTE[0x209b] = PG3Pattern;
//select PG
XBYTE[0x209C] = SelectPG;
// return
//PRINT_L2(" L2_ConfigPG: Exit\n");
return(status);
}
//-----------------------------------------------------------------------------
//L2_StartPG
//-----------------------------------------------------------------------------
/*
routine description:
Poll the ready of pattern generator and then start the pattern generator
arguments:
none
return value:
none
*/
void L2_StartPG(void) USING_0
{
//body
//PRINT_L2(" L2_StartPG: Enter\n");
XBYTE[0x209E] = 0x02;
// return
//PRINT_L2(" L2_StartPG: Exit\n");
return;
}
//-----------------------------------------------------------------------------
//L2_StopPG
//-----------------------------------------------------------------------------
/*
routine description:
Stop the pattern generator
arguments:
none
return value:
none
*/
void L2_StopPG(void) USING_0
{
//body
//PRINT_L2(" L2_StopPG: Enter\n");
XBYTE[0x20E8] = 0x02;
XBYTE[0x20E8] = 0x00;
// return
//PRINT_L2(" L2_StopPG: Exit\n");
return;
}
//-----------------------------------------------------------------------------
//L2_ConfigUI
//-----------------------------------------------------------------------------
/*
routine description:
Configure UI controller to communicate with the UI processor (SPL10A)
arguments:
PollIntvl:
The time interval to poll the UI processor. The unit is mini-second
return value:
0x00 - success
0x01 - general error
0x02 - parameter error
others - error
*/
UCHAR L2_ConfigUI(UCHAR PollIntvl) USING_0
{
UCHAR status;
status = L2K_SUCCESS;
//body
//PRINT_L2(" L2_ConfigUI: Enter\n");
//polling interval
XBYTE[0x2063] = PollIntvl;
//clear UI mini-second counter
XBYTE[0x2062] = 0x04;
XBYTE[0x2062] = 0x00;
// return
//PRINT_L2(" L2_ConfigUI: Exit\n");
return(status);
}
//-----------------------------------------------------------------------------
//L2_WakeUI
//-----------------------------------------------------------------------------
/*
routine description:
Wake up the UI processor.
arguments:
none
return value:
none
*/
void L2_WakeUI(void) USING_0
{
//body
//PRINT_L2(" L2_WakeUI: Enter\n");
//set UITxreq
XBYTE[0x2062] = 0x01;
//polling UITxRxCmplt
while(!(XBYTE[0x2064] = 0x01));
//clear UITxreq
XBYTE[0x2062] = 0x00;
// return
//PRINT_L2(" L2_WakeUI: Exit\n");
return;
}
//-----------------------------------------------------------------------------
//L2_WriteUI
//-----------------------------------------------------------------------------
/*
routine description:
Transmit data to the UI processor.
arguments:
Txdata: the UI processor interprets the data as the command of "write", "set"
or "sleep".
return value:
0x00 - success
0x01 - general error
0x02 - parameter error
others - error
*/
UCHAR L2_WriteUI(USHORT UITxdata) USING_0
{
UCHAR status;
status = L2K_SUCCESS;
//body
//PRINT_L2(" L2_WriteUI: Enter\n");
//set UITxreq
XBYTE[0x2062] = 0x01;
//polling UITxRxCmplt
while(!(XBYTE[0x2064] = 0x01));
//write UITxdata
XBYTE[0x2060] = M_LoByteOfWord(UITxdata);
XBYTE[0x2061] = M_HiByteOfWord(UITxdata);
//polling UITxRxCmplt
while(!(XBYTE[0x2064] = 0x01));
//clear UITxreq
XBYTE[0x2062] = 0x00;
// return
//PRINT_L2(" L2_WriteUI: Exit\n");
return(status);
}
//-----------------------------------------------------------------------------
//L2_ReadUI
//-----------------------------------------------------------------------------
/*
routine description:
Read the data from the UI processor.
arguments:
*RxdataPt: the data that is automatically read from the UI processor.
return value:
0x00 - success
0x01 - general error
0x02 - parameter error
others - error
*/
UCHAR L2_ReadUI(PUCHAR UIRxdataPt) USING_0
{
UCHAR status;
status = L2K_SUCCESS;
//body
//PRINT_L2(" L2_ReadUI: Enter\n");
*UIRxdataPt = XBYTE[0x2065];
//PRINT_L2(" L2_ReadUI: UIRxdata = %bx\n", *UIRxdataPt);
//clear UIInt
XBYTE[0x20C0] = 0xFE;
// return
//PRINT_L2(" L2_ReadUI: Exit\n");
return(status);
}
//-----------------------------------------------------------------------------
//L2_ConfigGPIOBit
//-----------------------------------------------------------------------------
/*
routine description:
Configure GPIO to input mode or ouput mode. There is a table to map the
GPIO index to the pin number on SPCA533.
arguments:
Index: the index of a GPIO pin
Value: when it is zero, the corresponding GPIO will be set to input mode;
otherwise the GPIO will be set to ouput mode.
return value:
0x00 - success
0x01 - general error
0x02 - parameter error
others - error
*/
UCHAR L2_ConfigGPIOBit(UCHAR Index, UCHAR Value) USING_0
{
UCHAR BitNum;
USHORT Addr;
UCHAR tmp0, tmp1;
UCHAR status;
status = L2K_SUCCESS;
//PRINT_L2(" L2_ConfigGPIOBit: Enter\n");
BitNum = Index&0x07;
Addr = 0x2038|(USHORT)(Index>>3);
tmp0 = XBYTE[Addr];
/*
if(Value)
{
tmp1 = 0x01<<BitNum;
XBYTE[Addr] = tmp0|tmp1;
}
else
{
tmp1 = 0xFE<<BitNum;
XBYTE[Addr] = tmp0&tmp1;
}
*/
//yichang@0508
tmp1 = 0x01<<BitNum;
if(Value)
XBYTE[Addr] = tmp0|tmp1;
else
XBYTE[Addr] = tmp0&(~tmp1);
//PRINT_L2(" L2_ConfigGPIOBit: Exit\n");
return(status);
}
//-----------------------------------------------------------------------------
//L2_ConfigGPIOByte
//-----------------------------------------------------------------------------
/*
routine description:
Configure GPIO to input mode or ouput mode. There is a table to map the GPIO
index to the pin number on SPCA533.
arguments:
Index: the index of eight GPIO pins
Value: when it is zero, the corresponding GPIO will be set to input mode;
otherwise the GPIO will be set to output mode.
return value:
0x00 - success
0x01 - general error
0x02 - parameter error
others - error
*/
UCHAR L2_ConfigGPIOByte(UCHAR Index, UCHAR Value) USING_0
{
USHORT Addr;
UCHAR status;
status = L2K_SUCCESS;
//body
//PRINT_L2(" L2_ConfigGPIOByte: Enter\n");
Addr = 0x2038|(USHORT)(Index>>3);
XBYTE[Addr] = Value;
// return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -