Quick start guide for SSG's MIRTOS for Atmel® microcontrollers

One distinguishing feature of the MIRTOS Operating System is the interactive system command console, implemented using the single ATmega Serial Port USART contained in the 328P Microcontroller (MCU) or the first Serial Port USART in the 1284P or 2560 MCU. Perhaps the easiest way to demonstrate system features is by using the step-by-step "getting your feet wet by doing" demo below.

In addition to MIRTOS loaded on a device with the ATmega microcontroller (e.g., the Arduino® Pro, Arduino Pro Mini, Arduino Uno, SSG Dual-Relay board or SSG WS2812 sequencer device) a USB controller (e.g., an FTDI Basic breakout board) and a terminal emulator program also needed. When generating some debug output, some lines can be up to 101 characters in width. The SSG CommTool program (available at no additional charge for all MIRTOS licensees) runs from the command line and supports all MIRTOS features. All examples below are shown using the CommTool program with the input command shown in this text style. A comment is text that begins with a semicolon, and is not within quotes. Although they are shown in this style, they may be omitted.

Set the terminal program to 57,600 BPS (Bits Per Second.) Note that this is the BPS, which does not have the same meaning as the "baud rate." The term "baud rate" means "state changes per second", which although true in this case is definitely not true with high-speed modems.

Let's begin with the display commands. MIRTOS uses the first 80 bytes of EEPROM. To display all of these system variables use DES or DSE, as shown here. Note that this document was written so you can copy (Control-C) the commands directly from the example below in order to try them:

>DSE
EEPROM contents:
0000:  10 01 00 9F 01 01 96 FF-04 00 FF FF 28 3C 50 FF  ............(.P
0010:  C0 00 3F FF 40 08 03 67-FF 15 74 FF FF FF FF FF  ..?.@..g..t....
0020:  FF 64 05 FF FF 10 FF FF-FF 20 FF 20 00 30 FF FF  .d....... . .0.
0030:  FF FF 06 00 FF FF FF FF-FF FF FF FF FF FF 80 16  ...............
0040:  FF FF 00 31 90 00 FF FF-FF FF F0 01 90 01 B0 00  ...1...........
>                                                                               

Each command action is based on the first letter of the command. The MIRTOS command processor then uses subsequent characters as modifiers, until it encounters the first space (' ') character. Neither the initial command character nor the modifiers are case sensitive for the standard commands which come with MIRTOS (more about that later.) The order of the modifiers is not significant in this case, e.g., "DES" and "DSE" (or "dSe" or "DeS", etc.) should all generate the very same output.

Note that this command is always output in the FOREGROUND. An indication of that is that the '>' prompt is output after the the system EEPROM contents have been displayed. The same information may be output in the BACKGROUND by explicitly stating the range to be displayed, which is 0 to 80, as shown below (with the '>' prompt being shown immediately after the "contents" line, before the actual data lines, and, in fact, causing the first data line to be right-shifted one position):

>DE 0 80
EEPROM contents:
>0000:  10 01 00 9F 01 01 96 FF-04 00 FF FF 28 3C 50 FF  ............(.P
0010:  C0 00 3F FF 40 08 03 67-FF 15 74 FF FF FF FF FF  ..?.@..g..t....
0020:  FF 64 05 FF FF 10 FF FF-FF 20 FF 20 00 30 FF FF  .d....... . .0.
0030:  FF FF 06 00 FF FF FF FF-FF FF FF FF FF FF 80 16  ...............
0040:  FF FF 00 31 90 00 FF FF-FF FF F0 01 90 01 B0 00  ...1...........
>                                                                               

Refer to the EEPROM map manual page for more information about how the 80 bytes of system EEPROM are utilized.

In the example below, the first 256 bytes of the 328P SRAM are displayed. These are actually all of the MCU's registers. The first 32 (0 through 0x1F) are its named Registers R0 through R31, the next 64 (0x20 to 0x5F) are its I/O registers and the last 160 (0x60 through 0xA0) are its remaining extended I/O registers. The internal general use SRAM begins at address 256 (= 0x100.) Note that the values in the "Reserved" 328P registers generally have very similar (if not the same) values, but are certainly not always "0xB8" as shown below:

>d 0 0x100
SRAM contents:
>0000:  00 00 BE 0E 5D 09 28 10-04 90 00 00 0C 00 A9 08  ....].(.........
0010:  10 0E 01 82 0A 00 00 2E-2D 00 FF 00 B6 08 1F 00  ........-.......
0020:  B8 B8 B8 00 A7 00 20 3F-20 8F 70 8C B8 B8 B8 B8  ...... ? .p.....
0030:  B8 B8 B8 B8 B8 06 27 07-B8 B8 B8 00 00 00 00 00  ......'.........
0040:  FF 1A 00 00 03 03 4A 00-00 B8 02 80 00 00 00 B8  ......J.........
0050:  10 FF B8 00 00 02 35 00-B8 15 B8 00 15 A5 08 83  ......5.........
0060:  0E 00 B8 B8 00 B8 A0 B8-00 00 B8 00 00 00 01 00  ................
0070:  00 B8 B8 B8 B8 B8 B8 B8-E0 00 87 00 4F B8 00 00  ............O...
0080:  01 03 00 15 68 00 11 00-00 00 00 00 B8 B8 B8 B8  ....h...........
0090:  B8 B8 B8 B8 B8 B8 B8 B8-B8 B8 B8 B8 B8 B8 15 B8  ................
00A0:  B8 B8 15 B8 B8 15 B8 B8-B8 B8 B8 B8 B8 B8 B8 B8  ................
00B0:  01 04 06 00 00 B8 00 B8-00 F8 FE FF 00 00 B8 B8  ................
00C0:  42 B8 06 B8 10 00 30 B8-B8 B8 B8 B8 B8 B8 B8 B8  B.....0.........
00D0:  B8 B8 B8 B8 B8 B8 B8 B8-B8 B8 B8 B8 B8 B8 B8 B8  ................
00E0:  B8 B8 B8 B8 B8 15 B8 B8-15 B8 B8 B8 B8 B8 B8 B8  ................
00F0:  B8 B8 B8 B8 B8 B8 B8 B8-B8 B8 B8 B8 B8 B8 B8 B8  ................
                                                                                

An example: The value at address 0xC4 above is 0x10, which is called UBRROL in the ATmega328 register summary. If one were to enter "ES 0xC4 = 8", for example, it would immediately double the communication rate (from 57,600 Bits Per Second (BPS) to 115,200 BPS, in this example.) When the unit reboots, it will not retain this value, so this would be a good way to test a new BPS value before changing it using the WORD at EEPROM address 0x3E. From the prior example, that value was shown as "80 16", which is the hexadecimal value 0x1680. The 328P uses little-endian data storage and retrieval system, so MIRTOS follows suit. What does 0x1680 have to do with anything regarding the communication rate? Let's see ...

>? 0x1680
5760
>                                                                               

The expected active comm rate is 57,600 BPS. So the value at EEPROM address 0x3E is the desired comm rate / 10. It would be 960 for 9600 BPS, and 2880 for 28,800 BPS, 3456 for 34,560 BPS (which is not exactly a standard comm rate.) The CommTool program can initialize the port to non-standard BPS rates. Note that the new COM rate may not exactly match the terminal program's comm rate. This is because UARTs do not set precise BPS rates, they use divisors so there are often some differences between higher BPS rates which can cause communication link to fail. With CommTool, it's occasionally necessary to set its BPS rate to something in the 58,000 to 59,000 range to allow the two devices to establish communication.

Let's return to our step-through examples. If "D" alone is used, for example, the entire MCU SRAM will be output in the BACKGROUND. This example shows an edited version of that, with the highest addresses displaying a portion of the MCU's stack contents:

>d
SRAM contents:
>0000:  00 00 BE 0E 5D 09 28 10-04 90 00 00 0C 00 A9 08  ....].(.........
0010:  10 0E 01 82 0A 00 00 2E-2D 00 FF 00 B6 08 1F 00  ........-.......
0020:  B8 B8 B8 00 A7 00 20 3F-20 8F 70 8C B8 B8 B8 B8  ...... ? .p.....
0030:  B8 B8 B8 B8 B8 06 27 07-B8 B8 B8 00 00 00 00 00  ......'.........
                            . . .
08C0:  0A 2B 11 2B 26 CE 09 28-FF 2B 6E DD 42 40 02 00  .+.+&..(.+n.B@..
08D0:  02 01 00 35 39 D6 E1 00-D9 00 80 01 36 00 00 00  ...59.......6...
08E0:  6D 18 D0 09 28 FF 04 22-20 01 F9 00 00 00 21 00  m...(.." .....!.
08F0:  01 FF 14 A0 1E 00 48 09-CA 07 00 02 80 01 3A B8  ......H.......:.
                                                                                

One nice way to print the EEPROM contents to a format that can be captured and then reinput later (specifically, for backup purposes), is shown here, using the command to "Display all of EEPROM in the FOREGROUND in iHEX format". The '+' overrides the default BACKGROUND with FOREGROUND and the 'i' specifies iHex format. Again, this is a shortened output so as not to display all 66 lines that were actually output:

>DE+i
EEPROM contents:
:02000002E0001C
:100000001001009F010196FF0400FFFF283C50FFF4
:10001000C0003FFF40080367FF1574FFFFFFFFFFAD
:10002000FF6405FFFF10FFFFFF20FF200030FFFFF0
:10003000FFFF0600FFFFFFFFFFFFFFFFFFFF801630
:10004000FFFF00319000FFFFFFFFF0019001B000C3
:100050006E52462050545820636F6E6669673A00AE
:100060007C3F3F03344E06584E303600584E3031F8
:100070000032333435584E3036003F0788D0070001
:100080006E52462050525820636F6E6669673A0080
                   . . .
:1003B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4D
:1003C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3D
:1003D0000000451402E0030C00FFFFFFFFFFFFF0E9
:1003E000FA000000021C0A070240262CFFFFFFF063
:1003F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0D
:00000001FF
>                                                                               

Note that if the BACKGROUND version of the command were to have been used ("dei", for example), the '>' prompt would have been output before the ":02000002E0001C" EEPROM iHEX specifier line. This will prevent the prompt from appearing in the output, which is nice if capturing the output. When output is being generated in the background, the BACKSPACE character will terminate the output as soon as it is processed. When the foreground version of the command is used, the '>' prompt appears at the end of the output, but the output cannot be interrupted with the BACKSPACE character. This is because the next command (starting with the BACKSPACE character) is not processed until after the prompt has been output. Note that the early termination exit feature is particularly helpful if a command such as "DFi" (which is the same as "DFH") is used, since that command dumps all accessible FLASH memory, generating a rather lengthy output (from 0 to 0x40FF bytes.)

Just for fun, try this:
>?, 0x40FF
16,639
>                                                                               

That simply converted the hexadecimal value 0x40FF (the number of FLASH data bytes that would have output in the prior example, by the way) to its decimal equivalent. The '?' is a mnemonic for 'what is', the ',' indicates include a comma or commas are to be included in the output. A few more examples are shown below:

>? 0xFFFFFFFF
4294967295
>?, 0xffffffff
4,294,967,295
>? 65536
0x10000
>?,= 57600
57,600 = 0xE100
>                                                                               

When a decimal value is input, the output is in hexadecimal. When a hexadecimal value is input, the output is in decimal, with commas optional (but certainly helpful for large hex values, as shown above.) When an equal sign is placed before the space, both decimal and hex values are printed.

In addition to displaying values, EEPROM and SRAM values may also be entered directly into EEPROM or SRAM using edit commands. Consider this example, in which a 32-byte block of EEPROM is being changed (from its "unused" or "cleared" values of 0xFF):

>de+ 0x300 - 0x31F
EEPROM contents:
0300:  FF FF FF FF FF FF FF FF-FF FF FF FF FF FF FF FF  ................
0310:  FF FF FF FF FF FF FF FF-FF FF FF FF FF FF FF FF  ................
>E 0x300 = 1 2 3 4
>De+ 0x300 32
EEPROM contents:
0300:  01 02 03 04 FF FF FF FF-FF FF FF FF FF FF FF FF  ................
0310:  FF FF FF FF FF FF FF FF-FF FF FF FF FF FF FF FF  ................
>eW 0x304 = 1 2 -3 4
>dE+ 0x300 - 0x31f
EEPROM contents:
0300:  01 02 03 04 01 00 02 00-FD FF 04 00 FF FF FF FF  ................
0310:  FF FF FF FF FF FF FF FF-FF FF FF FF FF FF FF FF  ................
>EL 0x30C = 1 2 3 -4 5
>de+ 0x300 32
EEPROM contents:
0300:  01 02 03 04 01 00 02 00-FD FF 04 00 01 00 00 00  ................
0310:  02 00 00 00 03 00 00 00-FC FF FF FF 05 00 00 00  ................
>EL 0x300 = -1 -1 -1 -1 -1 -1 -1 -1
>D+E 0x300 32
EEPROM contents:
0300:  FF FF FF FF FF FF FF FF-FF FF FF FF FF FF FF FF  ................
0310:  FF FF FF FF FF FF FF FF-FF FF FF FF FF FF FF FF  ................
>                                                                               

OK, the first command was to display contents of the 32 bytes of EEPROM from address 0x300 through 0x31F, inclusive. Note that they are all cleared back to their reset values of 0xFF. The "E 0x300 = 1 2 3 4" assigns the values 1, 2, 3 and 4 to successive BYTES in EEPROM (at 0x300, 0x301, 0x302 and 0x303.) Also note the range display option using a dash, as in "de+ 0x300 - 0x31F".

The "eW 0x304 = 1 2 -3 4" entered WORD (2-byte) values into EEPROM beginning at address 0x304 (so, 0x0001 begins at 0x304, 0x0002 at 0x306, -3 = 0xFFFD at 0x308 and 0x0004 at 0x30A.) Please take notice at this point that the 328P MPU stores and uses bytes in "little-endian" order, or Least Significant Byte (LSB) first, so the value 1 = 0x0001 is actually stored in bytes 0x304 (LSB) and 0x305 (MSB), the value 2 at 0x306 and 0x307, the value -3 (= 0xFFFD) at 0x0308 and 0x309 and the value 4 at 0x30A and 0x30B.

The "EL 0x30C = 1 2 3 -4 5" entered LONG (4-byte) values into EEPROM beginning at address 0x30C. The value 0x00000001 is contained in addresses 0x30C, 0x30D, 0x30E, and 0x30F. The next 4 bytes have the value 2L, then the next 4 have 3L. Note that the bytes at 0x318, 0x319, 0x31A and 0x31B are the value -4 (0xFFFFFFFC).

As you can see, negative values may be entered, therefore these are signed BYTES ("C" type CHAR), signed WORDs ("C" type INT) and signed LONGs.

The command "EL 0x300 = -1 -1 -1 -1 -1 -1 -1 -1" enters the 4-byte values of 0xFFFFFFFF into 8 successive locations, restoring the 32 bytes to their original contents.

The following example displays a portion of FLASH memory, both in standard DEBUG format and in iHex format:

>DF+ 0x100 0x100
FLASH (program memory) contents:
0100:  53 65 74 75 70 20 61 74-20 30 78 31 31 30 3A 00  Setup at 0x110:.
0110:  11 24 F0 90 1B 01 11 E1-1F 0D 81 17 10 F4 C8 0F  .$..............
0120:  D1 1D B9 80 CA 80 DB 80-EC 80 AD 81 BE 81 1F 81  ................
0130:  28 85 39 85 5B 2D 5F 70-6A 2F 6B 2B 65 9F 01 28  (.9.[-_pj/k+e..(
0140:  B9 F1 11 24 92 E0 80 EA-8F 0D 91 1D EE 85 FF 85  ...$............
0150:  F8 30 18 F4 E8 17 F9 07-08 F4 FC 01 AD 01 4A 0F  .0............J.
0160:  5B 1F 4A 0F 5B 1F 1F 01-41 93 51 93 08 95 00 00  [.J.[...A.Q.....
0170:  4F 75 74 70 75 74 20 61-74 20 30 78 31 38 32 3A  Output at 0x182:
0180:  20 00 89 81 EA E3 3C DF-09 F4 88 E2 AC 01 F1 01   .....<.........
0190:  61 91 71 91 CF 01 E8 E7-33 CF 20 20 20 20 20 20  a.q.....3.
01A0:  45 78 69 74 20 61 74 20-30 78 31 42 30 3A 20 00  Exit at 0x1B0: .
01B0:  E1 E0 26 CF 20 20 45 78-61 6D 70 6C 65 20 61 74  ..&.  Example at
01C0:  20 30 78 31 43 38 3A 00-E0 E0 1A DF A1 DF EB E7   0x1C8:.........
01D0:  17 DF 7B 32 69 F7 EC E7-13 DF EA CF 00 00 00 00  ..{2i...........
01E0:  3D 3D 3D 3D 3D 3D 3D 3D-3D 3D 3D 3D 3D 3D 3D 3D  ================
01F0:  00 05 E0 E0 0E 94 00 00-0E 94 88 00 20 E0 DD 28  ............ ..(
>Di+F 0x100 0x100
FLASH (program memory) contents:
:1001000053657475702061742030783131303A0055
:100110001124F0901B0111E11F0D811710F4C80F7D
:10012000D11DB980CA80DB80EC80AD81BE811F818A
:10013000288539855B2D5F706A2F6B2B659F0128A1
:10014000B9F1112492E080EA8F0D911DEE85FF85B3
:10015000F83018F4E817F90708F4FC01AD014A0F6C
:100160005B1F4A0F5B1F1F014193519308950000CD
:100170004F75747075742061742030783138323A5C
:1001800020008981EAE33CDF09F488E2AC01F10157
:1001900061917191CF01E8E733CF2020202020200A
:1001A000457869742061742030783142303A2000FB
:1001B000E1E026CF20204578616D706C6520617488
:1001C0002030783143383A00E0E01ADFA1DFEBE776
:1001D00017DF7B3269F7ECE713DFEACF000000009E
:1001E0003D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3F
:1001F0000005E0E00E9400000E94880020E0DD2869
:00000001FF
>                                                                               
This last example block shows some of the built-in debbbbuggging commands. By default, the output is as shown in the first "R" (Registers) command:
>R

 10   32   54   76   98  1110 1312 1514 1716 1918 2120 2322 2524 2726 2928 3130  SP    SREG
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --------
0000 2636 09F1 FF28-2204 0200 02C9 0000-0021 FF01 A001 3161-0000 0240 0200 3161 08F4 ItHSvNzC
>
>ES 0x1DF = 0x3A
>r

 10   32   54   76   98  1110 1312 1514 1716 1918 2120 2322 2524 2726 2928 3130  SP  RetAdd   SREG
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ -------- 
0000 0A6B 093C FF28-2204 0240 02C9 0000-0021 FF10 4F01 3161-0000 0240 0200 3161 08F4  6A16  ItHSvNzC 
>r+

 10   32   54   76   98  1110 1312 1514 1716 1918 2120 2322 2524 2726 2928 3130  SP  RetAdd   SREG
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ -------- 
0000 3230 096F FF28-2204 0250 0349 0000-0021 FF01 A002 3161-002B 0240 0200 3161 08F4  6A16  IthSvNzC 
STACK contents:
08F0:              31 35 0E 31-3C 40 02 31 10 02 3A AA      15.1<@.1..:.
>es 0x1df |= 0x40
>r

 10   32   54   76   98  1110 1312 1514 1716 1918 2120 2322 2524 2726 2928 3130  SP  RetAdd   SREG
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ -------- 
0000 0B56 0992 FF28-2204 0260 02C9 0000-0021 FF01 A001 3161-0000 0240 0200 3161 08F4  6A16  ItHSvNzC 
STACK contents:
08F0:              31 35 0B 31-3C 40 02 31 10 01 3A AA      15.1<@.1..:.

>
Note the form of the data change command above using "|=" instead of simply "=". This is the standard "C" notation for a BITWISE OR operation, so the prior value is "OR"ed with the data value entered. It may be used with any "Edit" command varities, as can other standard "+=", "-=", "&=", "^=", "<=", ">=" C-language operators and the nonstandard "~=" (or "v=" or "!=", which all mean bitwise mask OFF.) Try them!

Refer to the Registers documentation for further information on that command.