Ethernet driver for ethercat modules - linux

I have EK1101, EL6002, EL2034 modules which is based on network devices. These modules are connected PC Ethernet port via ethernet cable. I have tested these modules with some application program, its working fine on my PC.
EK1101 working as a Coupler. It connects PC Ethernet Port and Other slave modules( EL6002, EL2034,..)
EL6002 working as a RS232 communication. EL2034 working as digital I/O. Similarly we have more than 10 different devices. These modules interfaced with EK1101 coupler at same time.
How can i implement as Linux driver? and start?Do I modify the existing network driver or start new driver from scratch? what type of i need to write, character or network driver? If its character driver how can i transfer data through Ethernet port?

Using the serial slice (EL6002) you can only send 22 bytes (each direction) per exchange for each port. At full serial bandwidth (115k) updating at 1kHz, you won't be able to miss an update without starving the transmitter and/or dropping data on the receiver. If that's a concern you will probably need to claim exclusive control over the Ethernet port being used to master the EtherCAT loop. This requires some form of root permissions, otherwise someone can always try to send packets over the port, affecting your timings. You haven't given much detail about your application or timing requirements, so maybe that's not critical for you.
I've been using the Etherlab IgH open source stack, which requires root permissions to load its kernel module which implements the underlying stack. Once that's done you can set everything else up to run from user space without root permissions.
Once your application acquires access to the master stack, you setup a data exchange domain (what TwinCat calls a task) and you will have a region of shared memory that can be used to monitor the EtherCAT frame data. Your application is responsible for deciding when to send and receive domain updates.

Related

How does the Linux Operating System understand the underlying hardware?

I want to learn how Linux OS understands the underlying hardware.Can anyone suggest me where to start for getting this understanding,As of now i just know the '/dev' sub-directory plays a vital role in that.
It has the device special files which are like a portal to the device driver which then takes it to the physical device.
I read somewhere that Udev daemon listens to the netlink socket to collect this information and Udev device manager detects addition and removal of devices as they occur.
But with these i am just not satisfied with the thought of how Linux reads the hardware.
Please let me know where to start to understand this, i am so thankful to anyone trying to help.
I think at first you need to find out how the memory mapping works. What is the address space and how it relates to physical memory. Then you could read about how the hardware is mapped in address space and how to access it. It is a big amount of docs to read.
Some of those information are in Linux Documentation Project.
Additionally some knowledge about electronic would be helpful.
In general - Linux for communication with devices needs some "channel" of communication. This channel may be for example ISA, PCI, USB, etc bus. For example PCI devices are memory mapped devices and Linux kernel communicates with them via memory accesses. So first Linux needs to see given device in some memory area and then it is able to configure this device and do some communication with it.
In case of USB devices it is a little bit complicated because USB devices are not memory mapped. You need to configure USB host first to be able to communicate with USB devices. Every communication with USB device is achieved via USB host.
There are also devices which are not connected via ISA, PCI or USB. They are connected directly to the processor and visible under some memory address. This solution is usually implemented in embedded devices. For example ARM processors use this approach.
Regarding udev - it is user-space application which listens for events from Linux kernel and helps other applications with recognizing device addition and configuration.

What is knet interface and what is it used for?

Can some expert please throw some light on what is knet interface and what is it used for.
One of my container images show knet2 as an interface for output of 'ifconfig'
I have no idea what it is, can someone please explain or point me to documents / web where I can find more about it.
knet is kernel network interface for efficient of packet exchange between switch and the kernel (linux operating system) network protocol stack.
There could be other methods which could used, such as implementing a software connector module over the Open NSL Rx/TX APIs.
The intent of theknet interface is to provide a network interface that
then delivers packets to the NetIO framework from the kernel.
this is nicely explained in user-networking.pdf.
I hope this is what you were expecting. feel free to comment for any clarification.
this is about knet reference
This module implements a Linux network driver for Broadcom
XGS switch devices. The driver simultaneously serves a
number of vitual Linux network devices and a Tx/Rx API
implemented in user space.
Packets received from the switch device are sent to either
a virtual Linux network device or the user mode Rx API
based on a set of packet filters.susp
Packets from the virtual Linux network devices and the user
mode Tx API are multiplexed with priority given to the Tx API

Is there any maximum limit to create tun/tap interfaces on a linux machine? Also, what are the parameters that put constraints to the limit?

I have been working on the ns-3 (communication network simulator) communication simulator, where there is a provision called TapBridge mechanism to interface external data sources to the communication nodes. But, for each data source a tap device need to be created on a linux OS bridge, and establish connection with a node in ns-3. I have a requirement of connecting many data sources (say 5000), thence I supposed to create those many tap devices and establish corresponding connections with communication nodes in ns-3. What would be the maximum limit to create tun/tap interfaces on a linux machine? Also, what are the parameters that put constraints to that limit?
Thanks in advance.
-- Gelli

Tun/Tap interface based tunnel: How is it working?

Tun/Tap interface based tunnel
Can someone tell me how such a tunnel is created and works?
I have tried Googling the answer, but there are very few ressources and they are primarily very technical.
I know that packets sent through such an interface gets injected into the OS network stack and look like packets received from an external host. Also, packets received on this interface gets passed to a user-space program.
However, what I do not understand the following:
Why does such a tunnel involve the use of setting up network connections? Is the programs on either side of the tunnel neccessarily running on the same host, or can they be running on different hosts? Does the network stack deliver tap or tun packages through TCP/UDP?
Both Tun and Tap interfaces deliver data from one host to another. The main difference is the features (pros/cons) that you get when you are using Tun or Tap.
Data delivered via Tap interface gets injected at layer2 of OSI stack and data delivered via Tun interface gets injected and layer3. There is no better/worse choice here - each is suited for specific purpose. You can read a very good explanation here.
Now to answer your questions:
Why does such a tunnel involve the use of setting up network connections?
You want to deliver packets from one host to another regardless the interface type (tun/tap). To do so you capture those packets, encapsulate them and then you need to send over encapsulated data to the remote end. To do this you need to set up a network connection.
Is the programs on either side of the tunnel neccessarily running on the same host, or can they be running on different hosts?
You are creating a VPN connection between two different hosts, so yes - there will be software running on both hosts which will handle the encapsulation/decapsulation.
Does the network stack deliver tap or tun packages through TCP/UDP?
TCP/UDP are layer4 protocols, so from point of view of TCP/UDP stack it does not matter at all if the packet came to your host via tun or tap interface.
EDIT: Clarification about the follow up questions:
Since you are asking about Tun/Tap adapters, let's take a step back. When you run a VPN, you have a computer A behaving as if it is directly connected to network N, even though it might be somewhere far away. To make this happen, you run a VPN software. You have to run this VPN software in two places - one in the computer A and another in computer (or network device) connected to the network N. When running a VPN software in the computer A, you have a choice of creating a Tun or Tap adapter.
Q1: Yes - delivered means sent and received.
Q2: Yes - means that VPN connection is like a pipe, and there is VPN software running at both ends.
Q3: When VPN software is running in the computer A, it creates what is called a virtual network adapter. This virtual network adapter, in the eyes of OS, behaves like a normal network adapter. Just instead of sending data over the wire or waves, it caputers the data, encapsulates it and sends over some other adapter in the system.

Looking for some mutex-like mechanism for exclusive USB access

I'm working on various USB hardware devices, each of which implementing a serial port. I'd like to access such serial ports by multiple (Chrome and non-Chrome) applications running on the system in a pseudo-parallel fashion.
Basically I'd like to use some mutex-like atomic primitive so that I could make sure that one application has access to the serial port at the same time and the others are temporarily blocked, waiting for the mutex to be released.
I'm afraid that the Chrome API doesn't offer any such low-level primitives but please disprove me. Also, I'm open to any suggestions.
I've just finished reading the full Chrome packaged apps API and mutexes are definitely not supported but mutexes only work inside a process anyways so it's not what I'm looking for to begin with.
I could create a native app that could bind to multiple ports on the local loopback interface and proxy those connections towards the /dev/ttyACM* serial interface.
The other solution is implementing multiple serial ports for my USB device in the firmware so that multiple clients could connect to my device without interference.
I think I'll go with the latter solution because I don't want to have a daemon proxy running in the background all the time.

Resources