<root>
<file schema='102' />
<macros >
<macro >
<flowline name='J1850_CRC' description='Calculate CRC on J1850 message frame' >
<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
<param name='msg' type='T8*' description='Message (max size 12 bytes) done as string to avoid copy' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
<array size='12' />
</param>
<param name='n' type='u8' description='Number of bytes in message' isconst='0' isinit='0' usrinit='0' setinit='' />
<local name='crc' type='u8' description='' isconst='0' isinit='1' usrinit='255' setinit='0xff' />
<local name='poly' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
<local name='i' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
<local name='nbit' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
<local name='mask' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
<command class_type='loop' title='For each byte in message' cmdcolor='12615680' cmdcolor_sec='15376912' type='2' forvar='.i' exp='.n' >
<flowline >
<command class_type='calculation' title='Initialise bit mask' cmdcolor='16760919' cmdcolor_sec='16760832' >
<exp exp='.mask = 0x80' />
</command>
<command class_type='loop' title='For each bit in the byte' cmdcolor='12615680' cmdcolor_sec='15376912' type='2' exp='8' >
<flowline >
<command class_type='decision' title='If &apos;1&apos; bit at current position' cmdcolor='12615680' cmdcolor_sec='15376912' exp='.mask &amp; .msg[.i]' swap='0' >
<flowline >
<command class_type='decision' title='Define polynomial' cmdcolor='12615680' cmdcolor_sec='15376912' exp='.crc &amp; 0x80' swap='0' >
<flowline >
<command class_type='calculation' title='Calculation' cmdcolor='16760919' cmdcolor_sec='16760832' >
<exp exp='.poly = 1' />
</command>
</flowline>
<flowline >
<command class_type='calculation' title='Calculation' cmdcolor='16760919' cmdcolor_sec='16760832' >
<exp exp='.poly = 0x1c' />
</command>
</flowline>
</command>
<command class_type='calculation' title='Calculation' cmdcolor='16760919' cmdcolor_sec='16760832' >
<exp exp='.crc = ((.crc &lt;&lt; 1) | 1) ^ .poly' />
</command>
</flowline>
<flowline >
<command class_type='decision' title='Decision' cmdcolor='12615680' cmdcolor_sec='15376912' exp='.crc &amp; 0x80' swap='0' >
<flowline >
<command class_type='calculation' title='Calculation' cmdcolor='16760919' cmdcolor_sec='16760832' >
<exp exp='.poly = 0x1D' />
</command>
</flowline>
<flowline >
<command class_type='calculation' title='Calculation' cmdcolor='16760919' cmdcolor_sec='16760832' >
<exp exp='.poly = 0' />
</command>
</flowline>
</command>
<command class_type='calculation' title='Calculation' cmdcolor='16760919' cmdcolor_sec='16760832' >
<exp exp='.crc = (.crc &lt;&lt; 1) ^ .poly' />
</command>
</flowline>
</command>
<command class_type='calculation' title='Calculation' cmdcolor='16760919' cmdcolor_sec='16760832' >
<exp exp='.mask = .mask &gt;&gt; 1' />
</command>
</flowline>
</command>
</flowline>
</command>
<command class_type='calculation' title='Return the CRC value' cmdcolor='16760919' cmdcolor_sec='16760832' >
<exp exp='.Return = ~ .crc' />
</command>
</flowline>
</macro>
</macros>
<variables />
</root>
