Moving ISR to SRAM

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

Moving ISR to SRAM

Jump to solution
910 Views
manishsangram
Contributor IV


Hi

We are using S12ZVMC128. We would like to move some of the ISRs to SRAM for faster execution. What is the easiest way to declare this to the compiler? How much performance improvement can we expect in code execution speed between SRAM and flash? We are running the core at 50Mhz/100Mhz speed. Would the execution speed be about 2x in SRAM compared to Flash?

Labels (1)
Tags (2)
1 Solution
720 Views
RadekS
NXP Employee
NXP Employee

Hi Manish,

The simplest way is just let it know to the linker. For example:

#pragma CODE_SEG DEFAULT_RAM

void PFLASH_Send_Command(void)

{

  DisableInterrupts;

  FSTAT_CCIF = 1;          //launch command

  while(FSTAT_CCIF == 0){}; //wait for done

  EnableInterrupts;

}

#pragma CODE_SEG DEFAULT

The Starts12z.c code will automatically load your code into RAM.

Note: The DEFAULT_RAM could be used only for S12Z and CW10. The S12(X) linker in CW 5.1(or 5.2; Classic IDE) needs use user segment instead of the default (like DEFAULT_RAM).

You are right that speed of Flash reading might limit code execution, but I will not expect that the speed increasing ratio will be directly 2. It is mainly because not all instructions have shortest execution time and because the flash is read few bus cycles prior instruction execution. The ratio will depend on executed instructions. However, I never measure it.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

1 Reply
721 Views
RadekS
NXP Employee
NXP Employee

Hi Manish,

The simplest way is just let it know to the linker. For example:

#pragma CODE_SEG DEFAULT_RAM

void PFLASH_Send_Command(void)

{

  DisableInterrupts;

  FSTAT_CCIF = 1;          //launch command

  while(FSTAT_CCIF == 0){}; //wait for done

  EnableInterrupts;

}

#pragma CODE_SEG DEFAULT

The Starts12z.c code will automatically load your code into RAM.

Note: The DEFAULT_RAM could be used only for S12Z and CW10. The S12(X) linker in CW 5.1(or 5.2; Classic IDE) needs use user segment instead of the default (like DEFAULT_RAM).

You are right that speed of Flash reading might limit code execution, but I will not expect that the speed increasing ratio will be directly 2. It is mainly because not all instructions have shortest execution time and because the flash is read few bus cycles prior instruction execution. The ratio will depend on executed instructions. However, I never measure it.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------