 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
ma740988@gmail.com Guest
|
Posted: Thu Sep 29, 2005 10:23 pm Post subject: struggling with a design approach ...... |
|
|
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
|
|
| Back to top |
|
 |
Dave Rahardja Guest
|
Posted: Sat Oct 01, 2005 5:28 am Post subject: Re: struggling with a design approach ...... |
|
|
On 29 Sep 2005 15:23:08 -0700, [email]ma740988 (AT) gmail (DOT) com[/email] wrote:
| Quote: | 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;
}
}
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|