main.c File Reference


Detailed Description

HTTP Server WiFi Demo Application.

This file provides a an example application for the H&D Wireless AB WiFi driver.

Author:
H&D Wireless AB

Definition in file main.c.

#include <compiler.h>
#include "board.h"
#include "gpio.h"
#include "adc.h"
#include "wl_api.h"
#include "wl_cm.h"
#include "lwip/init.h"
#include "lwip/dhcp.h"
#include "lwip/tcp.h"
#include "netif/etharp.h"
#include "netif/wlif.h"
#include "startup.h"
#include "trace.h"
#include "fw_download.h"
#include "timer.h"
#include "wl_util.h"
#include "util.h"
#include "cmd_wl.h"
#include "httpd.h"
#include "ping.h"
#include "ttcp.h"
#include "gui.h"
#include "http_server_gui.h"

Go to the source code of this file.

Data Structures

struct  http_server

Functions

void adc_init (void)
static void dhcp_coarse_tmr_cb (void *ctx)
static void dhcp_fine_tmr_cb (void *ctx)
static void etharp_tmr_cb (void *ctx)
static void ip_status_cb (struct netif *netif)
void led_init (void)
int main (void)
void poll (struct http_server *hs)
static void tcp_tmr_cb (void *ctx)
static void wl_cm_conn_cb (struct wl_network_t *net, void *ctx)
static void wl_cm_disconn_cb (void *ctx)
void wl_init_complete_cb (void *ctx)


Function Documentation

void adc_init ( void   ) 

Definition at line 251 of file main.c.

Referenced by wl_init_complete_cb().

00252 {
00253         static const gpio_map_t ADC_GPIO_MAP = {
00254                 { AVR32_ADC_AD_0_PIN, AVR32_ADC_AD_0_FUNCTION },
00255         };
00256         volatile avr32_adc_t *adc = &AVR32_ADC;
00257 
00258         gpio_enable_module(ADC_GPIO_MAP,
00259                            sizeof(ADC_GPIO_MAP) / sizeof(ADC_GPIO_MAP[0]));
00260         AVR32_ADC.mr |= 0x1 << AVR32_ADC_MR_PRESCAL_OFFSET;
00261         adc_configure(adc);
00262         adc_enable(adc, 0);
00263 }

static void dhcp_coarse_tmr_cb ( void *  ctx  )  [static]

Definition at line 181 of file main.c.

Referenced by wl_init_complete_cb().

00182 {
00183     dhcp_coarse_tmr();
00184 }

static void dhcp_fine_tmr_cb ( void *  ctx  )  [static]

Definition at line 171 of file main.c.

Referenced by wl_init_complete_cb().

00172 {
00173     dhcp_fine_tmr();
00174 }

static void etharp_tmr_cb ( void *  ctx  )  [static]

Definition at line 161 of file main.c.

Referenced by wl_init_complete_cb().

00162 {
00163     etharp_tmr();
00164 }

static void ip_status_cb ( struct netif *  netif  )  [static]

Definition at line 227 of file main.c.

References gui_status_down_cb, gui_status_up_cb, httpd_start(), httpd_stop(), ip2str(), and printk().

Referenced by wl_init_complete_cb().

00228 {
00229         if (netif_is_up(netif)) {
00230                 gui_status_up_cb();
00231                 printk("bound to %s\n", ip2str(netif->ip_addr));
00232                 printk("starting httpd ... ");
00233                 if (httpd_start() == ERR_OK)
00234                         printk("ok\n");
00235                 else
00236                         printk("fail\n");
00237 
00238         }
00239         else {
00240                 gui_status_down_cb();
00241                 printk("stopping httpd\n");
00242                 httpd_stop();
00243         }
00244 }

void led_init ( void   ) 

Definition at line 270 of file main.c.

Referenced by wl_init_complete_cb().

00271 {
00272     gpio_enable_gpio_pin(LED0_GPIO);
00273     gpio_enable_gpio_pin(LED1_GPIO);
00274     gpio_enable_gpio_pin(LED2_GPIO);
00275     gpio_enable_gpio_pin(LED3_GPIO);
00276         LED_Toggle(LED0);
00277         LED_Toggle(LED1);
00278         LED_Toggle(LED2);
00279         LED_Toggle(LED3);
00280 }

int main ( void   ) 

Definition at line 369 of file main.c.

References ASSERT, fw_download_cb(), fw_download_init(), http_server::netif, poll(), printk(), startup_init(), timer_init(), and wl_init_complete_cb().

00370 {
00371     wl_err_t wl_status;
00372     int status;
00373     struct http_server *hs;
00374 
00375         startup_init();
00376 
00377     hs = calloc(1, sizeof(struct http_server));
00378     ASSERT(hs, "out of memory");
00379 
00380     hs->netif = calloc(1, sizeof(struct netif));
00381     ASSERT(hs->netif, "out of memory");
00382 
00383         timer_init(NULL, NULL);
00384         lwip_init();
00385         
00386     status = fw_download_init();
00387     ASSERT(status == 0, "failed to prepare for firmware download\n");
00388 
00389         wl_status = wl_init(hs, fw_download_cb, wl_init_complete_cb);
00390         switch (wl_status) {
00391         case WL_SUCCESS:
00392                 /* ok */
00393                 break;
00394 
00395         case WL_CARD_FAILURE:
00396                 printk("Could not detect wl device, aborting\n");
00397                 return -1;
00398 
00399         case WL_FIRMWARE_INVALID:
00400                 printk("Invalid firmware data, aborting\n");
00401                 return -1;
00402 
00403         default:
00404                 printk("Failed to start wl initialization\n");
00405                 return -1;
00406         }
00407 
00408     /* start main loop */
00409         for (;;)
00410                 poll(hs);
00411 }

void poll ( struct http_server hs  ) 

Definition at line 287 of file main.c.

References console_poll(), gui_exec(), http_server::netif, timer_get_ms(), and timer_poll().

Referenced by main().

00288 {
00289         /* this will trigger any scheduled timer callbacks */
00290         timer_poll();
00291 
00292         /* handle console input */
00293         console_poll();
00294 
00295         /* wl api 'tick' */
00296         wl_poll(timer_get_ms());
00297 
00298         /* lwip driver poll */
00299         wlif_poll(hs->netif);
00300 
00301 #ifdef WITH_GUI
00302         gui_exec(timer_get_ms());
00303 #endif
00304 }

static void tcp_tmr_cb ( void *  ctx  )  [static]

Definition at line 151 of file main.c.

Referenced by wl_init_complete_cb().

00152 {
00153     tcp_tmr();
00154 }

static void wl_cm_conn_cb ( struct wl_network_t *  net,
void *  ctx 
) [static]

Definition at line 191 of file main.c.

References gui_link_up_cb, http_server::netif, printk(), and ssid2str().

Referenced by wl_init_complete_cb().

00192 {
00193     struct http_server* hs = ctx;
00194 
00195         gui_link_up_cb();
00196         printk("link up, connected to \"%s\"\n", ssid2str(&net->ssid));
00197         printk("requesting dhcp ... ");
00198 
00199         dhcp_start(hs->netif);
00200 }

static void wl_cm_disconn_cb ( void *  ctx  )  [static]

Definition at line 207 of file main.c.

References gui_link_down_cb, http_server::netif, and printk().

Referenced by wl_init_complete_cb().

00208 {
00209     struct http_server* hs = ctx;
00210 
00211         gui_link_down_cb();
00212 
00213         if (netif_is_up(hs->netif)) {
00214                 printk("link down, release dhcp\n");
00215                 dhcp_release(hs->netif);
00216                 dhcp_stop(hs->netif);
00217         } else {
00218                 printk("link down\n");
00219         }
00220 }

void wl_init_complete_cb ( void *  ctx  ) 

Definition at line 311 of file main.c.

References adc_init(), ASSERT, cmd_connect(), cmd_delpass(), cmd_ping(), cmd_power(), cmd_psconf(), cmd_scan(), cmd_setkey(), cmd_setpass(), cmd_status(), cmd_ttcp(), console_add_cmd(), console_init(), dhcp_coarse_tmr_cb(), dhcp_fine_tmr_cb(), etharp_tmr_cb(), gui_start, ip_status_cb(), led_init(), http_server::netif, tcp_tmr_cb(), TIMEOUT_PERIODIC, timer_sched_timeout_cb(), wl_cm_conn_cb(), wl_cm_disconn_cb(), and wl_cm_start().

Referenced by main().

00312 {
00313     struct http_server *hs = ctx;
00314         struct ip_addr ipaddr, netmask, gw;
00315     wl_err_t wl_status;
00316     
00317         IP4_ADDR(&gw, 0,0,0,0);
00318         IP4_ADDR(&ipaddr, 0,0,0,0);
00319         IP4_ADDR(&netmask, 0,0,0,0);
00320         
00321     /* add wl to lwip interface list and set as default */
00322         hs->netif = netif_add(hs->netif, &ipaddr, &netmask, &gw, NULL,
00323                   wlif_init, /* init */
00324                   ethernet_input /* handles ARP and IP packets */);
00325     ASSERT(hs->netif, "failed to add netif");
00326         netif_set_default(hs->netif);
00327         netif_set_status_callback(hs->netif, ip_status_cb);
00328 
00329     /* register lwip timer callbacks for tcp, arp and dhcp protocols */
00330         timer_sched_timeout_cb(5000, TIMEOUT_PERIODIC, 
00331                    etharp_tmr_cb, hs);
00332         timer_sched_timeout_cb(TCP_TMR_INTERVAL, TIMEOUT_PERIODIC, 
00333                    tcp_tmr_cb, hs);
00334     timer_sched_timeout_cb(DHCP_FINE_TIMER_MSECS, TIMEOUT_PERIODIC, 
00335                    dhcp_fine_tmr_cb, hs);
00336         timer_sched_timeout_cb(DHCP_COARSE_TIMER_MSECS, TIMEOUT_PERIODIC,
00337                    dhcp_coarse_tmr_cb, hs);
00338 
00339     /* initialize shell */
00340         console_init();
00341         console_add_cmd("scan", cmd_scan, NULL);
00342         console_add_cmd("connect", cmd_connect, NULL);
00343         console_add_cmd("setkey", cmd_setkey, NULL);
00344         console_add_cmd("status", cmd_status, NULL);
00345         console_add_cmd("powersave", cmd_power, NULL);
00346         console_add_cmd("psconf", cmd_psconf, NULL);
00347         console_add_cmd("ping", cmd_ping, NULL);
00348         console_add_cmd("ttcp", cmd_ttcp, NULL);
00349 #ifdef WITH_WPA
00350         console_add_cmd("wpass", cmd_setpass, NULL);
00351         console_add_cmd("dpass", cmd_delpass, NULL);
00352 #endif
00353         
00354     /* start connection manager */
00355     wl_status = wl_cm_start(NULL, wl_cm_conn_cb, wl_cm_disconn_cb, hs);
00356     ASSERT(wl_status == WL_SUCCESS, "failed to init wl conn mgr");
00357 
00358         /* init devices used by httpd */
00359         adc_init();
00360         led_init();
00361 
00362         gui_start();
00363 }


Generated on Fri Feb 19 02:24:08 2010 for AVR32 - H&D by  doxygen 1.5.5