Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
423B

  1. ( c n -- c )
  2. ( Computes n into crc c with polynomial 0x09
  3. Note that the result is "left aligned", that is, that 8th
  4. bit to the "right" is insignificant (will be stop bit). )
  5. : _crc7
  6. XOR ( c )
  7. 8 0 DO
  8. 2 * ( <<1 )
  9. DUP 255 > IF
  10. ( MSB was set, apply polynomial )
  11. 0xff AND
  12. 0x12 XOR ( 0x09 << 1, we apply CRC on high bits )
  13. THEN
  14. LOOP
  15. ;