Platform-dependent Programming Information

Top  Previous  Next

This section contains miscellaneous information that sets this platform apart from other platforms. Various objects described in the Object Reference direct you to this topic in all cases when object capabilities or behavior depends on the platform and, hence, cannot be described in the object reference itself. Each platform section in this manual has its own "Platform-dependent Programming Information" topic. If you are reading documentation top-to-bottom (we have never actually met anyone who does) you can skip this section now.

Supported variable types

This platform supports all available variable types: byte, word, dword, char, short (integer), long, real (float), string, boolean, user-defined structures and enumeration types.

You have to explicitly configure I/O lines as inputs or outputs

On this platform you need to explicitly enable or disable the output driver of each I/O line (controlled by the io object). The io.enabled property allows you to do this. When the driver is enabled (ser.enabled= 1-YES) and you read the state of the pin you will get back the state of your own output buffer. To turn the line into an input switch the output buffer off (ser.enabled= 0- NO). This will allow you to sense the state of the external signal applied to the I/O line:

 

 

...

io.num= PL_IO_NUM_4        'just to select some line as an example

io.enabled= NO                'now the output driver is off

x=io.state                        'read line state into x

...

 

 

When the device boots up all pins are configured as inputs. If you want to use any particular I/O pin as an output you need to enable the output driver first:

 

 

...

io.num= PL_IO_NUM_5        'select the line

io.enabled= YES                'enable output driver (you need to do this only once)

io.state= LOW                'set the state

...

 

 

note_warning-wt

Make sure that your external circuitry does not attempt to drive the I/O lines that have their output buffers enabled. Severe damage to the device and/or your circuitry may occur if this happens!

You can remap RTS/W0out/cout and CTS/W0&1in/cin lines of the serial port

Two lines of the serial port -- RTS/W0out/cout output, and CTS/W0&1in/cin input -- can be reassigned (remapped) to other I/O pins of the device. This is done through ser.rtsmap and ser.ctsmap properties.

By default, the mapping of these two lines is different for each serial port. See Enum pl_io_num for details.

Positions of TX/W1out/dout output and RX/W1in/din input are fixed and cannot be changed.  

You have to explicitly configure certain I/O lines of the serial port as inputs or outputs

On this platform, it is necessary to configure the lines of the serial port as inputs our outputs. Depending on the mode of the serial port (see ser.mode) you need to set the following:

 

ser.mode

TX/W1out/dout output

RX/W1in/din input

RTS/W0out/cout output

CTS/W0&1in/cin input

0- PL_SER_MODE_UART

Will auto-configure as output

(Note 1)

Will auto-configure as input

(Note 1)

Requires configuration as output

(Note2)

Requires configuration as input

(Note2)

1- PL_SER_MODE_WIEGAND

Requires configuration as output

Requires configuration as input

2- PL_SER_MODE_CLOCKDATA

Note 1. This line does not require configuration, it will be configured automatically as input or output when the port is opened. When the port is closed the line will return to the input/output and high/low state it had before the port was opened.

Note 2. Please, remember that you need to configure the I/O pin to which this line of the serial port is currently mapped!

Each serial port has 16 bytes of send FIFO

When the serial port is in the UART/full-duplex/flow control mode (ser.mode= PL_SER_MODE_UART, ser.interface= PL_SER_SI_FULLDUPLEX, and ser.flowcontrol= 1- ENABLED) the device is monitoring its CTS input to see if attached serial device is ready to receive more data. If the CTS state changes to "cannot transmit"  the device will stop sending out data immediately. However, the data that has already entered the FIFO will still be sent out. Therefore, after the CTS state becomes "cannot transmit" the device can still send out up to 16 characters.

There is a PLL

On this platform, there is a PLL that, when switched on, increases the main clock of the device 8-fold (power cosumption also increases roughly by as much). When the PLL is off, the clock frequency of the device is 11.0592MHz; when the PLL is on the clock frequency is 88.4736MHz.

The clock frequency affects all aspects of device operation that rely on this clock. Naturally, program execution speed depends on this clock. Additionally, the baudrates of the serial port (defined by the ser.baudrate property) depend on the main clock. Finally, the frequency of the square wave generated by the beep object depends on the main clock as well.

To deal with PLL, the sys object has a sys.currentpll read-only property and sys.newpll method. See PLL Management topic- it explains how to switch PLL on and off.

After the external reset (see sys.resettype) the EM1000 boots with the PLL on or off depending on the state of the PE pin (a jumper is provided on the EM1000-EV).

For the serial port, there is a way to set the baudrate in the clock-independent (and, actually, platform-independent) way -- see ser.div9600 property for details, (example of use can be found in the Serial Settings topic). For the beep object, you just have to set the beep.divider correctly depending on the value returned by the sys.currpll property.

Data in the special configuration section of the EEPROM

Bottom 8 bytes of the EEPROM (accessible through the stor object) are reserved for storing MAC address of the device. On power-up, the MAC address is read out from the EEPROM and programmed into the Ethernet controller. You can always check current MAC through the net.mac read-only property of the net object but there is no direct way to change it. Instead, you can change the MAC address data in the EEPROM. Then, next time the device boots up it will start using this new address.

By default, the area storing MAC address is not accessible to your application- the stor.base property takes care of that. Unless you change it, this property specifies that your application's storage area starts at address 9 (counting from 1). To change MAC, set the stor.base to 1.

MAC address data in the EEPROM has a certain formatting -- you have to follow it if you want the MAC to be recognized by the firmware (TiOS). Here is the format:

 

Byte1

Byte2

Byte3

Byte4

Byte5

Byte6

Byte7

Byte8

6

MAC0

MAC1

MAC2

MAC3

MAC4

MAC5

Checksum

 

Byte at address 1 must be set to 6- this means, that 6 byte of data follow (MAC address consists of 6 bytes). Addresses from 2 to 7 carry actual MAC data. Address 8 stores the checksum, which is calculated like this:

255-(modulo8_sum_of_addr_1_through_7)

Here is a sample code that stores new MAC address into the EEPROM and then reboots the device to make the device load this new MAC:

 

dim s as string

dim x as byte

...

s= "0.2.123.124.220.240"        'supposing, we want to set this MAC

...

...

s=chr(6)+ddval(s)                'added first byte (always 6) and coverted readable MAC into bytes

x=255-strsum(s)                        'calculated checksum and assigned the result to a BYTE variable (!!!)

s=s+chr(x)                                'now our string is ready

 

stor.base(1)                        'will access EEPROM from the bottom

x=stor.set(s,1)                        'save data

if x<>len(s) then                'it is a good programming practive to check the result

       'failed

else

       sys.reboot                        'new MAC set, reboot!

end if

 

...

 

 

There are limitations on what MAC you can set. When loading the MAC into the Ethernet controller the device always resets the first byte of this address to 0. For example, if you set the MAC to 1.2.3.4.5.6 then the actual MAC used by the device will be 0.2.3.4.5.6.

 

note_warning-wt

If you write incorrect MAC data (wrong first byte or error in checksum calculation) the device will ignore it and boot up with default MAC, which is 0.1.2.3.4.100.

Available network interfaces

This platform supports two network interfaces -- the Ethernet interface and Wi-Fi interface . The sock.allowedinterfaces property refers to these interfaces as "NET" and "WLN". Also see the pl_sock_interfaces enum which is used by sock.targetinterface and sock.currentinterface properties.

Miscellaneous

Sys object supports the sys.onsystimerperiod property and the on_sys_timer event generation period depends on the value of this property.