I am struggling to setup a model that uses a reference model such that when they call c-code, they are accessing the same RAM (variable instances). The hierarchy is as follows:
In both "main_model" and "function_model" the Simulation Target is set to use "interface.[ch]", which very simply contains an array of 4 structures to allow both global and accessor functions for access. The header is as follows:
typedef struct { bool enabled; uint32_t value; } counter_t; counter_t counter_list[4]; #define COUNTER_0 ((counter_t *)&(counter_list[0])) #define COUNTER_1 ((counter_t *)&(counter_list[1])) #define COUNTER_2 ((counter_t *)&(counter_list[2])) #define COUNTER_3 ((counter_t *)&(counter_list[3])) void initialize(void); void counter_enable(counter_t *ptr); void counter_disable(counter_t *ptr); uint32_t counter_get_current(counter_t *ptr); void counter_reset(counter_t *ptr);
I do understand in regards to C-code, choose either the global access or accessor functions, however, this scenerio is setup to mimic that of a hardware and firmware relationship special function register (SFR) access to something like an input compare using vendor supplied packages (such as NXP or STM) and maintain the call footprint for code generation.
The problem is when this setup is run, the "main_model" and the "function_model" each have their own internal values for "counter_list" rather than sharing a single instance of them. The "main_model" will initialize the counter value to 100 and the "function_model" increments by 1 per function call (occuring every 0.1 seconds). Looking at the values during simulation from both the "main_model" and "function_model" the following is observed:
The expectation would be that they both have the same value, starting at 100 and incrementing up to 200 over the 10 seconds. Is this possible? If so, how what am I missing? or help point me to the proper documentation (I haven't been able to find this in the user guide… yet). I've also attached the project and all files (2019b). Appreciate any guidance, thanks!
Best Answer