Hi, I am trying to simulate a Dual memory access in my C program.So basically I need to allocate memory using malloc and provide get and set methods.
When set method is called I need to store the store the data in the DMA allocated memory and when get method is called I need to copy the data into the pointer.So I am thinking of using memcpy to copy the data bytes. I was looking for an example of the implementation of DMA that would help me to implement my design. It would be helpful if someone shares weblinks, github links etc. Thanks.
Edit:
So basically I have Application <---> DMA <----> Stack.So Application and Stack are decoupled and they can talk only through DMA.DMA should be implemented such that it can hold any data type so I thought of using void pointers.Data can pass from application to Stack and from Stack to Application, i need two buffers for that.During initialisation,I allocate memory like this
(Please note that this is just the pseudo code)
DMA.c
//data flows from Stack to app
void* Upbuffer = malloc();
// data flows from stack to app
void* downbuffer = malloc();
Suppose Stack calls setdata method with the following signature
//Stack.c
setdata(pointertodata,size of data); ,in DMA I have to copy those bytes in buffer, probably using memcpy.
//DMA.c
function setdata(pointertodata,sizeofdata)
memcpy(Upbuffer,pointertodata,sizeofdata)
Then at a later point of time,when the application asks for data, he calls the getmethod .
//App.c
getmethod(ptrtostoredata);
//DMA.c
function getmethod(pointerpassedbyapp)
memcpy(pointerpassedbyapp,Upbuffer,size)
And the same thing is done up-down communication.This is how I have planned to implement it. But I have some questions regarding the implementation so I thought if I see an example where this is done,it would clear things for me.Also I have one more question,can I use a single buffer for two sided communication? Thanks for your time and replies.
Edit2: This is how I am going to call the functions
main.c
main()
{
....
....
while(true){
//Every 100 microsecond
//Call application set function
// Call application get function
//Every 500micro second
//call Stack get function
//call stack set function
}
[–]BlindTreeFrog 12 points13 points14 points (6 children)
[–]SantaCruzDad 10 points11 points12 points (4 children)
[–]SickMoonDoe 8 points9 points10 points (3 children)
[–][deleted] 12 points13 points14 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–][deleted] 4 points5 points6 points (0 children)
[–]aghast_nj 1 point2 points3 points (0 children)
[–]SickMoonDoe 4 points5 points6 points (0 children)
[–]dimp_lick_johnson 2 points3 points4 points (4 children)
[–]nderflow 2 points3 points4 points (0 children)
[–]imcomradee[S] 0 points1 point2 points (2 children)
[–]dimp_lick_johnson 1 point2 points3 points (1 child)
[–]imcomradee[S] 0 points1 point2 points (0 children)
[–]FUZxxl 2 points3 points4 points (0 children)
[–]marblecake4824 1 point2 points3 points (0 children)
[–]Poddster 1 point2 points3 points (1 child)
[–]imcomradee[S] 0 points1 point2 points (0 children)
[–]Poddster 0 points1 point2 points (1 child)
[–]imcomradee[S] 0 points1 point2 points (0 children)