long ReadWlanInterruptPin(void)
{
  DEBUGPRINT_F("\tCC3000: ReadWlanInterruptPin - ");
  DEBUGPRINT_DEC(digitalRead(g_irqPin));
  DEBUGPRINT_F("\n\r");

  return(digitalRead(g_irqPin));
}
//*****************************************************************************
//
//!  simple_link_recv
//!
//!  @param sd       socket handle
//!  @param buf      read buffer
//!  @param len      buffer length
//!  @param flags    indicates blocking or non-blocking operation
//!  @param from     pointer to an address structure indicating source address
//!  @param fromlen  source address structure size
//!
//!  @return         Return the number of bytes received, or -1 if an error
//!                  occurred
//!
//!  @brief          Read data from socket
//!                  Return the length of the message on successful completion.
//!                  If a message is too long to fit in the supplied buffer,
//!                  excess bytes may be discarded depending on the type of
//!                  socket the message is received from
//
//*****************************************************************************
int
simple_link_recv(long sd, void *buf, long len, long flags, sockaddr *from,
                socklen_t *fromlen, long opcode)
{
	unsigned char *ptr, *args;
	tBsdReadReturnParams tSocketReadEvent;
	
	ptr = tSLInformation.pucTxCommandBuffer;
	args = (ptr + HEADERS_SIZE_CMD);
	
	// Fill in HCI packet structure
	args = UINT32_TO_STREAM(args, sd);
	args = UINT32_TO_STREAM(args, len);
	args = UINT32_TO_STREAM(args, flags);

	// Generate the read command, and wait for the 
	hci_command_send(opcode,  ptr, SOCKET_RECV_FROM_PARAMS_LEN);
	
	// Since we are in blocking state - wait for event complete
	SimpleLinkWaitEvent(opcode, &tSocketReadEvent);

	DEBUGPRINT_F("\n\r\tRecv'd data... Socket #");
	DEBUGPRINT_DEC(tSocketReadEvent.iSocketDescriptor);
	DEBUGPRINT_F(" Bytes: 0x");
	DEBUGPRINT_HEX(tSocketReadEvent.iNumberOfBytes);
	DEBUGPRINT_F(" Flags: 0x");
	DEBUGPRINT_HEX(tSocketReadEvent.uiFlags);
	DEBUGPRINT_F("\n\r");

	// In case the number of bytes is more then zero - read data
	if (tSocketReadEvent.iNumberOfBytes > 0)
	{
		// Wait for the data in a synchronous way. Here we assume that the bug is 
		// big enough to store also parameters of receive from too....
	  SimpleLinkWaitData((unsigned char *)buf, (unsigned char *)from, (unsigned char *)fromlen);
	}
	
	errno = tSocketReadEvent.iNumberOfBytes;

#if (DEBUG_MODE == 1)
	for (uint8_t i=0; i<errno; i++) {
	  uart_putchar(((unsigned char *)buf)[i]);
	}
#endif
	
	return(tSocketReadEvent.iNumberOfBytes);
}
void WriteWlanPin( unsigned char val )
{  
  if (DEBUG_MODE)
  {
    DEBUGPRINT_F("\tCC3000: WriteWlanPin - ");
    DEBUGPRINT_DEC(val);
    DEBUGPRINT_F("\n\r");
    delay(1);
  }
  if (val)
  {
    digitalWrite(g_vbatPin, HIGH);
  }
  else
  {
    digitalWrite(g_vbatPin, LOW);
  }
}