.title "CRC-16 for program RAM." ; Note that the Laser Jet prints in landscape mode such that there is a ; half-inch margin at the top and at the bottom of the page; there are ; 8 lines per inch vertically over 7.5 inches for a total of 60 lines. .length 59 ;59 lines per page vertically .width 132 ;132 characters per line horizontally ;**************************************************************************** ;Filename: CRC16.ASM ;Created on: Wednesday 17-August-1994, 09:43 ;Revision History: ; -Wednesday 26-October-1994, 10:55, TVJM: Enabled SETC SXM code for Iwen. ; -Monday 24-October-1994, 18:12, TVJM: Incorporated subroutine FAILURE. ; -Tuesday 20-September-1994, 13:25, TVJM: restored bsar instruction. ; -Friday 16-September-1994, 11:47, TVJM: incorporated into main code. ; -Monday 22-August-1994, 12:09, TVJM: corrected code. ;Created by: Tom V. J. Maglione ; 29 Rice Road ; Wayland, Massachusetts 01778 ; (508) 655-9120 ;Purpose: This file contains the TMS320C50 assembly language code used to ; compute and verify the program ROM CRC-16 checksum. ;**************************************************************************** .version 50 ;generate code for TMS320C5x devices .mmregs ;define memory-mapped registers .include "..\headers\global.h" .include "..\headers\constant.h" .text ;start code section ;**************************************************************************** ; The next section uses AR6 as a pointer to program RAM space; ; The next section uses AR5 as a counter of program RAM words; ; The next section uses AR4 as a counter of nybbles in each source pgm word; ;**************************************************************************** CRC16: lar ar6,#PGM_START ;ar6=start address program RAM lar ar5,#PGM_SIZE-2 ;ar5=count minus 1 of words to process ;excluding last word containing stored CRC16 zap ;clear ACC and PREG sacb ;clear ACCB => initializes CRC holder clrc SXM ;turn-off sign-extension for logical ops. mar *,ar6 ;ARP => AR6 ;**************************************************************************** ; The next section includes one word at a time in the CRC-16 checksum: ; The next section assumes that the ACCB contains the current CRC word: ; The next section assumes that ARP = AR6 = source program memory pointer ;**************************************************************************** LOOP1: lamm ar6 ;ACCH=0, ACCL = ar6 = pointer to program mem tblr TREG0 ;TREG0 = pgm.mem(ar6) lacl TREG0 ;ACCH=0, ACCL = pgm.mem(ar6) xorb ;ACC = ACC xor ACCB (CRC ^= new data) sacb ;ACCB = CRC lar ar4,#(BIPDWD/BIPCRC)-1 ;use AR4 to count nybbles mar *+,ar4 ;ar6 points to next pgm word, ar4 next ;**************************************************************************** ; The next section uses the CRC table to update the CRC for each nybble: ; The next section assumes that the ACC and the ACCB contain the CRC word: ; The next section assumes that ARP = AR4; ;**************************************************************************** LOOP2: ;inner loop for 4 nybbles of each program word and #CRC_MASK ;ACCL = CRC table offset add #CRC_TABLE ;ACC = address CRC table entry in program RAM tblr TREG0 ;TREG0 = CRC table entry from program RAM lacb ;ACC = ACCB = CRC bsar BIPCRC ;ACC = ACC>>4 (right-shift) (SXM must be 0) banzd LOOP2,*-,ar4 ;delayed: to LOOP2 if ar4!=0, ar4--, ar4 next xor TREG0 ;ACC ^= CRC table entry sacb ;ACCB = ACC = CRC ;**************************************************************************** ; This marks the bottom of the loop to process each CRC nybble... ;**************************************************************************** mar *,ar5 ;ARP = AR5 banz LOOP1,*-,ar6 ;to LOOP1 if ar5!=0, ar5--, ar6 next ;**************************************************************************** ; This marks the bottom of the loop to process all program RAM words... ;**************************************************************************** setc SXM ;restore sign extension mode lamm ar6 ;ACCH=0, ACCL = ar6 = pointer to program mem tblr TREG0 ;TREG0 = pgm.mem(ar6) lacl TREG0 ;ACCH=0, ACCL = pgm.mem(ar6) = stored CRC16 sbb ;compare with computed CRC-16 word retc eq ;done if computed = stored ; Else, failure indicated here. lacl #FAIL_CRC ;load failure code call FAILURE ;handle failure, never returns. ; ;**************************************************************************** ; Subroutine FAILURE: this subroutine never returns. ; This subroutine puts the failure code in A out to the reserve bits 8-15. ;**************************************************************************** ; FAILURE: setc INTM ;Disable all maskable interrupts rpt #BIPBYT ;Shift ACC left by 8 bits sfl ;Shift ACC left 1 bit => ACC * 2**1 FAIL_LOOP samm PT_CLK ;ACC out to reserve-bits output port b FAIL_LOOP ;loop forever ; ;**************************************************************************** ; End of subroutine "FAILURE"... TVJM. ;**************************************************************************** ; ;**************************************************************************** ; The next section defines the CRC-16 data table: ;**************************************************************************** .data ;start initialized data section CRC_TABLE: .word 00000h ;table entry #0 .word 0CC01h ;table entry #1 .word 0D801h ;table entry #2 .word 01400h ;table entry #3 .word 0F001h ;table entry #4 .word 03C00h ;table entry #5 .word 02800h ;table entry #6 .word 0E401h ;table entry #7 .word 0A001h ;table entry #8 .word 06C00h ;table entry #9 .word 07800h ;table entry #10 .word 0B401h ;table entry #11 .word 05000h ;table entry #12 .word 09C01h ;table entry #13 .word 08801h ;table entry #14 .word 04400h ;table entry #15 ;*************************************************************************** ; End of module CRC16.ASM... TVJM ;***************************************************************************