给Hi3518e的Uboot添加UDP广播收发功能

基于个人兴趣,决定实现一个和方案公司提供的uboot收发广播的功能。记录笔记如下。

SDK版本:Hi3518E_V100R001C01SPC081

1. 由于我手头的板子的Phy是RMII模式,因此先按这篇帖子进行将uboot默认的网络驱动改为RMII模式。

http://blog.csdn.net/skdkjzz/article/details/39931915

2. 然后设置好Phy的CONFIG_PHY_ADDR_U和CONFIG_PHY_ADDR_D,这个我不太懂是为什么,估计和硬件有关,各位看官可能这里不能完全照抄,我有空翻一翻Phy的规格书。编辑 u-boot-2010.06\include\configs\hi3518e.h


3. 在common目录下新建文件cmd_udp.c,新建一个uboot cmd

#include <common.h>
#include <command.h>
#include <net.h>

 char _ctoi(char c)
{
    if(c>='0'&&c<='9')return c-'0';
    if(c>='a'&&c<='f')return c-'a'+10;
    return 0;
}

int _atoi(char* s)
{
    unsigned int  a=0;
    unsigned int  b=0;
    int i=0;
    while(s[i]){
        a*=10;
        a+=_ctoi(s[i]);
        i++;    
    }
    return a;
}

int _atox(char* s)
{
    unsigned int  a=0;
    unsigned int  b=0;
    int i=0;
    while(s[i]){
        a<<=4;
        a|=_ctoi(s[i]);
        i++;    
        if(i>=8)break;
    }
    return a;
}

int _strlen(char*s)
{
    int i=0;
    while(s[i]){
        i++;
    }
    return i;
}

void _getmac(char* s,char* eth)
{
    unsigned char  a=0;
    int i=0;
    while(s[i]){
        a<<=4;
        a|=_ctoi(s[i]);            
        if((i&1)==1){
            eth[i>>1]=a;
            a=0;            
        }
        i++;
    }
}

int do_udp_broadcast(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
    uchar eth[6]= {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
    char* UdpServerIP="255.255.255.255";
    int dest_port = 25500, src_port =25300;
    uchar *str;
    int len;

    switch(argc){
    case 1:
        puts("Params error, try again\nusage: [udp_b] [string] or [udp_b] [dest_port] [src_port] [string]\n");
        return 1;
        break;
    case 2:
        str = argv[1];
        len = strlen(str);
        break;
    case 4:
        dest_port = _atoi(argv[1]);
        src_port = _atoi(argv[2]);
        str = argv[3];
        len 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值