Force a Fixed Memory location for Variable

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

User avatar
Jay Dee
Posts: 352
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 116 times
Been thanked: 134 times
Contact:

Force a Fixed Memory location for Variable

Postby Jay Dee » Sun Mar 10, 2019 12:06 pm

Hi,
Is there a way to force FC to store a variable in a specific memory location?

Why
I'm looking to simplify how an external program accesses variables from a PIC via USB serial.
If I could force a variable to save to a specific address location, I could then always use this location in future FC programs. The external program should then always be able to just read out that specific address. This might all sound a bit screwy but it quite specific to a setup I've been playing around with.

Yep, I have also been using the EEPROM for saving static values, works OK. But for highly dynamic variable, I dontt want to keep writing them to EE mem every few milliseconds.

Any ideas? J.

kersing
Valued Contributor
Valued Contributor
Posts: 1873
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 530 times
Been thanked: 1040 times
Contact:

Re: Force a Fixed Memory location for Variable

Postby kersing » Sun Mar 10, 2019 12:36 pm

Variables are stored in RAM. Starting any external program would very likely wipe the contents of that RAM or at least initialize part of it. Also, how do you want to run two programs one one controller?

There might be ways to force FC to use a specific RAM location to store a variable, however what is possible depends on the controller you are using (and the compiler FC uses to generate the code).
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
Jay Dee
Posts: 352
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 116 times
Been thanked: 134 times
Contact:

Re: Force a Fixed Memory location for Variable

Postby Jay Dee » Sun Mar 10, 2019 1:04 pm

Ah yeah.. the compiler. Forgot that step.. could be kinda hard to work around that.

Currently I have a tool that allows me to read values stored at a specific address and that works in my testing so far. So the tricky bit of reading the data back from the PIC over USB Serial is basically sorted. The tool is only for the PIC ECIO units... so my bench testing is currently on a 18F2455

However the current method requires extracting the memory location of each variable from a flowcode debug file, with this information each variable can be individually queried. This does however add steps to the process.
So I thought... If I could force my FC or supplementary C to write specific variables to known memory locations, i could skip the extraction step.
All a work in progress. :)

kersing
Valued Contributor
Valued Contributor
Posts: 1873
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 530 times
Been thanked: 1040 times
Contact:

Re: Force a Fixed Memory location for Variable

Postby kersing » Sun Mar 10, 2019 7:21 pm

Forcing the PIC compiler to use specific memory locations should be doable, however this will have a huge impact on the optimizations the compiler does to fit variables and arrays into the available RAM. PIC RAM is not exactly the easiest to work with due to the way memory banks are designed and by fixing certain variables at certain positions you are severely hampering the compiler in choosing the optimal layout.

Wouldn’t be easier to use a small program (script) to extract the required information from the compiler output?
These users thanked the author kersing for the post:
Jay Dee (Thu Mar 14, 2019 11:19 am)
Rating: 5.26%
 
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
Jay Dee
Posts: 352
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 116 times
Been thanked: 134 times
Contact:

Re: Force a Fixed Memory location for Variable

Postby Jay Dee » Mon Mar 11, 2019 4:09 pm

Hi Kersing,
I agree it may well be less than optimal and yes currently the extraction is currently perfomed by a PHP script. This chain works but I'm just trying to speed up some aspects of the process. I have found during deveolopement, that sometimes I need to re-run through the process, this can be a pain when tyring to push a project forward. During dev, I would happliy exchange some inefficiency in compiled code over speed of turnaround.

It is really about looking at the optioins, trying them and drawing conclusions on the results.

After a bit more reading the XC8 compiler does allow 'absolute addressing' , not knowing the details of what is being described I'm unsure of the method to try. It is also suggested that a 'sensible' locatin in memory is chosen. However not having an extensive knowloedge of the memory map any suggestions are appreciated.
As to the method employed, ref;
http://microchipdeveloper.com/faq:38

Which of these options do people this would be most suitable to try;
Using __section specifier with CCI syntax enabled
Using __at specifier with CCI syntax enabled
Absolute variables in Data Space using '@' qualifier:
Absolute variables in Program Space using '@' qualifier:
Absolute functions using '@' qualifier:

Thanks, J.

kersing
Valued Contributor
Valued Contributor
Posts: 1873
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 530 times
Been thanked: 1040 times
Contact:

Re: Force a Fixed Memory location for Variable

Postby kersing » Mon Mar 11, 2019 10:39 pm

If you want to use this for Flowcode variables you will need some magic to include the right modifiers when it’s generating code. Ben will probably know what magic to apply as well as the right directive to use.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
Benj
Matrix Staff
Posts: 14312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4404 times
Been thanked: 4128 times
Contact:

Re: Force a Fixed Memory location for Variable

Postby Benj » Tue Mar 12, 2019 12:17 pm

Here's an example of the magic in practise :wink:

I have created a Compile -> AddVar Event macro that is called repeatedly when we are generating the C code for variables.

I simply check for a specific variable name and when I find it I slightly change the code generation to add a location for the variable.

VarLocations.fcfx
(9.33 KiB) Downloaded 25 times


The project generates the following code.

Code: Select all

MX_GLOBAL MX_UINT8 FCV_TESTC;
MX_GLOBAL MX_UINT8 FCV_TESTB @ 0x101;
MX_GLOBAL MX_UINT8 FCV_TESTA @ 0x100;


Hope this helps.
These users thanked the author Benj for the post (total 2):
kersing (Tue Mar 12, 2019 6:56 pm) • Jay Dee (Thu Mar 14, 2019 11:19 am)
Rating: 10.53%
 

User avatar
Jay Dee
Posts: 352
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 116 times
Been thanked: 134 times
Contact:

Re: Force a Fixed Memory location for Variable

Postby Jay Dee » Thu Mar 14, 2019 11:21 am

Great stuff Ben, I'll have a play next week. Currently trying to climb out from under the bulk of work that built up whilst away from the office! J. :)