How to define ISR for a module which is not contained in the MBDT library

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to define ISR for a module which is not contained in the MBDT library

1,339 Views
Yunhe
Contributor I

Hi:

Since there is no SWT in the MBDT library, I configure the watchdog through the register r/w module, but what if I configure ISR for SWT because there is no related module in the library?

best wishes;

zhang.

0 Kudos
6 Replies

1,318 Views
mariuslucianand
NXP Employee
NXP Employee

Hello Zhang,

Can you tell me please, which MCU are you using?

Regards,

Marius

0 Kudos

1,311 Views
Yunhe
Contributor I

Hi Marius,

The MCU I use is MPC5744P, and the version of MBDT is 3.0.0.

Best Regards

Zhang

0 Kudos

1,301 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @Yunhe ,

Well, in this case, you shall implement the interrupt using custom code.

First of all, you have to create a handler in a C file in which you can include the interrupt custom function. The following article might be a good tutorial on how to do that: https://community.nxp.com/t5/NXP-Model-Based-Design-Tools/How-to-use-your-own-C-code-in-our-Toolbox-...

Now you need to enable and assign a priority for the interrupt and assign a handler. For that you can use some of the functions defined in the interrupt_manager_MPC57xx.c file, which is automatically copied in the final project as default:

INT_SYS_EnableIRQ(SWT0_IRQn);

INT_SYS_SetPriority(SWT0_IRQn, priority);

INT_SYS_InstallHandler(SWT0_IRQn, C_function_handler, NULL);

One more note: the latest release of the MBDT for the MPC57xx is 3.2.0 so I strongly recommend you to update to the latest version.

Hope this helps,

Marius

0 Kudos

1,274 Views
Yunhe
Contributor I

Hi Marius,

Your answers and articles have benefited me a lot. Based on your article, I not only embed the SWT ISR as C code into Simulink, but also embed the SWT initialization code into Simulink based on the SWT code generated by the S32DS SDK, and It is working. But in this process, I encountered a problem, I hope you can answer it. Since SWT requires swt_hw_access.h, swt_driver.h and swt_driver.c, swt_hw_access.c, I added the corresponding path and file in MATLAB:

Yunhe_0-1641538998735.png

(If do not specify the path of the header file, then S32DS will report an error when compiling the code and the corresponding header file cannot be found. e.g. Cpu.h No such file or directory)

Add source file path:

Yunhe_1-1641539220333.png

Then execute the initialization function "init1" , in the function, initialize and configure the SWT ISR.

Yunhe_2-1641539408375.png

When I generated the code and compiled it in S32DS, some errors appeared. These errors were resolved when I dragged the corresponding source files (main.c, swt_driver.c, swt_hw_access.c) into the project:

Yunhe_3-1641539448660.png

And worked successfully.
But I think this is a bit troublesome, so I want to ask if there is a way to automatically add the corresponding source files to the generated code.


In addition, I want to talk about the C code of SWT initialization and interrupt configuration encapsulated as Simulink modules and added to the Simulink library. I would like to ask you if there are any corresponding posts on the forum.

Best Regards

Zhang

 

0 Kudos

1,265 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @Yunhe,

In case you want to automatically copy inside the generated code some files, you can use our script mbd_mpc574x_user_copy_required_files. This is an m file that can be modified on your side to automatically copy some files when the code is generated.

You can access the swt driver files from our toolbox using the following line:  fullfile(mbd_find_mpc_root, 'MPC_Platform_SDK', 'platform', 'drivers', 'src', 'swt')

Please let me know if the above approach worked on your side.

Hope this helps,

Marius

 

 

 

0 Kudos

1,248 Views
Yunhe
Contributor I

Hi Marius,

One problem when I use mbd_mpc574x_user_copy_required_files,That is to generate an error when generating the code:

Yunhe_0-1641641329722.png

I declared a function called copy1 directly below the SWT init function:

Yunhe_1-1641641422468.png

To pass compilation, I added coder.extrinsic('fullfile');But another error occurred:

Yunhe_2-1641641779220.png

So again I use the coder.extrinsic function:

Yunhe_3-1641642125151.png

Finally no error occurred,But there is no "swt_driver.c" I copied in the folder where the code is generated.

I think it may be due to the existence of the coder.extrinsic function in the process of generating the code, and the copy1 function is not run, the help document of MATLAB may explain this problem:

Yunhe_4-1641642867967.png

Actually, I may have misunderstood what you mean, you may mean to make me write a script that copies files by referring to script mbd_mpc574x_user_copy_required_files. Because the script that copies the files doesn't have to generate code, and I did:

Yunhe_5-1641643227792.png

In order to automatically run this script, I use it as a callback function:

Yunhe_6-1641643387221.png

According to the CallbackTracing function of Simulink, can see that the copy function does run:

Yunhe_7-1641643567729.png

But there is still no copied source file in the code generated file:

Yunhe_8-1641643639513.png

I think maybe the copy function needs to be executed after the generated code is done, but I don't know how to automate it

If I run it manually, copy the source file to the folder where the code is generated, and then import it into S32DS through the XML file, the copied source file cannot actually be imported into the project, so I have to run it manually and copy the source file to Under the directory of the S32DS project.

But I wonder if there is a way to make the script run automatically?

Best Regards

Zhang

0 Kudos