int xenon_smc_i2c_write(uint16_t addr, uint8_t val) { uint8_t buf[16]; memset(buf, 0, 16); int tmp=(addr>=0x200)?0x3d:0x39; int ddc=(addr>=0x1d0 && addr<=0x1f5); buf[0] = 0x11; buf[1] = (ddc)?0x21:0x20; buf[3] = tmp | 0x80; //3d buf[6] = addr & 0xff; //3a buf[7] = val; xenon_smc_send_message(buf); xenon_smc_receive_response(buf); if (buf[1] != 0) { printf("xenon_smc_i2c_write failed, addr=%04x, err=%d\n", addr, buf[1]); return -1; } return 0; }
int xenon_smc_ana_write(uint8_t addr, uint32_t val) { uint8_t buf[16]; memset(buf, 0, 16); buf[0] = 0x11; buf[1] = 0x60; buf[3] = 0x80 | 0x70; buf[6] = addr; buf[8] = val; buf[9] = val >> 8; buf[10] = val >> 16; buf[11] = val >> 24; xenon_smc_send_message(buf); xenon_smc_receive_response(buf); if (buf[1] != 0) { printf("xenon_smc_ana_write failed, addr=%02x, err=%d\n", addr, buf[1]); return -1; } return 0; }
int gettimeofday(struct timeval * tp, void * tzp) { unsigned char msg[16] = {0x04}; unsigned long long msec; unsigned long sec; xenon_smc_send_message(msg); xenon_smc_receive_response(msg); msec = msg[1] | (msg[2] << 8) | (msg[3] << 16) | (msg[4] << 24) | ((unsigned long long) msg[5] << 32); sec = msec / 1000; tp->tv_sec = sec + RTC_BASE; msec -= sec * 1000; tp->tv_usec = msec * 1000; return 0; }
int xenon_smc_i2c_ddc_lock(int lock) { uint8_t buf[16]; memset(buf, 0, 16); buf[0] = 0x11; buf[1] = (lock)?3:5; xenon_smc_send_message(buf); xenon_smc_receive_response(buf); if (buf[1] != 0) { printf("xenon_smc_i2c_ddc_lock failed, err=%d\n", buf[1]); return -1; } return 0; }
static int xenon_gettimeofday(struct _reent *ptr, struct timeval *tp, struct timezone *tz) { unsigned char msg[16] = {0x04}; union{ uint8_t u8[8]; uint64_t t; } time; time.t = 0; xenon_smc_send_message(msg); xenon_smc_receive_response(msg); time.u8[3] = msg[5]; time.u8[4] = msg[4]; time.u8[5] = msg[3]; time.u8[6] = msg[2]; time.u8[7] = msg[1]; tp->tv_sec = (time.t / 1000) + RTC_BASE; tp->tv_usec = (time.t % 1000) * 1000; return 0; }
int xenon_smc_ana_read(uint8_t addr, uint32_t *val) { uint8_t buf[16]; memset(buf, 0, 16); buf[0] = 0x11; buf[1] = 0x10; buf[2] = 5; buf[3] = 0x80 | 0x70; buf[5] = 0xF0; buf[6] = addr; xenon_smc_send_message(buf); xenon_smc_receive_response(buf); if (buf[1] != 0) { printf("xenon_smc_ana_read failed, addr=%02x, err=%d\n", addr, buf[1]); return -1; } *val = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24); return 0; }
int xenon_smc_i2c_read(uint16_t addr, uint8_t *val) { uint8_t buf[16]; memset(buf, 0, 16); int tmp=(addr>=0x200)?0x3d:0x39; int ddc=(addr>=0x1d0 && addr<=0x1f5); buf[0] = 0x11; //40 buf[1] = (ddc)?0x11:0x10;//3f buf[2] = 1; //3e buf[3] = buf[5] = tmp | 0x80; //3d 3b buf[6] = addr & 0xff; //3a xenon_smc_send_message(buf); xenon_smc_receive_response(buf); if (buf[1] != 0) { printf("xenon_smc_i2c_read failed, addr=%04x, err=%d\n", addr, buf[1]); return -1; } *val = buf[3]; return 0; }