Skip to content

Commit

Permalink
Merge pull request #408 from TG9541/onewire
Browse files Browse the repository at this point in the history
Onewire and minor UM/MOD improvement
  • Loading branch information
TG9541 committed Mar 9, 2021
2 parents 0c3dcaf + b80c180 commit 22185fd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
4 changes: 2 additions & 2 deletions forth.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1508,10 +1508,10 @@ UMMOD:
CPW X,YTEMP
JRULT MMSM1 ; X is still on the R-stack
POPW X ; restore stack pointer
LDW Y,#0xFFFF ; overflow result:
LDW (X),Y ; quotient max. 16 bit value
CLRW Y
LDW (2,X),Y ; remainder 0
DECW Y
LDW (X),Y ; quotient max. 16 bit value
RET
MMSM1:
LD A,#16 ; loop count
Expand Down
2 changes: 1 addition & 1 deletion inc/defconf.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
;--------------------------------------------------------
RELVER1 = 2 ; Revision digit 1
RELVER0 = 7 ; Revision digit 0
PRE_REL = 3 ; Pre Release digit 0 (0: release)
PRE_REL = 0 ; Pre Release digit 0 (0: release)

TERM_LINUX = 1 ; LF terminates line

Expand Down
28 changes: 28 additions & 0 deletions lib/CRC8
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
\ STM8 eForth: CRC8 for 1-Wire protocol, polynomial x8 + x5 + x4 + 1
\ refer to github.com/TG9541/stm8ef/blob/master/LICENSE.md

\ implementation for 1-wire protocol

: CRC8 ( crc c -- crc ) [ \ 1-Wire CRC8
$A608 , \ LD A,#8 ; loop through 8 bits
$F7 C, \ LD (X),A ; use MSB as bit counter
$E601 , \ LD A,(1,X) ;
$E803 , \ 1$: XOR A,(3,X) ; crc XOR c.bit0
$46 C, \ RRC A ; to carry
$E603 , \ LD A,(3,X) ; crc -> A
$2402 , \ JRNC 0$
$A818 , \ XOR A,#0x18 ; apply x5 + x4
$46 C, \ 0$: RRC A ; apply x8 + 1
$E703 , \ LD (3,X),A ; update crc value
$6401 , \ SRL (1,X) ; next c.bit0
$E601 , \ LD A,(1,X)
$7A C, \ DEC (X) ; bit counter until 0
$26ED , \ JRNE 1$ ; loop?
$5C C, \ INCW X ; DROP
$5C C, \ INCW X
] ;

\\ Test

\ DALLAS MAXIM AN937 Figure 3 Example Calculation for DOW CRC
HEX 0 2 CRC8 1C CRC8 B8 CRC8 1 CRC8 0 CRC8 0 CRC8 0 CRC8 . DECIMAL \ -> A2
15 changes: 15 additions & 0 deletions lib/LSHIFT
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
\ STM8eForth : LSHIFT TG9541-210301
\ refer to github.com/TG9541/stm8ef/blob/master/LICENSE.md

: LSHIFT ( n c - n ) \ shift n left c times
[ $5C C, \ INCW X
$F6 C, \ LD A,(X)
$5C C, \ INCW X
$4D C, \ TNZ A
$2705 , \ JREQ 1$
$6801 , \ 2$: SLA (1,X)
$79 C, \ RLC (X)
$4A C, \ DEC A
$26F8 , \ JRNE 2$
] \ 1$:
;

0 comments on commit 22185fd

Please sign in to comment.