Note that there are some explanatory texts on larger screens.

plurals
  1. POUART ISR Tx Rx Architecture
    primarykey
    data
    text
    <p>Am I complicating things?</p> <p>I'm architecting my code to talk from a 8051 micro to a peripheral device over UART. The peripheral responds to commands from the host and can only respond to one command at a time. It's a simple send and receive protocol. (tx1, rx1, tx2, rx2, tx3, rx3) Each TX message is terminated with a CR, each response is terminated with a >. I can't send a new message until I receive the response to the last one. Responses can also echo print the original TX message in the beginning if I enable that option (but this causes more traffic)</p> <p>An example message would be:</p> <ul> <li>TX: Hello </li> <li>RX: World!></li> </ul> <p>Or with echo option...</p> <ul> <li>TX: Hello</li> <li>RX: Hello\rWorld!></li> </ul> <p><strong>Option A</strong> A function such as getHello would consist of both the send and receive. A parallel ISR routine would gather the incoming bytes and throw a flag when the '>' character is received. </p> <pre><code>char* getHello(char * buf){ sendMsg("Hello\r"); delay(10ms); //wait a little bit //wait for receive to come in or timeout to occur while(!receiveFlag || !timeoutFlag); //thrown by ISR receiveMsg(buf); //parse the message and do some other stuff return buf; } </code></pre> <p><em>Pros:</em> </p> <ul> <li>Everything is contained within one function. </li> <li>Easier to debug</li> </ul> <p><em>Cons:</em> </p> <ul> <li>This function is blocking and could hang if the peripheral never responds so a timeout must be implemented. </li> <li>Messages can't be received out of order, must be in series (ie, tx1, rx1, tx2, rx2, tx3, rx3)</li> </ul> <p><strong>Option B</strong> A parallel approach is taken. Two separate functions would created. one to send the message, and one that would vertexed upon receiving a response from the ISR.</p> <pre><code>void sendHello(){ sendMsg("Hello\r"); //do some other stuff if needed } char* receiveMsg(char * buf){ //figure out from echo print what the tx message was //use a switch statement to decide which response parser to call switch(txMessage){ //pseudo code case "Hello": receiveMsg(buf); //parse the message and do some other stuff break; } return buf; } </code></pre> <p><em>Pros:</em> </p> <ul> <li>Can handle parallel messages coming back out of order because it relies on the echo printing of the tx message to figure out how to parse it. (ie, tx1, tx2, tx3, rx1,rx2,rx3)</li> </ul> <p><em>Cons:</em> </p> <ul> <li>quite difficult to debug</li> <li>spawns multiple threads</li> <li>lots of extra code</li> <li>not worth it since messages will definitely come back in order</li> </ul> <hr> <p>Right now, I'm doing Option B, but as I continue on with the project, I begin to feel like this is getting overly complex. I'm curious what you guys think.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload