Re: How to read/write an 'address' from a memory location......
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Mon, 22 Oct 2007 17:28:56 -0400
aeroboro221@xxxxxxxxxxxxxx wrote:
.... snip ...
My problem is: I have two processors exchanging data over a shared
section of memory. Now before processor 1 can write the data for
processor 2 (in the shared memory), processor 1 needs to tell
processor 2 where exactly it will be writing. Thats where i was
coming from - processor 1 basically needs to write an "address"
into a predefined location for processor 2 and that "address" will
hold the actual data for processor 2.
That is outside the abilities of the C language, which has no
intrinsic knowledge of multiple processes and managing them.
However, if your description is adequate, the following might work:
Global (common memory):
int running = 1;
Type *ptr = NULL;
Sender code fragment:
do {
/* prepare data */
while (ptr && running) continue;
if (running) {
ptr = malloc(sizeof *ptr);
*ptr = data;
}
} while (running)'
Receiver code fragment:
do {
while (!ptr && running) continue;
if (running) {
rcvdata = *ptr;
free(*ptr);
ptr = NULL;
/* process rcvdata */
}
} while (running);
Note that either process can shut down the interaction by setting
running to zero. Sender has a local variable named data, and
receiver has one named rcvdata. The processes are in strict sync,
i.e. one item of data causes one item to be transmitted, and
nothing more is done until that item is received. Similarly the
receiver can do nothing while waiting for new data to be prepared.
Note that malloc failing in sender is a fatal error. The
initialization values ensure that the sender runs first. The
definition of 'Type' controls the amount of data transferred. The
'continue' statements can be changed into function calls to do
other things.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com
.
- Follow-Ups:
- Re: How to read/write an 'address' from a memory location......
- From: aeroboro221
- Re: How to read/write an 'address' from a memory location......
- From: aeroboro221
- Re: How to read/write an 'address' from a memory location......
- References:
- How to read/write an 'address' from a memory location......
- From: aeroboro221
- Re: How to read/write an 'address' from a memory location......
- From: Hans-Bernhard Bröker
- Re: How to read/write an 'address' from a memory location......
- From: aeroboro221
- How to read/write an 'address' from a memory location......
- Prev by Date: Re: Languages for embedded
- Next by Date: Re: How to read/write an 'address' from a memory location......
- Previous by thread: Re: How to read/write an 'address' from a memory location......
- Next by thread: Re: How to read/write an 'address' from a memory location......
- Index(es):
Relevant Pages
|