首页 > 代码库 > write_chip,read_chip
write_chip,read_chip
int write_chip(UINT32 addr, UINT32 data){ if(0 == fpgaRWMode) /* localbus mode */ { UINT16 datah, datal; UINT32 dataread; datah = (UINT16)(data >> 16); FPGA_REG(addr) = datah; rwWait(60); datal = (UINT16)(data & 0xFFFF); FPGA_REG(addr) = datal; rwWait(60); #if 0 read_chip(addr, &dataread); if (data != dataread) { printf("ERROR:write 0x%08X; read 0x%08X\n", data, dataread); return OK; } #endif read_chip(addr, (UINT32 *)(&dataread)); if(print_level == 1) printf("spi write 0x%05X: 0x%08X\n", addr, data); return OK; } else if(1 == fpgaRWMode) /* i2c mode */ { int ret = 0; ret = fpgaMAC_i2c_write(0,0,0,addr,(unsigned char *)(&data),4); if(print_level == 1) { if(ret != 0) printf("spi write failed! read 0x%05x: 0x%08x\n", addr, data); else printf("spi write 0x%05x: 0x%08x\n", addr, data); } if(!ret) return OK; else return ERROR; } else if(2 == fpgaRWMode) /* spi mode */ { int ret = 0; unsigned char *wtBuff = (unsigned char *)malloc(8); if(NULL == wtBuff) { printf("No memory!\n"); return -1; } *wtBuff = (unsigned char)((data>>24) & 0xff); *(wtBuff+1) = (unsigned char)((data>>16) & 0xff); *(wtBuff+2) = (unsigned char)((data>>8 ) & 0xff); *(wtBuff+3) = (unsigned char)((data ) & 0xff); ret = fpga_spi_write(addr,(unsigned char *)(wtBuff),4); if(print_level == 1) { if(ret != 0) printf("spi write failed! read 0x%05x: 0x%08x\n", addr, data); else printf("spi write 0x%05x: 0x%08x\n", addr, data); } free(wtBuff); if(!ret) return OK; else return ERROR; } else { return ERROR; }}int read_chip(UINT32 addr, UINT32 *data){ if(data =http://www.mamicode.com/= NULL)"localbus read 0x%05X: 0x%08X\n", addr, *data); return OK; } else if(1 == fpgaRWMode) /* i2c mode */ { int ret = 0; ret = fpgaMAC_i2c_read(0,0,0,addr,(unsigned char *)data,4); if(print_level == 1) { if(ret != 0) printf("i2c read failed! read 0x%05x: 0x%08x\n", addr, *data); else printf("i2c read 0x%05x: 0x%08x\n", addr, *data); } if(!ret) return OK; else return ERROR; } else if(2 == fpgaRWMode) /* spi mode */ { int ret = 0; ret = fpga_spi_read(addr,(unsigned char *)data,4); if(print_level == 1) { if(ret != 0) printf("spi read failed! read 0x%05x: 0x%08x\n", addr, *data); else printf("spi read 0x%05x: 0x%08x\n", addr, *data); } if(!ret) return OK; else return ERROR; } else { return ERROR; }}
write_chip,read_chip
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。