📄 l2_global.c
字号:
if(tmp0&0x80)
{
XBYTE[0x2010] |= 0x02; //enable clk48m on the DMA module
}
if(tmp1&0x01)
{
XBYTE[0x2010] |= 0x40; //enable clk48m on the JPEG module
}
// return
//PRINT_L2(" L2_SetModuPowerUp: Exit\n");
return(status);
}
//-----------------------------------------------------------------------------
//L2_ConfigGTimer
//-----------------------------------------------------------------------------
/*
routine description:
The setting of interrupt, operation mode and watch dog function.
arguments:
Mode:
Bit 0: operation mode
0: down count mode
1: up count mode
Bit 1: reset CPU
0: disable
1: enable
Bit 2: timebase
0: 10 us
1: 1 ms
return value:
0x00 - success
0x01 - general error
0x02 - parameter error
others - error
*/
UCHAR L2_ConfigGTimer(UCHAR Mode) USING_0
{
UCHAR status;
status = L2K_SUCCESS;
//body
//PRINT_L2(" L2_ConfigGTimer: Enter\n");
XBYTE[0x2073] = Mode;
if((Mode&0x01)==0x00) XBYTE[0x20C0] |= 0x04;
else XBYTE[0x20C0] &= 0xFB;
// return
//PRINT_L2(" L2_ConfigGTimer: Exit\n");
return(status);
}
//-----------------------------------------------------------------------------
//L2_StartGTimer
//-----------------------------------------------------------------------------
/*
routine description:
Resume the operation of the SPCA533. It clears the related interrupt and puts
all the IO pins back to the normal operation states. In firmware coding,
this function must be called right after the Suspend function.
arguments:
none
return value:
none
*/
void L2_StartGTimer(void) USING_0
{
//body
//PRINT_L2(" L2_StartGTimer: Enter\n");
XBYTE[0x2074] = 0x01;
// return
//PRINT_L2(" L2_StartGTimer: Exit\n");
return;
}
//-----------------------------------------------------------------------------
//L2_StopGTimer
//-----------------------------------------------------------------------------
/*
routine description:
Stop the global timer. The function is used to measure the performance of
the camera. The global timer must be stopped before reading its values.
arguments:
none
return value:
none
*/
void L2_StopGTimer(void) USING_0
{
//body
//PRINT_L2(" L2_StopGTimer: Enter\n");
XBYTE[0x2074] = 0x02;
// return
//PRINT_L2(" L2_StopGTimer: Exit\n");
return;
}
//-----------------------------------------------------------------------------
//L2_WriteGTimer
//-----------------------------------------------------------------------------
/*
routine description:
Load the global timer with the specified value.
arguments:
Value: the value is specified with the unit of minii-second.
return value:
0x00 - success
0x01 - general error
0x02 - parameter error
others - error
*/
UCHAR L2_WriteGTimer(ULONG Value) USING_0
{
UCHAR status;
status = L2K_SUCCESS;
//body
//PRINT_L2(" L2_WriteGTimer: Enter\n");
XBYTE[0x2070] = M_LoByteOfDword(Value);
XBYTE[0x2071] = M_MidLoByteOfDword(Value);
XBYTE[0x2072] = M_MidHiByteOfDword(Value);
// return
//PRINT_L2(" L2_WriteGTimer: Exit\n");
return(status);
}
//-----------------------------------------------------------------------------
//L2_ReadGTimer
//-----------------------------------------------------------------------------
/*
routine description:
Read the global timer value that is specified with the unit of mini-second
arguments:
*ValuePt : the value of global timer.
return value:
0x00 - success
0x01 - general error
0x02 - parameter error
others - error
*/
//patch3.2@cytsai@0410 to read time correctly
void L2_ReadGTimer(PULONG GtimerPt) USING_0
{
BIT mode, retry;
UCHAR tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
ULONG tmp6, tmp7;
//body
//PRINT_L2(" L2_ReadGTimer: Enter\n");
mode = XBYTE[0x2073]&0x01;
do
{
tmp0 = XBYTE[0x2070];
tmp1 = XBYTE[0x2071];
tmp2 = XBYTE[0x2072];
tmp6 = ((ULONG)tmp2<<16)|((ULONG)tmp1<<8)|(ULONG)tmp0;
tmp3 = XBYTE[0x2070];
tmp4 = XBYTE[0x2071];
tmp5 = XBYTE[0x2072];
tmp7 = ((ULONG)tmp5<<16)|((ULONG)tmp4<<8)|(ULONG)tmp3;
if(mode) // up count mode
retry = (tmp6>tmp7);
else // down count mode
retry = (tmp6<tmp7);
} while(retry);
//PRINT_L2(" Gtimer low byte = %bx\n",tmp0);
//PRINT_L2(" Gtimer middle byte = %bx\n",tmp1);
//PRINT_L2(" Gtimer high byte = %bx\n",tmp2);
*GtimerPt = tmp6;
//PRINT_L2(" L2_ReadGTimer: Gtimer = %lx\n", *GtimerPt);
// return
//PRINT_L2(" L2_ReadGTimer: Exit\n");
return;
}
//-----------------------------------------------------------------------------
//L2_Wait
//-----------------------------------------------------------------------------
/*
routine description:
Pause the firmware execution by calling a waiting a period of time. The
timing is calculated by the up-count mode of the global timer.
arguments:
WaitTime: The wait time that is specified by the unit of mini-second.
return value:
0x00 - success
0x01 - general error
0x02 - parameter error
0x03 - write global timer error
others - error
*/
UCHAR L2_Wait(ULONG WaitTime) USING_0
{
ULONG Gtimer;
UCHAR error0, error1, status;
//body
//PRINT_L2(" L2_Wait: Enter\n");
if(WaitTime<=0xffffff)
{
error0 = L2_ConfigGTimer(0x05); //up count mode and time stick: 1ms
error1 = L2_WriteGTimer(0x000000);
if((error0==0x00) && (error1==0x00))
{
L2_StartGTimer();
do
{
L2_ReadGTimer(&Gtimer);
} while(Gtimer<WaitTime);
L2_StopGTimer();
status = L2K_SUCCESS;
}
else
{
status = 0x03;
//PRINT_L2(" L2_Wait: Error Code = %bx\n", status);
}
}
else
{
status = L2K_ERROR_PARAMETER;
//PRINT_L2(" L2_Wait: Error Code = %bx\n", status);
}
//PRINT_L2(" L2_Wait: Gtimer = %lx\n", Gtimer);
// return
//PRINT_L2(" L2_Wait: Exit\n");
return(status);
}
//-----------------------------------------------------------------------------
//L2_WriteRTC
//-----------------------------------------------------------------------------
/*
routine description:
Read the value of the date structure, translate them to 48-bit binary
count and then program the binary count to the RTC counter.
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 L3_DateToBin(PDATE DatePt, PDATE BinPt) USING_0
{
UCHAR status;
USHORT DMonth[14];
USHORT iday;
ULONG isec;
ULONG tmp0;
DMonth[0] = 0;
DMonth[1] = 0;
DMonth[2] = 31;
DMonth[3] = 59;
DMonth[4] = 90;
DMonth[5] = 120;
DMonth[6] = 151;
DMonth[7] = 181;
DMonth[8] = 212;
DMonth[9] = 243;
DMonth[10] = 273;
DMonth[11] = 304;
DMonth[12] = 334;
DMonth[13] = 365;
//body
//PRINT_L2(" L3_DateToBin: Enter\n");
if((DatePt->Second<60) || (DatePt->Minute<60) ||
(DatePt->Hour<24) || (DatePt->Day<32) ||
(DatePt->Month<13) || (DatePt->Year<100))
{
iday = 365*((USHORT)DatePt->Year - 1)+
DMonth[DatePt->Month]+
(USHORT)DatePt->Day - 1; //days since 2001/1/1
iday = iday+((USHORT)DatePt->Year - 1) / 4; //leap days since 2001/1/1
if((DatePt->Month > 2) && ((DatePt->Year % 4 )==0))
iday++; //add this year's leap day
isec = (ULONG)DatePt->Second +
60*((ULONG)DatePt->Minute +
60*((ULONG)DatePt->Hour + 24*(ULONG)iday)); //seconds since 2001/1/1
BinPt->Second = 0;
if(isec%2) BinPt->Minute = 0x80;
else BinPt->Minute = 0x00;
tmp0 = isec>>1;
BinPt->Hour = M_LoByteOfDword(tmp0);
BinPt->Day = M_MidLoByteOfDword(tmp0);
BinPt->Month = M_MidHiByteOfDword(tmp0);
BinPt->Year = M_HiByteOfDword(tmp0);
status = L2K_SUCCESS;
}
else
{
status = L2K_ERROR_PARAMETER;
//PRINT_L2(" L3_DateToBin: Error Code = %bx\n", status);
}
// return
//PRINT_L2(" L3_DateToBin: Exit\n");
return(status);
}
UCHAR L3_WriteRTCData(UCHAR Addr, UCHAR Data) USING_0
{
UCHAR status;
status = L2K_SUCCESS;
//body
//PRINT_L2(" L3_WriteRTCData: Enter\n");
XBYTE[0x206B] = Addr; //RTC address
XBYTE[0x206C] = Data; //RTC write data
XBYTE[0x2069] = 0x01; //write RTC register
while(XBYTE[0x206A]==0x00); // polling until RTC is ready
// return
//PRINT_L2(" L3_WriteRTCData: Exit\n");
return(status);
}
UCHAR L2_WriteRTC(PDATE DatePt) USING_0
{
struct DATESTC Bin;
UCHAR status0, status1, status2, status3, status4, status5, status6, status7;
UCHAR status;
//body
//PRINT_L2(" L2_WriteRTC: Enter\n");
status0 = L3_DateToBin(DatePt, &Bin); //translate the date to binary count
status1 = L3_WriteRTCData(0x10, Bin.Second);
status2 = L3_WriteRTCData(0x11, Bin.Minute);
status3 = L3_WriteRTCData(0x12, Bin.Hour);
status4 = L3_WriteRTCData(0x13, Bin.Day);
status5 = L3_WriteRTCData(0x14, Bin.Month);
status6 = L3_WriteRTCData(0x15, Bin.Year);
status7 = L3_WriteRTCData(0xB0, 0x01); //load timer
status = status0|status1|status2|status3|status4|status5|status6|status7;
// return
//PRINT_L2(" L2_WriteRTC: Exit\n");
return(status);
}
//-----------------------------------------------------------------------------
//L3_ReadRTCData
//-----------------------------------------------------------------------------
/*
routine description:
Read the value of RTC counter 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 L3_ReadRTCData(UCHAR Addr, PUCHAR DataPt) USING_0
{
UCHAR status;
status = L2K_SUCCESS;
//body
//PRINT_L2(" L3_ReadRTCData: Enter\n");
XBYTE[0x206B] = Addr; //RTC address
XBYTE[0x2069] = 0x02; //read RTC register
while(XBYTE[0x206A]==0x00); // polling until RTC is ready
*DataPt = XBYTE[0x206D];
// return
//PRINT_L2(" L3_ReadRTCData: Exit\n");
return(status);
}
//patch4.5@cytsai@fix RTC problem begin
/*
UCHAR L3_BinToDate(PDATE BinPt, PDATE DatePt) USING_0
{
UCHAR status = 0; // WWWW
UCHAR iyrs, mon;
USHORT DMonth[14];
USHORT iday, lday, qday, jday, mday;
ULONG imin, ihrs;
ULONG tmp0;
DMonth[0] = 0;
DMonth[1] = 0;
DMonth[2] = 31;
DMonth[3] = 59;
DMonth[4] = 90;
DMonth[5] = 120;
DMonth[6] = 151;
DMonth[7] = 181;
DMonth[8] = 212;
DMonth[9] = 243;
DMonth[10] = 273;
DMonth[11] = 304;
DMonth[12] = 334;
DMonth[13] = 365;
//body
//PRINT_L2(" L3_BinToDate: Enter\n");
//whole seconds since 2001/1/1
tmp0 = BinPt->Year;
tmp0 = (tmp0<<8)|(ULONG)BinPt->Month;
tmp0 = (tmp0<<8)|(ULONG)BinPt->Day;
tmp0 = (tmp0<<8)|(ULONG)BinPt->Hour;
tmp0 = tmp0<<1;
if(BinPt->Minute & 0x80) tmp0 = tmp0|0x00000001;
imin = tmp0/60; //whole minutes since 2001/1/1
DatePt->Second = tmp0-(60*imin);
ihrs = imin/60; //whole hours since 2001/1/1
DatePt->Minute = imin-60*ihrs;
iday = ihrs/24;
DatePt->Hour = ihrs-24*iday;
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 status0, status1, status2, status3, status4, status5, status6;
UCHAR status;
//body
//PRINT_L2(" L2_ReadRTC: Enter\n");
status0 = L3_ReadRTCData(0xA0, &(Bin.Second));
status1 = L3_ReadRTCData(0xA1, &(Bin.Minute));
status2 = L3_ReadRTCData(0xA2, &(Bin.Hour));
status3 = L3_ReadRTCData(0xA3, &(Bin.Day));
status4 = L3_ReadRTCData(0xA4, &(Bin.Month));
status5 = L3_ReadRTCData(0xA5, &(Bin.Year));
status6 = L3_BinToDate(&Bin, DatePt); //translate binary count to date
status = status0|status1|status2|status3|status4|status5|status6;
//PRINT_L2(" L2_ReadRTC: Second = %bu\n", DatePt->Second);
//PRINT_L2(" L2_ReadRTC: Minute = %bu\n", DatePt->Minute);
//PRINT_L2(" L2_ReadRTC: Hour = %bu\n", DatePt->Hour);
//PRINT_L2(" L2_ReadRTC: Day = %bu\n", DatePt->Day);
//PRINT_L2(" L2_ReadRTC: Month = %bu\n", DatePt->Month);
//PRINT_L2(" L2_ReadRTC: Year = %bu\n", DatePt->Year);
// return
//PRINT_L2(" L2_ReadRTC: Exit\n");
return(status);
}
old*/
/////*
UCHAR L3_BinToDate(PDATE BinPt, PDATE DatePt) USING_0
{
UCHAR status;
UCHAR iyrs, mon;
USHORT DMonth[14];
USHORT iday, lday, qday, jday, mday;
ULONG imin, ihrs;
ULONG tmp0;
status = L2K_SUCCESS;
DMonth[0] = 0;
DMonth[1] = 0;
DMonth[2] = 31;
DMonth[3] = 59;
DMonth[4] = 90;
DMonth[5] = 120;
DMonth[6] = 151;
DMonth[7] = 181;
DMonth[8] = 212;
DMonth[9] = 243;
DMonth[10] = 273;
DMonth[11] = 304;
DMonth[12] = 334;
DMonth[13] = 365;
//body
//PRINT_L2(" L3_BinToDate: Enter\n");
//whole seconds since 2001/1/1
tmp0 = BinPt->Year;
tmp0 = (tmp0<<8)|(ULONG)BinPt->Month;
tmp0 = (tmp0<<8)|(ULONG)BinPt->Day;
tmp0 = (tmp0<<8)|(ULONG)BinPt->Hour;
tmp0 = tmp0<<1;
if(BinPt->Minute & 0x80) tmp0 = tmp0|0x00000001;
imin = tmp0/60; //whole minutes since 2001/1/1
DatePt->Second = tmp0-(60*imin);
ihrs = imin/60; //whole hours since 2001/1/1
DatePt->Minute = imin-60*ihrs;
iday = ihrs/24;
DatePt->Hour = ihrs-24*iday;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -