return( data ); } /*--------------------------------------------------------- */ FLWORD ioPutw( IdeDocReg *ioRegPtr, FLWORD data ) { /* Write 16-bit 'data' into specific Register */ ioRegPtr->value = data; outport( ioRegPtr->port, data ); return( data ); } /*----- IdeDoc Socket functions ------------------------------------- */
void user_init(void) { stdoutInit(); ioInit(); httpdInit(builtInUrls, 80); dnsserver_init(); os_printf("\nReady\n"); }
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. void user_init(void) { wifi_station_set_auto_connect(FALSE); stdoutInit(); CFG_Load(); ioInit(); MAIN_DEBUG("\nInitialise ENC stack, dhcp if requested\n"); stack_init(); /* This DNS is only for the wifi interface, as wired never acts as an 'AP' */ captdnsInit(); // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position // where image is written in flash that is defined in Makefile. #ifdef ESPFS_POS espFsInit((void*)(0x40200000 + ESPFS_POS)); #else espFsInit((void*)(webpages_espfs_start)); #endif httpdInit(builtInUrls, 80); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_arm(&prHeapTimer, 3000, 1); #endif os_timer_disarm(&websockTimer); os_timer_setfn(&websockTimer, websockTimerCb, NULL); os_timer_arm(&websockTimer, 1000, 1); os_printf("\nReady\n"); }
//Main routine. Initialize stdout, the I/O and the webserver and we're done. void user_init(void) { uart_init(); ioInit(); websocketdInit(8080, &onWsConnection); //Start os task system_os_task(rxLoop, RX_PRIO, user_procTaskQueue, RX_QUEUE_LEN); system_os_post(RX_PRIO, 0, 0 ); os_printf("\nReady\n"); }
void wsInit(const char* filename) { // Init memory emulation memInit(filename); // Init GPU gpuInit(); // Init I/O emulation ioInit(); // And reset everything wsReset(); }
// ---------------------------------------------------------------------------- // Init function // ---------------------------------------------------------------------------- void user_init(void) { ioInit(); // initialize UART, GPIO and crap like that os_delay_us(10000); for(int i = 0; i < 30; i++) os_printf(" \n"); menu(); // ------------------------------------------------------------------------ // Start os task // ------------------------------------------------------------------------ system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen); system_os_post(user_procTaskPrio, 0, 0 ); }
/************************************************ * name: user_init * parameters: none * return value: none * purpose: main logic ************************************************/ void user_init(void) { /* initialization */ struct softap_config tWifiSettings = { 0 }; uint8 puMacAddress[6] = { 0 }; os_memset((void *)&tWifiSettings, 0, sizeof(tWifiSettings)); wifi_softap_get_config(&tWifiSettings); /* retrieve mac address */ wifi_get_macaddr(1, puMacAddress); /* append to ssid name */ memcpy(tWifiSettings.ssid, HOTSPOT_SSID_STRING, sizeof(HOTSPOT_SSID_STRING)); os_sprintf(tWifiSettings.ssid + sizeof(HOTSPOT_SSID_STRING) - 1, "%x%x%x%x%x%x", puMacAddress[0], puMacAddress[1], puMacAddress[2], puMacAddress[3], puMacAddress[4], puMacAddress[5]); /* set password */ memcpy(tWifiSettings.password, HOTSPOT_PASSWORD_STRING, os_strlen(HOTSPOT_PASSWORD_STRING)); /* update other settings */ tWifiSettings.authmode = AUTH_WPA_WPA2_PSK; tWifiSettings.ssid_len = 0; tWifiSettings.channel = 6; tWifiSettings.max_connection = 4; /* update wifi configuration */ wifi_softap_set_config(&tWifiSettings); /* initialize stdout */ stdoutInit(); /* initialize IOs */ ioInit(); /* initialize server */ httpdInit(g_ptSupportedUrls, 80); #ifdef USER_MAIN_DEBUG os_printf("user_init: ready; partition %d\n", system_upgrade_userbin_check()); #endif }
//Main routine. Initialize stdout, the I/O and the webserver and we're done. void user_init(void) { // HTTPD stdoutInit(); ioInit(); httpdInit(builtInUrls, 80); //MQTT uart_init(115200, 115200); CFG_Load(); sleepms(1000); MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, SEC_NONSSL); //MQTT_InitConnection(&mqttClient, "192.168.11.122", 1880, 0); MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); //MQTT_InitClient(&mqttClient, "client_id", "user", "pass", 120, 1); // MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnPublished(&mqttClient, mqttPublishedCb); MQTT_OnData(&mqttClient, mqttDataCb); INFO("device_ID:%s\r\n",sysCfg.device_id); INFO("MQTTHOST:%s\r\n",sysCfg.mqtt_host); //DS18B20 timers os_timer_disarm(&ds18b20_timer); os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)ds18b20_cb, (void *)0); os_timer_arm(&ds18b20_timer, DELAY, 1); //NTP timers ntp_get_time(); os_timer_disarm(&NTP_timer); os_timer_setfn(&NTP_timer, (os_timer_func_t *)ntp_get_time, (void *)0); os_timer_arm(&NTP_timer, NTPDELAY, 1); // initialize GPIO2 PIN_FUNC_SELECT(PIN_GPIO2_MUX, PIN_GPIO2_FUNC); GPIO_OUTPUT_SET(PIN_GPIO2, 0); INFO("GPIO2 set to OFF\r\n"); WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb); os_printf("\nReady\n"); }
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. void user_init(void) { stdoutInit(); ioInit(); captdnsInit(); // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position // where image is written in flash that is defined in Makefile. #ifdef ESPFS_POS espFsInit((void*)(0x40200000 + ESPFS_POS)); #else espFsInit((void*)(webpages_espfs_start)); #endif httpdInit(builtInUrls, 80); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_arm(&prHeapTimer, 3000, 1); #endif os_printf("\nReady\n"); }
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. void user_init(void) { mmInit(mmData); //Redirect stdout to websocket os_install_putc1((void *)stdoutPutcharWs); ioInit(); captdnsInit(); telnetInit(333); // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position // where image is written in flash that is defined in Makefile. #ifdef ESPFS_POS espFsInit((void*)(0x40200000 + ESPFS_POS)); #else espFsInit((void*)(webpages_espfs_start)); #endif httpdInit(builtInUrls, 80); os_timer_disarm(&websockTimer); os_timer_setfn(&websockTimer, websockTimerCb, NULL); os_timer_arm(&websockTimer, 1000, 1); os_printf("\nReady\n"); wifi_set_sleep_type(LIGHT_SLEEP_T); }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; static DhcpClientSettings dhcpClientSettings; static DhcpClientCtx dhcpClientContext; //Update system core clock SystemCoreClockUpdate(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP FTP Client Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2013 Oryx Embedded\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: SAM4E\r\n"); TRACE_INFO("\r\n"); //IO configuration ioInit(); //Initialize LCD display GLCD_Init(); GLCD_SetBackColor(Blue); GLCD_SetTextColor(White); GLCD_Clear(Blue); //Welcome message lcdSetCursor(0, 0); printf("FTP Client Demo\r\n"); //TCP/IP stack initialization error = tcpIpStackInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Select the relevant network adapter interface->nicDriver = &sam4eEthDriver; interface->phyDriver = &ksz8051PhyDriver; //Interface name strcpy(interface->name, "eth0"); //Set host MAC address macStringToAddr("00-AB-CD-EF-04-16", &interface->macAddr); #if (IPV6_SUPPORT == ENABLED) //Set link-local IPv6 address ipv6StringToAddr("fe80::00ab:cdef:0416", &interface->ipv6Config.linkLocalAddr); #endif //Initialize network interface error = tcpIpStackConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if 1 //Set the network interface to be configured by DHCP dhcpClientSettings.interface = &netInterface[0]; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //Start DHCP client error = dhcpClientStart(&dhcpClientContext, &dhcpClientSettings); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Manual configuration interface = &netInterface[0]; //IPv4 address ipv4StringToAddr("192.168.0.20", &interface->ipv4Config.addr); //Subnet mask ipv4StringToAddr("255.255.255.0", &interface->ipv4Config.subnetMask); //Default gateway ipv4StringToAddr("192.168.0.254", &interface->ipv4Config.defaultGateway); //Primary and secondary DNS servers interface->ipv4Config.dnsServerCount = 2; ipv4StringToAddr("212.27.40.240", &interface->ipv4Config.dnsServer[0]); ipv4StringToAddr ("212.27.40.241", &interface->ipv4Config.dnsServer[1]); #endif //Create user task task = osTaskCreate("User Task", userTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osTaskCreate("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStart(); //This function should never return return 0; }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP Web Server Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2016 Oryx Embedded SARL\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: SAM7SE512\r\n"); TRACE_INFO("\r\n"); //Configure I/Os ioInit(); //Generate a random seed //PRNG initialization error = yarrowInit(&yarrowContext); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize PRNG!\r\n"); } //Properly seed the PRNG error = yarrowSeed(&yarrowContext, seed, sizeof(seed)); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to seed PRNG!\r\n"); } //TCP/IP stack initialization error = netInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name netSetInterfaceName(interface, "eth0"); //Set host name netSetHostname(interface, "WebServerDemo"); //Select the relevant network adapter netSetDriver(interface, &dm9000Driver); //Set external interrupt line driver netSetExtIntDriver(interface, &extIntDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); netSetMacAddr(interface, &macAddr); //Initialize network interface error = netConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, 0, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, 0, &ipv6Addr); //Set default router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetDefaultRouter(interface, 0, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Get default settings httpServerGetDefaultSettings(&httpServerSettings); //Bind HTTP server to the desired interface httpServerSettings.interface = &netInterface[0]; //Listen to port 80 httpServerSettings.port = HTTP_PORT; //Client connections httpServerSettings.maxConnections = APP_HTTP_MAX_CONNECTIONS; httpServerSettings.connections = httpConnections; //Specify the server's root directory strcpy(httpServerSettings.rootDirectory, "/www/"); //Set default home page strcpy(httpServerSettings.defaultDocument, "index.shtm"); //Callback functions httpServerSettings.authCallback = httpServerAuthCallback; httpServerSettings.cgiCallback = httpServerCgiCallback; httpServerSettings.uriNotFoundCallback = httpServerUriNotFoundCallback; //HTTP server initialization error = httpServerInit(&httpServerContext, &httpServerSettings); //Failed to initialize HTTP server? if(error) { //Debug message TRACE_ERROR("Failed to initialize HTTP server!\r\n"); } //Start HTTP server error = httpServerStart(&httpServerContext); //Failed to start HTTP server? if(error) { //Debug message TRACE_ERROR("Failed to start HTTP server!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("******************************\r\n"); TRACE_INFO("*** CycloneSSL Client Demo ***\r\n"); TRACE_INFO("******************************\r\n"); TRACE_INFO("Copyright: 2010-2015 Oryx Embedded SARL\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: AT32UC3A0512\r\n"); TRACE_INFO("\r\n"); //Configure I/Os ioInit(); //Initialize LCD display /*GLCD_Init(); GLCD_SetBackColor(Blue); GLCD_SetTextColor(White); GLCD_Clear(Blue);*/ //Welcome message lcdSetCursor(0, 0); printf("SSL Client Demo\r\n"); //Generate a random seed //PRNG initialization error = yarrowInit(&yarrowContext); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize PRNG!\r\n"); } //Properly seed the PRNG error = yarrowSeed(&yarrowContext, seed, sizeof(seed)); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to seed PRNG!\r\n"); } //Debug message TRACE_INFO("Loading credentials...\r\n"); //Start of exception handling block do { //Load trusted CA certificates error = resGetData(APP_CA_CERT_BUNDLE, (uint8_t **) &trustedCaList, &trustedCaListLength); //Any error to report? if(error) break; //Load client's certificate error = resGetData(APP_CLIENT_CERT, (uint8_t **) &clientCert, &clientCertLength); //Any error to report? if(error) break; //Load client's private key error = resGetData(APP_CLIENT_PRIVATE_KEY, (uint8_t **) &clientPrivateKey, &clientPrivateKeyLength); //Any error to report? if(error) break; //End of exception handling block } while(0); //Check error code if(error) { //Debug message TRACE_ERROR("Failed to load credentials!\r\n"); } //TCP/IP stack initialization error = netInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name netSetInterfaceName(interface, "eth0"); //Set host name netSetHostname(interface, "SSLClientDemo"); //Select the relevant network adapter netSetDriver(interface, &avr32EthDriver); netSetPhyDriver(interface, &dp83848PhyDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); netSetMacAddr(interface, &macAddr); //Initialize network interface error = netConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, &ipv6Addr); //Set router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetRouter(interface, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Create user task task = osCreateTask("User Task", userTask, NULL, 850, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
TDisplay(){ ioInit(); spi.init(5120000, TSpiMaster::CLK_IDDLE_HIGH, TSpiMaster::TOGGLE_ON_START, TSpiMaster::MSB_FIRST, TSpiMaster::WRITE_ONLY, false); }
//------------------------------------------------------------------------------ /// Performs the low-level initialization of the chip. This includes EFC, master /// clock, AIC & watchdog configuration, as well as memory remapping. //------------------------------------------------------------------------------ void lowLevelInit( void ) { unsigned char i; volatile unsigned int j; AT91C_BASE_RSTC->RSTC_RCR = AT91C_RSTC_KEY_A5 | AT91C_RSTC_PERRST; BOARD_ConfigureFlash48MHz(); //#if !defined(sdram) /* Initialize main oscillator ****************************/ AT91C_BASE_PMC->PMC_MOR = BOARD_OSCOUNT | AT91C_CKGR_MOSCEN; while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS)); /* Initialize PLL at 96MHz (96.109) and USB clock to 48MHz */ AT91C_BASE_PMC->PMC_PLLR = BOARD_USBDIV | BOARD_CKGR_PLL | BOARD_PLLCOUNT | BOARD_MUL | BOARD_DIV; while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK)); /* Wait for the master clock if it was already initialized */ while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY)); /* Switch to fast clock **********************/ /* Switch to slow clock + prescaler */ AT91C_BASE_PMC->PMC_MCKR = BOARD_PRESCALER; while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY)); /* Switch to fast clock + prescaler */ AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK; while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY)); //#endif //#if !defined(sdram) /* Initialize AIC ****************/ AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF; AT91C_BASE_AIC->AIC_SVR[0] = (unsigned int) defaultFiqHandler; for (i = 1; i < 31; i++) { AT91C_BASE_AIC->AIC_SVR[i] = (unsigned int) defaultIrqHandler; } AT91C_BASE_AIC->AIC_SPU = (unsigned int) defaultSpuriousHandler; // Unstack nested interrupts for (i = 0; i < 8; i++) { AT91C_BASE_AIC->AIC_EOICR = 0; } // Enable Debug mode AT91C_BASE_AIC->AIC_DCR = AT91C_AIC_DCR_PROT; /* Watchdog initialization *************************/ AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS; //BOARD_ConfigureSdram(16); //Enable external RST pin AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_KEY_A5 | AT91C_RSTC_URSTEN; //SDRAM initialization /// sdramInit(); /* Remap *******/ BOARD_RemapRam(); //IO configuration ioInit(); /*for(i = 0; i < 10; i++) { setLed(AT91B_LED1); clearLed(AT91B_LED2); for(j = 0; j < 100000; j++); clearLed(AT91B_LED1); setLed(AT91B_LED2); for(j = 0; j < 100000; j++); }*/ //Disable RTT and PIT interrupts (potential problem when program A //configures RTT, then program B wants to use PIT only, interrupts //from the RTT will still occur since they both use AT91C_ID_SYS) AT91C_BASE_RTTC->RTTC_RTMR &= ~(AT91C_RTTC_ALMIEN | AT91C_RTTC_RTTINCIEN); AT91C_BASE_PITC->PITC_PIMR &= ~AT91C_PITC_PITIEN; }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP Web Server Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2014 Oryx Embedded\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: STM32F407\r\n"); TRACE_INFO("\r\n"); //Configure I/Os ioInit(); //Initialize LCD display STM32f4_Discovery_LCD_Init(); LCD_SetBackColor(Blue); LCD_SetTextColor(White); LCD_SetFont(&Font16x24); LCD_Clear(Blue); //Welcome message lcdSetCursor(0, 0); printf("Web Server Demo"); //TCP/IP stack initialization error = tcpIpStackInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name tcpIpStackSetInterfaceName(interface, "eth0"); //Set host name tcpIpStackSetHostname(interface, "WebServerDemo"); //Select the relevant network adapter tcpIpStackSetDriver(interface, &stm32f4x7EthDriver); tcpIpStackSetPhyDriver(interface, &lan8720PhyDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); tcpIpStackSetMacAddr(interface, &macAddr); //Initialize network interface error = tcpIpStackConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID); //Set router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetRouter(interface, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Get default settings httpServerGetDefaultSettings(&httpServerSettings); //Bind HTTP server to the desired interface httpServerSettings.interface = &netInterface[0]; //Listen to port 80 httpServerSettings.port = HTTP_PORT; //Specify the server's root directory strcpy(httpServerSettings.rootDirectory, "/www/"); //Set default home page strcpy(httpServerSettings.defaultDocument, "index.shtm"); //Callback functions httpServerSettings.cgiCallback = httpServerCgiCallback; httpServerSettings.uriNotFoundCallback = httpServerUriNotFoundCallback; //HTTP server initialization error = httpServerInit(&httpServerContext, &httpServerSettings); //Failed to initialize HTTP server? if(error) { //Debug message TRACE_ERROR("Failed to initialize HTTP server!\r\n"); } //Start HTTP server error = httpServerStart(&httpServerContext); //Failed to start HTTP server? if(error) { //Debug message TRACE_ERROR("Failed to start HTTP server!\r\n"); } //Create user task task = osCreateTask("User Task", userTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
/* * Main entry point. */ void main(void) { static TICK8 t = 0; #ifdef HEATHERD NODE_INFO tcpServerNode; static TCP_SOCKET tcpSocketUser = INVALID_SOCKET; BYTE c; #endif static BYTE testLED; testLED = 1; //Set SWDTEN bit, this will enable the watch dog timer WDTCON_SWDTEN = 1; aliveCntrMain = 0xff; //Disable alive counter during initialization. Setting to 0xff disables it. //Initialize any application specific hardware. InitializeBoard(); //Initialize all stack related components. Following steps must //be performed for all applications using PICmicro TCP/IP Stack. TickInit(); //Initialize buses busInit(); //Initialize serial ports early, because they could be required for debugging if (appcfgGetc(APPCFG_USART1_CFG & APPCFG_USART_ENABLE)) { appcfgUSART(); //Configure the USART1 } if (appcfgGetc(APPCFG_USART2_CFG & APPCFG_USART_ENABLE)) { appcfgUSART2(); //Configure the USART2 } //After initializing all modules that use interrupts, enable global interrupts INTCON_GIEH = 1; INTCON_GIEL = 1; //Initialize file system. fsysInit(); //Intialize HTTP Execution unit htpexecInit(); //Initialize Stack and application related NV variables. appcfgInit(); //First call appcfgCpuIOValues() and then only appcfgCpuIO()!!! This ensures the value are set, before enabling ports. appcfgCpuIOValues(); //Configure the CPU's I/O port pin default values appcfgCpuIO(); //Configure the CPU's I/O port pin directions - input or output appcfgADC(); //Configure ADC unit appcfgPWM(); //Configure PWM Channels //Serial configuration menu - display it for configured time and allow user to enter configuration menu scfInit(appcfgGetc(APPCFG_STARTUP_SER_DLY)); //LCD Display Initialize lcdInit(); //Initialize expansion board appcfgXboard(); StackInit(); #if defined(STACK_USE_HTTP_SERVER) HTTPInit(); #endif #if defined(STACK_USE_FTP_SERVER) FTPInit(); #endif //Intialise network componet of buses - only call after StackInit()! busNetInit(); //Initializes events. evtInit(); //Initializes "UDP Command Port" and "UDP Even Port". cmdInit(); ioInit(); #if (DEBUG_MAIN >= LOG_DEBUG) debugPutMsg(1); //@mxd:1:Starting main loop #endif /* * Once all items are initialized, go into infinite loop and let * stack items execute their tasks. * If application needs to perform its own task, it should be * done at the end of while loop. * Note that this is a "co-operative mult-tasking" mechanism * where every task performs its tasks (whether all in one shot * or part of it) and returns so that other tasks can do their * job. * If a task needs very long time to do its job, it must broken * down into smaller pieces so that other tasks can have CPU time. */ #ifdef HEATHERD //Create a TCP socket that listens on port 54123 tcpSocketUser = TCPListen(HEATHERD); #define HEATHERD_ENABLE (!(appcfgGetc(APPCFG_TRISA) & 1)) #define HEATHERD_WRITE_ENABLE (!(appcfgGetc(APPCFG_TRISA) & 2)) #endif while(1) { aliveCntrMain = 38; //Reset if not services in 52.42ms x 38 = 2 seconds //Blink SYSTEM LED every second. if (appcfgGetc(APPCFG_SYSFLAGS) & APPCFG_SYSFLAGS_BLINKB6) { //Configure RB6 as output, and blink it every 500ms if ( TickGetDiff8bit(t) >= ((TICK8)TICKS_PER_SECOND / (TICK8)2) ) { t = TickGet8bit(); //If B6 is configured as input, change to output if (appcfgGetc(APPCFG_TRISB) & 0x40) { appcfgPutc(APPCFG_TRISB, appcfgGetc(APPCFG_TRISB) & 0b10111111); } TRISB_RB6 = 0; LATB6 ^= 1; //Toggle //Toggle IOR5E LED, if IOR5E is present if (appcfgGetc(APPCFG_XBRD_TYPE) == XBRD_TYPE_IOR5E) { ior5eLatchData.bits.ledPWR ^= 1; // Toggle } } } //This task performs normal stack task including checking for incoming packet, //type of packet and calling appropriate stack entity to process it. StackTask(); //Service LCD display lcdService(); //Process commands cmdTask(); //Process events evtTask(); //Process serial busses busTask(); //I2C Task i2cTask(); #ifdef HEATHERD //Has a remote node made connection with the port we are listening on if ((tcpSocketUser != INVALID_SOCKET) && TCPIsConnected(tcpSocketUser)) { if (HEATHERD_ENABLE) { //Is there any data waiting for us on the TCP socket? //Because of the design of the Modtronix TCP/IP stack we have to //consume all data sent to us as soon as we detect it. while(TCPIsGetReady(tcpSocketUser)) { //We are only interrested in the first byte of the message. TCPGet(tcpSocketUser, &c); if (HEATHERD_WRITE_ENABLE) serPutByte(c); } //Discard the socket buffer. TCPDiscard(tcpSocketUser); while (serIsGetReady() && TCPIsPutReady(tcpSocketUser)) { TCPPut(tcpSocketUser,serGetByte()); } TCPFlush(tcpSocketUser); } else { TCPDisconnect(tcpSocketUser); } } #endif #if defined(STACK_USE_HTTP_SERVER) //This is a TCP application. It listens to TCP port 80 //with one or more sockets and responds to remote requests. HTTPServer(); #endif #if defined(STACK_USE_FTP_SERVER) FTPServer(); #endif #if defined(STACK_USE_ANNOUNCE) DiscoveryTask(); #endif #if defined(STACK_USE_NBNS) NBNSTask(); #endif //Add your application speicifc tasks here. ProcessIO(); //For DHCP information, display how many times we have renewed the IP //configuration since last reset. if ( DHCPBindCount != myDHCPBindCount ) { #if (DEBUG_MAIN >= LOG_INFO) debugPutMsg(2); //@mxd:2:DHCP Bind Count = %D debugPutByteHex(DHCPBindCount); #endif //Display new IP address #if (DEBUG_MAIN >= LOG_INFO) debugPutMsg(3); //@mxd:3:DHCP complete, IP = %D.%D.%D.%D debugPutByteHex(AppConfig.MyIPAddr.v[0]); debugPutByteHex(AppConfig.MyIPAddr.v[1]); debugPutByteHex(AppConfig.MyIPAddr.v[2]); debugPutByteHex(AppConfig.MyIPAddr.v[3]); #endif myDHCPBindCount = DHCPBindCount; #if defined(STACK_USE_ANNOUNCE) AnnounceIP(); #endif } } }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP FTP Client Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2015 Oryx Embedded SARL\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: RX63N\r\n"); TRACE_INFO("\r\n"); //Configure I/Os ioInit(); //Initialize RSPI channel R_RSPI_Init(RSPI_CHANNEL_0); //Initialize LCD display GlyphOpen(&lcdHandle, 0); GlyphNormalScreen(lcdHandle); GlyphSetFont(lcdHandle, GLYPH_FONT_6_BY_13); //Clear display GlyphClearScreen(lcdHandle); //Welcome message lcdSetCursor(0, 0); printf("FTP Client\r\nDemo\r\n"); //TCP/IP stack initialization error = netInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name netSetInterfaceName(interface, "eth0"); //Set host name netSetHostname(interface, "FTPClientDemo"); //Select the relevant network adapter netSetDriver(interface, &rx63nEthDriver); netSetPhyDriver(interface, &dp83620PhyDriver); //Set external interrupt line driver netSetExtIntDriver(interface, &extIntDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); netSetMacAddr(interface, &macAddr); //Initialize network interface error = netConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, &ipv6Addr); //Set router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetRouter(interface, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Create user task task = osCreateTask("User Task", userTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Enable interrupts __enable_interrupt(); //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
//Main routine void ICACHE_FLASH_ATTR user_init(void) { stdoutInit(); os_delay_us(100000); CFG_Load(); ioInit(); WIFI_Connect(wifiConnectCb); httpdInit(builtInUrls, sysCfg.httpd_port); if(sysCfg.ntp_enable==1) { sntp_init(sysCfg.ntp_tz); //timezone } if(sysCfg.mqtt_enable==1) { MQTT_InitConnection(&mqttClient, (uint8_t *)sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.mqtt_use_ssl ); MQTT_InitClient(&mqttClient, (uint8_t *)sysCfg.mqtt_devid, (uint8_t *)sysCfg.mqtt_user, (uint8_t *)sysCfg.mqtt_pass, sysCfg.mqtt_keepalive,1); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnPublished(&mqttClient, mqttPublishedCb); MQTT_OnData(&mqttClient, mqttDataCb); } if(sysCfg.sensor_dht22_enable) DHTInit(SENSOR_DHT22, 30000); if(sysCfg.sensor_ds18b20_enable) ds_init(30000); broadcastd_init(); thermostat_init(30000); /* //Netbios to set the name struct softap_config wiconfig; os_memset(netbios_name, ' ', sizeof(netbios_name)-1); if(wifi_softap_get_config(&wiconfig)) { int i; for(i = 0; i < sizeof(netbios_name)-1; i++) { if(wiconfig.ssid[i] < ' ') break; netbios_name[i] = wiconfig.ssid[i]; }; } else os_sprintf(netbios_name, "ESP8266"); netbios_name[sizeof(netbios_name)-1]='\0'; netbios_init(); */ os_printf("\nRelay Board Ready\n"); os_printf("Free heap size:%d\n",system_get_free_heap_size()); #ifdef CGIPWM_H //Mind the PWM pin!! defined in pwm.h duty=0; pwm_init( 50, &duty); pwm_set_duty(duty, 0); pwm_start(); #endif //OLEDInit(); }
//Main routine. Initialize stdout, the I/O and the webserver and we're done. void user_init(void) { // my stuff dBR_BOILER_SET=65; // default setting 65C boiler temperature on reboot dBR_TEMP_ROOM_SET=18; // default setting 18C room temperature on reboot dBR_HUMIDITY_SET=60; // default setting 65% humidity target on reboot dBR_MODE=2; // default BR MODE is AUTO dDEVICE_MODE=1; // This mode defines if device uses remote (MQTT) management or uses local logics - 0 for remote, 1 for local mode. DEFAULT is 0 - remote // HTTPD stdoutInit(); ioInit(); httpdInit(builtInUrls, 80); //MQTT uart_init(115200, 115200); CFG_Load(); sleepms(1000); MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, SEC_NONSSL); //MQTT_InitConnection(&mqttClient, "192.168.11.122", 1880, 0); MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); //MQTT_InitClient(&mqttClient, "client_id", "user", "pass", 120, 1); // MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnPublished(&mqttClient, mqttPublishedCb); MQTT_OnData(&mqttClient, mqttDataCb); INFO("device_ID:%s\r\n",sysCfg.device_id); INFO("MQTTHOST:%s\r\n",sysCfg.mqtt_host); //DS18B20 timers os_timer_disarm(&ds18b20_timer); os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)ds18b20_cb, (void *)0); os_timer_arm(&ds18b20_timer, DELAY, 1); // DHT22 initialize DHTInit(DHT22, DELAY); os_timer_disarm(&dht22_timer); os_timer_setfn(&dht22_timer, (os_timer_func_t *)dht22_cb, (void *)0); os_timer_arm(&dht22_timer, DELAY, 1); // INPUT PIN initialize ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts ETS_GPIO_INTR_ATTACH(read_input_pin, 13); // GPIO13 interrupt handler PIN_FUNC_SELECT(PIN_GPIO13_MUX, PIN_GPIO13_FUNC); gpio_output_set(0, 0, 0, BIT13); // Set GPIO13 as input PIN_PULLUP_EN(PIN_GPIO13_MUX); // Enable pullup GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(13)); // Clear GPIO12 status gpio_pin_intr_state_set(GPIO_ID_PIN(13), GPIO_PIN_INTR_NEGEDGE); // Interrupt on NEGATIVE GPIO13 edge ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts // INFO("Input pin INITIALIZED ! ! !"); // initialize GPIO12 PIN_FUNC_SELECT(PIN_GPIO12_MUX, PIN_GPIO12_FUNC); GPIO_OUTPUT_SET(PIN_GPIO12, 0); // INFO("GPIO12 set to OFF\r\n"); // initialize GPIO5 GPIO_OUTPUT_SET(PIN_GPIO5, 0); // INFO("GPIO5 set to OFF\r\n"); // initialize GPIO14 PIN_FUNC_SELECT(PIN_GPIO14_MUX, PIN_GPIO14_FUNC); GPIO_OUTPUT_SET(PIN_GPIO14, 0); // INFO("GPIO14 set to OFF\r\n"); WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb); os_printf("\nReady\n"); }
void initStepper(){ ioInit(); }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //Update system core clock SystemCoreClockUpdate(); //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP FTP Client Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2014 Oryx Embedded\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: MK60N512MD100\r\n"); TRACE_INFO("\r\n"); //Configure I/Os ioInit(); //TCP/IP stack initialization error = tcpIpStackInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name tcpIpStackSetInterfaceName(interface, "eth0"); //Set host name tcpIpStackSetHostname(interface, "FTPClientDemo"); //Select the relevant network adapter tcpIpStackSetDriver(interface, &mk60EthDriver); tcpIpStackSetPhyDriver(interface, &ksz8041PhyDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); tcpIpStackSetMacAddr(interface, &macAddr); //Initialize network interface error = tcpIpStackConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID); //Set router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetRouter(interface, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Create user task task = osCreateTask("User Task", userTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
void main() { SCB->VTOR = 0x08000000; // set clock source as HSI / 2 * (PLL) 4 RCC->CFGR |= RCC_CFGR_PLLMULL8 | RCC_CFGR_PLLXTPRE_HSE_Div2 /*| RCC_CFGR_PLLSRC*/; RCC->CR |= RCC_CR_PLLON; while (!(RCC->CR & RCC_CR_PLLRDY)); RCC->CFGR |= RCC_CFGR_SW_PLL; while (!(RCC->CFGR & RCC_CFGR_SWS_PLL)); // enable peripherals RCC->APB1ENR = RCC_APB1ENR_TIM2EN; RCC->APB2ENR = RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_ADC1EN | RCC_APB2ENR_USART1EN | RCC_APB2ENR_AFIOEN; AFIO->MAPR = AFIO_MAPR_SWJ_CFG_JTAGDISABLE; // configure USART IO_ALT_PUSH_PULL(UART_TX); USART1->BRR = USART_BRR(230400); USART1->CR1 = USART_CR1_UE | USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE; ENABLE_INTERRUPT(USART1_IRQn); // enable systick SysTick->LOAD = SysTick->VAL = (F_CPU / 1000) / 8; SysTick->CTRL = /*SysTick_CTRL_CLKSOURCE |*/ SysTick_CTRL_ENABLE | SysTick_CTRL_TICKINT; _delay_init(); IO_PUSH_PULL(LED); IO_HIGH(LED); #ifndef ETHERNET_MODULE OW_UART_init(); tempInit(); ioInit(); irInit(); #endif #ifdef ETHERNET ethInit(); #endif uint8_t b; uint32_t lastCheck = 0; for (;;) { // if (IO_IS_LOW(IN1)) dodump = 1; // else dodump = 0; // dodump=1; #ifndef ETHERNET_MODULE ioProcess(); tempProcess(); irProcess(); #endif provTmr(); #ifdef ETHERNET ethProcess(); #endif } }