S12ZVC assembly instruction and S12G assembly instruction, what can I do?

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

S12ZVC assembly instruction and S12G assembly instruction, what can I do?

1,299 Views
jiakaihua
Contributor I

Because working reason I met problems.My company want to abandon S12G, new products all use S12ZVC.In order to reduce the development cycle, the company wanted to transplant some of the S12G code to the S12ZVC.Old product use S12G, although most of the code of transplant is no problem, but the migration problems appeared on the assembly code.I posted these S12G below code, hope someone know how to change the code to transplant to S12ZVC,Thank you very much!(My native language is not English, I didn't work hard enough to learn English, my English is very poor, I hope you understand)

/****************************************************************************
Name : VStdLL_GlobalInterruptDisable
Called by : -
Preconditions : -
Parameters : tVStdIrqStateType* pOldState: pointer to the local irq state
Return values : none
Description : saves the current CCR value to *pOldState and disables the
global interrupt
****************************************************************************/



asm{
pshy ; save index register
tfr d,y ; transfer pointer to index register
tpa ; load ccr to accumulator
sei ; disable global interrupt
staa 0,y ; store the value of ccr into loction pointed by pOldState
puly ; restore index register
}

/****************************************************************************
Name : VStdLL_GlobalInterruptRestore
Called by : -
Preconditions : -
Parameters : tVStdIrqStateType nOldState: value of the local irq state
Return values : none
Description : restores the CCR value stored in nOldState
****************************************************************************/

asm{
tba ; b to a
tap ; load accumulator to ccr
}

Tags (1)
0 Kudos
3 Replies

783 Views
MJW
NXP Employee
NXP Employee

Hello,

here is some S12Z assembly code (CW 10.7) to get you started:

asm {
   ld   x,pOldState
   tfr  ccl,d0
   sei
   st   d0,(0,x)
};

and

asm {
   ld   d0,nOldState
   tfr  d0,ccl
};

This assumes oldState is a byte variable.

This can probably be refined some more (e.g. optimize for calling convention, inlining). Use at your own risk.

HTH,

MJW

0 Kudos

783 Views
jiakaihua
Contributor I

Hello.

   Thank you for your help!

I use your code to replace the old code,CW10.7 prompt compile errors.I will change the format of your code to compile:

VSTD_DEF_FUNC_API(VSTD_NONE, void, CODE) VStdLL_GlobalInterruptDisable(VSTD_DEF_P2VAR_PARA(VSTD_NONE, tVStdIrqStateType, AUTOMATIC, VAR_NEAR) pOldState) VSTD_API_2
{
__asm(ld x,pOldState);
__asm(tfr ccl,d0);
__asm(sei);
__asm(st d0,(0,x));
}

VSTD_DEF_FUNC_API(VSTD_NONE, void, CODE) VStdLL_GlobalInterruptRestore(tVStdIrqStateType nOldState) VSTD_API_2
{
__asm(ld d0,nOldState);
__asm(tfr d0,ccl);

}

The compiled without error!

But at the time of debugging problems:

pastedImage_8.png

pastedImage_9.png

I hope you can help me again,Thank you very much!

0 Kudos

783 Views
MJW
NXP Employee
NXP Employee

Hello,

my guess would be that those are problems caused by stack over-/underflow.

On S12Z an interrupt stack-frame is 29 bytes (compared to 9 bytes on S12G). This must be taken into account when defining the stack-size.

Also, with-out knowing what interrupt vector "Cpu_Interrupt()" is actually serving, please be aware that compared to S12 there is a new exception type called "machine exception" on S12Z. This is mapped to a single interrupt vector (please refer to the interrupt table in the RM).

A machine exception is a non-maskable hardware interrupt, meant to flag severe system errors, with the special property that no interrupt stack-frame is written. And, since there is no context information present on the stack, this means the machine-exception service routine cannot be left with a simple "RTI" instruction.

HTH,

MJW

0 Kudos