Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how replace a function in data & program memory during running my code.(Using MikroC)

Status
Not open for further replies.

taroot

Member level 2
Joined
Jun 9, 2010
Messages
50
Helped
26
Reputation
52
Reaction score
24
Trophy points
1,298
Location
Home
Activity points
1,510
how replace a function in data & program memory during running my code.(Using MikroC)

i have 2 function for example d1() and d2().d1() burned in program memory.i want to replace d1() function that d2() take his memory location.but main() remain old one.d2() will use a bootloader to take place the d1(). 1 thing more that in actual programming name of the both functions will same.i have some queries.
1- did it work i mean main() will call d2() normally.
2- Did any one do that, during runing the program, write the data/program memory.
its basically self flash writing kind of thing.Pic 18f have that ability.
 

Re: how replace a function in data & program memory during running my code.(Using Mik

Usually bootloaders are designed to rewrite all of the application flash memory, except for the bootloader area itself. Cautious people are even protecting the bootloader area against unintended overwrite by hardware fuses and provide a safe recovery in case of bootloader failure.

Rewriting only part of the application is generally possible, but the memory layout has to consider it. The flash self rewrite feature is operating on erase block entities of the respective microprocessor. You have to care, that no other code is sharing the rewritten block of memory. Most PIC compilers have compiler commands for it, e.g. #org statements.
 
  • Like
Reactions: taroot

    taroot

    Points: 2
    Helpful Answer Positive Rating
Re: how replace a function in data & program memory during running my code.(Using Mik

HI

You need to use ptr to function (pointer to function ) just load the pointer in real time

All the best

Bobi
 
  • Like
Reactions: taroot

    taroot

    Points: 2
    Helpful Answer Positive Rating
Re: how replace a function in data & program memory during running my code.(Using Mik

thx for reply.
yes FvM i keep in mind this thing.that how and where to place my function in memory.

Bobi ur idea seem to be interesting.
Actually i have no more space for my cod in RAM and ROM.i want i save my some of function in External EEPROM and when i need them than i put them in ROM by replacing some any function. did any one try this successfully.????
 

Re: how replace a function in data & program memory during running my code.(Using Mik

Hi

It is more easy to replace your micro with larger memory one.

Anyhow - in order to do what you ask you will need to define an array in RAM who can be accessed by a function pointer(rather complicated)
the function data need to be copy from EEPROM to RAM array prior to execution and accessed by the function Ptr
the function body should be located in RAM using compiler predefined MACRO "__RAM"

All the best

Bobi
 
  • Like
Reactions: taroot

    taroot

    Points: 2
    Helpful Answer Positive Rating
Re: how replace a function in data & program memory during running my code.(Using Mik

I was assuming in fact, that having both function in flash memory won't be an option. Otherwise, you don't need to think about a bootloader and similar. You should however consider the limited flash endurance. The PIC18 datasheets aren't very exact in this regard, they promise "many thousands of erase/write cycles - up to 100,000".

function body should be located in RAM using compiler predefined MACRO "__RAM"
Most PIC processors don't have an option to execute code from RAM, execpt for a few special devices.
 
  • Like
Reactions: taroot

    taroot

    Points: 2
    Helpful Answer Positive Rating
i cant place the code in RAM or ROM.i just have a defined address in main function and want to call it when i place some code that address. Otherwise this address is used by another function.Idea behind is i want to update a complete function(i take care of the addresses).
Main purpose is to memory organization.Have any idea to organize the memory of embedded systems .
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top