>On Oct 24, 9:37 pm, "Vy" <vyw...@yahoo.com> wrote:
>
>> Is there someone who has access to the CRC_CCITT 16-bit code written
in
>> ARM7 assembly language?
>
>I use the following C code:
>
>uint16_t crc_ccitt_update( uint16_t crc, uint8_t data )
>{
> uint16_t tmp;
>
> tmp = data ^ (crc >> 8);
> tmp ^= tmp >> 4;
> crc = (crc << 8) ^ tmp ^ (tmp << 5) ^ (tmp << 12);
> return crc;
>}
>
>Using an initialization of 0xffff for the CRC, the results agree with
>this on-line CRC calculator:
>
>http://www.lammertbies.nl/comm/info/crc-calculation.html
>
>The ARM7 assembly version could be something like this (not tested)
>
>// a1 contains old crc (initialize with 0xffff)
>// a2 contains data byte
>// result: a1 contains new crc
>
> eor a2, a2, a1, lsr #8
> eor a2, a2, a2, lsr #4
> eor a1, a2, a1, lsl #8
> eor a1, a1, a2, lsl #5
> eor a1, a1, a2, lsl #12
> bic a1, a1, #0xff0000
>
>(The last 'bic' converts the result to 16 bit, using the observation
>that the MSB remained 0)
>
>A table based approach could probably save a couple of instructions,
>but requires 512 bytes of fast memory for the table, which is often
>not desirable on an embedded system.
>
>Regards,
>Arlet Ottens
>
>
I've checked out Lammert's website. He does not append zeroes (equal to
width) to his calculation and also as i mentioned in the beginning my
initial value is 1d0f. So my calculations and his never match.
A better place to check values and according to me the best online
calculator on the web for CRC where one can change all the parameters
according to one's choice can be found at
http://www.zorc.breitbandkatze.de/crc.html
Having said that, i have just finished writing and testing my own code and
voila it works. However i must mention that it's an application specific
code that may or may not be of use to one and all.
;R0= initial value
;R1= data word
;R2= polynomial
;R3= length of message in bits which shall be the outermost counter in the
program
;R4=R8 tells us when to stop rotating the word in case there are less than
4 bytes in the word, R8 is in bits
crc_16
ldr R0,=0x1d0f
ldr R2,=2_10001000000100001
subs R3,R3,#16
;mov R3 ;load in program,
crc16_next mov R0,R0,LSL#1 ;since the poly is actually 17 bits long and
not 16 bits the first
;step is to shift it left by one to accomodate the first bit of the
;message and then start the XOR process
mov R4,R8 ;this is for when to stop rotating the
word,1-9,2-17,3-25,4-33
mainloop
subs R3,R3,#1 ;if zero, crc calc ic over and result is present in R0
beq finish
cmp R3,#16 ;If R3 is <=16, go to the subroutine that appends the
zeroes
bls append_zeroes
subs R4,R4,#1
bit_shift
mov R1,R1,ROR#31 ;R1 is the data word
mov R5,R1
and R5,R5,#0x00000001
orr R0,R0,R5
append_zeroes
mov R10,R0
ands R10,R10,#0x00010000 ;to check if CRC must be Exclusive ORed
bne docrc
next mov R0,R0,LSL#1
bal mainloop
docrc eor R0,R0,R2
bal next
next_word mov R0,R0,LSR#1
BX R14
finish mov R0,R0,LSR#1
BX R14