bool platform_initialize(void* tcb) { OS_ERR osErr; mainTcb = tcb; SYS_Init(); GPIO_SetBit(LED_LINK_PORT, LED_LINK_PIN); GPIO_Open(LED_LINK_PORT, GPIO_PMD_PMD8_OUTPUT, GPIO_PMD_PMD8_MASK); #if NABTO_ENABLE_LOGGING uart_initialize(115200); #endif // Initialize OS tick system OS_CPU_SysTickInit(SYS_GetHCLKFreq() / OS_CFG_TICK_RATE_HZ); OSSemCreate(&loggingSemaphore, NULL, 1, &osErr); if(osErr != OS_ERR_NONE) { NABTO_LOG_FATAL(("Unable to create logging semaphore")); } NABTO_LOG_INFO(("Initializing...")); if (RAK_DriverInit() != RAK_OK) { NABTO_LOG_FATAL(("Platform initialize failed!")); } { char mac[6]; if (RAK_GetMacAddr(mac) != RAK_OK) { NABTO_LOG_FATAL(("RAK_GetMacAddr() failed!")); } NABTO_LOG_INFO(("MAC: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5])); } { RAK_CONNECT param; param.mode = NET_MODE_STA; param.sec_mode = PSK_MODE_SEC; param.ssid = wifiSsid; param.psk = wifiKey; param.conn_handle = wifi_callback; if (RAK_ConnectAP(¶m) != RAK_OK) { NABTO_LOG_FATAL(("Wifi connect error!")); } } while(linkIsUp == false); // wait for callback to set connection status { RAK_IPCONFIG dhcp; if (RAK_IPConfigDHCP(&dhcp) != RAK_OK) { NABTO_LOG_FATAL(("DHCP error!")); } localAddress = dhcp.addr; localMask = dhcp.mask; gateway = dhcp.gw; dnsServer = dhcp.dnsrv1; NABTO_LOG_TRACE(("DHCP: Address=" PRI_IP " mask=" PRI_IP " gateway=" PRI_IP " DNS=" PRI_IP, PRI_IP_FORMAT(localAddress), PRI_IP_FORMAT(localMask), PRI_IP_FORMAT(gateway), PRI_IP_FORMAT(dnsServer))); } memset(sockets, 0, sizeof(sockets)); sendBuffer = RAK_SendMalloc(SEND_BUFFER_SIZE); return true; }
int main(void) { int32_t i32Err; sysDisableCache(); sysFlushCache(I_D_CACHE); sysEnableCache(CACHE_WRITE_BACK); sysInitializeUART(); sysprintf("+-------------------------------------------------+\n"); sysprintf("| GPIO Sample Code |\n"); sysprintf("+-------------------------------------------------+\n\n"); /* Configure Port C to input mode and pull-up */ GPIO_Open(GPIOC, DIR_INPUT, PULL_UP); /* Set Port C output data to 0xFFF */ GPIO_Set(GPIOC, 0xFFF); /* Set Port C output data to 0x000 */ GPIO_Clr(GPIOC, 0xFFF); /* Configure Port C to default value */ GPIO_Close(GPIOC); i32Err = 0; sysprintf("GPIO PD.3(output mode) connect to PD.4(input mode) ......"); /* Configure PD3 to output mode */ GPIO_OpenBit(GPIOD, BIT3, DIR_OUTPUT, NO_PULL_UP); /* Configure PD4 to output mode */ GPIO_OpenBit(GPIOD, BIT4, DIR_INPUT, NO_PULL_UP); /* Use Pin Data Input/Output Control to pull specified I/O or get I/O pin status */ /* Pull PD.3 to High and check PD.4 status */ GPIO_SetBit(GPIOD, BIT3); if(GPIO_ReadBit(GPIOD,BIT4)==0) i32Err = 1; /* Pull PD.3 to Low and check PD.4 status */ GPIO_ClrBit(GPIOD, BIT3); if(GPIO_ReadBit(GPIOD,BIT4)==1) i32Err = 1; if(i32Err) { sysprintf(" [FAIL].\n"); } else { sysprintf(" [OK].\n"); } /* Configure PD3 to default value */ GPIO_CloseBit(GPIOD, BIT3); /* Configure PD4 to default value */ GPIO_CloseBit(GPIOD, BIT3); /* Set MFP_GPF11 to EINT0 */ outpw(REG_SYS_GPF_MFPH,(inpw(REG_SYS_GPF_MFPH) & ~(0xF<<12)) | (0xF<<12)); /* Configure PF11 to input mode and pull-up */ GPIO_OpenBit(GPIOF, BIT11, DIR_INPUT, PULL_UP); /* Confingure PF11 to rising-edge trigger */ GPIO_EnableTriggerType(GPIOF, BIT11,RISING); /* Enable external 0 interrupt */ GPIO_EnableEINT(NIRQ0, (GPIO_CALLBACK)EINT0Callback, 0); /* waiting for external 0 interrupt */ sysprintf("waiting for PF11 rsing-edge trigger..."); while(!eint_complete); /* Disable PF11 trigger type */ GPIO_DisableTriggerType(GPIOF, BIT11); /* Enable external 0 interrupt */ GPIO_DisableEINT(NIRQ0); sysprintf(" [OK].\n"); /* Configure PF11 to default value */ GPIO_CloseBit(GPIOF, BIT11); /* Configure PE3 to output mode */ GPIO_OpenBit(GPIOE, BIT3, DIR_INPUT, NO_PULL_UP); /* Confingure PE3 to falling-edge trigger */ GPIO_EnableTriggerType(GPIOE, BIT3,FALLING); /* Enable GPIOE interrupt */ GPIO_EnableInt(GPIOE, (GPIO_CALLBACK)GPIOECallback, 0); /* waiting for external 0 interrupt */ sysprintf("waiting for PE3 falling-edge trigger..."); while(!gpio_complete); /* Disable PE3 to trigger type */ GPIO_DisableTriggerType(GPIOE, BIT3); /* Disable GPIOE interrupt */ GPIO_DisableInt(GPIOE); /* Configure PE0 to default value */ GPIO_CloseBit(GPIOE, BIT3); sysprintf(" [OK].\n"); while(1); }