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