English
Language : 

AN247 Datasheet, PDF (21/32 Pages) Microchip Technology – A CAN Bootloader for PIC18F CAN Microcontrollers
AN247
; *****************************************************************************
; Function: VOID _ReadWriteMemory()
;
; PreCondition:Enter only after _CANMain().
; Input: None.
; Output: None.
; Side Effects: N/A.
; Stack Requirements: N/A
; Overview: This routine is technically not a function since it will not
;
return when called. It has been written in a linear form to
;
save space.Thus 'call' and 'return' instructions are not
;
included, but rather they are implied.
;
;
This is the memory I/O engine. A total of eight data
;
bytes are received and decoded. In addition two control
;
bits are received, put/get and control/data.
;
;
A pointer to the buffer is passed via FSR0 for reading or writing.
;
;
The control register set contains a pointer, some control bits
;
and special command registers.
;
;
Control
;
<PG><CD><ADDRL><ADDRH><ADDRU><_RES_><CTLBT><SPCMD><CPDTL><CPDTH>
;
;
Data
;
<PG><CD><DATA0><DATA1><DATA2><DATA3><DATA4><DATA5><DATA6><DATA7>
;
;
PG bit: Put = 0, Get = 1
;
CD bit: Control = 0, Data = 1
;
; *****************************************************************************
_ReadWriteMemory:
btfscCAN_CD_BIT ; Write/read data or control registers
bra
_DataReg
; *****************************************************************************
; This routine reads or writes the bootloader control registers,
; then executes any immediate command received.
_ControlReg
lfsr 1, _bootCtlMem
_ControlRegLp1
#ifdef ALLOW_GET_CMD
btfsc CAN_PG_BIT
; or copy control registers to buffer
movff POSTINC1, POSTINC0
btfss CAN_PG_BIT
; Copy the buffer to the control registers
#endif
movff POSTINC0, POSTINC1
decfsz WREG1, F
bra
_ControlRegLp1
#ifdef ALLOW_GET_CMD
btfsc CAN_PG_BIT
bra
_CANSendResponce; Send response if get
#endif
; *********************************************************
; This is a no operation command.
movf
bz
_bootSpcCmd, W; NOP Command
_SpecialCmdJp2; or send an acknowledge
; *********************************************************
 2003 Microchip Technology Inc.
DS00247A-page 21