-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow global variables to be directly used (not as wires) to communicate between functions #73
Comments
First off: |
Immediately - like WIREs these globals are going to be limited to have a single function writing the variable and 0 or more functions reading the variable. Otherwise very hard to make sense of what something like this means - would implied shared/arbitrated access to the global variable register for writing. Ex. bad example below // Ex. What occurs in this code? Not specified/apparent
uint32_t the_global = 0;
// Must be same clock domain or mark global as ASYNC_WIRE
#pragma MAIN_MHZ write_main 100.0
#pragma MAIN_MHZ read_main 100.0
uint32_t write_main()
{
the_global += 1;
return the_global;
}
uint32_t read_main()
{
the_global += 1;
return the_global;
} |
Ok so @suarezvictor what do you make of this int32_t the_global = 0;
// Must be same clock domain or mark global as ASYNC_WIRE
#pragma MAIN_MHZ write_main 100.0
#pragma MAIN_MHZ read_main 100.0
void write_main()
{
// Save global
int32_t temp = the_global;
// 'Erase it'
the_global = -1;
// Do some stuff
do_some_stuff();
// Reset global
the_global = temp;
// Count as demo
the_global += 1;
}
uint32_t read_main()
{
static uint32_t local_counter;
if(the_global==-1)
{
// Never reaches here
// the_global = -1; from write_main not seen
}
// Count as demo
local_counter += the_global;
return local_counter;
} Does the I propose no. Currently writes to globals dont 'go through'/'commit'/'write to registers' until the 'end of the function' / clock edge. So in that same sense that each 'iteration' of the function updates the registers: writes to globals are not updated/'seen' in other functions until the next clock cycle. (Otherwise if yes read_main should see -1 then oh gosh... somehow need to figure out 'ordering'/mixing of wiring of the combinatorial logic of |
This should almost certainly hijack the existing VHDL generation clock cross module hierarchy signal routing stuff - maybe good time to rename signals 'global_bus' or something |
Its good to realize that the above is almost a 'trick' question in that Again I am planning to implement this as one clock delayed/registered 'Does the read_main ever see the temp -1 value? No.' style... |
One the above is done. It should be possible to add a pragma to global var def making it a wire - and same checks of one driver process and many readers is fine - but driver of wire is comb logic D into reg, instead of from output Q |
Seems possible to make the default the opposite - global readers get the comb. logic D input but for something meant to be storage that seems to itself to making comb. loops out of your intended storage too easily... hmmm |
Ive decided to actually make the default behavior to have writes to global wires - and the comb logic attached - to be directly wired into reading locations. Not from the register itself. (wire doing into D, not wire from Q) This makes the default behavior of shared globals like WIREs - which also completes some of this issue #72 |
@suarezvictor and others would be happy to know that this issue has implemented and tested. 👍 Now // Dont need clock cross marker/include
#include "clock_crossing/the_global.h" // NOT NEEDED
WIRE_WRITE(type, the_global, rhs)
// Can be replaced with
the_global = rhs;
WIRE_READ(type, lhs, the_global)
// Can be replaced with
lhs = the_global; Recent uart demos are a working demo of the syntax Line 17 in 346b038
Documentation will be updated shortly to point users to use of this new syntax... |
it looks so much better! |
It seems truly interesting, could you write an approximate example of use?
…On Fri, Jun 24, 2022 at 12:49 AM Julian Kemmerer ***@***.***> wrote:
Ive decided to actually make the default behavior to have writes to global
wires - and the comb logic attached - to be directly wired into reading
locations. Not from the register itself. (wire doing into D, not wire from
Q)
This makes the default behavior of shared globals like WIREs - which also
completes some of this issue #72
<#72>
—
Reply to this email directly, view it on GitHub
<#73 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACBHVWJOBZMQXPZ3H5K5I33VQUV3NANCNFSM5RXNTOLQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
The bare minimum example is like above int32_t the_global = 0;
// Must be same clock domain or mark global as ASYNC_WIRE
#pragma MAIN_MHZ write_main 100.0
#pragma MAIN_MHZ read_main 100.0
void write_main()
{
// Count as demo
the_global += 1;
}
uint32_t read_main()
{
static uint32_t local_counter;
// Count as demo
local_counter += the_global;
return local_counter;
} Where the function reading the global variable So during the first clock Happy to talk more about it on Discord 🤓 |
As @suarezvictor has pointed out - wouldnt it be nice to not have to specify WIRE for things - and have the tool do it all? 😏
Currently global variables are identical in functionality to static local variables. They are associated with a single function only. Even though global variables are in the global scope, they cannot be directly used by multiple functions. Global variables are locked to a single function right now.
Currently WIRE's are the work around for this. A global variable is declared but special WIRE/clock crossing functions are used to make clear where writes to the global vs reads to global are occurring.
Why is it needed to know when writes and reads occur? Well lets get into why this issue has few layers to it...
The text was updated successfully, but these errors were encountered: