<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en" style='--code-editor-font: var(--default-mono-font, "GitLab Mono"), JetBrains Mono, Menlo, DejaVu Sans Mono, Liberation Mono, Consolas, Ubuntu Mono, Courier New, andale mono, lucida console, monospace;'>
<head>
<meta content="text/html; charset=US-ASCII" http-equiv="Content-Type">
<title>
GitLab
</title>

<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>

<style>img {
max-width: 100%; height: auto;
}
body {
font-size: .875rem;
}
body {
-webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px;
}
body {
font-family: var(--default-regular-font, "GitLab Sans"),-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style='font-size: inherit; -webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px; font-family: var(--default-regular-font, "GitLab Sans"),-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";'>
<div class="content">

<p class="details" style="font-style: italic; color: #737278;">
<a href="https://gitlab.rtems.org/sebhub">Sebastian Huber</a> created a merge request: <a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/94">!94</a>
</p>
<div class="branch">
Project:Branches: sebhub/rtems:test-packet-processor to rtems/rtos/rtems:main
</div>
<div class="author">
Author: Sebastian Huber
</div>
<div class="assignee">
Assignee: Sebastian Huber
</div>
<div class="reviewer">
Reviewers: 
</div>
<div class="approvers">

</div>
<div class="md gl-mt-5" style="color: #333238; word-wrap: break-word; margin-top: 1rem;">
<h2 dir="auto" style="font-size: 1.5em; font-weight: 600; padding-bottom: .3em; border-bottom-width: 1px; border-bottom-color: #bfbfc3; border-bottom-style: solid; color: #333238; margin: 0 0 16px;" align="initial">
<a href="#summary" aria-hidden="true" class="anchor" id="user-content-summary" style="margin-top: 0; float: left; margin-left: -20px; text-decoration: none; outline: none;"></a>Summary</h2>
<p dir="auto" style="color: #333238; margin: 0 0 16px;" align="initial">libtest: Add packet processor</p>
<p dir="auto" style="color: #333238; margin: 0 0 16px;" align="initial">The RTEMS Test Framework packet processor provides a simple mechanism to exchange reliable and in-order data through transmitting and receiving one character at a time.</p>
<p dir="auto" style="color: #333238; margin: 0 0 16px;" align="initial">The packet processor does not buffer data. The processor uses a stop-and-wait automatic repeat request method. There is at most one packet in transmission. The data transfer is done using a single character input and output method. The protocol uses 12-bit sequence numbers, so a host could use a sliding window method to increase throughput. All integers and data are base64url encoded. A 24-bit CRC is used to ensure the data integrity. The '{' character starts a packet. The '}' character terminates a packet. The '#' character prefixes a 24-bit CRC value. The ':' character separates fields. The '+' character prefixes data fields. The following packets are defined:</p>
<ul dir="auto" style="text-align: initial; list-style-type: disc; margin: 0 0 16px; padding: 0;">
<li style="margin-top: 0; line-height: 1.6em; margin-left: 25px; padding-left: 3px;">hello: {<12-bit seq><12-bit ack>:H#<24-bit CRC>}</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">acknowledge: {<12-bit seq><12-bit ack>:A#<24-bit CRC>}</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">reject: {<12-bit seq><12-bit ack>:R :<12-bit seq of rejected packet> #<24-bit CRC>}</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">signal: {<12-bit seq><12-bit ack>:S :<64-bit signal number> :<64-bit signal value> <optional list of colon separated 64-bit values> #<24-bit CRC>}</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">channel: {<12-bit seq><12-bit ack>:C :<64-bit channel number> :<64-bit channel data size> <optional list of colon separated 64-bit values> #<24-bit CRC> + #<24-bit CRC>}</li>
</ul>
<p dir="auto" style="color: #333238; margin: 0 0 16px;" align="initial">The intended use case are boot loaders and test runners. For example, test runners may interface with an external test server performing equipment handling on request using the packet processor.</p>
<p dir="auto" style="color: #333238; margin: 0 0 16px;" align="initial">Use T_packet_initialize() to initialize the packet processor. Use T_packet_process() to drive the packet processing. You can enqueue packets for transmission with T_packet_enqueue(). You can reliably send signals with T_packet_send(). You can reliably, in-order transmit and receive channel data with T_packet_channel_push() and T_packet_channel_exchange().</p>
<p dir="auto" style="color: #333238; margin: 0 0 16px;" align="initial">A simple boot loader for test runs could be implemented like this:</p>
<p dir="auto" style="color: #333238; margin: 0 0 16px;" align="initial">#include <bsp.h> #include <rtems/bspIo.h> #include <rtems/counter.h> #include <rtems/test-packet.h></p>
<p dir="auto" style="color: #333238; margin: 0 0 16px;" align="initial">typedef struct { T_packet_event_control base; uint8_t *load_address; } boot_control;</p>
<p dir="auto" style="color: #333238; margin: 0 0 16px;" align="initial">static void output_char(T_packet_control* self, uint8_t ch) { (void)self; rtems_putc(ch); }</p>
<p dir="auto" style="color: #333238; margin: 0 0 16px;" align="initial">static T_packet_status event_handler(T_packet_control* self, T_packet_event_control* base, T_packet_event evt) { boot_control* evt_ctrl = (boot_control*)base;</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre class="code highlight js-syntax-highlight language-plaintext" v-pre="true" style='display: block; font-size: 14px; color: #333238; line-height: 1.6em; overflow-x: auto; border-radius: 4px; position: relative; font-family: var(--default-mono-font, "GitLab Mono"),"JetBrains Mono","Menlo","DejaVu Sans Mono","Liberation Mono","Consolas","Ubuntu Mono","Courier New","andale mono","lucida console",monospace; word-break: break-all; word-wrap: break-word; background-color: #fbfafd; margin: 0 0 16px; padding: 12px; border: 1px solid #dcdcde;'><code style='font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: 4px; white-space: pre; margin-top: 0; font-family: var(--default-mono-font, "GitLab Mono"),"JetBrains Mono","Menlo","DejaVu Sans Mono","Liberation Mono","Consolas","Ubuntu Mono","Courier New","andale mono","lucida console",monospace; vertical-align: bottom; overflow-wrap: normal; padding: unset;'><span id="LC1" class="line" lang="plaintext" style="margin-top: 0;">switch (evt) {</span>
<span id="LC2" class="line" lang="plaintext">  case T_PACKET_EVENT_SIGNAL:</span>
<span id="LC3" class="line" lang="plaintext">if (T_packet_get_signal_number(self) == 0) {</span>
<span id="LC4" class="line" lang="plaintext">  T_packet_output_acknowledge(self);</span>
<span id="LC5" class="line" lang="plaintext">  bsp_restart(T_packet_get_signal_value_as_address(self));</span>
<span id="LC6" class="line" lang="plaintext">}</span>
<span id="LC7" class="line" lang="plaintext"></span>
<span id="LC8" class="line" lang="plaintext">break;</span>
<span id="LC9" class="line" lang="plaintext">  case T_PACKET_EVENT_HELLO:</span>
<span id="LC10" class="line" lang="plaintext">T_packet_output_acknowledge(self);</span>
<span id="LC11" class="line" lang="plaintext">break;</span>
<span id="LC12" class="line" lang="plaintext">  case T_PACKET_EVENT_CHANNEL_BEGIN:</span>
<span id="LC13" class="line" lang="plaintext">if (T_packet_get_channel_number(self) == 0) {</span>
<span id="LC14" class="line" lang="plaintext">  void *address;</span>
<span id="LC15" class="line" lang="plaintext"></span>
<span id="LC16" class="line" lang="plaintext">  if (T_packet_get_extra_count(self) >= 1) {</span>
<span id="LC17" class="line" lang="plaintext">    address = T_packet_get_extra_as_address(self, 0);</span>
<span id="LC18" class="line" lang="plaintext">    evt_ctrl->load_address = address;</span>
<span id="LC19" class="line" lang="plaintext">  } else {</span>
<span id="LC20" class="line" lang="plaintext">    address = evt_ctrl->load_address;</span>
<span id="LC21" class="line" lang="plaintext">  }</span>
<span id="LC22" class="line" lang="plaintext"></span>
<span id="LC23" class="line" lang="plaintext">  T_packet_set_channel_target(self, address);</span>
<span id="LC24" class="line" lang="plaintext">}</span>
<span id="LC25" class="line" lang="plaintext"></span>
<span id="LC26" class="line" lang="plaintext">break;</span>
<span id="LC27" class="line" lang="plaintext">  case T_PACKET_EVENT_CHANNEL_END:</span>
<span id="LC28" class="line" lang="plaintext">if (T_packet_get_channel_number(self) == 0) {</span>
<span id="LC29" class="line" lang="plaintext">  evt_ctrl->load_address += T_packet_get_channel_size(self);</span>
<span id="LC30" class="line" lang="plaintext">  T_packet_output_acknowledge(self);</span>
<span id="LC31" class="line" lang="plaintext">}</span>
<span id="LC32" class="line" lang="plaintext"></span>
<span id="LC33" class="line" lang="plaintext">break;</span>
<span id="LC34" class="line" lang="plaintext">  case T_PACKET_EVENT_OUTPUT_END:</span>
<span id="LC35" class="line" lang="plaintext">rtems_putc('\n');</span>
<span id="LC36" class="line" lang="plaintext">break;</span>
<span id="LC37" class="line" lang="plaintext">  default:</span>
<span id="LC38" class="line" lang="plaintext">break;</span>
<span id="LC39" class="line" lang="plaintext">}</span>
<span id="LC40" class="line" lang="plaintext"></span>
<span id="LC41" class="line" lang="plaintext">return T_PACKET_SUCCESSFUL;</span></code></pre>
<copy-code></copy-code>
</div>
<p dir="auto" style="color: #333238; margin: 0 0 16px;" align="initial">}</p>
<p dir="auto" style="color: #333238; margin: 0 0 16px;" align="initial">static uint32_t clock_monotonic(T_packet_control* self) { (void)self; return rtems_counter_read(); }</p>
<p dir="auto" style="color: #333238; margin: 0 0 16px;" align="initial">static void Init(rtems_task_argument arg) { (void)arg;</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre class="code highlight js-syntax-highlight language-plaintext" v-pre="true" style='display: block; font-size: 14px; color: #333238; line-height: 1.6em; overflow-x: auto; border-radius: 4px; position: relative; font-family: var(--default-mono-font, "GitLab Mono"),"JetBrains Mono","Menlo","DejaVu Sans Mono","Liberation Mono","Consolas","Ubuntu Mono","Courier New","andale mono","lucida console",monospace; word-break: break-all; word-wrap: break-word; background-color: #fbfafd; margin: 0 0 16px; padding: 12px; border: 1px solid #dcdcde;'><code style='font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: 4px; white-space: pre; margin-top: 0; font-family: var(--default-mono-font, "GitLab Mono"),"JetBrains Mono","Menlo","DejaVu Sans Mono","Liberation Mono","Consolas","Ubuntu Mono","Courier New","andale mono","lucida console",monospace; vertical-align: bottom; overflow-wrap: normal; padding: unset;'><span id="LC1" class="line" lang="plaintext" style="margin-top: 0;">T_packet_control self;</span>
<span id="LC2" class="line" lang="plaintext">T_packet_initialize(&self, 0, NULL, output_char, clock_monotonic);</span>
<span id="LC3" class="line" lang="plaintext"></span>
<span id="LC4" class="line" lang="plaintext">boot_control event;</span>
<span id="LC5" class="line" lang="plaintext">event.load_address = NULL;</span>
<span id="LC6" class="line" lang="plaintext">T_packet_prepend_event_handler(&self, &event.base, event_handler);</span>
<span id="LC7" class="line" lang="plaintext"></span>
<span id="LC8" class="line" lang="plaintext">while (true) {</span>
<span id="LC9" class="line" lang="plaintext">  T_packet_process(&self, getchark());</span>
<span id="LC10" class="line" lang="plaintext">}</span></code></pre>
<copy-code></copy-code>
</div>
<p dir="auto" style="color: #333238; margin: 0;" align="initial">}</p>
</div>

</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #737278;">

<br>
<a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/94">View it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.rtems.org">gitlab.rtems.org</a>. <a href="https://gitlab.rtems.org/-/sent_notifications/f12d9d8f4f8360a20d5e87d132943d7f/unsubscribe" target="_blank" rel="noopener noreferrer">Unsubscribe</a> from this thread · <a href="https://gitlab.rtems.org/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link">Manage all notifications</a> · <a href="https://gitlab.rtems.org/help" target="_blank" rel="noopener noreferrer" class="help-link">Help</a>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Merge request","url":"https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/94"}}</script>


</p>
</div>
</body>
</html>