Example #1
0
void sw_timeString(char *buf) {
  buf[0]=0;
  
  if(readDays()>0)sprintf(buf,"%d days ",readDays()); 
  buf=strchr(buf,0);
  if(readHours()>0)sprintf(buf,"%d hours ",readHours()); 
  buf=strchr(buf,0);
  if(readMinutes()>0)sprintf(buf,"%d min. ",readMinutes()); 
  buf=strchr(buf,0);
  if(readSeconds()>0)sprintf(buf,"%d seconds ",readSeconds()); 
  buf=strchr(buf,0);
  sprintf(buf,"%d ms ",readmSeconds()); 
}
Example #2
0
/**
 * Read the registers from the Real Time Clock.
 *
 * It reads the registers from the RTC and stores the data in the struct which
 * pointer it receives. It handles the different types of format in which the data
 * is stored in the RTC registers.
 *
 * @param regs Pointer to struct where the data from RTC registers will be stored.
 *
 */
void readRTCRegisters(RTCRegisters *regs){
    int format;

    // Getting format register
    outB(RTCADDRESS, 11);
    format = inB(RTCDATA);

    // Getting seconds
    regs->seconds = readSeconds();

    // Getting minutes
    regs->minutes = readMinutes();

    // Getting hours (value may be 12hs o 24hs format)
    regs->hours = readHours();

    // Getting day of the month
    regs->day = readDay();

    // Getting month
    regs->month = readMonth();

    // Getting year
    regs->year = readYear();

    // Getting century
    regs->century = readCentury();

    // If in BCD mode, convert to binary
    if ((format & 0x02) ==  0x02 ) {
       regs->seconds = BCDTOBINARY(regs->seconds);
       regs->minutes = BCDTOBINARY( regs->minutes);
       regs->hours = BCDTOBINARY(regs->hours);
       regs->day = BCDTOBINARY(regs->day );
       regs->month = BCDTOBINARY(regs->month);
       regs->year = BCDTOBINARY(regs->year);
       regs->century = BCDTOBINARY(regs->century);
    }

    // If in 12 hs mode, convert to 24 hs mode
    if ((format & 0x04) == 0x04) {
      // Masking off the pm/am bit
        if ( (regs->hours & 0x80) == 0x80 ) {
            regs->hours &= 0x7F;
            // Setting 12 pm as 0 regs->hours and adjusting the rest
            regs->hours = (regs->hours == 12)? 0 : regs->hours + 12;
        }
    }
}