MCPcopy Create free account
hub / github.com/F-Stack/f-stack / pcf2123_rtc_settime

Function pcf2123_rtc_settime

freebsd/mips/atheros/pcf2123_rtc.c:142–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142static int
143pcf2123_rtc_settime(device_t dev, struct timespec *ts)
144{
145 struct clocktime ct;
146 struct pcf2123_rtc_softc *sc;
147 struct spi_command cmd;
148 unsigned char rxTimedate[8];
149 unsigned char txTimedate[8];
150 int err;
151
152 sc = device_get_softc(dev);
153
154 /* Resolution: 1 sec */
155 if (ts->tv_nsec >= 500000000)
156 ts->tv_sec++;
157 ts->tv_nsec = 0;
158 clock_ts_to_ct(ts, &ct);
159
160 memset(&cmd, 0, sizeof(cmd));
161 memset(rxTimedate, 0, sizeof(rxTimedate));
162 memset(txTimedate, 0, sizeof(txTimedate));
163
164 /* Start reading from seconds */
165 cmd.rx_cmd = rxTimedate;
166 cmd.tx_cmd = txTimedate;
167 cmd.rx_cmd_sz = sizeof(rxTimedate);
168 cmd.tx_cmd_sz = sizeof(txTimedate);
169
170 /*
171 * Counter is stopped when access to time registers is in progress
172 * So there is no need to stop/start counter
173 */
174 txTimedate[0] = PCF2123_WRITE(PCF2123_REG_SECONDS);
175 txTimedate[1] = TOBCD(ct.sec);
176 txTimedate[2] = TOBCD(ct.min);
177 txTimedate[3] = TOBCD(ct.hour);
178 txTimedate[4] = TOBCD(ct.day);
179 txTimedate[5] = TOBCD(ct.dow);
180 txTimedate[6] = TOBCD(ct.mon);
181 txTimedate[7] = TOBCD(ct.year - YEAR_BASE);
182
183 err = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd);
184 DELAY(PCF2123_DELAY);
185
186 return (err);
187}
188
189static device_method_t pcf2123_rtc_methods[] = {
190 DEVMETHOD(device_probe, pcf2123_rtc_probe),

Callers

nothing calls this directly

Calls 5

device_get_softcFunction · 0.85
clock_ts_to_ctFunction · 0.85
memsetFunction · 0.85
device_get_parentFunction · 0.85
DELAYFunction · 0.50

Tested by

no test coverage detected