A Beginner’s Guide to GTM-MCS VX-toolset

1 Overview

The Bosch GTM IP module provides a general-purpose timer platform for complex applications in the automotive industry, such as powertrain, power steering, chassis, and transmission control. GTM offers various timer functions, such as counters, multifunction capture/comparison, PWM functions, duty cycle measurement, etc. GTM also features a RISC-like programmable core MCS for data processing and complex output sequence generation. MCS can be programmed to run code, significantly reducing the load on the CPU. GTM IP continuously releases new versions, with the latest version being 5.0, integrated in the AURIX 2G TC3xx as version 3.x. Depending on the type of chip, each GTM has 1~12 clusters, each cluster contains 1 MCS, and each MCS has 8 channels for software threads. The basic architecture is shown in the figure below:

A Beginner's Guide to GTM-MCS VX-toolset

Figure 1 Basic Architecture of GTM

The GTM-MCS VX-toolset supports engineers in fully leveraging the advantages of GTM through code, achieving precise and stable control while reducing CPU load. The GTM-MCS VX-toolset comes in two versions: one is integrated (integrated), embedded within the TASKING VX-toolset for TriCore; the other is a standalone version TASKING VX-toolset for GTM.

2 Getting Started with GTM-MCS VX-toolset

The GTM-MCS compiler is actually a standalone toolset, with its own compiler, assembler, and linker. For documentation on this toolset, please refer to the MCS user guide. First, start by creating a project to understand the GTM compiler. To create a GTM-MCS project, use the “New” command, and from the menu, select “TASKING MCS C Project” (as shown in Figure 2).

A Beginner's Guide to GTM-MCS VX-toolset

Figure 2 Create New MCS Project

The software will pop up a window titled “New Assembly/C Project“, where you need to name the project and select the project type. For practical applications, choose “TASKING MCS Application → Empty Project“. Then click “Next“.

A Beginner's Guide to GTM-MCS VX-toolset

Figure3 Select Project Type

Next is the project settings. It is important to note that there are differences between the integrated GTM-MCS compiler (see Figure 4) and the standalone “VX-toolset for MCS” interface. For the integrated GTM-MCS compiler, you need to complete three operations at this stage: 1. Select the chip type (Processor selection); 2. In the “Mulit-core configuration”, select the MCS core, as a project can only compile one core; 3. Whether to add a linker script (lsl) file, which should be considered based on actual conditions. If the main TriCore project uses the default TASKING lsl file, check this option.A Beginner's Guide to GTM-MCS VX-toolset

Figure4 MCS Project Settings (VX-toolset for TriCore)

After configuring the MCS project settings, click the “Next” button to enter the debug options configuration. However, for the MCS core, only instruction simulation is supported, so you can directly click “Finish” to complete the project creation. Once the project is created, the remaining work is to import source files and write source code according to the software development design document to meet the final functional requirements. Note that each MCS core has 8 channels.

3 Understanding GTM Project Applications

We import the built-in examples from TASKING VX-toolset for TriCore 6.3r1, through which we can gain a deeper understanding of the usage of the TASKING GTM compiler and initially recognize the function scheduling relationship between the two software GTM projects and the TriCore main core project, providing reference for engineers’ development.

3.1Importing Demo Project

First, find the “Welcome” interface, in the menu bar, go to “Help → Welcome“. After opening the “Welcome” interface, find “MCS examples” (see Figure 6).

A Beginner's Guide to GTM-MCS VX-toolset

Figure6 Open Welcome Interface

After clicking run, a project import window will appear, containing multiple projects. Projects with the _c suffix are C language projects, while those without the _c suffix are assembly language projects. We select all the C projects. Next, a brief introduction to each project.1. gtm_mcs_start_sieve_c: This is the main project for the TriCore core, responsible for starting and scheduling the various channels of the MCS.2. gtm_mcs00_sieve_c: The mcs00 project can control the scheduling functions of the 8 channels of mcs00.3. gtm_mcs01_sieve_c: The mcs01 project can control the scheduling functions of the 8 channels of mcs01.4. gtm_mcs02_sieve_c: The mcs02 project can control the scheduling functions of the 8 channels of mcs02.5. gtm_mcs03_sieve_c: The mcs03 project can control the scheduling functions of the 8 channels of mcs03.

A Beginner's Guide to GTM-MCS VX-toolset

Figure7 Importing MCS Example Projects

3.2 Project Introduction

After importing these 5 projects into the TASKING IDE, we can view them in the “Project” window, where each project has a readme.txt file. A brief introduction to this example: “gtm_mcs_start_sieve_c” is the main project for the TriCore core, responsible for starting and scheduling the MCS project execution; “gtm_mcs00~03_sieve_c” are the MCS projects that schedule the respective channels of mcs00~mcs03 to run the Sieve function. In the TriCore main project “gtm_mcs_start_sieve_c“, there is a column called “Project References“, indicating that this project references other projects, and details can be viewed by expanding it (see Figure 8). Additionally, among these 5 projects, only the TriCore main project contains a .lsl file, while the other 4 MCS projects do not. This is allowed when compiling the MCS and TriCore projects together. However, if the MCS project needs to be compiled separately, it must include the .lsl file.A Beginner's Guide to GTM-MCS VX-toolset

Figure8 Overview of GTM Example Projects

By configuring project references to other projects, multiple projects can be compiled together. The method for setting this is found in the project configuration item “Properties“, where you can find the “Project References” option and check the projects that need to be referenced (i.e., compiled together). After selecting, click “OK” to complete the settings. (see Figure 9)

A Beginner's Guide to GTM-MCS VX-toolset

Figure9 Configuration of Project Cross-References

3.2.1 TriCore Main Project

The main function of the TriCore main project is to start the entire chip and invoke the various channels of the MCS. The invocation order starts from MCS00 CH0, then switches to CH1, followed by CH2, …, MCS01 CH0 to CH7, MCS02 CH0 to CH7, and MCS03 CH0 to CH7; after executing CH7, the execution of the MCS channels is terminated (see Figure 10). The entire project’s code is designed and developed around achieving this functionality.

A Beginner's Guide to GTM-MCS VX-toolset

Figure10 Invocation Order of MCS Channels

Next, we will interpret the code details. The source file gtm_mcs_start_sieve.c contains the main function, which implements the sequential invocation of the MCS channels. In the main function, after enabling global interrupts, the channels from MCS00 0 to 7 are enabled, followed by MCS01 0 to 7, MCS02 0 to 7, and MCS03 0 to 7, enabling interrupts sequentially. The MCS00 channel 0 is started, and then it waits for the execution of MCS03 channel 7 to complete, printing the execution results of each channel. (The program flow is shown in Figure 11).

A Beginner's Guide to GTM-MCS VX-toolset

Figure11 Flowchart of the Main Function

In the code, a macro function for enabling MCS interrupts is defined (as shown in Figure 12), which has two parameters:

1. MCS_NR ——MCS core number2. CHANNEL_NR ——channel numberBy adjusting the input parameters, the corresponding MCS core’s channel can be enabled to respond to interrupt requests when an interrupt occurs, entering the interrupt service function for processing. In the main function, this macro function is used to enable the interrupt services for the 28 channels of MCS00~03.

A Beginner's Guide to GTM-MCS VX-toolset

Figure12 Definition of MCS Channel Interrupt Enable Macro Function

Below the main function, a macro function for the interrupt service MCS_CHANNEL_ISR is defined (see), which has 4 parameters:1. MCS_NR ——current MCS core number2. MCS_NEXT_NR ——next MCS core number to run3. CHANNEL_NR ——current running channel number4. CHANNEL_NEXT_NR——next channel number to runThis interrupt service function saves the results of the current MCS core’s channel function execution into a two-dimensional array channelx_return_value. It then sets the next MCS channel to be executed. So if the next running channel is MCS00 channel 0, it ends the execution.

A Beginner's Guide to GTM-MCS VX-toolset

Figure13 Definition of Interrupt Service Function

Next, by calling the macro function, we define the interrupt service functions for the 28 MCS channels. Here, we can see that using the macro function to expand the definition of functions has its conveniences.

A Beginner's Guide to GTM-MCS VX-toolset

Returning to the main function, the first step is to enable all interrupt requests using __enable(), followed by calling the MCS channel interrupt enable function MCS_CHANNEL_IRQ_ENABLE, enabling all 28 channels of MCS00~MCS03 sequentially.

A Beginner's Guide to GTM-MCS VX-toolset

Figure14 Enabling MCS00~03 Channels in Main Function

By setting GTM_MCS0_CH0_CTRL.U to 1, the MCS00 channel 0 is started. Then, it waits for all channels to complete execution. When MCS03 CH7 completes execution, the flag done is set to 1, and the following loop ends, allowing the program to proceed. According to the MCS core and channel numbers, the execution results of each channel are printed. The results are stored in the channelx_return_value array.

A Beginner's Guide to GTM-MCS VX-toolset

Figure15 Part of the Code in the Main Function

3.2.2 GTM MCS Projects

The projects gtm_mcs00_sieve_c~ gtm_mcs03_sieve_c are quite similar, all controlling different channels to call a function sieve, which is used to count how many prime numbers are between 0 and 1024. The function itself is not significant for this project, but interested engineers can study the function in detail. The source file only contains sieve.c, and its main function has only two lines, using a library function atexit, which registers a termination function (i.e., a function called after the main execution ends). From the code below, the registered function is raise_irq_flag_and_halt, which is used to enable interrupts and terminate tasks. The actual result of this main function is that it first executes sieve(0), and then executes the function raise_irq_flag_and_halt(). Here, STA is the MCS status register.

A Beginner's Guide to GTM-MCS VX-toolset

Figure16 Main Function in MCS Project

The macro definition CHANNEL(x) is a macro function that expands to a __channel type function, which is a keyword specifically established by the TASKING compiler to support MCS (see MCS user guide 1.9.6. Channel Functions). By using the termination function exit() to call sieve(x), the execution ends after completion. Here, functions for Channel 1~7 are defined. The function sieve(x) is executed, and then clicking exit ends the current program.

A Beginner's Guide to GTM-MCS VX-toolset

Figure17 Channel Functions in MCS Project

Here, it can be seen that the entry point for channel 0’s function is the main function, while the entry points for channels 1~7 are CHANNEL(1)~CHANNEL(7). The operation of these channels is controlled by the TriCore main project.

3.2.3 Code Debugging

After gaining a deeper understanding of this project, we can debug it to see the actual execution results. This project uses the TriCore project as the main project, supporting online debugging, allowing the program to be downloaded to the chip for debugging. We open the “Debug Configurations” interface, create a debugging configuration, and select the chip type of the “Demo board“.

A Beginner's Guide to GTM-MCS VX-toolset

Figure18 Debug Configuration Window

After downloading the program to the chip, during execution, the results of MCS00~MCS03 channels are printed in the FSS window. Since the execution of the sieve function is actually independent of the MCS core or channel number, the results are the same (see Figure 19). Interested engineers can make small modifications to include the core number and channel number in the execution results.A Beginner's Guide to GTM-MCS VX-toolset

Figure 19 Execution Results of the Project

4 Conclusion

This article briefly introduces Bosch’s GTM-IP, the standalone version of the toolset VX-toolset for GTM developed by TASKING, and the integrated version in the VX-toolset for TriCore. Taking version v6.3r1 as an example, it outlines the considerations for creating GTM projects, mixed compilation of TriCore and GTM projects, and the function scheduling relationship between the TriCore main core and the GTM-MCS core. It is hoped that this article will assist engineers in developing actual application programs. (Friendly reminder: If images do not display fully, please click on the images to view them in full.)

5 Contact Us

If you have technical questions, please contact TASKING’s technical support in China.

Email: [email protected]

Official Website: www.tasking.com

Trial Application: https://www.tasking.com/trial

Leave a Comment