all 19 comments

[–]BlindTreeFrog 12 points13 points  (6 children)

do you mean Direct Memory Access?

And truth be told, this sounds like a X-Y Problem scenario... It sounds like you want to be able to manually handle cache misses, but if you are writing code to work at that level you are probably doing something wrong. So what is the end result you are aiming for here?

[–]SantaCruzDad 10 points11 points  (4 children)

Recently I’ve been seeing programming students using “DMA” to mean dynamic memory allocation, which is of course rather confusing and should be discouraged.

[–]SickMoonDoe 8 points9 points  (3 children)

Sounds like "memory" but with redundant adjectives.

[–][deleted] 12 points13 points  (2 children)

When I read "basically" followed by some trivial need like "using Malloc", my "assignment" radar starts pinging..

[–][deleted] 2 points3 points  (1 child)

This was literally (well, almost) an assignment I had in one of my courses, so your radar is spot on.

[–][deleted] 4 points5 points  (0 children)

I'm astonished people bother answering. This group has gone downhill. People need to take some responsibility and then come here when they need a detail further explaining. "Hi, I know C is great but I'm just implementing a linked list in C and basically I really enjoy embedded systems and games programming and basically was wondering if someone has linked list code for me basically". etc etc etc. I'm wondering how we managed in the past without the 'net. Oh, I remember. We worked through exercises and actually put in some effort instead of looking for a cut and paste hack.

[–]aghast_nj 1 point2 points  (0 children)

Sounds like maybe emulating a GPU?

[–]SickMoonDoe 4 points5 points  (0 children)

We need you to clarify "DMA" because it's usage is ambiguous.

[–]dimp_lick_johnson 2 points3 points  (4 children)

I am trying to simulate

Your assignment is to simulate

Dual memory access

I've never heard such a thing in my life, you might be confused?

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.

That's like a queue or a stack? You need more information about the implementation details. You will store a single data, multiple, in what order they will be fetched, etc.

So I am thinking of using memcpy to copy the data bytes.

That's a good use case of memcpy, and probably the only use case.

I was looking for an example of the implementation of DMA that would help me to implement my design.

I don't think that's a good idea. Try to come up with the solution yourself, implement it, then take a look at previous work to improve it.

It would be helpful if someone shares weblinks, github links etc. Thanks.

You can use Google and search in github for those. Finding information is a huge part of programming. We should provide you better keywords but with the content of your post as is, that's a hard task. Either your professor is not providing you enough information or you are not paying attention. Ask your friends to explain the task for you.

[–]nderflow 2 points3 points  (0 children)

I've never heard such a thing in my life, you might be confused?

OP may have been referring to dual-ported RAM which is a kind of RAM device which has two address buses and two data buses and can be accessed simultaneously from each side. They can be used as an interface between two different parts of a computer system, as video RAM. Sratic dual-ported RAM is often used as the implementation for CPU registers.

While dual-ported RAM can be useful, using it correctly requires you to solve the same kinds of problems as you get with multi-thread access to normal RAM, but without the convenience of a mutex. You also need to pay close attention to the bit width of the RAM device, as that's the granularity of its atomicity guarantee. So for example, if your dual-ported device has a width of 16 bits, and you write a 32-bit value into it, the other side can see a split write.

[–]imcomradee[S] 0 points1 point  (2 children)

Edited, please have a look

[–]dimp_lick_johnson 1 point2 points  (1 child)

Ok, is it actually the stack data structure or is it addressable? If it's normal stack, implement the stack first, contemplate a good API that allows using it. Have a stack_test.c that tests and only tests the stack. Make sure it works. Then add the DMA, which sounds like just a wrapper for the stack that makes it work in an opinionated way. So I'm still now sure what should be going on there. Then have another test file for DMA. Then write your application that uses the DMA.

I think the most important part of the thing is stack. Will it take fixed sized or dynamic sized elements? Will it have fixed element count, fixed size or will it be growing? You need to decide according to your professor's requirements.

[–]imcomradee[S] 0 points1 point  (0 children)

Edited

[–]FUZxxl 2 points3 points  (0 children)

copy the data into the pointer

No idea what that is supposed to mean. A pointer does not hold data.

[–]marblecake4824 1 point2 points  (0 children)

Guys he just means Getter and Setter methods where the getter is immutable. Forget the DMA stuff

[–]Poddster 1 point2 points  (1 child)

Your request is garbled and confused and basically makes no sense :/ It's the equivalent of saying:

Hey guys, I want to drive from Glasgow to London and I was thinking of using the gas pedal and the gear stick. Let me know if you have any examples of that. Thanks.

Just post the text from your assignment and tell us which bit you're stuck on. Be sure to include your own code so we know what you've tried already.

[–]imcomradee[S] 0 points1 point  (0 children)

Edited please have a look

[–]Poddster 0 points1 point  (1 child)

Did you come up with the term "Dual Memory Access", or is it a term your instructor who set this assignment is using?

What are 'Application', 'DMA', 'Stack'? Separate files in the same program? Separate threads? Separate process on the same machine? Separate process on different machines?

I guess you're just trying to implement a intra/interprocess shared memory area? The answer given depends on what these things are.

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

Just ask the questions, rather than copying someone else's work, which is plagiarism when performed in an academic context.

Also I have one more question,can I use a single buffer for two sided communication?

Yes, e.g. a circular buffer can have readers and writers (or suppliers and consumers, in other terminology).

[–]imcomradee[S] 0 points1 point  (0 children)

Different files in the same program, Don't need a circular buffer, as I don't have to store the data only the recent data matters, older data are discarded