Helpful ReplyHot!How do you share data between applications?

Author
RodoPIC
Senior Member
  • Total Posts : 138
  • Reward points : 0
  • Status: offline
2018/05/16 13:57:19 (permalink)
0

How do you share data between applications?

Hi all,
 
The harmony documentation says:
 
"With MHC, it is possible to create up to 10 applications. Using multiple applications allows you to perform multiple operations at the same time. For example, you can have one application read from the file system and another application can write to the file system.Each application has its own state machine and variables with independent data scope of each other. The state machines of the individual applications run ‘concurrently’ with one state machine being called, and then the next instead of having one state machine to do all the work. This allows separating the work into more logical and understandable ‘chunks’."

I'm wondering how do you send data from one application to the other after reading the part: "...variables with independent data scope of each other."

Thanks
#1
NKurzman
A Guy on the Net
  • Total Posts : 16262
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: How do you share data between applications? 2018/05/16 14:06:36 (permalink) ☄ Helpfulby DGTLMAN 2018/05/16 14:59:19
0
They are Not Full Applications. More Round Robin Tasks. (unless you are using an RTOS.
Since they are all in the same scope functions or globals would work.
#2
DGTLMAN
Moderator
  • Total Posts : 71
  • Reward points : 0
  • Joined: 2010/03/15 10:23:31
  • Location: 0
  • Status: offline
Re: How do you share data between applications? 2018/05/16 14:58:16 (permalink) ☄ Helpfulby RodoPIC 2018/05/17 09:01:27
2 (1)
Hi RodoPIC,
 
MPLAB Harmony does not currently (as of v2.05.01 and earlier) comprehend protected process spaces.  So, as NKurzman suggested, global data is actually addressable by all applications.  However, I would recommend conceptually associating a specific data set with a specific application or module that "owns" it and providing a set of functions to allow other applications or modules to access it in a controlled way.
 
Since there is only one "main" function, the MPLAB Harmony application model is a design convention where all applications (actually all Harmony modules except PLIBs) have an "Initialize" function and (optionally) one or more "Tasks" functions.  The "Initialize" function for each application or module is called before entering the main system loop (or before launching the RTOS scheduler) and the "Tasks" function(s) for each module are called every iteration, from the main loop (or from an RTOS thread or task when using an RTOS). 
 
No assumptions should be made about the order in which these functions are called.  So, when sharing data between modules, atomic access must be enforced by the functions that provide it.  MPLAB Harmony provides an Operating System Abstraction Layer (OSAL) that has functions for Semaphores, Mutexes, and Critical Sections that can be used (with or without an RTOS) to ensure that only one application module accesses the data at a time.
 
Volume IV: MPLAB Harmony Development in the Harmony help documentation has additional information about key concepts.
 
I hope this helps.

-DGTLMAN 
#3
campbellCustom
Starting Member
  • Total Posts : 43
  • Reward points : 0
  • Joined: 2014/08/30 14:35:35
  • Location: 0
  • Status: offline
Re: How do you share data between applications? 2018/05/16 15:03:31 (permalink) ☄ Helpfulby DGTLMAN 2018/05/18 08:53:15
0
Creating an application auto generates two files, app.c and app.h ... and inserts calls to APP_Initialize in the system_init.c file, as well as APP_Tasks in system_tasks.c (ctrl click around in main.c and you can find whats going on)
 
There is also some #includes that go various places, and I'm sure some other behind the scenes harmony stuff.
 
The app.c file will automatically have near the top: APP_DATA appData; You can add your variables into this data structure, or into the app.c file wherever. The harmony examples do this either way on occasion. Other application's source files won't be able to 'see' these variables. 
 
If you need across-application data exchange, you could use an extern ... which I've moved away from as it can create some spaghetti code and sometimes code that compiles fine, then runs and crashes for weird reasons (like inconsistent data lengths for arrays... ). 
 
I've been making a lot of functions that look like...

APP_GetFlag() {
    return(appData.flag);
}

... and making sure to put the prototypes in the header to make them accessible to other tasks.
 
not sure this is the best approach, but it's where I've ended up. Curious to see the other responses here. One problem I've had is when you want to copy an application into another project, it is now dependent on another application that's maybe not there, causing build errors. 
#4
Jump to:
© 2018 APG vNext Commercial Version 4.5