BOOLEAN reversalPichinchaOk(void) { if( getReverseFile() == -1) { printf("\ferror al leer reverso"); WaitKey(3000, 0); return FALSE; } if( gRevTable.enableReverse == NO_PENDING) { //printf("\fNo hay reverso");WaitKey(3000, 0); return TRUE; } TX_DATA.b_trans = EDC_REV; ReadRTC( &TX_DATA.s_dtg ); IncTraceNoCNBReverse(); PackHostMsg(); ClearResponse(); if ((RSP_DATA.w_rspcode=APM_SendRcvd(&TX_BUF, &RX_BUF))==COMM_OK) { RSP_DATA.b_response = CheckHostRsp(); if (RSP_DATA.b_response <= TRANS_REJ) { //UpdateHostStatus(NO_PENDING); clearReversoPichincha(); } } if (RSP_DATA.b_response <= TRANS_REJ) { //gAppDat.reversal_count++; // Daniel 23/07/12 return TRUE; } return FALSE; }
void _reentrant SyncSMVFrame(void) { DWORD dw_time, dw_SkipJpegBlock; LONG dwCurrentTime; //read the current RTC stc_dwCurrentTime = ReadRTC() * 1000; if( stc_iHandle != -1) { //calculate the current time from audio decoder dw_time = ((DWORD)g_wSongByteTotalHigh << 24) + (DWORD)g_wSongByteTotalLow; dw_time *= (DWORD)1000000; dw_time /= (DWORD)g_SmvWave_dwAvgBytesPerSec; // Elapsed time in us //find the nearest JPEG block to the current point of audio decoder //the next JPEG block is preferred to the previous block //since frame drop within one JPEG block is time consuming //If more preference for the next block, increase the value added to dw_time in the following equation dw_SkipJpegBlock = (dw_time + (DWORD)((stc_iDurationInJpegBlock * 6) / 10)) / (DWORD)stc_iDurationInJpegBlock; if( (dw_SkipJpegBlock * (DWORD)stc_iDurationInJpegBlock) >= dw_time ) { //the next block is selected. Adjust the LastTime to the starting point of next JPEG block stc_dwLastTime = stc_dwCurrentTime + ((dw_SkipJpegBlock * (DWORD)stc_iDurationInJpegBlock) - dw_time); } else { //the previous block is selected. Adjust the LastTime to the starting point of previous JPEG block. //Then, we use frame drop machanism to fine tune the synchronization stc_dwLastTime = stc_dwCurrentTime - (dw_time - (dw_SkipJpegBlock * (DWORD)stc_iDurationInJpegBlock)); } //update the number of frame leave for rendering stc_dwTotalFrame = stc_dwTotalFrameBackup - dw_SkipJpegBlock * (DWORD)stc_iFrameInJpegBlock; //this is the file offset for the selected JPEG block dw_SkipJpegBlock = (dw_SkipJpegBlock * stc_iByteinJpegBlock) + stc_dwVideoStart; Fseek( stc_iHandle, dw_SkipJpegBlock, SEEK_SET); //initialize JPEG decoder the the selected JPEG block SmvCurrentJpeg.iHandle = stc_iHandle; SmvCurrentJpeg.DisplayParams.x = 0; SmvCurrentJpeg.DisplayParams.y = 0; SmvCurrentJpeg.DecParams.output_image_width = stc_iVideoWidth; SmvCurrentJpeg.DecParams.output_image_height = stc_iFrameHeight*stc_iFrameInJpegBlock; SMV_InitDecoder(); } else { //?? stc_dwLastTime = stc_dwCurrentTime - stc_iFrameDuration; } stc_iNumFrameStop = 0; }
void RTC_Service( void ) { static TICK8 trtc = 0; // execute once per second if ( TickGetDiff8bit(trtc) >= (TICK8)TICKS_PER_SECOND ) { trtc = TickGet8bit(); ReadRTC(); } }
void InstallCMOSHandler() { SendByteToPort(CMOSAddressPort, 0x8B); char PreviousValueOfRegisterB=ReadByteFromPort(CMOSAddressPort); SendByteToPort(CMOSAddressPort, 0x8B); SendByteToPort(CMOSDataPort, PreviousValueOfRegisterB | 0x40); //InstallIRQHandler(7,CMOSHandler); InstallIRQHandler(8,CMOSHandler); ReadRTC(); SendByteToPort(0x70,0x0C);// select register C ReadByteFromPort(0x71); // just throw away contents //PrintString(GetDateTime()); }
//--------------------------------------- // Main program //--------------------------------------- void main(void) { InitSerial(); // Initialize serial port //printf("%s",&Int2Day(1)); //----------------------------------- // Setup time and enable oscillator //----------------------------------- ReadRTC(&RTC_ARR[0]); RTC_ARR[0] = RTC_ARR[0] & 0x7F; // enable oscillator (bit 7=0) RTC_ARR[1] = 0x59; // minute = 59 RTC_ARR[2] = 0x23; // hour = 05 ,24-hour mode(bit 6=0) RTC_ARR[3] = 0x04; // Day = 1 or sunday RTC_ARR[4] = 0x31; // Date = 30 RTC_ARR[5] = 0x10; // month = August RTC_ARR[6] = 0x05; // year = 05 or 2005 WriteRTC(&RTC_ARR[0]); // Set RTC //----------------------------------- while(1) { ReadRTC(&RTC_ARR[0]); putchar(0x0C); // clear Hyper terminal printf("Day : %s\r\n",Int2Day(RTC_ARR[3])); printf("Time : %02bX:%02bX:%02bX\r\n",RTC_ARR[2],RTC_ARR[1],RTC_ARR[0]); printf("Data : %02bX-%s-20%02bX",RTC_ARR[4],Int2Month(RTC_ARR[5]),RTC_ARR[6]); // DelayMs(1000); // delay about 1 second } }
_reentrant void UpdateTime(int a,int b,int *Unused) { int iRTCMilliSeconds; long lRTCStartTime; a,b; lRTCStartTime = ReadRTC(); iRTCMilliSeconds = (unsigned int) (lRTCStartTime%1000); lRTCStartTime /= (long) 1000; //Start time now has the number of seconds lRTCStartTime=(long)lRTCStartTime + (long)g_UserTimeoffset; g_iCurrentRTCValues.B.m_iSeconds = (unsigned int) (lRTCStartTime%60); lRTCStartTime /= (long) 60; //now has number of minutes g_iCurrentRTCValues.B.m_iMinutes = (unsigned int) (lRTCStartTime%60); lRTCStartTime /= (long) 60; //now has number of hours g_iCurrentRTCValues.B.m_iHours = (unsigned int) (lRTCStartTime%24); }
int _reentrant DisplaySMV(void) { INT a,b,d; DWORD dwTimeDiff; //read the current RTC stc_dwCurrentTime = ReadRTC() * 1000; //if the current time is less than last time, no action //it is valid since last time will be used to synchronize audio playback if( stc_dwCurrentTime < stc_dwLastTime ) return 1; dwTimeDiff = stc_dwCurrentTime - stc_dwLastTime; //decode a frame if the time different is greater than frame duration if( dwTimeDiff >= stc_iFrameDuration ) { //perform frame drop machanism if the time different is greater than frame drop threshold if( dwTimeDiff >= stc_iFrameDrop ) { //calculate how many frame to drop dwTimeDiff = dwTimeDiff / stc_iFrameDuration; stc_dwTotalFrame -= dwTimeDiff; stc_dwLastTime += dwTimeDiff * stc_iFrameDuration; stc_iNumFrameStop += dwTimeDiff; // for house keeping for( ;dwTimeDiff >0; dwTimeDiff-- ) { if( SMV_DecodeDisplay(FALSE) != JPEG_SUCCESS ) { SysCallFunction(RSRC_MOTION_VIDEO_MENU_INITSTATE_CODE_BANK,CloseSMVFile,0,0,0); return 1; } } } //update the last time stc_dwLastTime += stc_iFrameDuration; stc_dwTotalFrame--; if( SMV_DecodeDisplay(TRUE) != JPEG_SUCCESS ) { SysCallFunction(RSRC_MOTION_VIDEO_MENU_INITSTATE_CODE_BANK,CloseSMVFile,0,0,0); } } return 1; }
///////////////////////////////////////////////////////////////////////////////////////// // //> Name: _reentrant void UpdateDateValues(int a, int b, int* iDateArray[]) // // // Type: Function // // Description: Retrieves and converts RTC to month,day, and year values // // Inputs: int a - space holder for SysCallFunction // int b - space holder for SysCallFunction // int* iDateArray[] - Array holding addresses of day,month,and year // from SetDateMenu.c // // Outputs: Day, Month, and Year in iDateArray contains the correct values // // Notes: This function was placed here for overlay memory considerations. // It is not used in SetTimeMenu. It is called with SysCallFunction by // SetDateMenu. SetTimeMenu had available memory space without increasing // the overlay block size. //< ////////////////////////////////////////////////////////////////////////////////////////// _reentrant void UpdateDateValues(int a, int b, int* iDateArray[]) { int iYears ; int iMonths; int iDays; // Get the addressed passed int* months = iDateArray[0]; int* days = iDateArray[1]; int* years = iDateArray[2]; long lRTCStartTime; int iRTCTotalDays; a,b; // prevent compiler unused warnings lRTCStartTime = ReadRTC(); lRTCStartTime /= (unsigned long) 1000; //now has seconds lRTCStartTime =lRTCStartTime+(long)g_UserTimeoffset;//+(long)g_Dateoffset; iRTCTotalDays = (unsigned int) (lRTCStartTime/86400); //now has number of days that have passed // Calculate years - calculate in groups of 4 to deal with leapyears without fraction divides // iYears = iRTCTotalDays/1461; iYears *= 4; iDays = iRTCTotalDays%1461; if(iDays >= 366) { iDays -= 366; iYears++; } while(iDays > 365) { iDays -= 365; iYears++; } // Calculate month and days // iRTCTotalDays = iDays; switch (iYears%4) { case 0: // leap year if(iRTCTotalDays < 182) { // first half of year if(iRTCTotalDays < 91) { // first quarter if(iRTCTotalDays > 59 ) {iMonths = MAR; iDays -= 59;} // MAR else if(iRTCTotalDays > 30) {iMonths = FEB; iDays -= 30;} // FEB else { iMonths = JAN; iDays += 1;} // JAN } // if(totalday < 91) else { // second quarter if(iRTCTotalDays > 151) {iMonths = JUN; iDays -= 151;} // JUN else if(iRTCTotalDays > 120){iMonths = MAY; iDays -= 120;} // MAY else { iMonths = APR; iDays -= 90;} // APR } } // end if(iRTCTotalDays < 182) else { // second half of year if(iRTCTotalDays < 274) { // third quarter if(iRTCTotalDays > 243) {iMonths = SEP; iDays -= 243;} // SEP else if(iRTCTotalDays > 212){iMonths = AUG; iDays -= 212;} // AUG else { iMonths = JUL; iDays -= 181;} // JUL } // if(iRTCTotalDays < 274) else { // fourth quarter if(iRTCTotalDays > 334) {iMonths = DEC; iDays -= 334;} // DEC else if(iRTCTotalDays > 304){iMonths = NOV; iDays -= 304;} // NOV else { iMonths = OCT; iDays -= 273;} // OCT } } break; // end leap year case default: // non-leap year if(iRTCTotalDays < 181) { // first half of year if(iRTCTotalDays < 90) { // first quarter if(iRTCTotalDays > 58 ) {iMonths = MAR; iDays -= 58;} // MAR else if(iRTCTotalDays > 30) {iMonths = FEB; iDays -= 30;} // FEB else { iMonths = JAN; iDays += 1;} // JAN } else { // second quarter if(iRTCTotalDays > 150) {iMonths = JUN; iDays -= 150;} // JUN else if(iRTCTotalDays > 119){iMonths = MAY; iDays -= 119;} // MAY else { iMonths = APR; iDays -= 89;} // APR } } // end if(iRTCTotalDays < 181) else { // second half of year if(iRTCTotalDays < 273) { // third quarter if(iRTCTotalDays > 242) {iMonths = SEP; iDays -= 242;} // SEP else if(iRTCTotalDays > 211){iMonths = AUG; iDays -= 211;} // AUG else { iMonths = JUL; iDays -= 180;} // JUL } else { // fourth quarter if(iRTCTotalDays > 333) {iMonths = DEC; iDays -= 333;} // DEC else if(iRTCTotalDays > 303){iMonths = NOV; iDays -= 303;} // NOV else { iMonths = OCT; iDays -= 272;} // OCT } } break; // end non-leap year case } // end switch (iYears%4) // pass back values *iDateArray[0] = iMonths; *iDateArray[1] = iDays; *iDateArray[2] = iYears; } // end UpdateDateValues
_reentrant void UpdateDate(int a, int b, int *Unused) { int iYears; int iMonths; int iDays; int iDayOfWeek; long lRTCStartTime; int iRTCTotalDays; a,b; lRTCStartTime = ReadRTC(); lRTCStartTime /= (unsigned long) 1000; //now has seconds lRTCStartTime = lRTCStartTime+(long)g_UserTimeoffset; iRTCTotalDays = (unsigned int) (lRTCStartTime/86400); //now has number of days that have passed #if 0 // This calculation does not work correctly for Dec 31 in each leap year. For example, // since 2008 is a leap year, Dec 31st is the 365th day of that year. Dec 31, 2008 is 10592 // days since Jan 1, 1980. Using the code below you would get // // iYears = 10592 / 1461 = 7 // iYears *= 4 = 28. // // iDays = 10592 % 1461 = 365 // // We skip the 'if(iDays>=366)' code because we have 365 days. But then we reach // the 'while(iDays >= 365)' code and we fall into that loop because iDays is equal // to 365. This changes iYears to 29 and iDays to 0, which is incorrect. We // should have iYears set to 28 and iDays left at 365 since Dec 31, 2008 is the // 365th day of 2008. // // NOTE: the 'while(iDays >= 365)' loop was 'while(iDays > 365)' which would fix // this problem BUT CAUSES MORE! // Calculate years - calculate in groups of 4 to deal with leapyears without fraction divides // iYears = iRTCTotalDays/1461; iYears *= 4; iDays = iRTCTotalDays%1461; if(iDays >= 366) { iDays -= 366; iYears++; } while(iDays >= 365) { iDays -= 365; iYears++; } #else // A leap year is a year that is divisible by 4 EXCEPT years that are // divisible by 100 but not 400. The next year divisible by 4 that // is not a leap year is 2100 so we can safely assume for our // calculations that it's just a year divisible by 4. iYears = iRTCTotalDays/1461; iYears *= 4; iDays = iRTCTotalDays%1461; // At this point we know we have less than 4 years of days // in iDays. We also know that the first year is going // to be a leap year. We need to find out how many years // are in iDays, add that to iyears and then subtract // that many days from iDays. The first year will be // a leap year so we need to add one 366 and rest 365. iYears = iRTCTotalDays/1461; iYears *= 4; iDays = iRTCTotalDays%1461; // NOTE: At this point, if iDays < 366 then we are in // a leap year. if(iDays >= 366) { iDays -= 366; iYears++; // The first year has 366 days and the // rest 365. while(iDays >= 365) { iDays -= 365; iYears++; } } #endif // calculate Day of Week g_iCurrentRTCValues.B.m_iDayOfWeek = iRTCTotalDays%7; // Calculate month and days // iRTCTotalDays = iDays; switch (iYears%4) { case 0: // leap year if(iRTCTotalDays < 182) { // first half of year if(iRTCTotalDays < 91) { // first quarter if(iRTCTotalDays > 59 ) {iMonths = MAR; iDays -= 59;} // MAR else if(iRTCTotalDays > 30) {iMonths = FEB; iDays -= 30;} // FEB else { iMonths = JAN; iDays += 1;} // JAN } // if(totalday < 91) else { // second quarter if(iRTCTotalDays > 151) {iMonths = JUN; iDays -= 151;} // JUN else if(iRTCTotalDays > 120){iMonths = MAY; iDays -= 120;} // MAY else { iMonths = APR; iDays -= 90;} // APR } } // end if(iRTCTotalDays < 182) else { // second half of year if(iRTCTotalDays < 274) { // third quarter if(iRTCTotalDays > 243) {iMonths = SEP; iDays -= 243;} // SEP else if(iRTCTotalDays > 212){iMonths = AUG; iDays -= 212;} // AUG else { iMonths = JUL; iDays -= 181;} // JUL } // if(iRTCTotalDays < 274) else { // fourth quarter if(iRTCTotalDays > 334) {iMonths = DEC; iDays -= 334;} // DEC else if(iRTCTotalDays > 304){iMonths = NOV; iDays -= 304;} // NOV else { iMonths = OCT; iDays -= 273;} // OCT } } break; // end leap year case default: // non-leap year if(iRTCTotalDays < 181) { // first half of year if(iRTCTotalDays < 90) { // first quarter if(iRTCTotalDays > 58 ) {iMonths = MAR; iDays -= 58;} // MAR else if(iRTCTotalDays > 30) {iMonths = FEB; iDays -= 30;} // FEB else { iMonths = JAN; iDays += 1;} // JAN } else { // second quarter if(iRTCTotalDays > 150) {iMonths = JUN; iDays -= 150;} // JUN else if(iRTCTotalDays > 119){iMonths = MAY; iDays -= 119;} // MAY else { iMonths = APR; iDays -= 89;} // APR } } // end if(iRTCTotalDays < 181) else { // second half of year if(iRTCTotalDays < 273) { // third quarter if(iRTCTotalDays > 242) {iMonths = SEP; iDays -= 242;} // SEP else if(iRTCTotalDays > 211){iMonths = AUG; iDays -= 211;} // AUG else { iMonths = JUL; iDays -= 180;} // JUL } else { // fourth quarter if(iRTCTotalDays > 333) {iMonths = DEC; iDays -= 333;} // DEC else if(iRTCTotalDays > 303){iMonths = NOV; iDays -= 303;} // NOV else { iMonths = OCT; iDays -= 272;} // OCT } } break; // end non-leap year case } // end switch (iYears%4) g_iCurrentRTCValues.B.m_iDays = iDays; g_iCurrentRTCValues.B.m_iMonths = iMonths; g_iCurrentRTCValues.B.m_iYears = iYears; } // end UpdateDate