OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 289|回复: 4

[XILINX] 基于microblaze使用lwip协议,添加中断

[复制链接]

0

主题

3

帖子

0

精华

新手入门

积分
10
金钱
10
注册时间
2024-3-14
在线时间
2 小时
发表于 2024-3-14 17:42:42 | 显示全部楼层 |阅读模式
1金钱
本帖最后由 haha185 于 2024-3-14 17:52 编辑

新手小白,在使用sdk中lwip echo server例程,过程中想要添加一个串口中断,但是添加上了串口中断的代码,串口中断可以使用,但是网络却连接不通了,去掉串口中断部分网络又可以通了,有没有大佬知道怎么改DHCP动态分配地址有问题,我改成了静态地址,还是冲突;
修改后的main.c代码:
#include "xil_exception.h"
#include "xdebug.h"
#include "xintc.h"
#include "xuartlite.h"
#include "xuartlite_l.h"
#include <stdio.h>
#include "xparameters.h"
#include "netif/xadapter.h"
#include "platform.h"
#include "platform_config.h"
#if defined (__arm__) || defined(__aarch64__)
#include "xil_printf.h"
#endif

#include "xil_printf.h"
#include "CAN_IP.h"
#include "xil_io.h"                        //sleep文件的头文件包含
#include "sleep.h"

#include "lwip/tcp.h"
#include "xil_cache.h"

#if LWIP_IPV6==1
#include "lwip/ip.h"
#else
#if LWIP_DHCP==1
#include "lwip/dhcp.h"
#endif
#endif


#define UART_DEVICE_ID XPAR_UARTLITE_0_DEVICE_ID     //串口器件ID
#define UART_INTR_ID   XPAR_INTC_0_UARTLITE_0_VEC_ID //串口中断ID
#define INTC_ID        XPAR_INTC_0_DEVICE_ID         //中断控制器ID

#define RX_NOEMPTY     XUL_SR_RX_FIFO_VALID_DATA     // 接收FIFO非空

static XIntc Intc;          //中断控制器实例
static XUartLite Uart;      //串口实例

void uart_handler(void *CallbackRef);


/* defined by each RAW mode application */
void print_app_header();
int start_application();
int transfer_data();
void tcp_fasttmr(void);
void tcp_slowtmr(void);

/* missing declaration in lwIP */
void lwip_init();

#if LWIP_IPV6==0
#if LWIP_DHCP==1
extern volatile int dhcp_timoutcntr;
err_t dhcp_start(struct netif *netif);
#endif
#endif

extern volatile int TcpFastTmrFlag;
extern volatile int TcpSlowTmrFlag;
static struct netif server_netif;
struct netif *echo_netif;

#if LWIP_IPV6==1
void print_ip6(char *msg, ip_addr_t *ip)
{
        print(msg);
        xil_printf(" %x:%x:%x:%x:%x:%x:%x:%x\n\r",
                        IP6_ADDR_BLOCK1(&ip->u_addr.ip6),
                        IP6_ADDR_BLOCK2(&ip->u_addr.ip6),
                        IP6_ADDR_BLOCK3(&ip->u_addr.ip6),
                        IP6_ADDR_BLOCK4(&ip->u_addr.ip6),
                        IP6_ADDR_BLOCK5(&ip->u_addr.ip6),
                        IP6_ADDR_BLOCK6(&ip->u_addr.ip6),
                        IP6_ADDR_BLOCK7(&ip->u_addr.ip6),
                        IP6_ADDR_BLOCK8(&ip->u_addr.ip6));

}
#else
void
print_ip(char *msg, ip_addr_t *ip)
{
        print(msg);
        xil_printf("%d.%d.%d.%d\n\r", ip4_addr1(ip), ip4_addr2(ip),
                        ip4_addr3(ip), ip4_addr4(ip));
}

void
print_ip_settings(ip_addr_t *ip, ip_addr_t *mask, ip_addr_t *gw)
{

        print_ip("Board IP: ", ip);
        print_ip("Netmask : ", mask);
        print_ip("Gateway : ", gw);
}
#endif



int main()
{
#if LWIP_IPV6==0
        ip_addr_t ipaddr, netmask, gw;

#endif
        /* the mac address of the board. this should be unique per board */
        unsigned char mac_ethernet_address[] =
        { 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 };

        echo_netif = &server_netif;


        init_platform();

#if LWIP_IPV6==0
#if LWIP_DHCP==1
    ipaddr.addr = 0;
        gw.addr = 0;
        netmask.addr = 0;
#else
        /* initliaze IP addresses to be used */
        IP4_ADDR(&ipaddr,  192, 168,   1, 10);
        IP4_ADDR(&netmask, 255, 255, 255,  0);
        IP4_ADDR(&gw,      192, 168,   1,  1);
#endif
#endif
        print_app_header();
        //初始化串口设备,只要不加这部分就没事
            XUartLite_Initialize(&Uart , UART_DEVICE_ID);
            //初始化中断控制器
            XIntc_Initialize(&Intc, INTC_ID);
            //关联处理函数
            XIntc_Connect(&Intc, UART_INTR_ID,(XInterruptHandler)uart_handler,&Uart);
            //使能串口
            XUartLite_EnableInterrupt(&Uart);
            //打开中断控制器
            XIntc_Start(&Intc, XIN_REAL_MODE);
            //使能中断控制器
            XIntc_Enable(&Intc,UART_INTR_ID);
            //设置并打开中断异常处理功能
            Xil_ExceptionInit();
                Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
                        (Xil_ExceptionHandler)XIntc_InterruptHandler , &Intc);
                Xil_ExceptionEnable();//到这
        lwip_init();

#if (LWIP_IPV6 == 0)//它是协议栈与底层网络硬件或软件之间的接口
        /* Add network interface to the netif_list, and set it as default */
        if (!xemac_add(echo_netif, &ipaddr, &netmask,
                                                &gw, mac_ethernet_address,
                                                PLATFORM_EMAC_BASEADDR)) {
                xil_printf("Error adding N/W interface\n\r");
                return -1;
        }
#else
        /* Add network interface to the netif_list, and set it as default */
        if (!xemac_add(echo_netif, NULL, NULL, NULL, mac_ethernet_address,
                                                PLATFORM_EMAC_BASEADDR)) {
                xil_printf("Error adding N/W interface\n\r");
                return -1;
        }
        echo_netif->ip6_autoconfig_enabled = 1;

        netif_create_ip6_linklocal_address(echo_netif, 1);
        netif_ip6_addr_set_state(echo_netif, 0, IP6_ADDR_VALID);

        print_ip6("\n\rBoard IPv6 address ", &echo_netif->ip6_addr[0].u_addr.ip6);

#endif
        netif_set_default(echo_netif);//默认网络接口
        xil_printf("one \r\n");
        /* now enable interrupts */
        platform_enable_interrupts();
        xil_printf("two \r\n");

        /* specify that the network if is up */
        netif_set_up(echo_netif);//表示该接口已经准备好接收和处理数据包
        xil_printf("three \r\n");
        IP4_ADDR(&(echo_netif->ip_addr),  192, 168,   1, 10);
        IP4_ADDR(&(echo_netif->netmask), 255, 255, 255,  0);
        IP4_ADDR(&(echo_netif->gw),      192, 168,   1,  1);



        /* start the application (web server, rxtest, txtest, etc..) */
        start_application();

        /* receive and process packets */
        // 主循环
        while (1) {
            // 处理网络等其他任务...
            if (TcpFastTmrFlag) {
                tcp_fasttmr();
                TcpFastTmrFlag = 0;
            }
            if (TcpSlowTmrFlag) {
                tcp_slowtmr();
                TcpSlowTmrFlag = 0;
            }

            xemacif_input(echo_netif);
                       transfer_data();
        }

        /* never reached */
        cleanup_platform();

        return 0;
}
void uart_handler(void *CallbackRef)//中断处理函数
{
    u8 Read_data;
    u32 isr_status;
    XUartLite *InstancePtr= (XUartLite *)CallbackRef;

    //读取状态寄存器
    isr_status = XUartLite_ReadReg(InstancePtr->RegBaseAddress ,
                                   XUL_STATUS_REG_OFFSET);
    if(isr_status & RX_NOEMPTY){  //接收FIFO中有数据
        //读取数据
        Read_data=XUartLite_ReadReg(InstancePtr->RegBaseAddress ,
                                    XUL_RX_FIFO_OFFSET);
        //发送数据
        XUartLite_WriteReg(InstancePtr->RegBaseAddress ,
                           XUL_TX_FIFO_OFFSET, Read_data);
    }
}

没删时,删了之后;

最佳答案

查看完整内容[请看2#楼]

应该是串口中断和LWIP里的中断冲突了,都对中断控制器做了配置
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

0

主题

3

帖子

0

精华

新手入门

积分
10
金钱
10
注册时间
2024-3-14
在线时间
2 小时
 楼主| 发表于 2024-3-18 16:30:02 | 显示全部楼层
因为两个中断的初始化同时使用了同一个指针,所以后初始化的中断使用的虽然是本身的变量,但指向了同一个内存,致使前一个初始化的中断被清空,所以只有后一个中断能够正常运行。修改方法为初始化两个中断时选用同一个实例指针,解决
回复

使用道具 举报

3

主题

1912

帖子

0

精华

资深版主

Rank: 8Rank: 8

积分
5317
金钱
5317
注册时间
2018-10-21
在线时间
1478 小时
发表于 2024-3-14 17:42:43 | 显示全部楼层
应该是串口中断和LWIP里的中断冲突了,都对中断控制器做了配置
回复

使用道具 举报

0

主题

3

帖子

0

精华

新手入门

积分
10
金钱
10
注册时间
2024-3-14
在线时间
2 小时
 楼主| 发表于 2024-3-15 11:32:18 | 显示全部楼层
那应该怎么修改啊?大佬
回复

使用道具 举报

0

主题

3

帖子

0

精华

新手入门

积分
10
金钱
10
注册时间
2024-3-14
在线时间
2 小时
 楼主| 发表于 2024-3-15 11:34:22 | 显示全部楼层
本帖最后由 haha185 于 2024-3-22 11:56 编辑
QinQZ 发表于 2024-3-14 17:42
应该是串口中断和LWIP里的中断冲突了,都对中断控制器做了配置

那应该怎么修改啊?大佬
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2024-5-29 11:20

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表