Exemple #1
0
void create_system_info_screen (void) {

uint16_t addr;

	tft_clrscr(TFT_COLOR_LIGHTGRAY);	// White before

    printf_tft_P( TFT_COLOR_BLUE, TFT_COLOR_WHITE, PSTR("Nut/OS %s "), NutVersionString());
    printf_tft_P( TFT_COLOR_BLUE, TFT_COLOR_WHITE, PSTR("Firmware V%d.%d"), pgm_read_byte_far((char*)&bootlodrinfo.app_version +1), pgm_read_byte_far((char*)&bootlodrinfo.app_version));
	printf_tft_P( TFT_COLOR_GREEN, TFT_COLOR_WHITE, PSTR("Build %s at %s"), __DATE__, __TIME__);

	addr = eib_get_device_address(EIB_DEVICE_CHANNEL);
    printf_tft_P( TFT_COLOR_RED, TFT_COLOR_WHITE, PSTR("Phys. Addr %d.%d.%d"), (addr >> 4) & 0x0f, addr & 0x0f, (addr >> 8) & 0xff );
	if (display_orientation == DISPLAY_ORIENTATION_HOR)
    	printf_tft_P( TFT_COLOR_BLACK, TFT_COLOR_WHITE, PSTR("Horizontal"));
	else if (display_orientation == DISPLAY_ORIENTATION_90L)
    	printf_tft_P( TFT_COLOR_BLACK, TFT_COLOR_WHITE, PSTR("90 left"));
	else if (display_orientation == DISPLAY_ORIENTATION_90R)
    	printf_tft_P( TFT_COLOR_BLACK, TFT_COLOR_WHITE, PSTR("90 right"));
	else if (display_orientation == DISPLAY_ORIENTATION_UPSIDE)
    	printf_tft_P( TFT_COLOR_BLACK, TFT_COLOR_WHITE, PSTR("180"));

	if (eib_get_status() == EIB_NORMAL)
    	printf_tft_P( TFT_COLOR_BLACK, TFT_COLOR_WHITE, PSTR("EIB online"));
	else
    	printf_tft_P( TFT_COLOR_RED, TFT_COLOR_WHITE, PSTR("EIB offline"));

	printf_tft_P (TFT_COLOR_BLACK, TFT_COLOR_WHITE, PSTR("TFT Ctrl = %d, R00=%4.4x"), controller_type, controller_id);

	draw_button (ERASE_BUTTON_XPOS, ERASE_BUTTON_YPOS, BUTTON_WIDTH, "Erase Flash");		// added by sh
	draw_button (MONITOR_BUTTON_XPOS, MONITOR_BUTTON_YPOS, BUTTON_WIDTH, "Monitor");
	draw_button (DOWNLOAD_BUTTON_XPOS, DOWNLOAD_BUTTON_YPOS, BUTTON_WIDTH, "Download");
	draw_button (EXIT_BUTTON_XPOS, EXIT_BUTTON_YPOS, BUTTON_WIDTH, "Exit");
	system_page_active = SYSTEM_PAGE_MAIN;
}
/*
 * PPP client application entry.
 */
int main(void)
{
    int pppcom;

    /* Initialize a debug port for standard output and display a banner. */
    DebugPortOpen();
    printf("\n\nPPP Client Sample - Nut/OS %s\n", NutVersionString());

    /* Initialize the network interface. */
    ProtocolPortInit();
    /* This loop runs once per hour. */
    for (;;) {
        /* Open the network interface. */
        pppcom = ProtocolPortOpen();
        if (pppcom == -1) {
            /* If this fails, we are busted. */
            break;
        }
        /* Establish the modem connection. */
        if (ProtocolPortConnect(pppcom) == 0) {
            /* Configure the network interface. */
            if (ProtocolPortConfigure() == 0) {
                /* Talk to the Internet. */
                QueryDateAndTime();
            }
        }
        /* Hang up. */
        ProtocolPortClose(pppcom);

        /* Sleep 1 hour. */
        puts("I'll be back in 1 hour.");
        NutSleep(3600000);
    }
    /* Ouch... */
    puts("Good bye cruel world");

    return 0;
}
Exemple #3
0
/*!
 * \brief Register MIB II system variables.
 *
 * \note Preliminary code with hard coded values.
 */
int MibRegisterSysVars(void)
{
    char *cp;

    strcpy(sys_descr, BOARD_NAME);
    strcat(sys_descr, " Nut/OS ");
    strcat(sys_descr, NutVersionString());

    if ((cp = getenv("SYSCONTACT")) != NULL) {
        sys_contact = UpdateStringEnv(NULL, sys_contact, cp);
    }
    if ((cp = getenv("SYSNAME")) != NULL) {
        sys_name = UpdateStringEnv(NULL, sys_name, cp);
    } else {
        sys_name = UpdateStringEnv(NULL, sys_name, confos.hostname);
    }
    if ((cp = getenv("SYSLOCATION")) != NULL) {
        sys_location = UpdateStringEnv(NULL, sys_location, cp);
    }

    sys_starttime = time(NULL);

    return SnmpMibRegister(base_oid, base_oidlen, mib_variables, sizeof(mib_variables) / sizeof(SNMPVAR));
}
Exemple #4
0
/*
 * Main application entry.
 */
    int play_stream(RADIO_STREAM rStream) {
        TCPSOCKET *sock;
        FILE *stream;
        u_long baud = DBG_BAUDRATE;
        u_long radio_ip = inet_addr(rStream.radio_ip);
        u_short tcpbufsiz = TCPIP_BUFSIZ;
        u_long rx_to = TCPIP_READTIMEOUT;
        u_short mss = TCPIP_MSS;
        u_long metaint;

        /*
         * Register UART device and assign stdout to it.
         */
        NutRegisterDevice(&DBG_DEVICE, 0, 0);
        freopen(DBG_DEVNAME, "w", stdout);
        _ioctl(_fileno(stdout), UART_SETSPEED, &baud);

        /*
         * Display system information.
         */
        printf("\n\nMedianut Tuotrial Part 3 - Nut/OS %s - " CC_STRING "\n", NutVersionString());
        printf("%u bytes free\n\n", NutHeapAvailable());

        /*
         * Register LAN device.
         */
        if (NutRegisterDevice(&DEV_ETHER, 0x8300, 5)) {
            puts("Error: No LAN device");
            for (; ;);
        }

        puts("configure LAN");
        /*
         * Configure LAN.
         */
        if (ConfigureLan("eth0")) {
            for (; ;);
        }

        puts("create a TCP socket");

        /*
         * Create a TCP socket.
         */
        if ((sock = NutTcpCreateSocket()) == 0) {
            puts("Error: Can't create socket");
            for (; ;);
        }

        puts("set socket options");

        /*
         * Set socket options. Failures are ignored.
         */
        if (NutTcpSetSockOpt(sock, TCP_MAXSEG, &mss, sizeof(mss)))
            printf("Sockopt MSS failed\n");
        if (NutTcpSetSockOpt(sock, SO_RCVTIMEO, &rx_to, sizeof(rx_to)))
            printf("Sockopt TO failed\n");
        if (NutTcpSetSockOpt(sock, SO_RCVBUF, &tcpbufsiz, sizeof(tcpbufsiz)))
            printf("Sockopt rxbuf failed\n");


        puts("connect the radio station");
        /*
         * Connect the radio station.
         */
        radio_ip = inet_addr(rStream.radio_ip);
        stream = ConnectStation(sock, rStream.radio_ip, rStream.radio_port, &metaint, rStream);
		send_message(rStream.radio_ip, rStream.radio_port, &metaint);
        /*
         * Play the stream.
         */
        if (stream) {
            puts("playing stream");
            PlayMp3Stream(stream, metaint);
            fclose(stream);
        }
        NutTcpCloseSocket(sock);


        NutThreadKill();
        NutThreadDestroy();
        return;
        puts("Reset me!");
        for (; ;);
}
/*
 * Basic monitor function.
 */
void BaseMon(void)
{
    char ch;
    int i;
    int n;
    char hostname[sizeof(confos.hostname)];
    static prog_char menu1_P[] = "\nPress any of the following keys:";
    static prog_char menu2_P[] = "    B - Send broadcasts";
    static prog_char menu3_P[] = "    E - Ethernet controller read/write\n"
                                 "    J - Jump to bootloader\n"
                                 "    S - SRAM read/write";
    static prog_char menu4_P[] = "    X - Exit BaseMon, configure network and start WebServer";

    /*
     * Print banner.
     */
    printf("\n\nBaseMon %s\nNut/OS %s\n", version, NutVersionString());
#ifdef INTECH21
    puts("Customized for Intech21");
#endif
    printf("Compiled by ");
#ifdef __IMAGECRAFT__
    printf("ICCAVR");
#else
    printf("AVRGCC");
#endif
    printf(" for ");
#if defined(__AVR_ATmega128__)
    puts("ATmega128");
#elif defined(__AVR_ATmega103__)
    puts("ATmega103");
#elif defined(__AVR_AT90CAN128__)
#   error CPU needs special consideration for stack and heap and is currently not supported by basemon
    puts("AT90CAN128");
#elif defined(__AVR_ATmega2561__)
    puts("ATmega2561");
#else
    puts("unknown");
#endif

    if (uart_bs >= 0) {
        printf("Baudrate select = %d\n", uart_bs);
    }
    else {
        puts("No user input detected");
    }

    /*
     * Test external SRAM.
     */
    printf("External RAM Test... ");
    sram = XMemTest();
    printf("%u bytes\n", (u_int)sram);

    printf("Banked RAM Test...   ");
    banksize = sram;
    banks = XMemBankTest(&banksize);
    if (banks)
        printf("%u banks, %u bytes ea.\n", banks, (u_int)banksize);
    else
        puts("none");

    /*
     * Test external Flash.
     */
    printf("Serial FLASH...      ");
    srom = SpiMemTest();
    printf("%lu bytes\n", srom);

    /*
     * Test Ethernet controller hardware.
     */
    printf("Detecting NIC...     ");
    if (SmscDetect()) {
        if (RealtekDetect()) {
            nic = 0;
            puts("none\x07");
        } else {
            nic = 1;
            puts("RTL8019AS");
        }
    } else {
        nic = 2;
        puts("LAN91C111");
    }

    if (nic) {
        printf("Testing NIC...       ");
        if (nic == 1) {
            RealtekTest();
        } else {
            SmscTest();
        }
    }

    /*
     * Test I/O ports.
     */
#if defined(ETHERNUT1) || defined(ETHERNUT2)
    printf("I/O Port Test...     ");
    if (TestPorts() == 0)
        puts("OK");
#endif

    /*
     * Return if running without serial port.
     */
    if (uart_bs < 0)
        return;
    for (;;) {
        for (;;) {
            while (GetChar());
            puts_P(menu1_P);
            if (sram)
                puts_P(menu2_P);
            puts_P(menu3_P);
            if (sram > 8191 && nic)
                puts_P(menu4_P);
            while ((ch = GetChar()) == 0 || ch == ' ');
            if (sram > 8191 && (ch == 'x' || ch == 'X'))
                break;
            if (sram && (ch == 'b' || ch == 'B')) {
                if (nic == 1)
                    RealtekSend();
                else
                    SmscSend();
            } else if (ch == 'e' || ch == 'E') {
                if (nic == 1) {
                    RealtekLoop();
                } else {
                    SmscLoop();
                }
            } else if (ch == 'j' || ch == 'J') {
                puts("Booting...");
#if defined(__AVR__)
                asm("jmp 0x1F000");
#endif
            } else if (ch == 's' || ch == 'S')
                LoopSRAM();
        }

        /*
         * Input MAC address.
         */
        for (;;) {
            printf("\nMAC address (%02X%02X%02X%02X%02X%02X): ", my_mac[0], my_mac[1], my_mac[2], my_mac[3], my_mac[4],
                   my_mac[5]);
            GetLine(inbuff, sizeof(inbuff));
            if ((n = strlen(inbuff)) == 0)
                break;
            for (i = 0; i < n; i++)
                if (inbuff[i] < '0' ||
                    (inbuff[i] > '9' && inbuff[i] < 'A') || (inbuff[i] > 'F' && inbuff[i] < 'a') || inbuff[i] > 'f')
                    n = 13;
            if (n <= 12 && (n & 1) == 0) {
                n >>= 1;
                for (i = 0; i < n; i++)
                    my_mac[6 - n + i] = hex2bin(inbuff[i * 2]) * 16 + hex2bin(inbuff[i * 2 + 1]);
                break;
            }
            printf("Bad MAC address");
        }

        /*
         * Input host name.
         */
        printf("Host name (%s): ", confos.hostname);
        GetLine(hostname, sizeof(confos.hostname) - 1);

        /*
         * Input IP address.
         */
        GetIP("IP address", my_ip);
        /*
         * Input netmask and gateway, if non-zero IP address.
         */
        if (inet_addr(my_ip)) {
            GetIP("Net mask", my_mask);
            GetIP("Default route", my_gate);
            if (inet_addr(my_gate) == 0 || (inet_addr(my_ip) & inet_addr(my_mask)) == (inet_addr(my_gate) & inet_addr(my_mask)))
                break;
        } else {
            printf("Using DHCP or ARP method (Y): ");
            GetLine(inbuff, sizeof(inbuff));
            if (strlen(inbuff) == 0 || inbuff[0] == 'Y' || inbuff[0] == 'y')
                break;
        }
    }
Exemple #6
0
/*
 * Main application routine.
 *
 * Nut/OS automatically calls this entry after initialization.
 */
int main(void)
{
    uint32_t baud = 115200;
    /* IP of the local network in host byte order. */
    uint32_t net_ip;
    /* Currently scanned IP in host byte order. */
    uint32_t scan_ip;
    /* Currently scanned IP in network byte order. */
    uint32_t dest;
    /* Host portion mask in host byte order. */
    uint32_t host_mask;
    /* Current echo request sequence number. */
    uint16_t seq = 0;

    /*
     * Assign stdout to the DEBUG device.
     */
    NutRegisterDevice(&DEV_CONSOLE, 0, 0);
    freopen(DEV_CONSOLE.dev_name, "w", stdout);
    _ioctl(_fileno(stdout), UART_SETSPEED, &baud);

    /*
     * Print out our version information.
     */
    printf("\n\nNut/OS %s\n", NutVersionString());
    printf("PingNet %s " __DATE__ " " __TIME__ "\n", APP_VERSION);

    /*
     * Configure the network interface. It is assumed, that
     * we got a valid configuration in non-volatile memory.
     *
     * For alternatives see
     * http://www.ethernut.de/nutwiki/Network_Configuration
     */
    printf("Configure %s...", DEV_ETHER_NAME);
    if (NutRegisterDevice(&DEV_ETHER, 0, 0)) {
        FatalError("failed");
    }
    if (NutDhcpIfConfig("eth0", 0, 60000)) {
        FatalError("no valid network configuration");
    }
    printf("%s ready\n", inet_ntoa(confnet.cdn_ip_addr));
    /* Some Ethernet device drivers seem to return from initialization
       even if they are not fully up and running. Typically this is no
       problem, because upper layers will do retries. However, in our
       special case we'd lose some nodes during the first scan. So just
       take a short nap to give the driver some more time. */
    NutSleep(2000);

    /*
     * Register an ICMP callback function to inspect all incoming
     * ICMP packets.
     */
    if (NutRegisterIpHandler(IPPROTO_ICMP, IcmpCallback)) {
        FatalError("failed to register ICMP callback");
    }

    /*
     * Determine the host portion mask and the IP of the local
     * network from our IP configuration. Note, that Nut/Net
     * stores all IP address items in network byte order.
     */
    host_mask = ~ntohl(confnet.cdn_ip_mask);
    net_ip = ntohl(confnet.cdn_ip_addr) & ~host_mask;

    /*
     * Allocate a bit field to store the state of all possible
     * nodes of our local network. Limit this to 2^16 (class B)
     * and also reject point to point configurations.
     */
    if (host_mask > 0xFFFF || host_mask < 0x0003) {
        FatalError("Bad network size");
    }
    upnodes = calloc((host_mask + 1) / 8, 1);
    if (upnodes == NULL) {
        FatalError("out of memory");
    }

    /*
     * Scan the whole network endlessly.
     */
    for (;;) {
        int retries = 0;

        seq++;
        scan_ip = net_ip;
        /*
         * Scan node by node.
         */
        for (;;) {
            int got = 0;

            /* If this is not a retry, move to the next possible node
               address. */
            if (retries == 0) {
                scan_ip++;
            }
            /* All nodes processed if we reached the broadcast address. */
            if ((scan_ip & host_mask) == host_mask) {
                break;
            }
            /* Send an echo request to the current IP (network byte order). */
            dest = htonl(scan_ip);
            printf("\r%s ", inet_ntoa(dest));
            if (IcmpSendPing(dest, 1, seq, 32) == 0) {
                /* Wait until our ICMP handler signals new packets. */
                while (got == 0 && NutEventWait(&sign_queue, 100) == 0) {
                    /* Inspect all queued packets. */
                    while (nbuf_queue) {
                        NETBUF *nb;
                        IPHDR *ip = (IPHDR *) nbuf_queue->nb_nw.vp;

                        /* Check if this packet is from the currently scanned
                           node address. We may additionally check ID and
                           sequence number, but actually anything from that
                           interface will be just fine to mark it as up. */
                        got += (ip->ip_src == dest);
                        nb = nbuf_queue;
                        nbuf_queue = nb->nb_next;
                        NutNetBufFree(nb);
                    }
                }
                if (NODE_IS_UP(scan_ip & host_mask)) {
                    /* If the node has been up and is now down, then
                       do a few retries first to be sure that it is
                       really not responding anymore. */
                    if (got == 0) {
                        if (retries < 3) {
                            retries++;
                        } else {
                            retries = 0;
                            NODE_DOWN(scan_ip & host_mask);
                            puts("down");
                        }
                    }
                }
                else if (got) {
                    /* New node detected. */
                    NODE_UP(scan_ip & host_mask);
                    puts("up");
                }
            } else {
                /* Failed to send out the request. */
                puts("ICMP transmit error");
            }
        }
        /* Sleep one minute before scanning the network again. */
        printf("\rSleeping                ");
        NutSleep(60000);
    }
    /* Never reached, but required to suppress compiler warning. */
    return 0;
}
Exemple #7
0
/*
 * Application entry.
 */
int main(void)
{
    uint32_t baud = 115200;
    int cmd;

    /* Use UART device for stdin and stdout. */
    NutRegisterDevice(&DEV_CONSOLE, 0, 0);
    freopen(DEV_CONSOLE.dev_name, "w", stdout);
    freopen(DEV_CONSOLE.dev_name, "r", stdin);
    _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
    printf("\n\nCalendar Time %s running on Nut/OS %s\n"
           , version, NutVersionString());

#ifdef USE_LINE_EDITOR
    /* Open line editor, if configured. */
    printf("Opening line editor...");
    edline = EdLineOpen(EDIT_MODE_ECHO);
    if (edline) {
        puts("OK");
    } else {
        puts("failed");
    }
#else
    puts("Note: Enable local echo!");
#endif

#if USE_TIME_ZONE
    _timezone = USE_TIME_ZONE;
#endif

#ifdef RTC_CHIP
    /* Register and query hardware RTC, if available. */
    printf("Registering RTC hardware...");
    if (NutRegisterRtc(&RTC_CHIP)) {
        puts("failed");
    } else {
        uint32_t rtc_stat;

        NutRtcGetStatus(&rtc_stat);
        if (rtc_stat & RTC_STATUS_PF) {
#if defined(USE_BUILD_TIME)
            puts("power failure, Setting Time from Build date");
            /* Initially use the compile date and time. */
            time_t now = RfcTimeParse("Unk, " __DATE__ " " __TIME__);
            stime(&now);
            puts("Built " __DATE__ " " __TIME__);
#else
            puts("power failure");
#endif
        } else {
            puts("OK");
        }
    }
#elif USE_BUILD_TIME
    {
        /* Initially use the compile date and time. */
        time_t now = RfcTimeParse("Unk, " __DATE__ " " __TIME__);
        stime(&now);
        puts("Built " __DATE__ " " __TIME__);
    }
#endif

    for (;;) {
        /* Print command menu. */
        puts("\n  0 - Display seconds counter");
        puts("  1 - Display universal time");
        puts("  2 - Display local time");
        puts("  3 - Display system uptime");
        puts("  C - Calculate weekday");
        puts("  S - Set local time");
        puts("  Y - Toggle DST calculation");
        puts("  Z - Set timezone");

        printf("What is thy bidding, my master? ");

        /* Flush input buffer. */
        while (kbhit()) {
            cmd = getchar();
        }

        /* Get the next command. */
        cmd = getchar();
        putchar('\n');

        /* Process the command. */
        switch (cmd) {
        case '0':
            DisplaySeconds();
            break;
        case '1':
            DisplayZuluTime();
            break;
        case '2':
            DisplayLocalTime();
            break;
        case '3':
            DisplayUpTime();
            break;
        case 'C':
        case 'c':
            CalcWeekDay();
            break;
        case 'S':
        case 's':
            SetLocalTime();
            break;
        case 'Y':
        case 'y':
            /* Nut/OS uses a global variable to enable/disable DST.
               Toggle the current status and display the result. */
            _daylight = _daylight == 0;
            printf("DST calculation %sabled\n", _daylight ? "en" : "dis");
            break;
        case 'Z':
        case 'z':
            SetTimeZone();
            break;
        }
    }
    return 0;
}
Exemple #8
0
/*! \fn Service(void *arg)
 * \brief HTTP service thread.
 *
 * The endless loop in this thread waits for a client connect,
 * processes the HTTP request and disconnects. Nut/Net doesn't
 * support a server backlog. If one client has established a
 * connection, further connect attempts will be rejected.
 * Typically browsers open more than one connection in order
 * to load images concurrently. So we run this routine by
 * several threads.
 *
 */
THREAD(Service, arg)
{
    TCPSOCKET *sock;
    FILE *stream;
    uint8_t id = (uint8_t) ((uintptr_t) arg);

    /*
     * Now loop endless for connections.
     */
    for (;;) {

        /*
         * Create a socket.
         */
        if ((sock = NutTcpCreateSocket()) == 0) {
            printf("[%u] Creating socket failed\n", id);
            NutSleep(5000);
            continue;
        }

        /*
         * Listen on port 80. This call will block until we get a connection
         * from a client.
         */
        NutTcpAccept(sock, 80);
#if defined(__AVR__)
        printf("[%u] Connected, %u bytes free\n", id, NutHeapAvailable());
#else
        printf("[%u] Connected, %lu bytes free\n", id, NutHeapAvailable());
#endif

        /*
         * Wait until at least 8 kByte of free RAM is available. This will
         * keep the client connected in low memory situations.
         */
#if defined(__AVR__)
        while (NutHeapAvailable() < 8192) {
#else
        while (NutHeapAvailable() < 4096) {
#endif
            printf("[%u] Low mem\n", id);
            NutSleep(1000);
        }

        /*
         * Associate a stream with the socket so we can use standard I/O calls.
         */
        if ((stream = _fdopen((int) ((uintptr_t) sock), "r+b")) == 0) {
            printf("[%u] Creating stream device failed\n", id);
        } else {
            /*
             * This API call saves us a lot of work. It will parse the
             * client's HTTP request, send any requested file from the
             * registered file system or handle CGI requests by calling
             * our registered CGI routine.
             */
            NutHttpProcessRequest(stream);

            /*
             * Destroy the virtual stream device.
             */
            fclose(stream);
        }

        /*
         * Close our socket.
         */
        NutTcpCloseSocket(sock);
        printf("[%u] Disconnected\n", id);
    }
}
#endif /* DEV_ETHER */

/*!
 * \brief Main application routine.
 *
 * Nut/OS automatically calls this entry after initialization.
 */
int main(void)
{
    uint32_t baud = 115200;
    uint8_t i;

    /*
     * Initialize the uart device.
     */
    NutRegisterDevice(&DEV_DEBUG, 0, 0);
    freopen(DEV_DEBUG_NAME, "w", stdout);
    _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
    NutSleep(200);
    printf("\n\nNut/OS %s HTTP Daemon...", NutVersionString());

#ifdef DEV_ETHER

#ifdef NUTDEBUG
    NutTraceTcp(stdout, 0);
    NutTraceOs(stdout, 0);
    NutTraceHeap(stdout, 0);
    NutTracePPP(stdout, 0);
#endif

    /*
     * Register Ethernet controller.
     */
    if (NutRegisterDevice(&DEV_ETHER, 0, 0)) {
        puts("Registering device failed");
    }

    printf("Configure %s...", DEV_ETHER_NAME);
    if (NutNetLoadConfig(DEV_ETHER_NAME)) {
        uint8_t mac[] = MY_MAC;

        printf("initial boot...");
#ifdef USE_DHCP
        if (NutDhcpIfConfig(DEV_ETHER_NAME, mac, 60000)) 
#endif
        {
            uint32_t ip_addr = inet_addr(MY_IPADDR);
            uint32_t ip_mask = inet_addr(MY_IPMASK);
            uint32_t ip_gate = inet_addr(MY_IPGATE);

            printf("No DHCP...");
            if (NutNetIfConfig(DEV_ETHER_NAME, mac, ip_addr, ip_mask) == 0) {
                /* Without DHCP we had to set the default gateway manually.*/
                if(ip_gate) {
                    printf("hard coded gate...");
                    NutIpRouteAdd(0, 0, ip_gate, &DEV_ETHER);
                }
                puts("OK");
            }
            else {
                puts("failed");
            }
        }
    }
    else {
#ifdef USE_DHCP
        if (NutDhcpIfConfig(DEV_ETHER_NAME, 0, 60000)) {
            puts("failed");
        }
        else {
            puts("OK");
        }
#else
        if (NutNetIfConfig(DEV_ETHER_NAME, 0, 0, confnet.cdn_ip_mask)) {
            puts("failed");
        }
        else {
            puts("OK");
        }
#endif
    }
    printf("%s ready\n", inet_ntoa(confnet.cdn_ip_addr));

#ifdef USE_DISCOVERY
    NutRegisterDiscovery((uint32_t)-1, 0, DISF_INITAL_ANN);
#endif

    /*
     * Register our device for the file system.
     */
    NutRegisterDevice(&MY_FSDEV, 0, 0);

#ifdef MY_BLKDEV
    /* Register block device. */
    printf("Registering block device '" MY_BLKDEV_NAME "'...");
    if (NutRegisterDevice(&MY_BLKDEV, 0, 0)) {
        puts("failed");
        for (;;);
    }
    puts("OK");

    /* Mount partition. */
    printf("Mounting block device '" MY_BLKDEV_NAME ":1/" MY_FSDEV_NAME "'...");
    if (_open(MY_BLKDEV_NAME ":1/" MY_FSDEV_NAME, _O_RDWR | _O_BINARY) == -1) {
        puts("failed");
        for (;;);
    }
    puts("OK");
#endif

#ifdef MY_HTTPROOT
    /* Register root path. */
    printf("Registering HTTP root '" MY_HTTPROOT "'...");
    if (NutRegisterHttpRoot(MY_HTTPROOT)) {
        puts("failed");
        for (;;);
    }
    puts("OK");
#endif

    NutRegisterCgiBinPath("cgi-bin/;user/cgi-bin/;admin/cgi-bin/");


    /*
     * Register our CGI sample. This will be called
     * by http://host/cgi-bin/test.cgi?anyparams
     */
    NutRegisterCgi("test.cgi", ShowQuery);

#if defined(USE_SSI)
    /* 
     * Register a cgi included by the ssi demo. This will show how dynamic 
     * content is included in a ssi page and how the request parameters for 
     * a site are passed down to the included cgi.
     */    
    NutRegisterCgi("ssi-demo.cgi", SSIDemoCGI);
#endif

    /*
     * Register some CGI samples, which display interesting
     * system informations.
     */
    NutRegisterCgi("threads.cgi", ShowThreads);
    NutRegisterCgi("timers.cgi", ShowTimers);
    NutRegisterCgi("sockets.cgi", ShowSockets);

    /*
     * Finally a CGI example to process a form.
     */
    NutRegisterCgi("form.cgi", ShowForm);

    /*
     * Protect the cgi-bin directory with
     * user and password.
     */
    NutRegisterAuth("admin", "root:root");
    NutRegisterAuth("user", "user:user");

    /*
     * Register SSI and ASP handler
     */
#if defined(USE_SSI)
    NutRegisterSsi();
#endif
#if defined(USE_ASP)
    NutRegisterAsp();
    NutRegisterAspCallback(ASPCallback);
#endif

    /*
     * Start four server threads.
     */
    for (i = 1; i <= 4; i++) {
        char thname[] = "httpd0";

        thname[5] = '0' + i;
        NutThreadCreate(thname, Service, (void *) (uintptr_t) i, 
            (HTTPD_SERVICE_STACK * NUT_THREAD_STACK_MULT) + NUT_THREAD_STACK_ADD);
    }
#endif /* DEV_ETHER */

    /*
     * We could do something useful here, like serving a watchdog.
     */
    NutThreadSetPriority(254);
    for (;;) {
        NutSleep(60000);
    }
    return 0;
}