Blog Datasheets Home About me Clients My work Services Contact

G2Labs Grzegorz Grzęda

Time-Sensitive Networking (TSN) on ESP32: Achieving Deterministic Behavior

June 4, 2024

Time-Sensitive Networking (TSN) on ESP32: Achieving Deterministic Behavior

In the world of IoT and embedded systems, achieving deterministic behavior in network communication is crucial. When it comes to time-sensitive applications, delays and variations in message delivery can have severe consequences. Time-Sensitive Networking (TSN) is an emerging technology that addresses these issues by providing deterministic behavior for real-time and time-critical applications.

In this blog post, we will explore the capabilities of TSN on the ESP32 platform, one of the most popular microcontroller-based solutions for IoT projects. We will dive into the basic concepts of TSN, explain how it works, and demonstrate how to achieve deterministic behavior using the ESP32.

Understanding Time-Sensitive Networking (TSN)

TSN is a collection of standards defined by the IEEE 802.1 working group. It aims to provide time synchronization, low latency, and deterministic behavior for real-time and time-critical applications over standard Ethernet networks. TSN ensures that time-sensitive traffic is transmitted within predefined time bounds, avoiding congestion and minimizing delays.

The primary mechanisms used by TSN include time synchronization through the Precision Time Protocol (PTP), time-aware scheduling, and traffic shaping techniques such as Stream Reservation Protocol (SRP) and time-based forwarding.

Leveraging TSN on ESP32

The ESP32 microcontroller, with its built-in Ethernet MAC, supports TSN functionality. To utilize TSN on the ESP32, we need to incorporate the required TSN software stack into our firmware. The ESP-IDF (Espressif IoT Development Framework) provides the necessary tools and APIs to enable TSN on the ESP32.

Setting up TSN on ESP32

To begin, we need to set up the ESP-IDF development environment. Start by installing ESP-IDF following the official documentation. Once the environment is ready, we can proceed with incorporating TSN into our firmware.

Configuring TSN Parameters

TSN configuration involves defining the TSN streams, their characteristics, and the required QoS (Quality of Service) parameters. The ESP-IDF provides APIs to configure the parameters programmatically or through configuration files.

1
2
3
4
5
6
7
8
9
esp_eth_tsn_stream_config_t stream_config = {
    .stream_id = 1,
    .priority = 1,
    .max_frame_size = 512,
    .interval_in_us = 10000,
    .type = ESP_ETH_TSN_STREAM_TYPE_TSN,
};

esp_eth_tsn_configure_stream(&stream_config);

The above example demonstrates how to configure a TSN stream with stream ID 1, priority 1, a maximum frame size of 512 bytes, an interval of 10,000 microseconds, and the stream type as TSN.

Enabling TSN on the ESP32

Once the TSN streams and configurations are set, we need to enable TSN on the ESP32 Ethernet MAC. This can be done using the esp_eth_tsn_enable() function:

1
esp_eth_tsn_enable();

This function enables TSN functionality on the ESP32, allowing it to process time-sensitive traffic according to the defined TSN streams and parameters.

Sending and Receiving Time-Sensitive Traffic

With TSN enabled, we can create time-sensitive applications on the ESP32. To send time-sensitive traffic, we use the esp_eth_tsn_send() function, which accepts a buffer and the stream ID:

1
2
uint8_t buffer[256];
esp_eth_tsn_send(buffer, sizeof(buffer), 1);

On the receiving end, we can listen for time-sensitive traffic using the esp_eth_tsn_register_recv_cb() function, which registers a callback function:

1
2
3
4
5
void tsn_receive_callback(uint8_t* buffer, size_t length) {
    // Process the received time-sensitive traffic
}

esp_eth_tsn_register_recv_cb(tsn_receive_callback);

The registered callback function tsn_receive_callback() will be invoked whenever time-sensitive traffic is received, allowing us to process the data accordingly.

Conclusion

Achieving deterministic behavior is crucial for time-sensitive applications in the IoT realm. Time-Sensitive Networking (TSN) provides the necessary mechanisms to guarantee low latency and time synchronization over Ethernet networks. With the ESP32 and the ESP-IDF framework’s TSN support, we can incorporate TSN into our IoT projects and achieve deterministic behavior.

In this blog post, we explored the basics of TSN, set up TSN on the ESP32 using the ESP-IDF, and demonstrated how to send and receive time-sensitive traffic. Incorporating TSN into our ESP32-based projects opens up possibilities for building real-time and time-critical applications that require deterministic behavior for reliable operation.

TSN on ESP32 combined with the flexibility and power of the platform can revolutionize industries like industrial automation, robotics, and real-time control systems where low latency and reliable communication are paramount.


➡️ Linux 'less' command


⬅️ Linux 'chmod' command


Go back to Posts.