[En-Nut-Discussion] scanf on uart0: Reboot - loop

Ernst Stippl ernst at stippl.com
Sun Dec 19 11:59:06 CET 2004


Hi!

I am trying to read from the serial i/f which is connected to a terminal emu
using scanf. In most circumstances, the program loops i.e. when hitting the
scanf, the main function starts from the beginning.
I tried to minimize th eprogram and sometimes the problem disappears but
when adding statements again, the reboot loop appears again.
 
I am using an 2.1b board and Nut/OS 3.9.1

Here is a sample program which produces the problem:

//-----------------------------------------------------------------------

int main(void)
{
 
u_long baud = 115200;
u_char mac[6] = { 0x00, 0x06, 0x98, 0x21, 0x03, 0xC8 };
u_long ip_addr;
u_long ip_mask;
u_long i_adr;
u_char addr_string[16] = "192.168.171.199";
u_short i;

addr_string[15] = 0;
    /*
     * Register all devices used in our application.
     */
NutRegisterDevice(&devDebug0, 0, 0);
NutRegisterDevice(&DEV_ETHER, 0x8300, 5);

    /*
     * Assign stdout/in to the UART device.
     */
freopen("uart0", "w", stdout);
freopen("uart0", "r", stdin);

_ioctl(_fileno(stdout), UART_SETSPEED, &baud);
_ioctl(_fileno(stdin ), UART_SETSPEED, &baud);


//NutRegisterDevice(&devUart0, 0, 0);
//uart = fopen("uart0", "r+");
//_ioctl(_fileno(uart), UART_SETSPEED, &baud);

    
printf ("\nBooting\n");

NutNetLoadConfig("eth0");
ip_addr = inet_addr("192.168.171.5");
ip_mask = inet_addr("255.255.255.0");
NutNetIfConfig("eth0", mac, ip_addr, ip_mask);
            
puts ("config OK, now arping");

printf ("IP: %s\n", inet_ntoa(confnet.cdn_ip_addr));


printf ("Enter IP Adr to be PINGed: ");  // if these lines are executed
scanf ("%s", addr_string);               // the printf-string appears on the
term
for (i = 0; i < 17; i++)                 // and immediately, the board
restarts.
   if (addr_string [i] == (u_char) 13)   // 
      addr_string[i] = (u_char) 0;       //

i_adr = inet_addr (addr_string);
do_work (i_adr); 
 
printf ("\nWork ended\n"); 
while (1) 
   NutSleep ((u_long) 2000); 
}


 





More information about the En-Nut-Discussion mailing list