AUTOSAR COM

Types and negative numbers

A signal often uses fewer bits on the bus than the variable that holds it in the application. COM stretches it to fit. For negative numbers that takes one extra trick.

The kinds of signal

Every signal has a type. It says what kind of value the application sees.

KindAUTOSAR types
Yes / noboolean
Whole number, never negativeuint8, uint16, uint32, uint64
Whole number, may be negativesint8, sint16, sint32, sint64
Number with a decimal pointfloat32, float64
Row of bytesuint8[n]: fixed length, or changing length (lesson 13)

The number in the name is the size of the variable in bits. The size on the bus is a separate setting and is often smaller. A temperature from −400 to 400 needs only 10 bits on the bus, but the smallest variable that can hold it has 16.

Stretching a number

When such a signal arrives, COM copies its 10 bits into the 16-bit variable. Six bits on the left are left over. What goes in there?

never negative

Fill with zeros

Zeros on the left do not change a number, just as 0042 is still 42.

may be negative

Copy the sign

The leftmost bit of the signal tells the sign: 0 is plus, 1 is minus. COM copies that bit into every left-over place.

Why copy the sign? Computers store negative numbers by counting backwards from all ones: with 10 bits, 1111111111 is −1 and 1111111110 is −2. In 16 bits, −1 is sixteen ones. So a negative number only stays the same number if the new places on the left are also ones.

Try it

A 10-bit signal that may be negative arrives and goes into a 16-bit variable.

10 bits on the bus (the underlined bit is the sign)

16 bits in the application, sign copied

16 bits if COM only filled with zeros

Things to notice. For zero and positive values both ways give the same result. For any negative value, filling with zeros gives a large wrong positive number.

Three smaller rules

Sending needs no trick

On the way out, COM simply takes the lowest bits of the variable. The application is expected to stay within the signal's range.

Start values are cut to size

A start value is trimmed to the signal's bits on the bus in the same way.

Decimal numbers are left alone

For float types COM only puts the bytes in the right order. It does no other conversion.

One more detail from the sending side: the parts of a packet that no signal uses are filled with a fixed pattern you can choose, often all ones.

Check yourself

Optional. Answer from memory.

The AUTOSAR words

Plain word hereAUTOSAR word
Copy the signSign extension
Putting bytes in the right orderEndianness conversion
Counting backwards from all onesTwo's complement
Fill pattern for unused partsUnused areas default

Source: AUTOSAR COM specification, R25-11, sections 7.1.3 and 7.2.1 (SWS_Com_00675, 00008, 00723, 00579, 00580, 00098, 00015). The example with −3 in 10 and 16 bits is the specification's own.

That was the last lesson. You have gone from "COM is the mail room" down to single bits. For a one-page reminder of everything, keep the COM at a glance sheet.