
Rev.1.00
2004.03.23
page 185 of 320
M306H3MC-XXXFP/FCFP
Figure 2.14.8 Example of program
;
Equations (Constant definition)
;
_CRC_ADRS
.equ
00212h
; SFR address of CRC register address control register
_CRC_DATA
.equ
00214h
; SFR address of CRC register data control register
SLICE_WORD_NUM
.equ
17
; Code data length (in nuits of word)
;
Macro definition
;
_wait
.macro
nop
.endm
;
CRC operation routine
;
;--------- A setup of a generator polinomial
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
mov.w
#0008H
, _CRC_ADRS
; Set up of the header address of the generator polinomial registers.
_wait
; Wait
mov.w
0000110000100011B
, _CRC_DATA
; Set up of the 82th to 66th generator polinomial coefficient ( x^77 +x~76 +x^71 +x^67 +x^66)
mov.w
0000000001000100B
, _CRC_DATA
; Set up of the 65th to 50th generator polinomial coefficient (+x^56 +x^52)
mov.w
0100000001000101B
, _CRC_DATA
; Set up of the 49th to 34th generator polinomial coefficient (+x^48 +x^40 +x^36 +x^34)
mov.w
0000000001010001B
, _CRC_DATA
; Set up of the 33th to 18th generator polinomial coefficient (+x^24 +x^22 +x^18)
mov.w
0000000100000100B
, _CRC_DATA
; Set up of the 17th to 2nd generator polinomial coefficient (+x^10 +x^4)
mov.w
0100000000000000B
, _CRC_DATA
; Set up of the 1st to 0th generator polinomial coefficient (+x^0),
no division of the shift clock and LSB first.
;------ Writing of code data ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
mov.w
#9010H
, _CRC_ADRS
; Set up of CRCON=1, CRCCHANGE=0, CRCLOOP=10H, Increment=ON, and CRC address=00H.
mov.w
#0000H
, _CRC_ADRS
; Initialization of CRC register address control register
mov.w
#0000H
, A0
L18:
; Branch label
cmp.w
#SLICE_WORD_NUM*2
, A0
; Comparison of the loop variable
; Initialization of a loop variable (A0)
jgeu
L20
; Go to L20 if writing code data is finished.
lde.w
_CrcCodeData[A0]
, _CRC_DATA
; Writing code data to the code data shift register.
add.w
#0002H
,A0
; Increment of the address storing code data.
jmp
L18
; Return to the head of this loop.
L20:
; Branch label
;--------- Dummy shift ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
; After finishing writing 272-bit code data,
; shift a bit for dummy surely in error correction mode.
; Specifying 1-bit is set up by CRCLOOP=01H.
mov.w
#8100H
, _CRC_ADRS
; Set up of CRCON=1, CRCCHANGE=0, CRCLOOP=10H, Increment=OFF, and CRC address=00H.
_wait
; Wait
mov.w
#0000H
, _CRC_DATA
; Writing data to the code data shift register for dummy shift.
;--------- Error detection -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
; Since the address automatic increment in dummy shift (Increment=OFF), set CRC address=01H here.
; When accessing other CRC registers, the processing shown in the following two lines is necessary.
;
mov.w
#9001H
, _CRC_ADRS
; Set up of CRCON=1, CRCCHANGE=0, CRCLOOP=10H, Incremet=OFF and CRC address=01H.
;
_wait
; Wait
mov.w
_CRC_DATA
, R0
; Read of CRC error detection register.
cmp.w
#0000H
, R0
; Judgement of CRC error.
jeq
L16
; In the case of R0=0, branch to L16 since CRC error has not occurred (CRC error correction is skipped).
;--------- Error correction ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
mov.w
#0D010H
, _CRC_ADRS
; Set up of CRCON=1, CRCCHANGE=1, CRCLOOP=10H, Increment=ON and CRC address=00H.
_wait
; Wait
mov.w
#0000H
, A0
; Initialization of a loop variable (A0)
L22:
; Branch label
cmp.w
#SLICE_WORD_NUB
, A0
; Comparison of the loop variable
jgeu
L24
; Go to L24 if correction of error data is finished.
lde.w
_CrcCodeData[A0]
, _CRC_DATA
; Writing code data to the code data shift register.
jsr
_waitlong
; Wait for finish of error correction.
mov.w
_CRC_DATA
, _CrcCodeData[A0]
; Read of error correction data in the address storing code data.
add.w
#0002H
, A0
; Increment of the address storing code data.
jmp
L22
; Return to the head of this loop.
L24:
; Branch label
;------- The check of error correction data--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
mov.w
#8111H
, _CRC_ADRS
; Set up of CRCON=1, CRCCHANGE=0, CRCLOOP=10H, Increment=ON and CRC address=00H
_wait
; Wait
mov.w
_CRC_DATA
, R0
; Error check after error correction. R0=000H if correction is performed.
L16:
;
; The function sample for weight for error correction
;
.align
.glb
_waitlong
_waitlong:
; Function label
rts