time_t parseDVBtime(__u8 t1, __u8 t2, __u8 t3, __u8 t4, __u8 t5, __u16 *hash) { tm t; t.tm_sec=fromBCD(t5); t.tm_min=fromBCD(t4); t.tm_hour=fromBCD(t3); int mjd=(t1<<8)|t2; int k; t.tm_year = (int) ((mjd - 15078.2) / 365.25); t.tm_mon = (int) ((mjd - 14956.1 - (int)(t.tm_year * 365.25)) / 30.6001); t.tm_mday = (int) (mjd - 14956 - (int)(t.tm_year * 365.25) - (int)(t.tm_mon * 30.6001)); k = (t.tm_mon == 14 || t.tm_mon == 15) ? 1 : 0; t.tm_year = t.tm_year + k; t.tm_mon = t.tm_mon - 1 - k * 12; t.tm_mon--; t.tm_isdst = 0; t.tm_gmtoff = 0; if (hash) { *hash = t.tm_hour * 60 + t.tm_min; *hash |= t.tm_mday << 11; } return timegm(&t); }
static inline void parseDVBtime_impl(tm& t, const uint8_t *data) { parseDVBdate(t, (data[0] << 8) | data[1]); t.tm_hour = fromBCD(data[2]); t.tm_min = fromBCD(data[3]); t.tm_sec = fromBCD(data[4]); }
time_t parseDVBtime(uint16_t mjd, uint32_t stime_bcd) { tm t; parseDVBdate(t, mjd); t.tm_hour = fromBCD(stime_bcd >> 16); t.tm_min = fromBCD((stime_bcd >> 8) & 0xFF); t.tm_sec = fromBCD(stime_bcd & 0xFF); return timegm(&t); }
void gettime() { outb(0x70, 0x04); unsigned char bcdtime = inb(0x71); char *convtime = sys_alloc_mem(5); fromBCD(bcdtime, convtime); serial_print(convtime); serial_print(":"); outb(0x70, 0x02); bcdtime = inb(0x71); fromBCD(bcdtime, convtime); serial_print(convtime); serial_print(":"); outb(0x70, 0x00); bcdtime = inb(0x71); fromBCD(bcdtime, convtime); serial_println(convtime); serial_println(""); sys_free_mem(convtime); }
void getdate() { outb(0x70, 0x06); unsigned char beforeconv = inb(0x71); char *afterconv = sys_alloc_mem(5); fromBCD(beforeconv, afterconv); char *weekday = toweekday(afterconv); serial_print(weekday); serial_print(" "); outb(0x70, 0x08); beforeconv = inb(0x71); fromBCD(beforeconv, afterconv); char *month = tomonth(afterconv); serial_print(month); serial_print(" "); outb(0x70, 0x07); beforeconv = inb(0x71); fromBCD(beforeconv, afterconv); serial_print(afterconv); serial_print(" "); outb(0x70, 0x09); beforeconv = inb(0x71); fromBCD(beforeconv, afterconv); char *year = sys_alloc_mem(5); year[0] = '2'; year[1] = '0'; year[2] = afterconv[0]; year[3] = afterconv[1]; year[4] = '\0'; serial_println(year); serial_println(""); sys_free_mem(afterconv); sys_free_mem(weekday); sys_free_mem(month); sys_free_mem(year); }
RESULT eServiceEvent::parseFrom(Event *evt, int tsidonid) { m_begin = parseDVBtime(evt->getStartTimeMjd(), evt->getStartTimeBcd()); m_event_id = evt->getEventId(); uint32_t duration = evt->getDuration(); m_duration = fromBCD(duration>>16)*3600+fromBCD(duration>>8)*60+fromBCD(duration); if (m_language != "---" && loadLanguage(evt, m_language, tsidonid)) return 0; if (m_language_alternative != "---" && loadLanguage(evt, m_language_alternative, tsidonid)) return 0; if (loadLanguage(evt, "eng", tsidonid)) return 0; if (loadLanguage(evt, "---", tsidonid)) return 0; return 0; }
extern "C" void TWI0_IRQHandler() { uint32_t status ; status = TWI0->TWI_SR ; // Read only once, some bits cleared on read if ( TwiOperation == TWI_READ_RTC ) { if ( status & TWI_SR_RXBUFF ) { TWI0->TWI_IDR = TWI_IDR_RXBUFF ; TwiOperation = TWI_WAIT_RTCSTOP ; TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx TWI0->TWI_RCR = 1 ; // Last byte return ; } else { // must be TXCOMP, prob. NAK in data if ( TWI0->TWI_RCR > 0 ) { Rtc_valid = -1 ; TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx } } } if ( TwiOperation == TWI_WAIT_RTCSTOP ) { Rtc_valid = 1 ; // Set the date and time struct gtm utm; utm.tm_sec = fromBCD( Rtc_status[0] & 0x7F ) ; utm.tm_min = fromBCD( Rtc_status[1] & 0x7F ) ; utm.tm_hour = fromBCD( Rtc_status[2] & 0x3F ) ; utm.tm_mday = fromBCD( Rtc_status[4] & 0x3F ) ; utm.tm_mon = fromBCD( Rtc_status[5] & 0x1F ) - 1; utm.tm_year = fromBCD( Rtc_status[6] ) + 100 ; g_rtcTime = gmktime(&utm); TWI0->TWI_PTCR = TWI_PTCR_RXTDIS ; // Stop transfers if ( status & TWI_SR_RXRDY ) { (void) TWI0->TWI_RHR ; // Discard any rubbish data } } if ( status & TWI_SR_NACK ) { TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx } TWI0->TWI_IDR = TWI_IDR_TXCOMP | TWI_IDR_TXBUFE | TWI_IDR_RXBUFF ; TWI0->TWI_PTCR = TWI_PTCR_TXTDIS | TWI_PTCR_RXTDIS ; // Stop transfers if ( ( status & TWI_SR_TXCOMP ) == 0 ) { TWI0->TWI_IER = TWI_IER_TXCOMP ; TwiOperation = TWI_WAIT_COMP ; return ; } TwiOperation = TWI_NONE ; i2cCheck() ; }
void getTime(TimeVal* timeVal) { /* I2C START BIT WRITE: 0xD0 ACK<< DS1307 write address WRITE: 0x00 ACK<< set write pointer I2C START BIT WRITE: 0xD1 ACK<< DS1307 read address READ: 0x30 ACK<< 30 seconds READ: 0x30 ACK<< 30 minutes READ: 0x09 ACK<< 9 hours, 24 hour clock mode READ: 0x02 ACK<< Monday (day 2) READ: 0x07 ACK<< 7th (date) READ: 0x09 ACK<< September (month) READ: 0x09 ACK<< '09 (year) READ: 0x00 NACK<< Control register I2C STOP BIT */ unsigned char ret; // Set device address and write mode ret = i2c_start(DEV_DS1307 + I2C_WRITE); if (ret != 0) return; // Write read address ret = i2c_write(0x00); if (ret != 0) return; // Set device address and read mode ret = i2c_rep_start(DEV_DS1307 + I2C_READ); if (ret != 0) return; // Read the time data unsigned char secByte = i2c_readAck(); unsigned char minByte = i2c_readAck(); unsigned char hourByte = i2c_readAck(); /*unsigned char dayByte=*/i2c_readAck(); unsigned char dateByte = i2c_readAck(); unsigned char monthByte = i2c_readAck(); unsigned char yearByte = i2c_readAck(); // Read the control register i2c_readNak(); // Release the bus i2c_stop(); // Compute the year timeVal->year = 2000 + fromBCD(yearByte); // Compute the month index timeVal->month = fromBCD(monthByte); // Compute the date timeVal->date = fromBCD(dateByte); // Compute the hours, minutes and seconds timeVal->hour = fromBCD(hourByte); timeVal->min = fromBCD(minByte); timeVal->sec = fromBCD(secByte); }
extern "C" void TWI0_IRQHandler() { uint32_t status ; status = TWI0->TWI_SR ; // Read only once, some bits cleared on read if ( TwiOperation == TWI_READ_VOL ) { if ( status & TWI_SR_RXRDY ) { *Twi_read_address = TWI0->TWI_RHR ; // Read data } } #ifndef REVX if ( TwiOperation == TWI_READ_COPROC ) { if ( status & TWI_SR_RXBUFF ) { TWI0->TWI_IDR = TWI_IDR_RXBUFF ; TwiOperation = TWI_WAIT_STOP ; TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx TWI0->TWI_RCR = 1 ; // Last byte return ; } else { // must be TXCOMP, prob. NAK in data // Check if from the bootloader? if ( TWI0->TWI_RCR < COPROC_RX_BUXSIZE - 1 ) { // We got at least 1 byte if ( Co_proc_status[0] & 0x80 ) // Bootloader { CoProc_appgo_pending = 1 ; // Action application } } else { Coproc_valid = -1 ; TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx } } } #endif #ifdef REVX if ( TwiOperation == TWI_READ_RTC ) { if ( status & TWI_SR_RXBUFF ) { TWI0->TWI_IDR = TWI_IDR_RXBUFF ; TwiOperation = TWI_WAIT_RTCSTOP ; TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx TWI0->TWI_RCR = 1 ; // Last byte return ; } else { // must be TXCOMP, prob. NAK in data if ( TWI0->TWI_RCR > 0 ) { Rtc_valid = -1 ; TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx } } } #endif #ifndef REVX if ( TwiOperation == TWI_WAIT_STOP ) { Coproc_valid = 1 ; Coproc_read = Co_proc_status[0] ; if ( Coproc_read & 0x80 ) // Bootloader { CoProc_appgo_pending = 1 ; // Action application } else { // Got data from tiny app // Set the date and time t_time *p = &Time ; p->second = Co_proc_status[1] ; p->minute = Co_proc_status[2] ; p->hour = Co_proc_status[3] ; p->date= Co_proc_status[4] ; p->month = Co_proc_status[5] ; p->year = Co_proc_status[6] + ( Co_proc_status[7] << 8 ) ; } TWI0->TWI_PTCR = TWI_PTCR_RXTDIS ; // Stop transfers if ( status & TWI_SR_RXRDY ) { (void) TWI0->TWI_RHR ; // Discard any rubbish data } } #endif #ifdef REVX if ( TwiOperation == TWI_WAIT_RTCSTOP ) { Rtc_valid = 1 ; // Set the date and time t_time *p = &Time ; p->second = fromBCD( Rtc_status[0] & 0x7F ) ; p->minute = fromBCD( Rtc_status[1] & 0x7F ) ; p->hour = fromBCD( Rtc_status[2] & 0x3F ) ; p->date = fromBCD( Rtc_status[4] & 0x3F ) ; p->month = fromBCD( Rtc_status[5] & 0x1F ) ; p->year = fromBCD( Rtc_status[6] ) + 2000 ; TWI0->TWI_PTCR = TWI_PTCR_RXTDIS ; // Stop transfers if ( status & TWI_SR_RXRDY ) { (void) TWI0->TWI_RHR ; // Discard any rubbish data } } #endif // if ( TwiOperation == TWI_WRITE_VOL ) // { // } #ifndef REVX if ( TwiOperation == TWI_WRITE_COPROC ) { if ( status & TWI_SR_TXBUFE ) { TWI0->TWI_IDR = TWI_IDR_TXBUFE ; TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx TWI0->TWI_PTCR = TWI_PTCR_TXTDIS ; // Stop transfers TwiOperation = TWI_NONE ; return ; } } #endif if ( TwiOperation == TWI_WRITE_ONE ) { I2cHeadPointer->done = 1 ; I2cHeadPointer = I2cHeadPointer->next ; } if ( TwiOperation == TWI_READ_ONE ) { if ( status & TWI_SR_RXRDY ) { *I2cHeadPointer->dataBuffer = TWI0->TWI_RHR ; // Read data I2cHeadPointer->done = 1 ; I2cHeadPointer = I2cHeadPointer->next ; } else { I2Cdebug = 'F' ; I2cHeadPointer->done = 2 ; I2cHeadPointer = I2cHeadPointer->next ; } } if ( TwiOperation == TWI_WRITE_BUFFER ) { I2Cdebug = 'C' ; if ( status & TWI_SR_TXBUFE ) { I2Cdebug = 'D' ; TWI0->TWI_IDR = TWI_IDR_TXBUFE ; TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx TWI0->TWI_PTCR = TWI_PTCR_TXTDIS ; // Stop transfers TwiOperation = TWI_NONE ; I2cHeadPointer->done = 1 ; I2cHeadPointer = I2cHeadPointer->next ; return ; } else { I2Cdebug = 'E' ; TWI0->TWI_IDR = TWI_IDR_TXBUFE ; TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx TWI0->TWI_PTCR = TWI_PTCR_TXTDIS ; // Stop transfers TwiOperation = TWI_NONE ; I2cHeadPointer->done = 1 ; I2cHeadPointer = I2cHeadPointer->next ; return ; } } if ( TwiOperation == TWI_READ_BUFFER ) { if ( status & TWI_SR_RXBUFF ) { TWI0->TWI_IDR = TWI_IDR_RXBUFF ; TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx TWI0->TWI_RCR = 1 ; // Last byte return ; } else { // must be TXCOMP, prob. NAK in data if ( TWI0->TWI_RCR > 0 ) { TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx } else { TwiOperation = TWI_NONE ; I2cHeadPointer->done = 1 ; I2cHeadPointer = (struct t_I2C_request *) NULL ; } } } if ( status & TWI_SR_NACK ) { Debug_I2C_event += 0x100 ; TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx } if ( status & TWI_SR_RXBUFF ) { if ( TWI0->TWI_IMR & TWI_IMR_RXBUFF ) { Debug_I2C_event += 0x1000000 ; } } TWI0->TWI_IDR = TWI_IDR_TXCOMP | TWI_IDR_TXBUFE | TWI_IDR_RXBUFF ; TWI0->TWI_PTCR = TWI_PTCR_TXTDIS | TWI_PTCR_RXTDIS ; // Stop transfers if ( ( status & TWI_SR_TXCOMP ) == 0 ) { TWI0->TWI_IER = TWI_IER_TXCOMP ; TwiOperation = TWI_WAIT_COMP ; return ; } TwiOperation = TWI_NONE ; CoProcTimer = 0 ; // Cancel timeout i2c_check_for_request() ; }