This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Changing CLA task content at runtime

Hi,

I have a task set to run on CLA Task 1 triggered by the ADC. it's getting quite big right now and I'm thinking about adding different algorithms to use based on external settings. Since I want each task to be optimal avoiding unnecessary tests for branching to use and because code size may be bigger than 2000 words if I include everything, I'm looking for a way to change the content of the CLA task 1 at runtime. When needed, I would stop CLA interrupt, memcopy the new CLA function from somewhere in flash to RAM and re-enable it. I'm trying to wrap my head around this to see if it's feasible.

Any thoughts?

Regards,

  • Hi Mosin,

    I haven't tried it myself but I believe you should be able to swtich out code at runtime. You would have to 

    1. Disable all interrupts using MIER

    2. memcpy() the new code to 0x9000

    3. Reassign new MVECT

    4. Re-enable MIER

    I think you would have to place the different pieces of codes in two sections and then make them a union in the linker command file

    UNION(CLa1Prog): RUN = RAML3, RUN_START(_Cla1funcsRunStart) {

    Cla1Prog_1 : LOAD = FLASHA,
      LOAD_START(_Cla1funcs1LoadStart),
      LOAD_SIZE(_Cla1funcs1LoadSize),
      PAGE = 0

    Cla1Prog_2 : LOAD = FLASHA,
      LOAD_START(_Cla1funcs2LoadStart),
      LOAD_SIZE(_Cla1funcs2LoadSize),
      PAGE = 0           

    }                        

  • Thanks Vishal!

    I was playing in the linker file trying to make it fit. I didn't know about the UNION! I'll try it out but like you said, I don't know why it wouldn't work.

    Thanks again