Utility functions – Maxim Integrated High-Speed Microcontroller Users Guide: Network Microcontroller Supplement User Manual

Page 191

Advertising
background image

High-Speed Microcontroller User’s

Guide: Network Microcontroller

Supplement

191

UTILITY FUNCTIONS

crc16

Description:

int crc16(
int crc,

/* initial CRC value */

unsigned char value);

/* value to include in the CRC calculation */

The

crc16 function computes the CRC-16 of a byte given an initial CRC value.

mem_clear

Description:

void mem_clear(
void *
target,

/* pointer to start of target memory to clear */

int length);

/* length (in number of bytes) to clear */

The

mem_clear function clears a block of memory of length beginning at starting address specified by *target.

mem_copy

Description:

void mem_copy(
void *
source,

/* pointer to the start of the source buffer */

void *target,

/* pointer to the start of the target buffer*/

int length);

/* length of data to be copied */

The

mem_copy function copies a block of memory. If the source and target memory buffers overlap, there is no guarantee

that the source bytes are not overwritten prior to being copied to the target.

INPUT

DESCRIPTION

OUTPUT

DESCRIPTION

B:ACC

DPTR0

DPTR1

length

*source

*target

DPTR0

DPTR1

*source+length

*target+length

Example:

MOV B, #high(MEMLENGTH)

MOV A, #low(MEMLENGTH)

MOV DPTR, #SOURCE

INC DPS

MOV DPTR, #TARGET

INC DPS

ROMCALL mem_copy

INPUT

DESCRIPTION

OUTPUT

DESCRIPTION

B:ACC

DPTR0

length

*target

-

Example:

MOV B, #high(MEMLENGTH)

MOV A, #low(MEMLENGTH)

MOV DPTR, #MEMTOCLEAR

ROMCALL mem_clear

INPUT

DESCRIPTION

OUTPUT

DESCRIPTION

ACC

R1:R0

value

crc

R1:R0

CRC-16 return value

Example:

MOV R1, #0

MOV R0, #0

MOV DPTR, #bytelocation

MOVX A, @DPTR

ROMCALL crc16

Maxim Integrated

Advertising