Brining Up Wi-Fi Interface |
Top Previous Next |
The easiest way to make the Wi-Fi interface work is by calling wln_start() of the WLN library. This will save you a ton of effort, seriously!
If you can't or won't use the library, here is the sequence of steps that you just have to take in order to bring up the Wi-Fi interface:
•Boot up the GA1000 add-on module
•Set the IP, gateway IP, and netmask
•Set TX power (really optional)
The following is a simplified sample code that demonstrates the process. Typically, it would be called from the on_sys_init event handler, but you can actually call it from anywhere in your application. You can also call this code repeatedly and even after the Wi-Fi interface has already been running. We call the code simplified because it does not check for any error conditions.
'BRINGING UP THE WI-FI MODULE (SIMPLIFIED)
#If PLATFORM_ID=EM500W #define WLN_RESET_MODE 1 'reset is controlled by the combination of CS and CLK 'there is no need to map CS, DI, DO, and CLK lines because they are fixed #elif PLATFORM_ID=EM1206W #define WLN_RESET_MODE 0 'there is a dedicated reset line #define WLN_RST PL_IO_NUM_11 #define WLN_CS PL_IO_NUM_15 #define WLN_DI PL_IO_NUM_12 #define WLN_DO PL_IO_NUM_13 #define WLN_CLK PL_IO_NUM_14 #else #define WLN_RESET_MODE 0 'there is a dedicated reset line #define WLN_RST PL_IO_NUM_51 #define WLN_CS PL_IO_NUM_49 #define WLN_DI PL_IO_NUM_52 #define WLN_Do PL_IO_NUM_50 #define WLN_CLK PL_IO_NUM_53 #endif
'----------------------------------------------------------------------------
'----- configure interface lines ----- '(on platforms with fixed mapping this will have no effect and do no harm) wln.csmap=WLN_CS io.num=WLN_CS io.enabled=YES wln.dimap=WLN_DI wln.domap=WLN_DO io.num=WLN_DO io.enabled=YES wln.clkmap=WLN_CLK io.num=WLN_CLK io.enabled=YES io.num=WLN_RST io.enabled=YES
'----- reset Wi-Fi module ----- #If WLN_RESET_MODE 'reset is controlled by the combination of CS and CLK io.lineset(wln.csmap,HIGH) io.lineset(wln.clkmap,LOW) io.lineset(wln.clkmap,HIGH) #Else 'there is a dedicated reset line io.num=WLN_RST io.state=LOW io.state=HIGH #endif
'in case we called wln_init() after it has already been up and running While wln.enabled=YES Wend
'----- set the domain ----- wln.domain=PL_WLN_DOMAIN_FCC
'----- allocate buffers ----- wln.buffrq(5) sys.buffalloc
'----- set MAC address (optional) ----- wln.mac="0.100.110.120.130.140"
'----- boot up the GA1000 ----- romfile.open("ga1000fw.bin") wln.boot(romfile.offset)
'----- setup the IP, gateway, netmask ----- wln.ip="192.168.1.86" wln.gatewayip="192.168.1.1" wln.netmask="255.255.255.0"
'----- set TX power (REALLY optional) ----- wln.settxpower(15) while wln.task<>PL_WLN_TASK_IDLE wend
|