资源简介
linux mdio 读写phy 寄存器工具

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifndef __GLIBC__
#include
#include
#endif
#include
#include
#include
/* This data structure is used for all the MII ioctl‘s */
static struct ifreq ifr;
static int mdio_read(int skfd int location)
{
struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&ifr.ifr_data;
mii->reg_num = location;
if (ioctl(skfd SIOCGMIIREG &ifr) < 0) {
fprintf(stderr “SIOCGMIIREG on %s failed: %s\n“ ifr.ifr_name
strerror(errno));
return -1;
}
return mii->val_out;
}
static void mdio_write(int skfd int location int value)
{
struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&ifr.ifr_data;
mii->reg_num = location;
mii->val_in = value;
if (ioctl(skfd SIOCSMIIREG &ifr) < 0) {
fprintf(stderr “SIOCSMIIREG on %s failed: %s\n“ ifr.ifr_name
strerror(errno));
}
}
int main(int argc char *argv[])
{
int skfd;
if((argc < 2) || (!strcmp(argv[1] “-h“))){
printf(“%s eth0 reg [val]\n“ argv[0]);
return 0;
}
if ((skfd = socket(AF_INET SOCK_DGRAM0)) < 0) {
perror(“socket“);
exit(-1);
}
strncpy(ifr.ifr_name argv[1] IFNAMSIZ);
if (ioctl(skfd SIOCGMIIPHY &ifr) < 0) {
fprintf(stderr “SIOCGMIIPHY on ‘%s‘ failed: %s\n“
argv[1] strerror(errno));
return -1;
}
if(!strcasecmp(argv[2] “dump“)){
int i = 0;
printf(“%s dump:\n“ argv[1]);
printf(“ “);
for(i = 0; i < 16; i++){
printf(“%4x “ i);
}
printf(“\n“);
for(i = 0; i < 32; i++){
if((i % 16) == 0){
printf(“%04x: “ i);
}
printf(“%04x “ mdio_read(skfd i));
if((i % 16) == 15){
printf(“\n“);
}
}
}else{
if (argc == 3) {
printf(“%03x ==> %08x\n“ strtoul(argv[2] NULL 0) mdio_read(skfd strtoul(argv[2] NULL 0)));
} else if(argc == 4) {
mdio_write(skfd strtoul(argv[2] NULL 0) strtoul(argv[3] NULL 0));
}
}
close(skfd);
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 182 2014-06-20 12:39 mdio\Makefile
....... 2419 2014-07-24 15:06 mdio\mdio.c
目录 0 2015-08-04 16:22 mdio
----------- --------- ---------- ----- ----
2601 3
- 上一篇:grbl-0.8_src
- 下一篇:EDA关于排队器的设计
相关资源
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- linux下用多进程同步方法解决生产者
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- Linux命令大全离线版&在线版
- 操作系统共享内存实验
- dos 下运行Linux 命令--gnu_utils
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
- 基于GTK的Linux环境下的简易任务管理器
- linux扫雷游戏代码
- CAN Linux驱动代码
- Linux系统教材
- intel 82579LM 网卡驱动Linux系统版 v1.9.
- SA1110处理器掌上电脑液晶显示器设计
- 基于Linux的串口服务器设计
- Windows下访问LINUX的利器-SSH
评论
共有 条评论