// Functions int initDevice() { int status=0; // Setup UART initUSART0STDIO(UBRR_MACRO); // Setup ADC initADC(); // Setup BT initBT(); // Wait for BT Connection #ifndef SIM while(!status) status = PING & (1 << PING0); #endif // Enable Timer initTimer(); // Enable I2C initI2C(); // Init wifi _delay_ms(310); DDRE |= (0x10|0x80|0x20) ; // PE4 = ~RST; PE7= ~WP; PE5=HIB; PORTE &= ~(0x80); // assert reset and WP PORTE |= (0x10 | 0x80); // deassert reset and WP PORTE &= ~(0x20); // De assert HIB // Enable ZG2100 Interrupt (use INT6) // Init wifi zg_init(); ZG2100_ISR_ENABLE(); // Enable Interrupts sei(); return 0; }
/** * In this function, the hardware should be initialized. * Called from g2100if_init(). * * @param netif the already initialized lwip network interface structure * for this g2100if */ static void low_level_init(struct netif *netif) { struct g2100if *g2100if = netif->state; zg_init(); /* set MAC hardware address length */ netif->hwaddr_len = ETHARP_HWADDR_LEN; U8* zg_mac = zg_get_mac(); /* set MAC hardware address */ netif->hwaddr[0] = zg_mac[0]; netif->hwaddr[1] = zg_mac[1]; netif->hwaddr[2] = zg_mac[2]; netif->hwaddr[3] = zg_mac[3]; netif->hwaddr[4] = zg_mac[4]; netif->hwaddr[5] = zg_mac[5]; /* maximum transfer unit */ netif->mtu = 1500; /* device capabilities */ /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */ netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_LINK_UP; }
boolean WiShield::init(U8 seconds) { boolean retVal = false; zg_init(); #ifdef USE_DIG0_INTR attachInterrupt(0, zg_isr, LOW); #endif #ifdef USE_DIG8_INTR // set digital pin 8 on Arduino // as ZG interrupt pin PCICR |= (1<<PCIE0); PCMSK0 |= (1<<PCINT0); #endif // TODO: potential for rollover bug after ~58 days... unsigned long time = millis(); while(time + (seconds * 1000) > millis()) { if(1 != zg_get_conn_state()) { zg_drv_process(); } else { retVal = true; break; } } stack_init(); return retVal; }
uint8_t macInitialize(uint8_t *address) { // 0 if success, 1 on error uint8_t i; uint8_t *p; INTDDR &= ~(1 << INTPIN); // Interrupt PIN debugPrint("Initializing WiFi..."); zg_init(); debugPrint(" Done!\nConnecting..."); addConditionalTask(zg_isr, zgInterruptOccured); // Emulate INT0 do { zg_drv_process(); } while (!macLinkIsUp()); debugPrint(" Done!\n"); p = zg_get_mac(); // Global Var. in g2100.c for (i = 0; i < 6; i++) { ownMacAddress[i] = p[i]; address[i] = ownMacAddress[i]; } return 0; }
void WiShield::init() { zg_init(); #ifdef USE_DIG0_INTR pinMode(D2, INPUT); attachInterrupt(D2, zg_isr, FALLING); #endif #ifdef USE_DIG8_INTR pinMode(D8, INPUT); attachInterrupt(D8, zg_isr, FALLING); #endif while(zg_get_conn_state() != 1) { zg_drv_process(); } stack_init(); }
void WiShield::init() { zg_init(); #ifdef USE_DIG0_INTR attachInterrupt(0, zg_isr, LOW); #endif #ifdef USE_DIG8_INTR // set digital pin 8 on Arduino // as ZG interrupt pin PCICR |= (1<<PCIE0); PCMSK0 |= (1<<PCINT0); #endif while(zg_get_conn_state() != 1) { zg_drv_process(); } stack_init(); }
void Server::init(pageServingFunction function) { // WiShield init zg_init(); #ifdef USE_DIG0_INTR attachInterrupt(0, zg_isr, LOW); #endif #ifdef USE_DIG8_INTR // set digital pin 8 on Arduino // as ZG interrupt pin PCICR |= (1<<PCIE0); PCMSK0 |= (1<<PCINT0); #endif while(zg_get_conn_state() != 1) { zg_drv_process(); } // Start the stack stack_init(); // Store the callback function for serving pages // and start listening for connections on port 80 if // the function is non-null callbackFunc = function; if (callbackFunc) { // Listen for server requests on port 80 uip_listen(HTONS(80)); } #ifdef DEBUG verbose = true; Serial.println("WiServer init called"); #endif // DEBUG }