-
Notifications
You must be signed in to change notification settings - Fork 2
/
old.c
143 lines (103 loc) · 2.82 KB
/
old.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
movlw 0x30 ; Program memory < 0x300000
cpfslt WREG2
bra DataRegJp1
btfss CAN_PG_BIT
bra PMEraseWrite
bra PMRead
DataRegJp1
movf WREG2,W ; Config memory = 0x300000
xorlw 0x30
bz CFGDecode
btfsc CAN_PG_BIT
bra PMRead
DataRegJp2
movf WREG2,W ; EEPROM data = 0xF00000
xorlw 0xF0
bz EEDecode
bra CANMain
; *********************************************************
EEReadOrWrite
btfsc CAN_PG_BIT
bra EERead
btfsc MODE_WRITE_LOCK ; Stop if write locked
bra CANMain
movf POSTINC0, W ; Load data
movwf EEDATA
rcall UpdateChksum ; Adjust the checksum
rcall WriteEEWait
bra EEReadOrWriteJp1
EERead
clrf EECON1
bsf EECON1, RD ; Read the data
movff EEDATA, POSTINC0
EEReadOrWriteJp1
infsnz EEADR, F ; Adjust EEDATA pointer
incf EEADRH, F
decfsz WREG1, F
bra EEReadOrWrite ; Not finished then repeat
btfsc CAN_PG_BIT
bra CANSendResponce
; *********************************************************
movf _bootSpcCmd, W ; NOP Command
bz CANSendAck
xorlw CMD_RESET ; RESET Command
btfsc STATUS, Z
reset
movf _bootSpcCmd, W ; RESET_CHKSM Command
xorlw CMD_RST_CHKSM
bnz SpecialCmdJp1
clrf _bootChksmH ; Reset chksum
clrf _bootChksmL
SpecialCmdJp1
movf _bootSpcCmd, W ; RUN_CHKSM Command
xorlw CMD_CHK_RUN
bnz SpecialCmdJp2
movf _bootChkL, W ; Add the control byte
addwf _bootChksmL, F
bnz SpecialCmdJp2
movf _bootChkH, W
addwfc _bootChksmH, F
bnz SpecialCmdJp2
setf EEADR ; Point to last location of EEDATA
setf EEADRH
clrf EEDATA ; and clear the data
movlw b'00000100' ; Setup for EEData
rcall StartWrite
SpecialCmdJp2
bra CANSendAck ; or send an acknowledge
btfss _bootSpcCmd, 0
bra SpecialCmdJp1
bcf _bootSpcCmd, 0
clrf _bootChksmH ; Reset chksum
clrf _bootChksmL
SpecialCmdJp1
btfss _bootSpcCmd, 1
bra SpecialCmdJp2
bcf _bootSpcCmd, 1
movf _bootChkL, W ; Add the control byte
addwf _bootChksmL, F
bnz SpecialCmdJp2
movf _bootChkH, W
addwfc _bootChksmH, F
bnz SpecialCmdJp2
setf EEADR ; Point to last location of EEDATA
setf EEADRH
clrf EEDATA ; and clear the data
movlw b'00000100' ; Setup for EEData
rcall StartWrite
SpecialCmdJp2
btfsc _bootSpcCmd, 7
reset
bra CANSendAck ; or send an acknowledge
#if 0
; *****************************************************************************
_WRITEWAIT CODE 0x0A
; *****************************************************************************
WriteEEWait:
movlw b'00000100' ; Setup for EEData
rcall StartWrite
btfsc EECON1, WR ; Write and wait
bra $ - 2
return
; *****************************************************************************
#endif