在这两个函数为什么需要做WATCHDOG_RESET()?

时间:2013-02-22 04:57:42

标签: c linux

    void NS16550_putc(NS16550_t com_port, char c)
    {
        while ((serial_in(&com_port->lsr) & UART_LSR_THRE) == 0);
    //write to the THR 
        serial_out(c, &com_port->thr);
        if (c == '\n')
    //why do we require to call this watch dog reset
        WATCHDOG_RESET();
    }

    char NS16550_getc(NS16550_t com_port)
    {
        while ((serial_in(&com_port->lsr) & UART_LSR_DR) == 0) {    
    #ifdef CONFIG_USB_TTY    
        extern void usbtty_poll(void);    
        usbtty_poll();    
    #endif
    //why do we require to call this watch dog reset
        WATCHDOG_RESET();    
    }
    //return the rbr value 
        return serial_in(&com_port->rbr);
    }

1 个答案:

答案 0 :(得分:0)

我不知道此代码的上下文。

但很可能是因为你不希望你的操作持续这么长时间以致看门狗超时(并重置你的设备......)

例如,

while ((serial_in(&com_port->lsr) & UART_LSR_DR) == 0) {    
    #ifdef CONFIG_USB_TTY    
        extern void usbtty_poll(void);    
        usbtty_poll();    
    #endif
    //why do we require to call this watch dog reset
        WATCHDOG_RESET();    
    }

在上面的代码中,你在这个while循环中重复验证了一些条件,现在这个循环可能会运行很长时间,如果你没有重置看门狗定时器(或踢你的看门狗),看门狗会可能最终会超时。