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

How to fix the local variables

I hava a need to fix one C file's local variables to some settled address in DATA area, how to do it, thanks very much.

Parents
  • The OVERLAY linker directive allows you to edit the call tree to suit yourself. Of course, you'd better understand exactly what you're doing when using it!

    I don't understand the reference to declaring schedule() reentrant. From the code shown, it's only called in one context anyway. ("schedule" hints that you're doing task switching, but I didn't see anything directly pointing out that there are preemptive tasks here. So, there's only two contexts/call trees: from main(), and from the ISR.)

    You mention a few other functions and C files. I assume these are all routines called by schedule(). They will all overlay each other; none of them will overlay with the ISR tree. schedule() cannot share its local variables with a function that schedule() calls; that's two different levels of the same call tree. (If you really don't need schedule's locals after you call some sub-task, then you can move the work done in schedule to another subroutine, which will overlay the other tasks.)

    If you're really sure the ISR cannot occur at the same time as other routines -- because, for instance, you mask the interrupts to prevent it -- then you might use the OVERLAY directive to overlay the ISR and main task memory. Note that the compiler will trust you, though, and if you slip on the mutual exclusion, you'll get weird bugs as your memory gets corrupted.

Reply
  • The OVERLAY linker directive allows you to edit the call tree to suit yourself. Of course, you'd better understand exactly what you're doing when using it!

    I don't understand the reference to declaring schedule() reentrant. From the code shown, it's only called in one context anyway. ("schedule" hints that you're doing task switching, but I didn't see anything directly pointing out that there are preemptive tasks here. So, there's only two contexts/call trees: from main(), and from the ISR.)

    You mention a few other functions and C files. I assume these are all routines called by schedule(). They will all overlay each other; none of them will overlay with the ISR tree. schedule() cannot share its local variables with a function that schedule() calls; that's two different levels of the same call tree. (If you really don't need schedule's locals after you call some sub-task, then you can move the work done in schedule to another subroutine, which will overlay the other tasks.)

    If you're really sure the ISR cannot occur at the same time as other routines -- because, for instance, you mask the interrupts to prevent it -- then you might use the OVERLAY directive to overlay the ISR and main task memory. Note that the compiler will trust you, though, and if you slip on the mutual exclusion, you'll get weird bugs as your memory gets corrupted.

Children
No data