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;
}
Example #2
0
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	
}
Example #3
0
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;
}
Example #4
0
uint8_t macPacketsReceived(void) { // 0 if no packet, 1 if packet ready
    if (rx_ready) {
        return 1;
    } else {
        zg_drv_process();
        if (rx_ready) {
            return 1;
        } else {
            return 0;
        }
    }
}
Example #5
0
void nic_send(void)
{
	if(uip_len < UIP_PAYLOADSIZE)
	{	
		// Transfer the message to the Wifi controller
		zg_set_buf((U8 *)uip_buf, uip_len);
		zg_set_tx_status(1);
	}
	
	// Process the in/out data from the Wifi controller
	zg_drv_process();	
	
}
Example #6
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;	
}
Example #7
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();
}
Example #8
0
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();
}
Example #9
0
static err_t
low_level_output(struct netif *netif, struct pbuf *p)
{
  struct g2100if *g2100if = netif->state;
  struct pbuf *q;

  // ***
  //initiate transfer();
  
#if ETH_PAD_SIZE
  pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif

  for(q = p; q != NULL; q = q->next) {
    /* Send the data from the pbuf to the interface, one pbuf at a
       time. The size of the data in each pbuf is kept in the ->len
       variable. */
    // ***
    //send data from(q->payload, q->len);
    zg_set_buf(q->payload, q->len);
	zg_set_tx_status(1);
    while (!zg_get_cnf_pending()) { // wait until transfer is confirmed
    	zg_drv_process();
    }
  }

  // ***
  //signal that packet should be sent();

#if ETH_PAD_SIZE
  pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif
  
  LINK_STATS_INC(link.xmit);

  return ERR_OK;
}
Example #10
0
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
}
Example #11
0
void WiShield::run()
{
	stack_process();
	zg_drv_process();
}
Example #12
0
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();
}