This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

A question about assigning SP

Hello,
I am trying to set the value of SP as part of my small RTOS. However, I have a little problem:
once I do this

__asm
{
MOV SP, stkptr
}

the address stored in stkptr (its type is unsigned int* ) is converted. If the address of strptr is 0xE2D4, SP get 0xF2D4.
My stack's top is at 0xFC00. I also disable the check for stack underflow/overflow (registers STKUN, STKOV in the A66 file).
What is happening here? Are the DPP registers involved? Can I use memory mapping facilities to solve this issue?
Kind regards,
Tamir Michael

Parents
  • Please look at the Infineon User's Manual. Since the least significant bit of register SP is tied to '0' and bits 15 through 12 are tied to '1' by hardware, the SP register can only contain values from 0xF000 to 0xFFFE. You are not allowed to move it to XRAM!

    I am also curious how you disabled a Class A TRAP as I am not aware that this is possible either.

    Secondly, you need to make sure the next instruction after modifying the system stack does not access it. I would recommend that you add a NOP after it to be safe.

    So assuming you have the system stack configured for the entire internal RAM and you have changed the STKOV to the lowest point of DPRAM plus 6 words.

Reply
  • Please look at the Infineon User's Manual. Since the least significant bit of register SP is tied to '0' and bits 15 through 12 are tied to '1' by hardware, the SP register can only contain values from 0xF000 to 0xFFFE. You are not allowed to move it to XRAM!

    I am also curious how you disabled a Class A TRAP as I am not aware that this is possible either.

    Secondly, you need to make sure the next instruction after modifying the system stack does not access it. I would recommend that you add a NOP after it to be safe.

    So assuming you have the system stack configured for the entire internal RAM and you have changed the STKOV to the lowest point of DPRAM plus 6 words.

Children
  • Hello Chris,
    Well, I don't have that much experience with the Infineon (I do write embedded stuff but I am new to this chip, and never before wrote a preemptive scheduler).
    I simply disabled the check in the A66 file, namely:
    ; MOV STKUN,#DPP3:_TOS ;
    ; MOV STKOV,#DPP3:(_BOS+6*2) ;

    This way, I can set SP to different locations in memory (in the area you specified). My prototype seems to work :)
    I guess I will have to build my own stack overflow/underflow checks in the scheduler (funny code there; mixed assembly and C, because I didn't want to calculate offsets in structures and all that. good enough for now).
    Thanks for your advise.
    Tamir

  • Hi Tamir,

    Good that you have a solution. I would comment that you stated that you disabled the stack checking but instead you did not trigger a stack trap because you used the MOV instruction. The system will still respond to the stack trap albeit to your new boundary conditions written to registers STKUN and STKOV.

    As a side note, the XC16x devices don't have this limitation.

    Best regards,
    Chris