Saving CRC Register on context switch

Hari
2012-06-20
2013-09-16
  • Hari

    Hari - 2012-06-20

    I am using MSP430F5418 with FreeRTOS 7 in medium data model.

    I want to save the MSP CRC registers on FreeRTOS context switch. I edited the portext.s43 like this.

    In save context macro, after pushing 15 registers to stack, I push the CRC registers. (CRCDI is the MSP register to save)

    mov.w CRCD1, r15
    pushx.a r15
    In restore context macro, I poped the CRC just before poping the 15 registers.

    popx.a r15
    mov.w r15, CRCDI
    It is supposed to be working , but it is not. The program control is going to unknow location.

    Anybody have any Idea?

     
  • Richard

    Richard - 2012-06-20

    You will also have to set up the initial stack given to the task when it is created to include the additional register - otherwise, when the task first starts, the restore context macro will try and pop a register that does not exist resulting in junk in the register and a stack underflow.

    Look at the function pxPortInitialiseStack() in whichever port.c file you are using.

    Regards.

     
  • Hari

    Hari - 2012-06-20

    Thank you Richard for your reply.
    In that function what should I change?

     
  • Richard

    Richard - 2012-06-20

    I don't know which port you are looking at, but if you look at FreeRTOS/Source/Portable/IAR/MSP430X/port.c, then assume PRELOAD_REGISTER_VALUES is set, you will see that the function writes a value for each register that is to be popped from the stack when the context is loaded.  If your new register is the last thing popped from the stack, add it to the start of the list, if it is the first thing popped from the stack, add it to the end of the list.

    Regards.

     
  • Hari

    Hari - 2012-06-21

    But PRELOAD_REGISTER_VALUES is not set in my port.c, what should I do?

     
  • Hari

    Hari - 2012-06-21

    I added the following at the top. before #ifdef PRELOAD_REGISTER_VALUES

    *pxTopOfStack = (portSTACK_TYPE) 0xffff;
    pxTopOfStack--;
    #ifdef PRELOAD_REGISTER_VALUES follows
    

    Now it is working but while restoring context, incorrect value is loaded

     
  • Hari

    Hari - 2012-06-21

    Ya Now it is working.

    I want to save CRCRESR register also to do that.

    So I need one more

    *pxTopOfStack = (portSTACK_TYPE) 0xffff;
    pxTopOfStack--;
    

    for that, right?

     
  • Richard

    Richard - 2012-06-21

    But PRELOAD_REGISTER_VALUES is not set in my port.c, what should I do?

    Which port are you using then?

    Regards.

     
  • Hari

    Hari - 2012-06-21

    I'm Sorry,
    I found it

     
  • Hari

    Hari - 2012-06-21

    I am sorry, I couldn't found the PRELOAD_REGISTER_VALUES, anywhere in the free RTOS 7.0 files.

    Could you please tell me how can I delete a post from this forum?

     

Log in to post a comment.