update docs
[web/altusmetrum] / AltOS / doc / companion.html
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <meta http-equiv="X-UA-Compatible" content="IE=edge">
6 <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 <meta name="generator" content="Asciidoctor 2.0.10">
8 <meta name="author" content="Keith Packard, Bdale Garbee">
9 <meta name="copyright" content="Bdale Garbee and Keith Packard 2018">
10 <title>AltOS Companion Port</title>
11 <link rel="stylesheet" href="./am.css">
12 </head>
13 <body class="article">
14 <div id="header">
15 <h1>AltOS Companion Port</h1>
16 <div class="details">
17 <span id="author" class="author">Keith Packard</span><br>
18 <span id="email" class="email"><a href="mailto:keithp@keithp.com">keithp@keithp.com</a></span><br>
19 <span id="author2" class="author">Bdale Garbee</span><br>
20 <span id="email2" class="email"><a href="mailto:bdale@gag.com">bdale@gag.com</a></span><br>
21 <span id="revdate">15 Jun 2020</span>
22 </div>
23 <div id="toc" class="toc">
24 <div id="toctitle">Table of Contents</div>
25 <ul class="sectlevel1">
26 <li><a href="#_license">License</a></li>
27 <li><a href="#_companion_port">Companion Port</a></li>
28 <li><a href="#_companion_spi_protocol">Companion SPI Protocol</a></li>
29 <li><a href="#_spi_message_formats">SPI Message Formats</a>
30 <ul class="sectlevel2">
31 <li><a href="#_setup_reply_message">SETUP reply message</a></li>
32 <li><a href="#_fetch_reply_message">FETCH reply message</a></li>
33 </ul>
34 </li>
35 <li><a href="#_history_and_motivation">History and Motivation</a></li>
36 </ul>
37 </div>
38 </div>
39 <div id="content">
40 <div id="preamble">
41 <div class="sectionbody">
42 <div id="logo" class="imageblock">
43 <div class="content">
44 <a class="image" href="https://altusmetrum.org"><img src="altusmetrum-oneline.svg" alt="Altus Metrum"></a>
45 </div>
46 </div>
47 </div>
48 </div>
49 <div class="sect1">
50 <h2 id="_license">License</h2>
51 <div class="sectionbody">
52 <div class="paragraph">
53 <p>Copyright © 2018 Bdale Garbee and Keith Packard</p>
54 </div>
55 <div class="paragraph">
56 <p>This document is released under the terms of the <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons ShareAlike 3.0 License</a></p>
57 </div>
58 </div>
59 </div>
60 <div class="sect1">
61 <h2 id="_companion_port">Companion Port</h2>
62 <div class="sectionbody">
63 <div class="paragraph">
64 <p>Many Altus Metrum products come with an eight pin Micro MaTch
65 connector, called the Companion Port. This is often used to
66 program devices using a programming cable. However, it can
67 also be used to connect TeleMetrum to external companion
68 boards (hence the name).</p>
69 </div>
70 <div class="paragraph">
71 <p>The Companion Port provides two different functions:</p>
72 </div>
73 <div class="ulist">
74 <ul>
75 <li>
76 <p>Power. Both battery-level and 3.3V regulated power are
77 available. Note that the amount of regulated power is not
78 huge; TeleMetrum contains a 150mA regulator and uses, at
79 peak, about 120mA or so. For applications needing more than
80 a few dozen mA, placing a separate regulator on them and
81 using the battery for power is probably a good idea.</p>
82 </li>
83 <li>
84 <p>SPI. The flight computer operates as a SPI master, using
85 a protocol defined in this document. Companion boards
86 provide a matching SPI slave implementation which supplies
87 telemetry information for the radio downlink during flight</p>
88 </li>
89 </ul>
90 </div>
91 </div>
92 </div>
93 <div class="sect1">
94 <h2 id="_companion_spi_protocol">Companion SPI Protocol</h2>
95 <div class="sectionbody">
96 <div class="paragraph">
97 <p>The flight computer implements a SPI master communications
98 channel over the companion port, and uses this to get
99 information about a connected companion board and then to get
100 telemetry data for transmission during flight.</p>
101 </div>
102 <div class="paragraph">
103 <p>At startup time, the flight computer sends a setup request
104 packet, and the companion board returns a board identifier,
105 the desired telemetry update period and the number of data
106 channels provided. The flight computer doesn&#8217;t interpret the
107 telemetry data at all, simply packing it up and sending it
108 over the link.  Telemetry packets are 32 bytes long, and
109 companion packets use 8 bytes as a header leaving room for a
110 maximum of 12 16-bit data values.</p>
111 </div>
112 <div class="paragraph">
113 <p>Because of the limits of the AVR processors used in the first
114 two companion boards, the SPI data rate is set to 187.5kbaud.</p>
115 </div>
116 </div>
117 </div>
118 <div class="sect1">
119 <h2 id="_spi_message_formats">SPI Message Formats</h2>
120 <div class="sectionbody">
121 <div class="paragraph">
122 <p>This section first defines the command message format sent from
123 the flight computer to the companion board, and then the various
124 reply message formats for each type of command message.</p>
125 </div>
126 <table class="tableblock frame-all grid-all stretch">
127 <caption class="title">Table 1. Companion Command Message</caption>
128 <colgroup>
129 <col style="width: 6.25%;">
130 <col style="width: 18.75%;">
131 <col style="width: 18.75%;">
132 <col style="width: 56.25%;">
133 </colgroup>
134 <tbody>
135 <tr>
136 <td class="tableblock halign-left valign-top"><p class="tableblock">Offset</p></td>
137 <td class="tableblock halign-left valign-top"><p class="tableblock">Data Type</p></td>
138 <td class="tableblock halign-left valign-top"><p class="tableblock">Name</p></td>
139 <td class="tableblock halign-left valign-top"><p class="tableblock">Description</p></td>
140 </tr>
141 <tr>
142 <td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
143 <td class="tableblock halign-left valign-top"><p class="tableblock">uint8_t</p></td>
144 <td class="tableblock halign-left valign-top"><p class="tableblock">command</p></td>
145 <td class="tableblock halign-left valign-top"><p class="tableblock">Command identifier</p></td>
146 </tr>
147 <tr>
148 <td class="tableblock halign-left valign-top"><p class="tableblock">1</p></td>
149 <td class="tableblock halign-left valign-top"><p class="tableblock">uint8_t</p></td>
150 <td class="tableblock halign-left valign-top"><p class="tableblock">flight_state</p></td>
151 <td class="tableblock halign-left valign-top"><p class="tableblock">Current flight computer state</p></td>
152 </tr>
153 <tr>
154 <td class="tableblock halign-left valign-top"><p class="tableblock">2</p></td>
155 <td class="tableblock halign-left valign-top"><p class="tableblock">uint16_t</p></td>
156 <td class="tableblock halign-left valign-top"><p class="tableblock">tick</p></td>
157 <td class="tableblock halign-left valign-top"><p class="tableblock">Flight computer clock (100 ticks/second)</p></td>
158 </tr>
159 <tr>
160 <td class="tableblock halign-left valign-top"><p class="tableblock">4</p></td>
161 <td class="tableblock halign-left valign-top"><p class="tableblock">uint16_t</p></td>
162 <td class="tableblock halign-left valign-top"><p class="tableblock">serial</p></td>
163 <td class="tableblock halign-left valign-top"><p class="tableblock">Flight computer serial number</p></td>
164 </tr>
165 <tr>
166 <td class="tableblock halign-left valign-top"><p class="tableblock">6</p></td>
167 <td class="tableblock halign-left valign-top"><p class="tableblock">uint16_t</p></td>
168 <td class="tableblock halign-left valign-top"><p class="tableblock">flight</p></td>
169 <td class="tableblock halign-left valign-top"><p class="tableblock">Flight number</p></td>
170 </tr>
171 <tr>
172 <td class="tableblock halign-left valign-top"><p class="tableblock">8</p></td>
173 <td class="tableblock halign-left valign-top"></td>
174 <td class="tableblock halign-left valign-top"></td>
175 <td class="tableblock halign-left valign-top"></td>
176 </tr>
177 </tbody>
178 </table>
179 <table class="tableblock frame-all grid-all stretch">
180 <caption class="title">Table 2. Companion Command Identifiers</caption>
181 <colgroup>
182 <col style="width: 7.6923%;">
183 <col style="width: 23.0769%;">
184 <col style="width: 69.2308%;">
185 </colgroup>
186 <tbody>
187 <tr>
188 <td class="tableblock halign-left valign-top"><p class="tableblock">Value</p></td>
189 <td class="tableblock halign-left valign-top"><p class="tableblock">Name</p></td>
190 <td class="tableblock halign-left valign-top"><p class="tableblock">Description</p></td>
191 </tr>
192 <tr>
193 <td class="tableblock halign-left valign-top"><p class="tableblock">1</p></td>
194 <td class="tableblock halign-left valign-top"><p class="tableblock">SETUP</p></td>
195 <td class="tableblock halign-left valign-top"><p class="tableblock">Supply the flight computer with companion
196 information</p></td>
197 </tr>
198 <tr>
199 <td class="tableblock halign-left valign-top"><p class="tableblock">2</p></td>
200 <td class="tableblock halign-left valign-top"><p class="tableblock">FETCH</p></td>
201 <td class="tableblock halign-left valign-top"><p class="tableblock">Return telemetry information</p></td>
202 </tr>
203 <tr>
204 <td class="tableblock halign-left valign-top"><p class="tableblock">3</p></td>
205 <td class="tableblock halign-left valign-top"><p class="tableblock">NOTIFY</p></td>
206 <td class="tableblock halign-left valign-top"><p class="tableblock">Tell companion board when flight state changes</p></td>
207 </tr>
208 </tbody>
209 </table>
210 <div class="paragraph">
211 <p>The flight computer will send a SETUP message shortly after
212 power-up and will then send FETCH messages no more often than
213 the rate specified in the SETUP reply. NOTIFY messages will be
214 sent whenever the flight state changes.</p>
215 </div>
216 <div class="paragraph">
217 <p>'flight_state' records the current state of the flight,
218 whether on the pad, under power, coasting to apogee or
219 descending on the drogue or main chute.</p>
220 </div>
221 <div class="paragraph">
222 <p>'tick' provides the current flight computer clock, which
223 be used to synchronize data recorded on the flight computer
224 with that recorded on the companion board in post-flight analysis.</p>
225 </div>
226 <div class="paragraph">
227 <p>'serial' is the product serial number of the flight computer,
228 'flight' is the flight sequence number. Together, these two
229 uniquely identify the flight and can be recorded with any
230 companion board data logging to associate the companion data
231 with the proper flight.</p>
232 </div>
233 <div class="paragraph">
234 <p>NOTIFY commands require no reply at all, they are used solely
235 to inform the companion board when the state of the flight, as
236 computed by the flight computer, changes. Companion boards can
237 use this to change data collection parameters, disabling data
238 logging until the flight starts and terminating it when the
239 flight ends.</p>
240 </div>
241 <div class="sect2">
242 <h3 id="_setup_reply_message">SETUP reply message</h3>
243 <table class="tableblock frame-all grid-all stretch">
244 <caption class="title">Table 3. SETUP reply contents</caption>
245 <colgroup>
246 <col style="width: 6.25%;">
247 <col style="width: 18.75%;">
248 <col style="width: 18.75%;">
249 <col style="width: 56.25%;">
250 </colgroup>
251 <tbody>
252 <tr>
253 <td class="tableblock halign-left valign-top"><p class="tableblock">Offset</p></td>
254 <td class="tableblock halign-left valign-top"><p class="tableblock">Data Type</p></td>
255 <td class="tableblock halign-left valign-top"><p class="tableblock">Name</p></td>
256 <td class="tableblock halign-left valign-top"><p class="tableblock">Description</p></td>
257 </tr>
258 <tr>
259 <td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
260 <td class="tableblock halign-left valign-top"><p class="tableblock">uint16_t</p></td>
261 <td class="tableblock halign-left valign-top"><p class="tableblock">board_id</p></td>
262 <td class="tableblock halign-left valign-top"><p class="tableblock">Board identifier</p></td>
263 </tr>
264 <tr>
265 <td class="tableblock halign-left valign-top"><p class="tableblock">2</p></td>
266 <td class="tableblock halign-left valign-top"><p class="tableblock">uint16_t</p></td>
267 <td class="tableblock halign-left valign-top"><p class="tableblock">board_id_inverse</p></td>
268 <td class="tableblock halign-left valign-top"><p class="tableblock">~board_id—used to tell if a board is present</p></td>
269 </tr>
270 <tr>
271 <td class="tableblock halign-left valign-top"><p class="tableblock">4</p></td>
272 <td class="tableblock halign-left valign-top"><p class="tableblock">uint8_t</p></td>
273 <td class="tableblock halign-left valign-top"><p class="tableblock">update_period</p></td>
274 <td class="tableblock halign-left valign-top"><p class="tableblock">Minimum time (in 100Hz ticks) between FETCH commands</p></td>
275 </tr>
276 <tr>
277 <td class="tableblock halign-left valign-top"><p class="tableblock">5</p></td>
278 <td class="tableblock halign-left valign-top"><p class="tableblock">uint8_t</p></td>
279 <td class="tableblock halign-left valign-top"><p class="tableblock">channels</p></td>
280 <td class="tableblock halign-left valign-top"><p class="tableblock">Number of data channels to retrieve in FETCH command</p></td>
281 </tr>
282 <tr>
283 <td class="tableblock halign-left valign-top"><p class="tableblock">6</p></td>
284 <td class="tableblock halign-left valign-top"></td>
285 <td class="tableblock halign-left valign-top"></td>
286 <td class="tableblock halign-left valign-top"></td>
287 </tr>
288 </tbody>
289 </table>
290 <div class="paragraph">
291 <p>The SETUP reply contains enough information to uniquely
292 identify the companion board to the end user as well as for
293 the flight computer to know how many data values to expect in
294 reply to a FETCH command, and how often to fetch that data.</p>
295 </div>
296 <div class="paragraph">
297 <p>To detect the presence of a companion board, the flight
298 computer checks to make sure that board_id_inverse is the
299 bit-wise inverse of board_id. Current companion boards use
300 USB product ID as the board_id, but the flight computer does
301 not interpret this data and so it can be any value.</p>
302 </div>
303 </div>
304 <div class="sect2">
305 <h3 id="_fetch_reply_message">FETCH reply message</h3>
306 <table class="tableblock frame-all grid-all stretch">
307 <caption class="title">Table 4. FETCH reply contents</caption>
308 <colgroup>
309 <col style="width: 6.25%;">
310 <col style="width: 18.75%;">
311 <col style="width: 18.75%;">
312 <col style="width: 56.25%;">
313 </colgroup>
314 <tbody>
315 <tr>
316 <td class="tableblock halign-left valign-top"><p class="tableblock">Offset</p></td>
317 <td class="tableblock halign-left valign-top"><p class="tableblock">Data Type</p></td>
318 <td class="tableblock halign-left valign-top"><p class="tableblock">Name</p></td>
319 <td class="tableblock halign-left valign-top"><p class="tableblock">Description</p></td>
320 </tr>
321 <tr>
322 <td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
323 <td class="tableblock halign-left valign-top"><p class="tableblock">uint16_t</p></td>
324 <td class="tableblock halign-left valign-top"><p class="tableblock">data0</p></td>
325 <td class="tableblock halign-left valign-top"><p class="tableblock">0th data item</p></td>
326 </tr>
327 <tr>
328 <td class="tableblock halign-left valign-top"><p class="tableblock">2</p></td>
329 <td class="tableblock halign-left valign-top"><p class="tableblock">uint16_t</p></td>
330 <td class="tableblock halign-left valign-top"><p class="tableblock">data1</p></td>
331 <td class="tableblock halign-left valign-top"><p class="tableblock">1st data item</p></td>
332 </tr>
333 <tr>
334 <td class="tableblock halign-left valign-top"><p class="tableblock">&#8230;&#8203;</p></td>
335 <td class="tableblock halign-left valign-top"></td>
336 <td class="tableblock halign-left valign-top"></td>
337 <td class="tableblock halign-left valign-top"></td>
338 </tr>
339 </tbody>
340 </table>
341 <div class="paragraph">
342 <p>The FETCH reply contains arbitrary data to be reported
343 over the flight computer telemetry link. The number of
344 16-bit data items must match the 'channels' value
345 provided in the SETUP reply message.</p>
346 </div>
347 </div>
348 </div>
349 </div>
350 <div class="sect1">
351 <h2 id="_history_and_motivation">History and Motivation</h2>
352 <div class="sectionbody">
353 <div class="paragraph">
354 <p>To allow cross-programming, the original TeleMetrum and
355 TeleDongle designs needed to include some kind of
356 connector. With that in place, adding the ability to connect
357 external cards to TeleMetrum was fairly simple. We set the
358 software piece of this puzzle aside until we had a companion
359 board to use.</p>
360 </div>
361 <div class="paragraph">
362 <p>The first companion board was TeleScience. Designed to collect
363 temperature data from the nose and fin of the airframe, the main
364 requirement for the companion port was that it be able to report
365 telemetry data during flight as a back-up in case the
366 TeleScience on-board data was lost.</p>
367 </div>
368 <div class="paragraph">
369 <p>The second companion board, TelePyro, provides 8 additional
370 channels for deployment, staging or other activities. To avoid
371 re-programming the TeleMetrum to use TelePyro, we decided to
372 provide enough information over the companion link for it to
373 independently control those channels.</p>
374 </div>
375 <div class="paragraph">
376 <p>Providing a standard, constant interface between the flight
377 computer and companion boards allows for the base flight
378 computer firmware to include support for companion boards.</p>
379 </div>
380 </div>
381 </div>
382 </div>
383 <div id="footer">
384 <div id="footer-text">
385 Last updated 2020-06-15 20:50:29 -0600
386 </div>
387 </div>
388 </body>
389 </html>