Table of Contents
1 Version History ________________________________________________________________________ 5
2 Introduction to BGScript _________________________________________________________________ 6
2.1 BGScript Example _________________________________________________________________ 7
3 BGScript Syntax _______________________________________________________________________ 8
3.1 Comments _______________________________________________________________________ 8
3.2 Variables and Values _______________________________________________________________ 8
3.2.1 Values ____________________________________________________________________ 8
3.2.2 Variables __________________________________________________________________ 8
3.2.3 Global Variables ___________________________________________________________ 10
3.2.4 Constant Values ___________________________________________________________ 10
3.2.5 Buffers ___________________________________________________________________ 10
3.2.6 Strings ___________________________________________________________________ 11
3.2.7 Constant Strings ___________________________________________________________ 11
3.3 Expressions _____________________________________________________________________ 13
3.4 Commands ______________________________________________________________________ 14
3.4.1 event <event_name> (< event_parameters >) ____________________________________ 14
3.4.2 if <expression> then [else] end if _______________________________________________ 14
3.4.3 while <expression> end while _________________________________________________ 14
3.4.4 call <command name>(<command parameters>..)[(response parameters)] _____________ 15
3.4.5 let <variable> = <expression> _________________________________________________ 15
3.4.6 return ____________________________________________________________________ 15
3.4.7 sfloat( mantissa , exponent) __________________________________________________ 16
3.4.8 float( mantissa , exponent) ___________________________________________________ 16
3.4.9 memcpy(destination, source , length ) __________________________________________ 17
3.4.10 memcmp( buffer1 , buffer2 , length ) ___________________________________________ 17
3.4.11 memset( buffer , value , length) _______________________________________________ 17
3.5 Procedures ______________________________________________________________________ 18
3.6 Using multiple script files ___________________________________________________________ 19
3.6.1 import ___________________________________________________________________ 19
3.6.2 export ___________________________________________________________________ 19
4 BGScript Limitations ___________________________________________________________________ 21
4.1 32-bit resolution __________________________________________________________________ 21
4.2 Performance _____________________________________________________________________ 21
5 Examples ____________________________________________________________________________ 22
5.1 Basics __________________________________________________________________________ 22
5.1.1 Catching system startup _____________________________________________________ 22
5.1.2 Performing a System Reset __________________________________________________ 23
5.1.3 Handling command responses ________________________________________________ 24
5.2 Wi-Fi ___________________________________________________________________________ 25
5.2.1 Catching Wi-Fi connection event _______________________________________________ 25
5.2.2 Catching Wi-Fi disconnection event ____________________________________________ 26
5.2.3 Catching a failed Wi-Fi connection event ________________________________________ 27
5.2.4 Performing a Wi-Fi scan _____________________________________________________ 28
5.2.5 Connecting to a Wi-Fi network ________________________________________________ 29
5.2.6 Creating a Wi-Fi Access Point _________________________________________________ 29
5.2.7 Using Wi-Fi Protected Setup __________________________________________________ 30
5.3 Hardware Interfaces _______________________________________________________________ 31
5.3.1 IO _______________________________________________________________________ 31
5.3.2 I2C ______________________________________________________________________ 33
5.3.3 RTC Usage _______________________________________________________________ 33
5.3.4 Ethernet __________________________________________________________________ 34
5.4 Timers __________________________________________________________________________ 36
5.4.1 Continuous Timer Generated Interrupt __________________________________________ 36
5.4.2 Single Timer Generated Interrupt ______________________________________________ 36
5.5 Endpoints _______________________________________________________________________ 37
5.5.1 UART endpoint ____________________________________________________________ 37
5.5.2 USB endpoint _____________________________________________________________ 38
5.5.3 Drop endpoint _____________________________________________________________ 38