void rtc_set_alarm(int h, int m) { unsigned char buf[4] = {0}; int i, rv; /* clear alarm interrupt */ rv = i2c_readbytes(RTC_ADDR, RTC_CTRL2, 1, buf); buf[0] &= RTC_AF; pp_i2c_send(RTC_ADDR, RTC_CTRL2, buf[0]); /* prepare new alarm */ if( m >= 0 ) buf[0] = DEC2BCD(m); else /* ignore minutes comparison query */ buf[0] = RTC_AE; if( h >= 0 ) buf[1] = DEC2BCD(h); else /* ignore hours comparison query */ buf[1] = RTC_AE; /* ignore day and wday */ buf[2] = RTC_AE; buf[3] = RTC_AE; /* write new alarm */ for(i = 0; i < 4; i++) pp_i2c_send(RTC_ADDR, RTC_ALARM_MINUTES + i, buf[i]); /* note: alarm is not enabled at the point */ }
void rtc_set_alarm(int h, int m) { /* Set us to wake at the first second of the specified time */ pcf50605_write(0x11, 0); /* Convert to BCD */ pcf50605_write(0x12, DEC2BCD(m)); pcf50605_write(0x13, DEC2BCD(h)); }
int rtc_write_datetime(const struct tm *tm) { unsigned int i; int rc, oldlevel; unsigned char buf[7]; buf[0] = tm->tm_sec; buf[1] = tm->tm_min; buf[2] = tm->tm_hour; buf[3] = tm->tm_wday; buf[4] = tm->tm_mday; buf[5] = tm->tm_mon + 1; buf[6] = tm->tm_year - 100; for (i = 0; i < sizeof(buf); i++) buf[i] = DEC2BCD(buf[i]); oldlevel = disable_irq_save(); if (get_pmu_type() == PCF50606) rc = pcf50606_write_multiple(PCF5060X_RTCSC, buf, sizeof(buf)); else rc = pcf50635_write_multiple(PCF5063X_REG_RTCSC, buf, sizeof(buf)); restore_irq(oldlevel); return rc; }
int rtc_write_datetime(const struct tm *tm) { unsigned int i; int rc = 0; unsigned char buf[7]; buf[0] = tm->tm_sec; buf[1] = tm->tm_min; buf[2] = tm->tm_hour; buf[3] = tm->tm_wday; buf[4] = tm->tm_mday; buf[5] = tm->tm_mon + 1; buf[6] = tm->tm_year - 100; /* Adjust weekday */ if (buf[3] == 0) buf[3] = 7; for (i = 0; i < sizeof(buf) ; i++) { rc |= rtc_write(i + 1, DEC2BCD(buf[i])); } rc |= rtc_write(8, 0x80); /* Out=1, calibration = 0 */ return rc; }
/* set alarm time registers to the given time (repeat once per day) */ void rtc_set_alarm(int h, int m) { unsigned char data; /* for daily alarm, RPT5=RPT4=on, RPT1=RPT2=RPT3=off */ rtc_write(0x0e, 0x00); /* seconds 0 and RTP1 */ rtc_write(0x0d, DEC2BCD(m)); /* minutes and RPT2 */ rtc_write(0x0c, DEC2BCD(h)); /* hour and RPT3 */ rtc_write(0x0b, 0xc1); /* set date 01 and RPT4 and RTP5 */ /* set month to 1, if it's invalid, the rtc does an alarm every second instead */ data = rtc_read(0x0a); data &= 0xe0; data |= 0x01; rtc_write(0x0a, data); }
void mcp7941x_set_date_time(struct rtc_time *t) { static char cmd[] = {MCP7941X_RTCC_TCR_SECONDS}; char reg[] = {0,0,0,0,0,0,0}; reg[MCP7941X_RTCC_TCR_SECONDS] = DEC2BCD(t->tm_sec & 0x7f); reg[MCP7941X_RTCC_TCR_MINUTES] = DEC2BCD(t->tm_min & 0x7f); reg[MCP7941X_RTCC_TCR_HOURS] = DEC2BCD(t->tm_hour & 0x1f); reg[MCP7941X_RTCC_TCR_DAY] = DEC2BCD(t->tm_wday & 0x07); reg[MCP7941X_RTCC_TCR_DATE] = DEC2BCD(t->tm_mday & 0x3f); reg[MCP7941X_RTCC_TCR_MONTH] = DEC2BCD(t->tm_mon & 0x1f); reg[MCP7941X_RTCC_TCR_YEAR] = DEC2BCD(t->tm_year); reg[MCP7941X_RTCC_TCR_SECONDS] |= MCP7941X_RTCC_BIT_ST; reg[MCP7941X_RTCC_TCR_DAY] |= MCP7941X_RTCC_BIT_VBATEN; char data[8]; data[0] = cmd[1]; data[1] = reg[0]; data[2] = reg[1]; data[3] = reg[2]; data[4] = reg[3]; data[5] = reg[4]; data[6] = reg[5]; data[7] = reg[6]; mcp7941x_setup(); bcm2835_i2c_write(data, sizeof(data)/sizeof(char)); }
/******写SD2068实时数据寄存器******/ static int SD2068A_I2CWriteDate(unsigned char* WriteData) { SD2068A_WriteTimeOn(); if(SD2068A_I2CStart() != 0) { return -1; } SD2068A_I2CSendByte(WRITE_COMMAND); if( 0 != SD2068A_I2CWaitAck()) { SD2068A_I2CStop(); return -1; } SD2068A_SDA_OUT(); SD2068A_I2CSendByte(Second_Address); //设置写起始地址 SD2068A_I2CWaitAck(); SD2068A_SDA_OUT(); SD2068A_I2CSendByte(DEC2BCD(WriteData[0])); //Second SD2068A_I2CWaitAck(); SD2068A_SDA_OUT(); SD2068A_I2CSendByte(DEC2BCD(WriteData[1])); //minute SD2068A_I2CWaitAck(); SD2068A_SDA_OUT(); SD2068A_I2CSendByte(DEC2BCD(WriteData[2]) | 0x80); //hour,24小时制 SD2068A_I2CWaitAck(); SD2068A_SDA_OUT(); SD2068A_I2CSendByte(DEC2BCD(WriteData[3])); //week SD2068A_I2CWaitAck(); SD2068A_SDA_OUT(); SD2068A_I2CSendByte(DEC2BCD(WriteData[4])); //DAY SD2068A_I2CWaitAck(); SD2068A_SDA_OUT(); SD2068A_I2CSendByte(DEC2BCD(WriteData[5])); //MONTH SD2068A_I2CWaitAck(); SD2068A_SDA_OUT(); SD2068A_I2CSendByte(DEC2BCD(WriteData[6])); //year SD2068A_I2CWaitAck(); SD2068A_I2CStop(); SD2068A_I2CStart(); SD2068A_I2CSendByte(WRITE_COMMAND); SD2068A_I2CWaitAck(); SD2068A_SDA_OUT(); SD2068A_I2CSendByte(ReviseTime);//设置调整时间地址 SD2068A_I2CWaitAck(); SD2068A_SDA_OUT(); SD2068A_I2CSendByte(0x00);//零数字调整寄存器 SD2068A_I2CWaitAck(); SD2068A_I2CStop(); SD2068A_WriteTimeOff(); return 0; }
int rtc_write_datetime(const struct tm *tm) { BCDSEC = DEC2BCD(tm->tm_sec); BCDMIN = DEC2BCD(tm->tm_min); BCDHOUR = DEC2BCD(tm->tm_hour); BCDDAY = DEC2BCD(tm->tm_wday) + 1; /* chip wants 1..7 for wday */ BCDDATE = DEC2BCD(tm->tm_mday); BCDMON = DEC2BCD(tm->tm_mon + 1); BCDYEAR = DEC2BCD(tm->tm_year - 100); return 1; }
int rtc_write_datetime(const struct tm *tm) { unsigned int i; unsigned char buf[7]; buf[0] = tm->tm_sec; buf[1] = tm->tm_min; buf[2] = tm->tm_hour; buf[3] = tm->tm_mday; buf[4] = tm->tm_wday; buf[5] = tm->tm_mon + 1; buf[6] = tm->tm_year - 100; for (i = 0; i < sizeof(buf); i++) pp_i2c_send(RTC_ADDR, 0x02 + i, DEC2BCD(buf[i])); return 1; }
int rtc_write_datetime(const struct tm *tm) { unsigned int i; unsigned char buf[7]; buf[0] = tm->tm_sec; buf[1] = tm->tm_min; buf[2] = tm->tm_hour; buf[3] = tm->tm_wday; buf[4] = tm->tm_mday; buf[5] = tm->tm_mon + 1; buf[6] = tm->tm_year - 100; for (i = 0; i < sizeof(buf); i++) buf[i] = DEC2BCD(buf[i]); pcf50605_write_multiple(0x0a, buf, sizeof(buf)); return 1; }
/* set alarm time registers to the given time (repeat once per day) */ void rtc_set_alarm(int h, int m) { ALMMIN = DEC2BCD(m); /* minutes */ ALMHOUR = DEC2BCD(h); /* hour */ }