How to read the Machine State Register (MSR) using the MBD toolbox - MPC5744P?

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

How to read the Machine State Register (MSR) using the MBD toolbox - MPC5744P?

Jump to solution
1,950 Views
rafael_barbosa
Contributor IV

Hello,

I am using the Devkit MPC5744P and the Model Based Design Toolbox 3.0.0.

I can not find the MSR register using the "Read Registers Block".
Is there a way to read it in the Model Based Design?

pastedImage_1.png

Kind Regards, Rafael

1 Solution
1,836 Views
mariuslucianand
NXP Employee
NXP Employee

Hello rafael.barbosa@chassisbrakes.com‌,

Our Read Registers Block provides access only to peripherals registers. The register you want to read is critical and is one of the process control registers in the PowerPC architecture. 

However, this register may be read using the mfmsr assembly instruction. For this, you need to insert some custom code.

One way is to create your own S-Function to return the mfmsrValue variable.

volatile uint32_t mfmsrValue ;

__asm__( "mfmsr %0" : "=r" (mfmsrValue ) );

OUTPUT_PORT = mfmsrValue ;

If you want to avoid avoid adding an S-function, you can also add a Data Store Memory Block in your model, call it as mfmsrValue, with DataType uint32 and Storage class: Volatile. Declaring as volatile, for most Simulink Versions it will declare the variable in the code as the name you typed in the Data Store Memory: mfmsrValue.

pastedImage_7.png

After that, in a  System Outputs block from Simulink Coder library, you can insert the following code which will read the MSR refisters and store the value in the decalred variable:

__asm__( "mfmsr %0" : "=r" (mfmsrValue ) );

If you make sure that the following blocks will be called exactly in this order (System Outputs first, followed by mfmsrValue Read) you will have the value from the desired register in the Data Store Memory.

pastedImage_10.png

Hope this helps,

Marius

View solution in original post

2 Replies
1,837 Views
mariuslucianand
NXP Employee
NXP Employee

Hello rafael.barbosa@chassisbrakes.com‌,

Our Read Registers Block provides access only to peripherals registers. The register you want to read is critical and is one of the process control registers in the PowerPC architecture. 

However, this register may be read using the mfmsr assembly instruction. For this, you need to insert some custom code.

One way is to create your own S-Function to return the mfmsrValue variable.

volatile uint32_t mfmsrValue ;

__asm__( "mfmsr %0" : "=r" (mfmsrValue ) );

OUTPUT_PORT = mfmsrValue ;

If you want to avoid avoid adding an S-function, you can also add a Data Store Memory Block in your model, call it as mfmsrValue, with DataType uint32 and Storage class: Volatile. Declaring as volatile, for most Simulink Versions it will declare the variable in the code as the name you typed in the Data Store Memory: mfmsrValue.

pastedImage_7.png

After that, in a  System Outputs block from Simulink Coder library, you can insert the following code which will read the MSR refisters and store the value in the decalred variable:

__asm__( "mfmsr %0" : "=r" (mfmsrValue ) );

If you make sure that the following blocks will be called exactly in this order (System Outputs first, followed by mfmsrValue Read) you will have the value from the desired register in the Data Store Memory.

pastedImage_10.png

Hope this helps,

Marius

1,836 Views
rafael_barbosa
Contributor IV

Hello Marius,

Thank you for the response.

I tried to implement using the Data Store Memory Block approach and it works good.

Regards, Rafael