DS3231_alarm2_t DS3231::getAlarmType2(void) { uint8_t values[3]; uint8_t mode = 0; Wire.beginTransmission(DS3231_ADDRESS); #if ARDUINO >= 100 Wire.write(DS3231_REG_ALARM_2); #else Wire.send(DS3231_REG_ALARM_2); #endif Wire.endTransmission(); Wire.requestFrom(DS3231_ADDRESS, 3); while(!Wire.available()) {}; for (int i = 2; i >= 0; i--) { #if ARDUINO >= 100 values[i] = bcd2dec(Wire.read()); #else values[i] = bcd2dec(Wire.receive()); #endif } Wire.endTransmission(); mode |= ((values[2] & 0b01000000) >> 5); mode |= ((values[1] & 0b01000000) >> 4); mode |= ((values[0] & 0b01000000) >> 3); mode |= ((values[0] & 0b00100000) >> 1); return (DS3231_alarm2_t)mode; }
static void stamp2dos(unsigned char *cpmstamp, unsigned char *dosstamp) { time_t secs; struct tm *ptime; int cpmdays; unsigned short dosdate, dostime; cpmdays = 256*cpmstamp[1] + cpmstamp[0]; secs = (cpmdays + 2921) * 86400; /* Unix day 2921 is CP/M day 0 */ secs += 3600 * bcd2dec(cpmstamp[2]); secs += 60 * bcd2dec(cpmstamp[3]); ptime = gmtime(&secs); dosdate = (ptime->tm_year - 80) << 9; dosdate |= ((ptime->tm_mon + 1) & 0x0F) << 5; dosdate |= (ptime->tm_mday & 0x1F); dostime = (ptime->tm_hour) << 11; dostime |= (ptime->tm_min & 0x3F) << 5; dosstamp[0] = dostime & 0xFF; dosstamp[1] = dostime >> 8; dosstamp[2] = dosdate & 0xFF; dosstamp[3] = dosdate >> 8; }
void Read_DS1307(void) { char data; // First we initial the pointer register to address 0x00 // Start the I2C Write Transmission i2c_start(DS1307_ID,DS1307_ADDR,TW_WRITE); // Start from Address 0x00 i2c_write(0x00); // Stop I2C Transmission i2c_stop(); // Start the I2C Read Transmission i2c_start(DS1307_ID,DS1307_ADDR,TW_READ); // Read the Second Register, Send Master Acknowledge i2c_read(&data,ACK); ds1307_addr[0]=bcd2dec(data & 0x7F); // Read the Minute Register, Send Master Acknowledge i2c_read(&data,ACK); ds1307_addr[1]=bcd2dec(data); // Read the Hour Register, Send Master Acknowledge i2c_read(&data,ACK); if ((data & 0x40) == 0x40) { hour_mode = HOUR_12; ampm_mode=(data & 0x20) >> 5; // ampm_mode: 0-AM, 1-PM ds1307_addr[2]=bcd2dec(data & 0x1F); } else {
RTCAlarmTime DS3231::getAlarm2(void) { uint8_t values[3]; RTCAlarmTime a; Wire.beginTransmission(DS3231_ADDRESS); #if ARDUINO >= 100 Wire.write(DS3231_REG_ALARM_2); #else Wire.send(DS3231_REG_ALARM_2); #endif Wire.endTransmission(); Wire.requestFrom(DS3231_ADDRESS, 3); while(!Wire.available()) {}; for (int i = 2; i >= 0; i--) { #if ARDUINO >= 100 values[i] = bcd2dec(Wire.read() & 0b01111111); #else values[i] = bcd2dec(Wire.receive() & 0b01111111); #endif } Wire.endTransmission(); a.day = values[0]; a.hour = values[1]; a.minute = values[2]; a.second = 0; return a; }
void LCD_DisplayTime(unsigned char hr,unsigned char min, unsigned char sec) { uint8_t d_hour, d_min, d_sec; uint8_t digit0=0, digit1=0, digit2=0; d_hour = bcd2dec(hr); d_min = bcd2dec(min); d_sec = bcd2dec(sec); if ( Time_Format == 1 ) // 12 hour format { LCD_SetCursor(1,14); if (d_hour >12) { d_hour -= 12; LCD_Printf("PM"); } else { if ( d_hour == 0) // time is 12 AM { d_hour = 12; } LCD_Printf("AM"); } } if ( Display_Style == 1) // both date and time are displayed in this style { LCD_GoToLine(1); LCD_Printf(" %2d:%2d:%2d",d_hour,d_min,d_sec); } else // only date is displayed, so display big numbers { digit1 = d_hour/10; digit0= d_hour%10; LCD_DisplayBigNum(digit1,0); //display hour LCD_DisplayBigNum(digit0,3); // set colon LCD_SetCursor(1,6); lcd_DataWrite(0xA5); LCD_SetCursor(2,6); lcd_DataWrite(0xA5); //display min digit1 = d_min/10; digit0= d_min%10; LCD_DisplayBigNum(digit1,7); LCD_DisplayBigNum(digit0,10); //display sec LCD_SetCursor(2,14); LCD_Printf("%2x",sec); } }
void LCD_DisplayDate(uint8_t day, uint8_t month, uint8_t year) { unsigned char digit0=0, digit1=0, digit2=0; if ( Display_Style == 1) { LCD_GoToLine(2); digit0 = bcd2dec(day); digit1 = bcd2dec(month); digit2 = bcd2dec(year); LCD_Printf(" %2d/%2d/%2d",digit0,digit1,digit2); } }
static dc_status_t shearwater_predator_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata) { dc_buffer_t *buffer = dc_buffer_new (SZ_MEMORY); if (buffer == NULL) return DC_STATUS_NOMEMORY; dc_status_t rc = shearwater_predator_device_dump (abstract, buffer); if (rc != DC_STATUS_SUCCESS) { dc_buffer_free (buffer); return rc; } // Emit a device info event. unsigned char *data = dc_buffer_get_data (buffer); dc_event_devinfo_t devinfo; devinfo.model = data[0x2000D]; devinfo.firmware = bcd2dec (data[0x2000A]); devinfo.serial = array_uint32_be (data + 0x20002); device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); rc = shearwater_predator_extract_dives (abstract, data, SZ_MEMORY, callback, userdata); dc_buffer_free (buffer); return rc; }
DateTime *ds1307_get(void) { Wire.beginTransmission(_ds1307_address); Wire.write((byte) 0x00); Wire.endTransmission(); Wire.requestFrom(_ds1307_address, 7); DateTime *date = (DateTime *) malloc(sizeof(DateTime)); date->second = bcd2dec(Wire.read()); date->minute = bcd2dec(Wire.read()); date->hour = bcd2dec(Wire.read() & 0b111111); // 24 hour time date->weekday = bcd2dec(Wire.read()); // 0-6 -> sunday - Saturday date->monthday = bcd2dec(Wire.read()); date->month = bcd2dec(Wire.read()); date->year = bcd2dec(Wire.read()); if (date->second <= 59 && date->minute <= 59 && date->hour <= 23 && date->month <= 12 && date->year < 100) { return date; } else { free(date); return NULL; } }
ALARM_TYPES_t DS3232RTC::readAlarm(byte alarmNumber, tmElements_t &tm) { uint8_t addr; uint16_t alarmType; if (alarmNumber == ALARM_1) { addr = ALM1_SECONDS; alarmType = 0x00; byte secondDcb = readRTC(addr++); if (secondDcb & _BV(A1M1)) alarmType &= 0x01; secondDcb &= ~(_BV(A1M1)); tm.Second = bcd2dec(secondDcb); } else { addr = ALM2_MINUTES; alarmType = 0x80; tm.Second = 0; } byte minuteDcb = readRTC(addr++); if (minuteDcb & _BV(A1M2)) alarmType |= 0x02; minuteDcb &= ~(_BV(A1M2)); tm.Minute = bcd2dec(minuteDcb); byte hourDcb = readRTC(addr++); if (hourDcb & _BV(A1M3)) alarmType |= 0x04; hourDcb &= ~(_BV(A1M3)); tm.Hour = bcd2dec(hourDcb); byte daydateBcd = readRTC(addr++); if (daydateBcd & _BV(DYDT)) alarmType |= 0x10; if (daydateBcd & _BV(A1M4)) alarmType |= 0x08; daydateBcd &= ~(_BV(A1M4)); if (daydateBcd & _BV(DYDT)) { daydateBcd &= ~(_BV(DYDT)); tm.Wday = bcd2dec(daydateBcd); tm.Day = 0; } else { tm.Day = bcd2dec(daydateBcd); tm.Wday = 0; } return ((ALARM_TYPES_t) alarmType); }
// Aquire data from the RTC chip in BCD format bool DS1307RTC::read(tmElements_t &tm) { uint8_t sec; Wire.beginTransmission(DS1307_CTRL_ID); Wire.write((uint8_t) 0x00); if (Wire.endTransmission() != 0) { exists = false; return false; } exists = true; // request the 7 data fields (secs, min, hr, dow, date, mth, yr) Wire.requestFrom(DS1307_CTRL_ID, tmNbrFields); if (Wire.available() < tmNbrFields) return false; sec = Wire.read(); tm.Second = bcd2dec(sec & 0x7f); tm.Minute = bcd2dec(Wire.read()); tm.Hour = bcd2dec(Wire.read() & 0x3f); // mask assumes 24hr clock tm.Wday = bcd2dec(Wire.read()); tm.Day = bcd2dec(Wire.read()); tm.Month = bcd2dec(Wire.read()); tm.Year = y2kYearToTm((bcd2dec(Wire.read()))); if (sec & 0x80) return false; // clock is halted return true; }
// -------------------------------------------------------- // Read the current time from the RTC and return it in a tmElements_t // structure. Returns the bus status (zero if successful). uint8_t DS1302RTC::read(tmElements_t &tm) { uint8_t buff[8]; readRTC(buff); tm.Second = bcd2dec(buff[0] & B01111111); // 7 bit (4L - sec, 3H - 10 sec), ignore CH bit tm.Minute = bcd2dec(buff[1] & B01111111); // 7 bit (4L - min, 3H - 10 min), ignore NULL bit tm.Hour = bcd2dec(buff[2] & B00111111); // 6 bit (4L - hrs, 2H - 10 hrs), ignore NULL & 12/24 bits tm.Day = bcd2dec(buff[3] & B00111111); // 6 bit (4L - dat, 2H - 10 dat), ignore 2 NULLs tm.Month = bcd2dec(buff[4] & B00011111); // 5 bit (4L - mth, 1H - 10 mth), ignore 3 NULLs tm.Wday = buff[5] & B00000111 ; // 3 bit, ignore 5 NULLs tm.Year = y2kYearToTm( bcd2dec(buff[6])); // 8 bit // Validation if(tm.Second >= 0 && tm.Second <= 59) if(tm.Minute >= 0 && tm.Minute <= 59) if(tm.Hour >= 0 && tm.Hour <= 23) if(tm.Day >= 1 && tm.Day <= 31) if(tm.Month >= 1 && tm.Month <= 12) if(tm.Wday >= 1 && tm.Wday <= 7) if(tm.Year >= 0 && tm.Year <= 99) return 0; // Success return 1; // Error }
static long rtctime(void) { struct RTCdev *dev; Rtc rtc; dev = nvr.rtc; dev->control |= RTCREAD; wbflush(); rtc.sec = bcd2dec(dev->sec) & 0x7F; rtc.min = bcd2dec(dev->min & 0x7F); rtc.hour = bcd2dec(dev->hour & 0x3F); rtc.mday = bcd2dec(dev->mday & 0x3F); rtc.mon = bcd2dec(dev->mon & 0x3F); rtc.year = bcd2dec(dev->year); dev->control &= ~RTCREAD; wbflush(); if (rtc.mon < 1 || rtc.mon > 12) return 0; /* * the world starts Jan 1 1970 */ if(rtc.year < 70) rtc.year += 2000; else rtc.year += 1900; return rtc2sec(&rtc); }
static DS1307 read_ds1307() { if (twi_mt_start(DS1307_CTRL_ID) != TWST_OK) return; twi_write(0x00); // Set pointer address to seconds if (twi_mr_start(DS1307_CTRL_ID) != TWST_OK) return; DS1307 time; //Reading values time.second = bcd2dec(twi_read() & 0x7f); time.minute = bcd2dec(twi_read()); time.hour = bcd2dec(twi_read() & 0x3f); twi_read(); // week number not needed time.day = bcd2dec(twi_read()); time.month = bcd2dec(twi_read()); time.year = bcd2dec(twi_read()); twi_stop(); return time; }
//-------------------------------------------------------------------------------- // Reads the current time from RTC device. void DS3232Controller::readCurrentTimeFromDevice() { Wire.beginTransmission(RTC_ADDR); Wire.write((uint8_t) RTC_SECONDS); // exit on error if (Wire.endTransmission() != 0) { return; } //request 7 bytes (secs, min, hr, dow, date, mth, yr) Wire.requestFrom(RTC_ADDR, 7); second = bcd2dec(Wire.read() & ~_BV(DS1307_CH)); minute = bcd2dec(Wire.read()); hour = bcd2dec(Wire.read() & ~_BV(HR1224)); //assumes 24hr clock const byte dayOfWeek = Wire.read(); const byte dayOfMonth = bcd2dec(Wire.read()); day = dayOfWeek * 32 + dayOfMonth; month = bcd2dec(Wire.read() & ~_BV(CENTURY)); //don't use the Century bit y2kYear = bcd2dec(Wire.read()) - 30; // convert year from 1970 to Y2K year const long nowInSeconds = (long) (millis() / 1000); const int minutesFromMidnight = int(60) * hour + minute; secondsFromMidnight = nowInSeconds - (60L * minutesFromMidnight + second); lastUpdateInSM = minutesFromMidnight; }
// Get time void ds3231_get(timeDate_s* timeData) { // Initialize to 0 // Otherwise if the RTC isn't connected then we'll end up with trying to use random data for the time byte data[7] = {0}; read(DS3231_ADDR_SECS, data, sizeof(data)); timeData->time.secs = bcd2dec(data[0]); timeData->time.mins = bcd2dec(data[1]); timeData->time.hour = bcd2dec(data[2]); timeData->date.day = data[3]; // Don't need to convert to DEC since it only stores 0 - 6 timeData->date.date = bcd2dec(data[4]); timeData->date.month = bcd2dec(data[5]); timeData->date.year = bcd2dec(data[6]); // Month and day start at 1, but we want to start at 0 if(timeData->date.day > 0) timeData->date.day--; if(timeData->date.month > 0) timeData->date.month--; /* // Can't subtract 1 if month is BCD 10, have to do it manually byte month = timeData->month; if(month > 0) { if(month != 0b00010000) month--; else month = 0b00001001; timeData->month = month; }*/ }
static void cmos_get_date_time(struct tm *date) { int sec, min, hour, mday, mon, year; time_t ts; struct tm dummy; sec = cmos_read(RTC_SECONDS); min = cmos_read(RTC_MINUTES); hour = cmos_read(RTC_HOURS); mday = cmos_read(RTC_DAY_OF_MONTH); mon = cmos_read(RTC_MONTH); year = cmos_read(RTC_YEAR); sec = bcd2dec(sec); min = bcd2dec(min); hour = bcd2dec(hour); mday = bcd2dec(mday); mon = bcd2dec(mon); year = bcd2dec(year); ts = time(NULL); localtime_r(&ts, &dummy); date->tm_isdst = dummy.tm_isdst; date->tm_sec = sec; date->tm_min = min; date->tm_hour = hour; date->tm_mday = mday; date->tm_mon = mon - 1; date->tm_year = base_year + year - 1900; date->tm_gmtoff = 0; ts = mktime(date); }
RTCDateTime DS3231::getDateTime(void) { int values[7]; Wire.beginTransmission(DS3231_ADDRESS); #if ARDUINO >= 100 Wire.write(DS3231_REG_TIME); #else Wire.send(DS3231_REG_TIME); #endif Wire.endTransmission(); Wire.requestFrom(DS3231_ADDRESS, 7); while(!Wire.available()) {}; for (int i = 6; i >= 0; i--) { #if ARDUINO >= 100 values[i] = bcd2dec(Wire.read()); #else values[i] = bcd2dec(Wire.receive()); #endif } Wire.endTransmission(); t.year = values[0] + 2000; t.month = values[1]; t.day = values[2]; t.dayOfWeek = values[3]; t.hour = values[4]; t.minute = values[5]; t.second = values[6]; t.unixtime = unixtime(); return t; }
uint8_t MCP7940RTC::getYear() { byte b=0; Wire.beginTransmission(MCP7940_CTRL_ID); #if ARDUINO >= 100 Wire.write((byte)6); #else Wire.send(6); #endif Wire.endTransmission(); Wire.requestFrom(MCP7940_CTRL_ID, 1); #if ARDUINO >= 100 byte b1 = Wire.read(); #else byte b1 = Wire.receive(); #endif; return bcd2dec(b1); }
int ds1307_clock_get(struct tm *tm) { int ret; struct ds1307_raw raw; // Read the values from the RTC ret = read((uint8_t *)&raw, ADDR_SEC, sizeof(raw)); if (ret) { return ret; } // Convert the values tm->tm_sec = bcd2dec(raw.sec); tm->tm_min = bcd2dec(raw.min); // hour is done below tm->tm_mday = bcd2dec(raw.mday); tm->tm_mon = bcd2dec(raw.mon) - 1; tm->tm_year = bcd2dec(raw.year) + 100; // we assume a century of 2000 tm->tm_wday = bcd2dec(raw.wday) - 1; // Convert hours, taking into account 12-hour mode if (raw.hour & HOUR_12) { if (raw.hour & HOUR_PM) { // 1 - 12 pm is 13 - 00 tm->tm_hour = bcd2dec(raw.hour & ~(HOUR_12 | HOUR_PM)); tm->tm_hour += 12; tm->tm_hour %= 24; } else { // 1 - 12 am is 01 - 12 tm->tm_hour = bcd2dec(raw.hour & ~HOUR_12); } } else { tm->tm_hour = bcd2dec(raw.hour); } return 0; }
/****************************************************************** * Update to current time */ void RTClib::now(){ Wire.beginTransmission(DS1307_ADDRESS); Wire.write(0); Wire.endTransmission(); Wire.requestFrom(DS1307_ADDRESS,7); ss = bcd2dec(Wire.read() & 0x7F); mm = bcd2dec(Wire.read()); hh = bcd2dec(Wire.read()); Wire.read(); d = bcd2dec(Wire.read()); m = bcd2dec(Wire.read()); y = bcd2dec(Wire.read()); }
// Aquire data from the RTC chip in BCD format void DS1307RTC::read( tmElements_t &tm) { Wire.beginTransmission(DS1307_CTRL_ID); Wire.write(0x00); Wire.endTransmission(); // request the 7 data fields (secs, min, hr, dow, date, mth, yr) Wire.requestFrom(DS1307_CTRL_ID, tmNbrFields); tm.Second = bcd2dec(Wire.read() & 0x7f); tm.Minute = bcd2dec(Wire.read() ); tm.Hour = bcd2dec(Wire.read() & 0x3f); // mask assumes 24hr clock tm.Wday = bcd2dec(Wire.read() ); tm.Day = bcd2dec(Wire.read() ); tm.Month = bcd2dec(Wire.read() ); tm.Year = y2kYearToTm((bcd2dec(Wire.read()))); }
/* * getTime */ time_t DS1339::getTime() // Aquire data from buffer and convert to time_t { byte buffer[7]; tmElements_t tm; if(readBytes(buffer, 0, 7) == 7) { tm.Second = bcd2dec(buffer[0] & DS1339_SEC_MASK); tm.Minute = bcd2dec(buffer[1]); tm.Hour = bcd2dec(buffer[2] & DS1339_HR_MASK); // mask assumes 24hr clock tm.Wday = bcd2dec(buffer[3]); tm.Day = bcd2dec(buffer[4]); tm.Month = bcd2dec(buffer[5]); tm.Year = y2kYearToTm((bcd2dec(buffer[6]))); } return(makeTime(tm)); }
uint8_t MCP7940RTC::getMinute() { byte b=0; Wire.beginTransmission(MCP7940_CTRL_ID); #if ARDUINO >= 100 Wire.write((byte)1); #else Wire.send(1); #endif Wire.endTransmission(); Wire.requestFrom(MCP7940_CTRL_ID, 1); #if ARDUINO >= 100 byte b1 = Wire.read(); #else byte b1 = Wire.receive(); #endif b = bcd2dec(b1 & 0x7f); //b = (b1 & 0xf) + ((b1 & 0x70)>>4) * 10; return b; }
// Aquire data from the RTC chip in BCD format void DS1307RTC::read( tmElements_t &tm) { if (!ctrl_id) return; Wire.beginTransmission(ctrl_id); Wire.write((uint8_t)0x00); Wire.endTransmission(); // request the 7 data fields (secs, min, hr, dow, date, mth, yr) Wire.requestFrom(ctrl_id, tmNbrFields); tm.Second = bcd2dec(Wire.read() & 0x7f); tm.Minute = bcd2dec(Wire.read() ); tm.Hour = bcd2dec(Wire.read() & 0x3f); // mask assumes 24hr clock tm.Wday = bcd2dec(Wire.read() & 0x07); tm.Day = bcd2dec(Wire.read() ); tm.Month = bcd2dec(Wire.read() & 0x1f); // fix bug for MCP7940 tm.Year = y2kYearToTm((bcd2dec(Wire.read()))); }
uint8_t MCP7940RTC::getHour() { //TODO: Check for 24-hr formation vs. am/pm, but for now, treat as 24-hr format due to init setting of same byte b=0; Wire.beginTransmission(MCP7940_CTRL_ID); #if ARDUINO >= 100 Wire.write((byte)2); #else Wire.send(2); #endif Wire.endTransmission(); Wire.requestFrom(MCP7940_CTRL_ID, 1); #if ARDUINO >= 100 byte b1 = Wire.read(); #else byte b1 = Wire.receive(); #endif; byte b2 = b1 & 0x1f; if((b1 & 0x40)>0) b2 |= 0x20; b = bcd2dec(b1 & 0x3f); return b; }
/*----------------------------------------------------------------------* * Read the current time from the RTC and return it in a tmElements_t * * structure. Returns the I2C status (zero if successful). * *----------------------------------------------------------------------*/ byte DS3232RTC::read(tmElements_t &tm) { i2cBeginTransmission(RTC_ADDR); i2cWrite((uint8_t)RTC_SECONDS); if ( byte e = i2cEndTransmission() ) return e; //request 7 bytes (secs, min, hr, dow, date, mth, yr) i2cRequestFrom(RTC_ADDR, tmNbrFields); tm.Second = bcd2dec(i2cRead() & ~_BV(DS1307_CH)); tm.Minute = bcd2dec(i2cRead()); tm.Hour = bcd2dec(i2cRead() & ~_BV(HR1224)); //assumes 24hr clock tm.Wday = i2cRead(); tm.Day = bcd2dec(i2cRead()); tm.Month = bcd2dec(i2cRead() & ~_BV(CENTURY)); //don't use the Century bit tm.Year = y2kYearToTm(bcd2dec(i2cRead())); return 0; }
void ds1307_get_time(i2c_dev_t *dev, struct tm *time) { uint8_t buf[7]; uint8_t reg = TIME_REG; i2c_slave_read(dev->bus, dev->addr, ®, buf, 7); time->tm_sec = bcd2dec(buf[0] & SECONDS_MASK); time->tm_min = bcd2dec(buf[1]); if (buf[2] & HOUR12_BIT) { // RTC in 12-hour mode time->tm_hour = bcd2dec(buf[2] & HOUR12_MASK) - 1; if (buf[2] & PM_BIT) time->tm_hour += 12; } else time->tm_hour = bcd2dec(buf[2] & HOUR24_MASK); time->tm_wday = bcd2dec(buf[3]) - 1; time->tm_mday = bcd2dec(buf[4]); time->tm_mon = bcd2dec(buf[5]) - 1; time->tm_year = bcd2dec(buf[6]) + 2000; }
static void cmos_get_date_time(struct tm *date) { int base_year = 2000, hour_offset; int sec, min, hour, mday, mon, year; time_t ts; struct tm dummy; sec = cmos_read(RTC_SECONDS); min = cmos_read(RTC_MINUTES); hour = cmos_read(RTC_HOURS); mday = cmos_read(RTC_DAY_OF_MONTH); mon = cmos_read(RTC_MONTH); year = cmos_read(RTC_YEAR); if ((cmos_read(RTC_REG_B) & REG_B_DM) == 0) { sec = bcd2dec(sec); min = bcd2dec(min); hour = bcd2dec(hour); mday = bcd2dec(mday); mon = bcd2dec(mon); year = bcd2dec(year); hour_offset = 80; } else { hour_offset = 0x80; } if ((cmos_read(0x0B) & REG_B_24H) == 0) { if (hour >= hour_offset) { hour -= hour_offset; hour += 12; } } ts = time(NULL); localtime_r(&ts, &dummy); date->tm_isdst = dummy.tm_isdst; date->tm_sec = sec; date->tm_min = min; date->tm_hour = hour; date->tm_mday = mday; date->tm_mon = mon - 1; date->tm_year = base_year + year - 1900; date->tm_gmtoff = 0; ts = mktime(date); }
void ntp_func(char *in) { uint8_t hb[6], t; if(in == 0 || in[1] == 0) { t = 1, hb[0] = 7; } else { t = fromhex(in+1, hb, 6); } if(t == 1) { t = hb[0]; ntp_get(hb); if(t&1) { DH2(hb[0]); DC('-'); DH2(hb[1]); DC('-'); DH2(hb[2]); } if((t&3) == 3) DC(' '); if(t&2) { DH2(hb[3]); DC(':'); DH2(hb[4]); DC(':'); DH2(hb[5]); } if(t&4) { DC('.'); display_udec((uint16_t)(ntp_hsec*100)/125, 2, '0'); } DNL(); } else if(t == 6) { tm_t t; t.tm_year = bcd2dec(hb[0]); t.tm_mon = bcd2dec(hb[1]); t.tm_mday = bcd2dec(hb[2]); t.tm_hour = bcd2dec(hb[3]); t.tm_min = bcd2dec(hb[4]); t.tm_sec = bcd2dec(hb[5]); ntp_sec = ntp_tm2sec(&t); } }
void cmos_read_values() { outb(CMOS_CTRL_PORT, CMOS_SEC_REG); cmos_time.sec = bcd2dec(inb(CMOS_DATA_PORT)); outb(CMOS_CTRL_PORT, CMOS_MIN_REG); cmos_time.min = bcd2dec(inb(CMOS_DATA_PORT)); outb(CMOS_CTRL_PORT, CMOS_HOUR_REG); cmos_time.hour = bcd2dec(inb(CMOS_DATA_PORT)); outb(CMOS_CTRL_PORT, CMOS_DAY_REG); cmos_time.day = bcd2dec(inb(CMOS_DATA_PORT)); outb(CMOS_CTRL_PORT, CMOS_MONTH_REG); cmos_time.month = bcd2dec(inb(CMOS_DATA_PORT)); outb(CMOS_CTRL_PORT, CMOS_YEAR_REG); cmos_time.year = bcd2dec(inb(CMOS_DATA_PORT)); }