Organization of TCP / IP stack for MK based on embedded module Tibbo

    This review article will focus on the organization of the TCP / IP stack in your project based on Tibbo Technology's plug-ins.

    TCP stack from Tibbo



    In most cases, developers work with their MK through a serial port. This is not always convenient. Often the task arises of “communicating” with the device remotely via the TCP / IP stack. The problem is not being raised for the first time. For example, herethis task is voiced and solved with a fairly detailed description. The link even contains a photo and a brief mention of the Tibbo EM100 module. The fact is that our company is the official representative of Tibbo Technology in the Russian Federation. Therefore, it’s a little disappointing that our product was mentioned casually, without revealing the full functionality and capabilities of the product. I know this orange box under the name EM100, which has been produced for more than 10 years and which is used in many objects of our vast expanses. But a lot of water has flowed since the release of this module. Let's try to create a TCP / IP stack for a device based on the Tibbo module, while simultaneously considering the capabilities of the product.

    Creating a TCP / IP stack.


    To solve this problem, we need:

    Embedded Modules (EM) are small intelligent modules that have their own microprocessor, the minimum necessary harness for a quick start, and various built-in protocols. Typically, EM runs its own operating system, which is not intended to communicate with a person. The purpose of using EM is to organize this or that functionality in the device as soon as possible and with minimal costs.

    The Tibbo Technology Embedded modules product family is quite powerful modules that already have the physical layer of the 10/100 BaseT interface implemented, have full-fledged work with the TCP / IP protocol stack, and have 1 to 4 UART serial ports at CMOS level (TTL compatible) . Modifications are available for sale with and without an integrated Ethernet connector. To connect the latter, an external connector and transformers or a connector with built-in transformers are required. The sizes of the modules vary, but in general they do not exceed (or slightly exceed) the RJ45 connector.

    I chose the model EM1206 + RJ203, brief characteristics:
    • Based on the high-performance 88MHz ASIC (T1000) controller.
    • 100BaseT with integrated transformer isolation (when using RJ203).
    • Up to 1024KB flash memory for firmware, applications and data.
    • 2KB EEPROM for data storage.
    • Real Time Clock (RTC) ..
    • Up to 17 general-purpose I / O lines (including 8 interrupt lines).
    • Control lines of two external status LEDs.
    • 4 built-in LEDs:
    • green and red status LEDs;
    • Green and yellow Ethernet status LEDs.
    • Software-controlled embedded PLL.
    • Reliable power reset circuitry.
    • Power: 230mA @ 3.3V (100BaseT mode, PLL on).
    • Dimensions: 33.2x18.1x5.5mm.

    For full and high-quality work with the module, it is necessary to provide on the board: supply of stabilized power (3.3V), a reset chip (preferably), in case the Ethernet socket is not implemented, unsolder the corresponding connector.

    The serial port must be installed on the controller of your device. As I wrote above, the CM1 level (TTL compatible) is implemented on the EM1206 module, so Rx / Tx lines can be connected directly to the legs of the MK.

    image

    Convenient software for work


    The software part is still simpler. We launch Device Explorer, which automatically detects the module on the network (by means of sending UDP broadcast requests), fill in the firmware. The process takes no more than 1 minute.
    image

    We launch DS Manager, which allows you to set the parameters of both the serial interface and the host parameters:

    image

    Brief characteristics of the Serial Over IP firmware:
    • Full and half duplex serial port modes.
    • Available modes: server, client, and server / client.
    • Many other options for serial and ethernet connections.
    • 8KB for each receive / transmit buffer (one buffer in each direction).
    • The configuration is stored in the EEPROM.
    • Detailed status indication via LEDs.
    • Configuration via RS232 or ethernet (UDP commands, Telnet).
    • Remote control of all I / O lines (including RTS, CTS, DTR and DSR).
    • On-the-fly commands for configuring a serial port.
    • "Modem" commands through RS232 to control the network connection.
    • Direct control of the ADSL modem.
    • Support UDP, TCP, ARP, ICMP (ping), DHCP, PPPoE, LCP protocols.
    • Built-in web management interface.


    Now our device transparently forwards the data stream to the Ethernet network and vice versa. On the remote machine, you can install the virtual COM port driver.

    Optionally, when using the GA1000 external expansion module , Tibbo devices allow you to transfer data using the WiFi wireless protocol (802.11 b / g). The GA1000 connects to the controller simply; through the DS Manager utility, you can configure the settings for connecting to the access point.

    image

    In addition to the standard modes of operation on the local network, an embedded object is implemented in the Tibbo embedded modules that allows you to automatically connect to the provider using PPPoE technology, which allows you to use the device as a client to connect to remote servers around the world.

    And it's all? And where is the intellect, where is the logic?



    Embedded modules Tibbo are freely programmable, while the process of debugging and downloading applications is carried out via an Ethernet network. Programming is carried out in the object-oriented event languages ​​Tibbo Basic and Tibbo C. For coding, the development environment from the manufacturer Tibbo IDE is used. The devices run the TiOS operating system , which processes the application written by the user and compiled into mnemonic codes in the interpretation mode. The modules have a general-purpose input / output line (GPIO) on board, which allows the embedded module to be used as a microcontroller.

    Most models have a web server that allows the user to program a web-based management interface. Some models have an RTC real time clock.
    Thus, the functionality of the module is determined only by the developer. If SoI firmware is not enough, open the sources and add what you need. Or from scratch create your own project. For example, by implementing the protocol of your controller and hooking it up to the OPC Server project (from Tibbo), the device can be connected to the SCADA system, and using the AggreGate Agent software library, you can connect the device to the AggreGate Server.

    Let's look at a simple example: you need to compare the received parameter from MK with a constant, and if the parameter exceeds the value, send a warning to the server. Elementary:
    Initialize the serial port:

    sub on_sys_init
            ser.num=0                                     'выбираем первый последовательный порт
            ser.rxbuffrq(4)                                'Резервируем 4*256-16=1008 байт под буфер прием последовательного порта
            ser.txbuffrq(4)                                 'Резервируем 4*256-16=1008 байт под буфер передачи последовательного порта
            .....
            sys.buffalloc                                   'Зарезервируем выделенные буферы памяти.
            ser.num=0			
            ser.flowcontrol=DISABLED          'Выключаем управление потоком
            ser.baudrate=12                             'ser.div9600/(38400/9600) устанавливаем скорость 38400
            ser.enabled=YES	                           'Включаем порт
            .......
    end sub
    


    Initialize the socket:

    sub on_sys_init
            .....
            sock.num=0	
    	sock.rxbuffrq(4)
    	sock.txbuffrq(4)
            .....
            sys.buffalloc
            sock.num=0	
    	sock.protocol=PL_SOCK_PROTOCOL_TCP
    	sock.localportlist="2000,3000"
    	sock.inconmode=PL_SOCK_INCONMODE_ANY_IP_ANY_PORT
            sock.targetip="192.168.1.100"
            sock.targetport="1001"
    end sub
    


    We will receive data, compare and send a critical event to the server:
    sub on_ser_data_arrival
    'Событие. Активируется при появлении данных на последовательном интерфейсе.
            dim s as string
            s = ser.getdata(ser.rxlen)
            If val(s) > Critical_value then
                      sock.num = 0
                      sock.connect
    	          sock.setdata("Внимание! Превышение параметра: "+s)
    	          sock.send
           end if
    end sub
    


    As you can see, programming is not at all complicated.

    If you don’t want to mess with the wiring, you can use ready-made debug boards, for example, EM500EV:

    image

    It is enough to connect a cable to the interface connector and you get the same functionality as with the embedded solution.

    Replacing MK with Tibbo embedded module.


    If your project does not require instant reactions, then Tibbo EM can be used as the main microcontroller of your device. Modules were created for the most convenient work with them. Free programming in high-level languages ​​Tibbo Basic and Tibbo C will reduce the time to develop firmware by several times. As an example, you can consider creating your own access controller with a relay for controlling locks or connecting an external alarm, a web server, serial ports, WiFi wireless connection, a keyboard and a display (schematic diagrams can be downloaded here ):

    image

    Serial ports can be used to connect RFID readers or magnetic cards. Relays are used to control locks. Need to open the door? To do this, activate the relay. From the circuit diagram, we see that the relay "hangs" on the DTR0 (or GPIO5) line, you need to activate this line:

    ....
    io.num = PL_IO_NUM_5
    io.enabled = YES
    io.state = LOW
    ....
    


    Finally, if you're interested in creating your own automation devices, see an overview of the hardware automation platform TPS by Tibbo.

    Other examples of using Tibbo products can be found here .

    PS
    Our company provides a free testing service for the entire line of Tibbo equipment.
    If you are interested in our products and would like to purchase them, when ordering in our office, say the code word "Habrahabr" and you will get a small pleasant discount. The promotion is valid until January 31, 2014.

    Also popular now: