void nic_connect(void) { /* This part of code is required only if using the interrupt while accessing the SPI attachInterrupt(0, zg_isr, LOW); */ zg_setpolling(); // Include debug functionalities, if required #if(VNET_DEBUG) // Print address VNET_LOG("(vNet)WiFi Connecting"); VNET_LOG("\r\n"); #endif // Connect to a Wifi network or in AdHoc mode while(zg_get_conn_state() != 1) { zg_drv_process(); } // Include debug functionalities, if required #if(VNET_DEBUG) // Print address VNET_LOG("(vNet)WiFi Connected"); VNET_LOG("\r\n"); #endif }
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 macLinkIsUp(void) { // 0 if down, 1 if up if (zg_get_conn_state()) { return 1; } else { return 0; } }
u8_t nic_poll(void) { u16_t packetLength; // Connection lost, retry if(zg_get_conn_state() != 1) { // Include debug functionalities, if required #if(VNET_DEBUG) // Print address VNET_LOG("(vNet)WiFi Connection lost, retry"); VNET_LOG("\r\n"); #endif while(zg_get_conn_state() != 1){ zg_drv_process(); } } // This method place the incoming data directly into the uIP buffer packetLength = zg_get_rx_status(); // Process the in/out data from the Wifi controller zg_drv_process(); // If there are no incoming data if(!packetLength) return packetLength = 0; // If the lenght exceed the buffer size if(packetLength > UIP_BUFSIZE) return packetLength = 0; // Return the lenght return packetLength; }
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 }
void main(void) { int status=0, flash=1; uint16_t data; char received[256]="(NULL)"; char r; // Init //DDRE |= 0xf0; initDevice(); //PORTE = 0x30; // Status Report (Initialized) #ifdef SIM int i; for(i=0;i<=10;i++) #else while(1) #endif { //PORTE = 0x20; // Status Report (Not Connected) #ifndef SIM //PORTE = 0x10; // Status Report (Connected) // Flash the led so we know we are alive //if(flash) PORTE |= 0x80; else PORTE &= ~0x80; _delay_ms(5000); #endif flash ^=1; // Monitor Supply Voltage checkSupply(); //if(flash) // OCR1BL = 18; //else // OCR1BL = 5; // Setup from INA219 // BRNG = Bus Voltage Range (0=16V 1=24V) // RST::-::BRNG::PG1::PG0::BADC4::BADC3::BADC2 // BADC1::SADC4::SADC3::SADC2::SADC1::MODE3::MODE2::MODE1 // Breakout uses 0.1 Ohm Rshunt // At +-320mV FSR -> +-3.2A // Using PGA/8 max 400mA if(!configINA219()){ getAmpINA219(); } while(zg_get_conn_state() != 1) { zg_drv_process(); } //printf("Press M (More) or L (Less): \n"); //r = getCHAR(stdin); //switch(r){ // case 'M': // printf("incrementing OCR1BL\n"); // OCR1BL += 1; // ~1ms // printf("OCR1BL=%u\n", 0x00FF & OCR1BL); // break; // case 'L': // printf("decrementing OCR1BL\n"); // OCR1BL -= 1; // ~1ms // printf("OCR1BL=%u\n", 0x00FF & OCR1BL); // break; // default: // break; //} } sleep_cpu(); }
/* Checks if the WiShield is currently connected */ boolean isConnected() { return (zg_get_conn_state() == 1); }