struggling with a design approach ......

M

ma740988

Consider a board with two processors A and B. A receive 16 MiB of data
in 2 MiB chunks.
Upon receipt of data A will 'keep' the first 8 MiB. The remainder A
will B will transfer to B.

My current approach works but I question the maintainability.
Because of 'board specific API calls' I'll provide a pseduo code
version of my current approach on the the board with the two
processors.

So now:
size_t const kilobyte(1024);
size_t const mebibyte(kilobyte*kilobyte);
bool new_msg_available(true); // assume true first time
unsigned int count(0);
size_t const payload(2 * mebibyte);
size_t source[payload];
size_t dest[8 * mebibyte];
size_t dest2[8 * mebibyte];

void test_func::rx_data_from_sender()
{
while (1)
{
// semTake (some_sema, -1);<- wait forever on a semaphore [1]

if ( new_msg_available )
{
size_t const msg_size(16 * mebibyte); // [2]
size_t const num_runs = msg_size / mebibyte;
//size_t const distribution = msg_size / payload;
new_msg_available = false;
count = 0;
}

if (count < (num_runs / 2))
{
memcpy(source, dest, payload); [3]
++count;
}

if (count >= num_runs ) // now 'copy' to B's memory
{
memcpy(source, dest2, payload);
++count;
}
if (count == num_runs) new_msg_available = true; // reset
}
}
Item [1] is RTOS 'functionality'
[2] The size varies and is obtained from a header. For demonstration
purposes I hard coded it.
[3] is not a memcpy but we use memcpy for demonstration purposes.

This of course is a synopsis. I suspect - perhaps - a chain of
responsibility approach would suffice here because in reality I ahve 4
processors on card. The example only show 2.

I'd like to be able to derive from a class and have objects maintain
their own state. When object A is done it hands off to B. B when
complete will 'reset'. I'm having a hard time determining how to do
this. Sample source appreaciated.

Thanks
 
D

Dave Rahardja

Consider a board with two processors A and B. A receive 16 MiB of data
in 2 MiB chunks.
Upon receipt of data A will 'keep' the first 8 MiB. The remainder A
will B will transfer to B.

It sounds like you could use a state machine. Hint:

enum state_t { RECEIVING_FIRST_HALF, RECEIVING_SECOND_HALF };

state_t state = RECEIVING_FIRST_HALF;

/* ... */

while (true) {
switch (state) {
case RECEIVING_FIRST_HALF:
/* ... */
if (received_bytes >= SOME_THRESHOLD) {
state = RECEIVING_SECOND_HALF;
}
break;

case RECEIVING_SECOND_HALF:
/* ... */
if (received_bytes >= SOME_OTHER_THRESHOLD) {
state = RECEIVING_FIRST_HALF;
}
break;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top