#include <stdio.h>
#include <stdlib.h>
#define I2C_SLAVE 0x703
#define O_RDWR 2
int i2c_rtc;
void rtc_open(int addr)
{
i2c_rtc = open("/dev/i2c-0", O_RDWR);
ioctl(i2c_rtc, I2C_SLAVE, addr);
}
void rtc_read(unsigned char *buf, int reg, int n)
{
buf[0] = reg;
write(i2c_rtc, buf, 1);
read(i2c_rtc, buf, n);
}
void i2cdemo(void)
{
int i;
unsigned char buf[7];
// mask for BCD SEC MIN HOUR WKDAY DAY MONTH YEAR
unsigned char mask[7] = {0x7F, 0x7F, 0x3F, 0x07, 0x3F, 0x1F, 0xFF};
rtc_read(buf, 0, sizeof(buf));
for(i = sizeof(buf)-1; i >= 0; i--)
printf(" %02x", buf[i] & mask[i]);
printf("\n");
}
int main(int argc, char *argv[])
{
int i;
rtc_open(0x6F);
for(i = 0; i < 60; i++)
{
i2cdemo();
sleep(1);
}
return 0;
}
root@buildroot:/home/root/rtc# ./a.out
20 09 22 02 21 14 27
20 09 22 02 21 14 28
20 09 22 02 21 14 29
20 09 22 02 21 14 30
20 09 22 02 21 14 31
date
is also off and I now have matched errors on the Cortex :^). Here is a reviewed routine. @lawrie - in this form it is not suitable for c.lib, because it does not take an argument but works on a global var.
@pnru_gitlab Do you know why lcc/bin/libs contains both softfloat and libsoftfloat and why it contains eeprintf? We do not include softfloat and eeprintf in c.lib.
Not sure. I think all the "extras" are test files once used during development and not needed in c.lib (because the final, debugged versions are included already).
I've asked Michael about the origins of his lib and it comes from a student / university project that looked at an optimized MIPS processor. All in all, as you already concluded there does not seem to be much point in keeping in line with "upstream".