原创 rtems在s3c2410上的移植(三)

2012-4-4 12:24 2072 20 20 分类: 消费电子

作者,下家山

 

11.3 需要添加的东东

     参考c/src/lib/libbsp/arm/edb7312/include/bsp.h,在c/src/lib/libbsp/arm/gp32/include/bsp.h中添加cs8900相关的东东;                                     针对s3c2410修改或添加c/src/lib/libbsp/arm/gp32/network/network.c,有下列内容要添加或修改:定义cs8900基址,即#define CS8900_BASE 0x19000300中断号,查看原理图,cs8900用的是EINT9号中断,所以cs8900_isr_data数组要改为rtems_irq_connect_data cs8900_isr_data = {BSP_EINT8_23,

                                         (rtems_irq_hdl)cs8900_isr,

                                         cs8900_isr_on,cs8900_isr_off, cs8900_isr_is_on,

                                         3,     /* unused for ARM cpus */

                                         0 };   /* unused for ARM cpus */    

      EINT9中断初始化,我把EINT9的中断初始化放在 cs8900_isr_on中,这样可以在安装isr_handler时

 初始化static void cs8900_isr_on(const rtems_irq_connect_data *unused)

{

         rGPGCON = (rGPGCON & 0xfffffff3)|(1<<3);        /*PG1/9 = EINT9*/

             rGPGUP  = 0xffff;

         rEXTINT1 = (rEXTINT1 & ~(7<<4)) | 0x4<<4; /*EINT9=high level triggered*/

         rEINTPEND=(1<<9);

             /*rSRCPND = BIT_EINT8_23; *//*to clear the previous pending states*/

             /*rINTPND = BIT_EINT8_23;*/

             rEINTMASK = ~(1<<9|0xf);/*enable EINT9*/

         rINTMSK &= ~BIT_EINT8_23;/*enable EINT8_23*/        

         return;

}

④中断复位,即中断发生后要清中断,如:

rtems_isr cs8900_isr(rtems_vector_number v)

{

    rEINTPEND=(1<<9);

        ClearPending(BIT_EINT8_23);

    cs8900_interrupt(v, g_cs);   

}

 针对s3c2410修改或添加c/src/libchip/network/cs8900.c,有下列内容要添加或修改:

      声明cs8900_device结构体,如static cs8900_device cs8900;

      attach cs8900_device结构体,即在函数cs8900_driver_attach的if语句前添加config->drv_ctrl=&cs8900;语句,这条语句必须添加,不然出现Driver eth0 already in use.的错误,即[printf ("Driver `%s' already in use.\n", config->name);]

      应用程序需要添加的东西,我开始调试的是rtems-4.6.99.3/testsuites/samples/loopback,但后来想到要从PC端PING 2410,就直接换成了调试netlink例程(rtems-4.6.99.3没有network例程,需要下载其他版本的例程),但调试了几天也没调试成功,后来看rtems-4.6.99.3下面的doc文档networking.pdf介绍了netdemo例程,又改成调netdemo。例程netdemo中需要添加networkconfig.h文件,并修改其中的rtems_bsdnet_ifconfig,rtems_bsdnet_config两个结构体.修改后的内容如下:

static char ethernet_address[6] = { 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 };

static struct rtems_bsdnet_ifconfig netdriver_config = {

         RTEMS_BSP_NETWORK_DRIVER_NAME,                 /* name */

         RTEMS_BSP_NETWORK_DRIVER_ATTACH,    /* attach function */

         NULL,                                   /* link to next interface */

         "192.168.13.88",          /* IP address */

         "255.255.255.0",          /* IP net mask */

         ethernet_address,               /* Ethernet hardware address */

         0                                   /* Use default driver parameters */

};

     struct rtems_bsdnet_config rtems_bsdnet_config = {

                 &netdriver_config,

                 NULL,

                  0,                          /* Default network task priority */

                  0,                          /* Default mbuf capacity */

                  0,                          /* Default mbuf cluster capacity */

                  "rtems_host",                /* Host name */

                  "nodomain.com",          /* Domain name */

                  "192.168.13.1",   /* Gateway */

                  "192.168.13.11", /* Log host */

                  {"192.168.13.88" },      /* Name server(s) */

};

11.4  ping

     开始ping板子,什么反应都没有,所以找了个抓包程序,发现PC端收到的包格式有错误,收到内容如下:ff ff ff ff ff ff 33 44 55 66 77 88 08 06 00 00 00 01 08 00 06 04 00 01 33 44 55 66 77 88 c0 a8 0d 58 00 00 00 00 00 00 c0 a8 0d 0b 0b 0b 0b 0b 0b 0b…分析后发现在08 06 后面多了两个字节00 00,分析原代码(花了很长时间)发现sizeof (struct ether_header)=16(应用到此结构的代码在cpukit/libnetworking/net/if_ethersubr.c),ether_header定义如下:

struct ether_header {

         u_char        ether_dhost[ETHER_ADDR_LEN];/* ETHER_ADDR_LEN =6*/

         u_char        ether_shost[ETHER_ADDR_LEN];/**/

         u_short       ether_type;

};/*见cpukit/libnetworking/net/Ethernet.h*/

按理所sizeof (struct ether_header)应为14但是我printf后的结构却为16,显然多出的两个字节在此,后来问同事说是字节对齐问题,果然在ether_header结构体后加__packed __attribute__((packed))属性后

struct ether_header {

         u_char        ether_dhost[ETHER_ADDR_LEN];/* ETHER_ADDR_LEN =6*/

         u_char        ether_shost[ETHER_ADDR_LEN];/**/

         u_short       ether_type;

}__packed __attribute__((packed));

果然ping通了。

转载:请注明,作者,下家山   请尊重原创!

文章评论0条评论)

登录后参与讨论
我要评论
0
20
关闭 站长推荐上一条 /2 下一条