void Set_NetApp_Timeout(void) { unsigned long aucDHCP = 14400; unsigned long aucARP = 3600; unsigned long aucKeepalive = 10; unsigned long aucInactivity = 60; netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity); }
void Set_NetApp_Timeout(void) { unsigned long aucDHCP = 14400; unsigned long aucARP = 3600; unsigned long aucKeepalive = 10; unsigned long aucInactivity = DEFAULT_SEC_INACTIVITY; SPARK_WLAN_SetNetWatchDog(S2M(DEFAULT_SEC_NETOPS)+ (DEFAULT_SEC_INACTIVITY ? 250 : 0) ); netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity); }
void hw_net_initialize (void) { CC3000_START; SpiInit(4e6); hw_wait_us(10); wlan_init(CC3000_UsynchCallback, NULL, NULL, NULL, ReadWlanInterruptPin, WlanInterruptEnable, WlanInterruptDisable, WriteWlanPin); wlan_start(0); int r = wlan_ioctl_set_connection_policy(0, 0, 0); if (r != 0) { TM_DEBUG("Fail setting policy %i", r); } r = wlan_ioctl_set_scan_params(10000, 100, 100, 5, 0x7FF, -100, 0, 205, wifi_intervals); if (r != 0) { TM_DEBUG("Fail setting scan params %i", r); } r = wlan_ioctl_set_connection_policy(0, true, true); if (r != 0) { TM_DEBUG("Fail setting connection policy %i", r); } wlan_stop(); hw_wait_ms(10); wlan_start(0); // tm_sleep_ms(100); // TM_COMMAND('w',"setting event mask\n"); wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE|HCI_EVNT_WLAN_UNSOL_INIT|HCI_EVNT_WLAN_ASYNC_PING_REPORT); // TM_COMMAND('w',"done setting event mask\n"); unsigned long aucDHCP = 14400; unsigned long aucARP = 3600; unsigned long aucKeepalive = 10; unsigned long aucInactivity = 0; if (netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity) != 0) { TM_DEBUG("Error setting inactivity timeout!"); } unsigned char version[2]; if (nvmem_read_sp_version(version)) { TM_ERR("Failed to read CC3000 firmware version."); } memcpy(hw_cc_ver, version, 2); CC3000_END; }
int avr_netinit(const char* wlan_ssid, const char* wlan_pwd, int wlan_security, uint32_t ip, uint32_t subnet_mask, uint32_t gateway, uint32_t dns) { init_sockets_buffer(); if (!cc3000.begin()) { return -1; } if (!cc3000.connectToAP(wlan_ssid, wlan_pwd, wlan_security)) { return -1; } if (!check_dhcp()) { return -1; } uint32_t current_ip = 0, current_subnet_mask = 0, current_gw = 0, currend_dhcp = 0, current_dns = 0; if (!cc3000.getIPAddress(¤t_ip, ¤t_subnet_mask, ¤t_gw, ¤d_dhcp, ¤t_dns)) { return -1; } if (current_ip != ip || current_subnet_mask != subnet_mask || current_gw != gateway || current_dns != dns) { if (!cc3000.setStaticIPAddress(ip, subnet_mask, gateway, dns)) { return -1; } /* Waiting while new address is really assigned */ if (!check_dhcp()) { return -1; } } if (netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity) != 0) { return -1; } /* TODO(alashkin): power fix */ delay(5000); return 0; }
// Initialize the server and start listening for connections. void Adafruit_CC3000_Server::begin() { // Set the CC3000 inactivity timeout to 0 (never timeout). This will ensure // the CC3000 does not close the listening socket when it's idle for more than // 60 seconds (the default timeout). See more information from: // http://e2e.ti.com/support/low_power_rf/f/851/t/292664.aspx unsigned long aucDHCP = 14400; unsigned long aucARP = 3600; unsigned long aucKeepalive = 30; unsigned long aucInactivity = 0; cc3k_int_poll(); if (netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity) != 0) { CC3K_PRINTLN_F(CC3000_MSG_ERR_SET_CLIENT_TIMEOUT); return; } // Create a TCP socket cc3k_int_poll(); int16_t soc = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (soc < 0) { CC3K_PRINTLN_F(CC3000_MSG_FAIL_CREATE_LISTEN_SOCK); return; } // Set the socket's accept call as non-blocking. cc3k_int_poll(); char arg = SOCK_ON; // nsd: looked in TI example code and they pass this as a 'short' in one example, and 'char' in two others. 'char' seems as likely work, and has no endianess issue if (setsockopt(soc, SOL_SOCKET, SOCKOPT_ACCEPT_NONBLOCK, &arg, sizeof(arg)) < 0) { CC3K_PRINTLN_F(CC3000_MSG_FAIL_SET_SOCKET_NOBLOCK); return; } // Bind the socket to a TCP address. sockaddr_in address; address.sin_family = AF_INET; address.sin_addr.s_addr = htonl(0); // Listen on any network interface, equivalent to INADDR_ANY in sockets programming. address.sin_port = htons(_port); // Listen on the specified port. cc3k_int_poll(); if (bind(soc, (sockaddr*) &address, sizeof(address)) < 0) { CC3K_PRINTLN_F(CC3000_MSG_FAIL_SOCKET_BIND_ADDR); return; } // Start listening for connections. // The backlog parameter is 0 as it is not supported on TI's CC3000 firmware. cc3k_int_poll(); if (listen(soc, 0) < 0) { CC3K_PRINTLN_F(CC3000_MSG_ERR_OPEN_SOCKET_LISTEN); // listening return; } _listenSocket = soc; }
/* * @brief Initialization is used to configure all of the registers of the microcontroller * Steps: * 1) Initialize CC3000 * 2) Set MUX Select_A to LOW, so we can send the Kill command from Atmega TX line * (C0 input on MUX) * 3) Set Mode to Safety Mode * 4) Set MUX Select A to HIGH, so we get into Autonomous mode by default * (C1 input on MUX) */ inline void Initialization (void) { #ifdef WATCHDOG_ENABLED wdt_enable(WDTO_8S); // WDTO_8S means set the watchdog to 8 seconds. #endif //Turn on the Power LED to identify that the device is on. // [UNUSED] DDRC |= (1 << DDC7); //STATUS LED //Set up the LEDs for WLAN_ON and DHCP: DDRC |= (1 << DDC6); //WLAN_INIT LED DDRC |= (1 << DDC7); //DHCP_Complete LED. This will turn on and very slowly blink DDRB |= (1 << DDB7); // MUX Select line, setting as output. DDRE |= (1 << DDE2); // DDRF set outbound for Safe Mode LED DDRD |= (1 << DDD6); // DDRF set outbound for Manual Mode LED DDRD |= (1 << DDD4); // DDRF set outbound for Auto Mode LED PORTF |= (1 << PF0); // Extra GPIO Pin PORTF |= (1 << PF1); // Extra GPIO Pin #ifndef SKIP_BOOT DDRB |= (1 << DDB4); DDRD |= (1 << DDD7); DDRD |= (1 << DDD6); PORTB |= (1 << PB4); _delay_ms(200); PORTD |= (1 << PD7); _delay_ms(200); PORTD |= (1 << PD6); _delay_ms(200); PORTB &= ~(1 << PB4); _delay_ms(200); PORTD &= ~(1 << PD7); _delay_ms(200); PORTD &= ~(1 << PD6); #endif _delay_ms(500); PORTF &= ~(1 << PF0); PORTF &= ~(1 << PF1); // #ifdef ENERGY_ANALYSIS_ENABLED // //Enable Timer/Counter0 Interrupt on compare match of OCR0A: // TIMSK0 = (1 << OCIE0A); // //Set the Output Compare Register for the timer to compare against: // OCR0A = Energy_Analysis_Interval; // //Configure the ADC to have the reference pin be AREF on pin 21, and make sure everything is set to defaults: // ADMUX = 0x00; // //Enable the Analog to Digital Conversion (ADC): // ADCSRA = (1 << ADEN); //25 Clock cycles to initialize. // #endif #ifdef CC3000_ENABLED //Enable the CC3000, and setup the SPI configurations. init_spi(); //Set up the CC3000 API for communication. wlan_init(CC3000_Unsynch_Call_Back, Send_WLFW_Patch, Send_Driver_Patch, Send_Boot_Loader_Patch, Read_WLAN_Interrupt_Pin, WLAN_Interrupt_Enable, WLAN_Interrupt_Disable, Write_WLAN_Pin); PORTB |= (1 << PB6); //Set the WLAN_INIT LED on. sei(); //Enable the CC3000, and wait for initialization process to finish. wlan_start(0); wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE|HCI_EVNT_WLAN_UNSOL_INIT|HCI_EVNT_WLAN_ASYNC_PING_REPORT); //Make sure we disconnect from any previous routers before we connect to a new one to prevent confusion on the device. wlan_disconnect(); wlan_connect(WLAN_SEC_UNSEC, ROUTER_SSID, SSID_LENGTH, NULL, NULL, 0); while(!DHCP_Complete) { _delay_ms(1000); } #ifdef WATCHDOG_ENABLED wdt_reset(); #endif //Bind a socket to receive data: //sockaddr Mission_Control_Address; memset((char *) &Mission_Control_Address, 0, sizeof(Mission_Control_Address)); Mission_Control_Address.sa_family = AF_INET; //The Source Port: Mission_Control_Address.sa_data[0] = (char)HEX_PORT_1; //(char)0x09; Mission_Control_Address.sa_data[1] = (char)HEX_PORT_2; //(char)0x56; //Configure the socket to not time out to keep the connection active. //-------------------------------------------------------------------- unsigned long aucDHCP = 14400; unsigned long aucARP = 3600; unsigned long aucKeepalive = 10; unsigned long aucInactivity = 0; netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity); //TODO: //Should check the CC3000's profiles. In the case that there are no profiles found, then //inform the PC system, or use an LED. //Open a UDP socket that grabs datagram: Socket_Handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); switch(Socket_Handle) { case -1: //Error //Flag somehow. break; default: //Success //Set the socket configuration for blocking (since it is the only thing that is allowed). switch( bind(Socket_Handle, &Mission_Control_Address, sizeof(sockaddr))) { case -1: //Flag as ERROR. break; default: //Flag as good. break; } break; } #endif // NEED TO SETUP A QUICK REMOVAL FLAG FOR THIS CODE TO TEST THE CC3000. // #ifdef MOTOR_CONTROL_FLAG // Set up our Motor Controller Selection lines and the output for the RS232 lines: // DDRD |= (1 << DDD3) | (1 << DDD4) | (1 << DDD5); DDRD |= (1 << DDD3) | (1 << DDD5); // Initialize the UART (RS-232 communications) for the motor controller interface: // Set the Baud rate to 115200 bits/s. ((System Oscillator clock frequency / (2 * BAUD) ) - 1) // NOTE: The value may not be correct, according to the data sheet (pg. 213). // With the value 16, the error is 2.1% (lower than 8, being -3.5%). // This comes from util/setbaud.h UBRR1H = UBRRH_VALUE; /*Set baud rate*/ UBRR1L = UBRRL_VALUE; /*Set baud rate*/ //Defined in util/setbaud.h: #if USE_2X UCSR1A |= (1 << U2X1); //Double the baud rate for asynchronous communication. #else UCSR1A &= ~(1 << U2X1); #endif // Set to no parity and in Asynchronous mode. // 1 Stop bit. // 1 Start bit. // Set to 8-bit data. UCSR1C |= (1 << UCSZ11) | (1 << UCSZ10); //Enable the Rx and Tx lines. UCSR1B |= (1 << TXEN1); #ifdef TWI_ENABLED //Set the SCL frequency to 200 KHz. From the equation: f(SCL) = F_CPU/(16 + (2*TWBR) * (4^TWPS)) TWBR = 12; DDRB |= (1 << DDB4); //Setup PortB4 as the TWI error LED. #endif //End TWI_ENABLED _delay_ms(1000); //Wait for one second for the RoboteQs to finish booting. Set_Mode(SAFETY_MODE); // Set to Safe Mode to send Kill Command to Roboteq's Set_Mode(AUTONOMOUS_MODE); #ifdef ROUTER_WATCHDOG_ENABLED Count = 0; //Clear the Count variable out. TCNT1 = 0; //Clear the TCNT register. TCCR1B = (1 << CS12) | (1 << CS10); //Set the prescaler for 1024. TIMSK1 = (1 << OCIE1A); //Enable output compare for 1A. OCR1A = 39063; //Set the system to interrupt every 5 seconds. //OCR1A = (Multiplier) * (F_CPU) / (Prescaler) //39063 = (5) * (8000000) / (1024) #endif }
//***************************************************************************** // //! initDriver //! //! \param None //! //! \return none //! //! \brief The function initializes a CC3000 device and triggers it to start operation // //***************************************************************************** int initDriver(void) { // Init GPIO's pio_init(); // Init SPI init_spi(); DispatcherUARTConfigure(); // Globally enable interrupts __enable_interrupt(); // // WLAN On API Implementation // wlan_init( CC3000_UsynchCallback, sendWLFWPatch, sendDriverPatch, sendBootLoaderPatch, ReadWlanInterruptPin, WlanInterruptEnable, WlanInterruptDisable, WriteWlanPin); // // Trigger a WLAN device // wlan_start(0); // // Mask out all non-required events from CC3000 // wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE|HCI_EVNT_WLAN_ASYNC_PING_REPORT|HCI_EVNT_WLAN_UNSOL_INIT); // Generate event to CLI: send a version string char cc3000IP[50]; char *ccPtr; unsigned short ccLen; DispatcherUartSendPacket((unsigned char*)pucUARTExampleAppString, sizeof(pucUARTExampleAppString)); ccPtr = &cc3000IP[0]; ccLen = itoa(PALTFORM_VERSION, ccPtr); ccPtr += ccLen; *ccPtr++ = '.'; ccLen = itoa(APPLICATION_VERSION, ccPtr); ccPtr += ccLen; *ccPtr++ = '.'; ccLen = itoa(SPI_VERSION_NUMBER, ccPtr); ccPtr += ccLen; *ccPtr++ = '.'; ccLen = itoa(DRIVER_VERSION_NUMBER, ccPtr); ccPtr += ccLen; *ccPtr++ = '\r'; *ccPtr++ = '\n'; *ccPtr++ = '\0'; ccLen = strlen(cc3000IP); DispatcherUartSendPacket((unsigned char*)cc3000IP, strlen(cc3000IP)); // CC3000 has been initialized setCC3000MachineState(CC3000_INIT); unsigned long aucDHCP, aucARP, aucKeepalive, aucInactivity; aucDHCP = 14400; aucARP = 3600; aucKeepalive = 10; aucInactivity = 50; if(netapp_timeout_values(&(aucDHCP), &(aucARP), &(aucKeepalive), &(aucInactivity)) != 0) { while(1); } return(0); }