Accès aux registres d'une RTC BQ32000
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <signal.h>
#include <time.h>
#include <sysio/delay.h>
#include <sysio/i2c.h>
static int fd;
static void
vSigIntHandler (int sig) {
if ( (sig == SIGINT) || (sig == SIGTERM) ) {
perror ("iI2cClose");
exit (EXIT_FAILURE);
}
printf ("\neverything was closed.\nHave a nice day !\n");
exit (EXIT_SUCCESS);
}
}
int
main (int argc, char **argv) {
uint8_t buf[9];
time_t t;
static const char * names[] = { "SECONDS ",
"MINUTES ",
"CENT_HOURS",
"DAY ",
"DATE ",
"MONTH ",
"YEARS ",
"CAL_CFG1 ",
"TCH2 ",
"CFG2 "
};
if (fd < 0) {
perror ("Failed to open i2c ! ");
}
signal (SIGINT, vSigIntHandler);
signal (SIGTERM, vSigIntHandler);
printf ("Press Ctrl+C to abort ...\n\n");
for (;;) {
t = time (NULL);
printf ("\n%s", ctime (&t) );
perror ("Failed to read i2c ! ");
continue;
}
for (int i = 0; i < sizeof (buf); i++) {
printf ("%s 0x%02X\n", names[i], buf[i]);
}
fflush (stdout);
}
return 0;
}