Deep Dive Analysis of CanFestival Architecture

Follow/Star Public Account to never miss any updates!

Deep Dive Analysis of CanFestival Architecture

This tutorial is originally published by the author strongerHuang in October 2018.

Tags: CAN, CANOpen, CanFestival

Copyright: Commercial use prohibited

Disclaimer:This document is for personal learning use only. For reprinting, please contact the author for authorization through the public account.

1Introduction

In the previous article of this tutorial “Setting Up the Environment for CanFestival and Object Dictionary Generation Tool“, we briefly introduced the free and open-source CANOpen protocol framework CanFestival.

This article will delve into the CanFestival framework guided by the downloaded PDF manual (which is also included in the source code).

This article is roughly divided into two parts:

1. Summary of the manual;

2. Analysis of CanFestival source code;

2

Summary of the Manual

Please first download the PDF manual mentioned in our previous article “Setting Up the Environment for CanFestival and Object Dictionary Generation Tool” (the manual_en.pdf document is also available in the directory objdictgen \\ doc after extracting the source code).

Upon opening the PDF manual, we can clearly see that it consists of 12 chapters. For beginners using STM32 development, the relatively important chapters are: 2, 3, 4, 9.

To accommodate beginners, I will summarize the content of each chapter here, and later focus on the key parts.

2.1 Content Summary

Chapter 1 Introduction

This chapter mainly introduces that CanFestival is an open-source (LGPL and GPL) CANopen framework, the origin of the CanFestival project, and its support. It also explains what the CANOpen protocol is and related standards.

Chapter 2 Features of CanFestival

1. Tools: Provides object dictionary GUI graphical editor, code generation, and scripts, etc.;

2. Multi-platform: The library source code is ANSI standard C, supporting multi-platform compilation and development;

3. CANopen Standards: Supports CANOpen protocols such as DS-301, 302, 305, etc.

Chapter 3 How to Start

This chapter mainly discusses the requirements and configuration of the environment, as well as how to obtain CanFestival, etc.

For those of us using MCU development, the important aspect is the environment for editing and generating the object dictionary (please refer to the previous tutorial article “Setting Up the Environment for Object Dictionary Generation Tool“). Other environments based on Windows and Linux can be configured according to the documentation, which will not be discussed here.

Chapter 4 Understanding CanFestival

This chapter mainly discusses: understanding the directory structure of source code files, implementing CanFestival in applications, the relationship of source file structures, and the calling and implementation of the CAN lower-level driver interface, as well as the implementation methods for event scheduling.

This chapter directly involves source code-related content, so it is quite important, and the following chapters will explain it in more detail.

Chapters 5 and 6

These two chapters mainly cover configuration and development related content for Linux and Windows platforms. Interested friends can study them carefully; I will not elaborate here.

Chapter 7

This chapter mainly discusses the compilation, downloading, hardware connection, and demonstration of the HCS12 example provided in the source code. The reference significance here is not great; if you have the corresponding development board, you can refer to it for demonstration.

Chapter 8 Examples and Test Programs

This chapter discusses the relevant instructions for the accompanying examples provided. For example, the TestMasterSlave master-slave testing example has a heartbeat generator time of 1000 milliseconds, etc.

These instructions are also available in the source code, making it clear upon reviewing the provided source code. Therefore, the reference value is not very high.

Chapter 9 Developing a New Node

This chapter is quite important; when developing a new node, we need to edit its object dictionary, which requires using the editor to edit the object dictionary and generate code.

In simple terms, the important content of this chapter is to teach you how to use this object dictionary editor tool.

Chapter 10 FAQ

This chapter is recommended for beginners to read as it addresses some questions that may be helpful, such as: Does CanFestival3 comply with DS301 V4.02 version?

Chapter 11 Documentation Resources

This chapter mainly provides some reference URLs.

Chapter 12 About This Project

This chapter is not a key focus but can provide some information.

3

Analysis of CanFestival Source Code

3.1 Source File Directory

After extracting the downloaded source code package, you will see the following files and folders:

Deep Dive Analysis of CanFestival Architecture

The three .c and .h source file directories that we mainly need are:

drivers: Lower-level drivers;

include: .h header files;

src: .c source code;

An object dictionary generation tool:

objdictgen: object dictionary generate.

examples: Examples for beginners to refer to;

3.2 Source Code Structure and How to Implement in Applications

Here is a diagram of the source file structure, which roughly categorizes the source files by their functions, and beginners need to look at and understand it more.

Deep Dive Analysis of CanFestival Architecture

From the diagram, we can see that the source code is divided into three parts. The library files in the middle will not be altered. We mainly modify the code on the left and right sides.

The left side is the CAN lower-level driver interface (previously I provided STM32 examples). The Target interface, such as the timer.

The right side is the object dictionary at the bottom, which we need to configure in advance using the tool and does not need to be manually written. Finally, we call API functions to implement the application program.

Note: The English on the far right should be understood by everyone, as it is helpful for beginners, such as opening the CAN interface (also called initialization), initializing the timer, etc.

3.3 Implementation and Requirements of the CAN Lower-Level Interface

Our lower-level sending requirements are implemented in a non-blocking manner. I generally recommend running an operating system and adding a queue for implementation.

Deep Dive Analysis of CanFestival Architecture

A sending thread and a receiving thread are needed, along with a timer for event scheduling.

This section’s content is relatively difficult for beginners to understand. You can get a concept first, and later I will combine code to help everyone better understand its meaning.

4

Notes

1. This document is for personal learning use only, copyright reserved, commercial use prohibited.

2. This article is edited and organized by myself, and there may inevitably be some errors.

3. This article is included in the public account “strongerHuang”. Follow the public account and reply with [CANOpen Series Tutorial] to view the entire series of tutorials.

5Conclusion

If you find this article helpful, please like and share; it is a great support and encouragement for me.

Scan the QR code below and follow the public account to see more exciting content in the bottom menu!

Deep Dive Analysis of CanFestival Architecture

Long press to recognize the QR code in the image to follow

Deep Dive Analysis of CanFestival Architecture

Appreciation is recognition and support for the author!

Leave a Comment