annotate src/comm.asm @ 3:72d9cb652604

interface description added
author heinrichsweikamp
date Mon, 06 May 2013 14:21:11 +0200
parents 11d4fc797f74
children 1ab317814dd7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
heinrichsweikamp
parents:
diff changeset
3 ; File comm.asm
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; RS232 via USB
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2012, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
9 ; HISTORY
heinrichsweikamp
parents:
diff changeset
10 ; 2011-08-22 : [mH] Creation
heinrichsweikamp
parents:
diff changeset
11 ; 2012-02-11 : [jDG] Added "c" set custom text, and "i" identify.
heinrichsweikamp
parents:
diff changeset
12
heinrichsweikamp
parents:
diff changeset
13 #include "ostc3.inc"
heinrichsweikamp
parents:
diff changeset
14 #include "eeprom_rs232.inc"
heinrichsweikamp
parents:
diff changeset
15 #include "tft.inc"
heinrichsweikamp
parents:
diff changeset
16 #include "wait.inc"
heinrichsweikamp
parents:
diff changeset
17 #include "strings.inc"
heinrichsweikamp
parents:
diff changeset
18 #include "convert.inc"
heinrichsweikamp
parents:
diff changeset
19 #include "external_flash.inc"
heinrichsweikamp
parents:
diff changeset
20 #include "tft_outputs.inc"
heinrichsweikamp
parents:
diff changeset
21 #include "surfmode.inc"
heinrichsweikamp
parents:
diff changeset
22 #include "rtc.inc"
heinrichsweikamp
parents:
diff changeset
23 #include "adc_lightsensor.inc"
heinrichsweikamp
parents:
diff changeset
24
heinrichsweikamp
parents:
diff changeset
25 extern testloop,do_main_menu,new_battery_menu,restart,option_reset_all
heinrichsweikamp
parents:
diff changeset
26
heinrichsweikamp
parents:
diff changeset
27 #DEFINE timeout_comm_pre_mode .120 ; Pre-loop
heinrichsweikamp
parents:
diff changeset
28 #DEFINE timeout_comm_mode .120 ; Download mode
heinrichsweikamp
parents:
diff changeset
29 #DEFINE timeout_service_mode .120 ; Service mode
heinrichsweikamp
parents:
diff changeset
30
heinrichsweikamp
parents:
diff changeset
31 #DEFINE comm_title_row .0
heinrichsweikamp
parents:
diff changeset
32 #DEFINE comm_title_column .50
heinrichsweikamp
parents:
diff changeset
33
heinrichsweikamp
parents:
diff changeset
34 #DEFINE comm_string_row .30
heinrichsweikamp
parents:
diff changeset
35 #DEFINE comm_string_column .40
heinrichsweikamp
parents:
diff changeset
36
heinrichsweikamp
parents:
diff changeset
37
heinrichsweikamp
parents:
diff changeset
38 #DEFINE comm_status1_row .70
heinrichsweikamp
parents:
diff changeset
39 #DEFINE comm_status1_column .10
heinrichsweikamp
parents:
diff changeset
40 #DEFINE comm_status2_row .100
heinrichsweikamp
parents:
diff changeset
41 #DEFINE comm_status2_column comm_status1_column
heinrichsweikamp
parents:
diff changeset
42 #DEFINE comm_status3_row .130
heinrichsweikamp
parents:
diff changeset
43 #DEFINE comm_status3_column comm_status1_column
heinrichsweikamp
parents:
diff changeset
44
heinrichsweikamp
parents:
diff changeset
45 #DEFINE comm_warning_row .160
heinrichsweikamp
parents:
diff changeset
46 #DEFINE comm_warning_column .65
heinrichsweikamp
parents:
diff changeset
47
heinrichsweikamp
parents:
diff changeset
48 comm code
heinrichsweikamp
parents:
diff changeset
49
heinrichsweikamp
parents:
diff changeset
50 ; test for comm
heinrichsweikamp
parents:
diff changeset
51 global comm_mode
heinrichsweikamp
parents:
diff changeset
52 comm_mode:
heinrichsweikamp
parents:
diff changeset
53 call TFT_ClearScreen
heinrichsweikamp
parents:
diff changeset
54 WIN_COLOR color_greenish
heinrichsweikamp
parents:
diff changeset
55 WIN_SMALL comm_title_column, comm_title_row
heinrichsweikamp
parents:
diff changeset
56 STRCPY_TEXT_PRINT tUsbTitle ; comm Mode
heinrichsweikamp
parents:
diff changeset
57 call TFT_standard_color
heinrichsweikamp
parents:
diff changeset
58 WIN_TOP .10
heinrichsweikamp
parents:
diff changeset
59 WIN_LEFT .1
heinrichsweikamp
parents:
diff changeset
60 movlw 0xDE
heinrichsweikamp
parents:
diff changeset
61 movwf TBLPTRL
heinrichsweikamp
parents:
diff changeset
62 movlw 0xEE
heinrichsweikamp
parents:
diff changeset
63 movwf TBLPTRH
heinrichsweikamp
parents:
diff changeset
64 movlw 0x01
heinrichsweikamp
parents:
diff changeset
65 movwf TBLPTRU
heinrichsweikamp
parents:
diff changeset
66 call color_image ; Show usb logo
heinrichsweikamp
parents:
diff changeset
67 WIN_SMALL comm_status1_column, comm_status1_row
heinrichsweikamp
parents:
diff changeset
68 STRCPY_TEXT_PRINT tUsbStarting ; Starting...
heinrichsweikamp
parents:
diff changeset
69 call TFT_serial ; Show serial and firmware version
heinrichsweikamp
parents:
diff changeset
70 bcf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump)
heinrichsweikamp
parents:
diff changeset
71 bcf switch_right
heinrichsweikamp
parents:
diff changeset
72 bcf comm_service_enabled
heinrichsweikamp
parents:
diff changeset
73 bsf menubit
heinrichsweikamp
parents:
diff changeset
74 bcf battery_removed_in_usb ; =1: The battery has been removed in USB
heinrichsweikamp
parents:
diff changeset
75 movlw timeout_comm_pre_mode
heinrichsweikamp
parents:
diff changeset
76 movwf timeout_counter
heinrichsweikamp
parents:
diff changeset
77 WIN_SMALL comm_status1_column+.80, comm_status1_row
heinrichsweikamp
parents:
diff changeset
78 STRCPY_TEXT_PRINT tUsbStartDone ; Done...
heinrichsweikamp
parents:
diff changeset
79 call enable_rs232 ; Also sets to speed_normal ...
heinrichsweikamp
parents:
diff changeset
80 comm_mode1:
heinrichsweikamp
parents:
diff changeset
81 bcf onesecupdate
heinrichsweikamp
parents:
diff changeset
82 bcf LEDr
heinrichsweikamp
parents:
diff changeset
83 dcfsnz timeout_counter,F
heinrichsweikamp
parents:
diff changeset
84 bra comm_service_exit ; Timeout -> Exit
heinrichsweikamp
parents:
diff changeset
85 comm_mode2:
heinrichsweikamp
parents:
diff changeset
86 call get_battery_voltage ; gets battery voltage
heinrichsweikamp
parents:
diff changeset
87 movlw .3
heinrichsweikamp
parents:
diff changeset
88 cpfslt batt_voltage+1 ; Batt Voltage less then 3*256mV?
heinrichsweikamp
parents:
diff changeset
89 bra comm_mode3 ; No
heinrichsweikamp
parents:
diff changeset
90 ; Set flag
heinrichsweikamp
parents:
diff changeset
91 bsf battery_removed_in_usb ; =1: The battery has been removed in USB
heinrichsweikamp
parents:
diff changeset
92 bra comm_mode4
heinrichsweikamp
parents:
diff changeset
93
heinrichsweikamp
parents:
diff changeset
94 comm_mode3:
heinrichsweikamp
parents:
diff changeset
95 ; Voltage ok. Do we have a new battery now?
heinrichsweikamp
parents:
diff changeset
96 btfsc battery_removed_in_usb ; =1: The battery has been removed in USB
heinrichsweikamp
parents:
diff changeset
97 goto new_battery_menu ; show "New battery dialog"
heinrichsweikamp
parents:
diff changeset
98
heinrichsweikamp
parents:
diff changeset
99 comm_mode4:
heinrichsweikamp
parents:
diff changeset
100 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
101
heinrichsweikamp
parents:
diff changeset
102 btfss vusb_in ; USB plugged in?
heinrichsweikamp
parents:
diff changeset
103 bra comm_service_exit_nousb ; Disconnected -> Exit
heinrichsweikamp
parents:
diff changeset
104
heinrichsweikamp
parents:
diff changeset
105 btfsc switch_right ; Abort with right
heinrichsweikamp
parents:
diff changeset
106 bra comm_service_exit
heinrichsweikamp
parents:
diff changeset
107
heinrichsweikamp
parents:
diff changeset
108 btfsc onesecupdate
heinrichsweikamp
parents:
diff changeset
109 bra comm_mode1
heinrichsweikamp
parents:
diff changeset
110
heinrichsweikamp
parents:
diff changeset
111 movlw 0xAA ; start byte=0xAA?
heinrichsweikamp
parents:
diff changeset
112 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
113 bra comm_mode2a
heinrichsweikamp
parents:
diff changeset
114 bra comm_mode2b ; Startbyte for service mode found
heinrichsweikamp
parents:
diff changeset
115 comm_mode2a:
heinrichsweikamp
parents:
diff changeset
116 movlw 0xBB ; start byte=0xBB?
heinrichsweikamp
parents:
diff changeset
117 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
118 bra comm_mode2 ; Cycle
heinrichsweikamp
parents:
diff changeset
119 bra comm_download_mode ; Startbyte for download mode found
heinrichsweikamp
parents:
diff changeset
120
heinrichsweikamp
parents:
diff changeset
121 comm_mode2b:
heinrichsweikamp
parents:
diff changeset
122 ; Startbyte found
heinrichsweikamp
parents:
diff changeset
123 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
124 movlw 0x4B
heinrichsweikamp
parents:
diff changeset
125 movwf TXREG1 ; Send Answer
heinrichsweikamp
parents:
diff changeset
126 ; Now, check comm command
heinrichsweikamp
parents:
diff changeset
127
heinrichsweikamp
parents:
diff changeset
128 call rs232_get_byte ; first byte
heinrichsweikamp
parents:
diff changeset
129 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
130 movff RCREG1,TXREG1 ; Echo
heinrichsweikamp
parents:
diff changeset
131 movlw UPPER comm_service_key
heinrichsweikamp
parents:
diff changeset
132 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
133 bra comm_mode1 ; Wrong -> Restart
heinrichsweikamp
parents:
diff changeset
134 call rs232_get_byte ; second byte
heinrichsweikamp
parents:
diff changeset
135 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
136 movff RCREG1,TXREG1 ; Echo
heinrichsweikamp
parents:
diff changeset
137 movlw HIGH (comm_service_key & 0xFFFF)
heinrichsweikamp
parents:
diff changeset
138 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
139 bra comm_mode1 ; Wrong -> Restart
heinrichsweikamp
parents:
diff changeset
140 call rs232_get_byte ; third byte
heinrichsweikamp
parents:
diff changeset
141 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
142 movff RCREG1,TXREG1 ; Echo
heinrichsweikamp
parents:
diff changeset
143 movlw LOW comm_service_key
heinrichsweikamp
parents:
diff changeset
144 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
145 bra comm_mode1 ; Wrong -> Restart
heinrichsweikamp
parents:
diff changeset
146
heinrichsweikamp
parents:
diff changeset
147 ; Enable comm service mode
heinrichsweikamp
parents:
diff changeset
148 WIN_SMALL comm_status2_column, comm_status2_row
heinrichsweikamp
parents:
diff changeset
149 STRCPY_TEXT_PRINT tUsbServiceMode ; Service mode enabled
heinrichsweikamp
parents:
diff changeset
150 bsf comm_service_enabled
heinrichsweikamp
parents:
diff changeset
151 bra comm_download_mode0 ; Startbyte for download mode found
heinrichsweikamp
parents:
diff changeset
152
heinrichsweikamp
parents:
diff changeset
153 comm_service_exit_nousb: ; Disconnected -> Exit
heinrichsweikamp
parents:
diff changeset
154 WIN_SMALL comm_status3_column, comm_status3_row
heinrichsweikamp
parents:
diff changeset
155 STRCPY_TEXT_PRINT tUsbClosed ; Port closed
heinrichsweikamp
parents:
diff changeset
156 bra comm_service_exit_common
heinrichsweikamp
parents:
diff changeset
157
heinrichsweikamp
parents:
diff changeset
158 comm_service_exit:
heinrichsweikamp
parents:
diff changeset
159 WIN_SMALL comm_status3_column, comm_status3_row
heinrichsweikamp
parents:
diff changeset
160 STRCPY_TEXT_PRINT tUsbExit ; Exited
heinrichsweikamp
parents:
diff changeset
161
heinrichsweikamp
parents:
diff changeset
162 comm_service_exit_common:
heinrichsweikamp
parents:
diff changeset
163 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
164 movlw 0xFF ; Reply FF
heinrichsweikamp
parents:
diff changeset
165 movwf TXREG1 ; Send Answer
heinrichsweikamp
parents:
diff changeset
166
heinrichsweikamp
parents:
diff changeset
167 ; Wait 1 second
heinrichsweikamp
parents:
diff changeset
168 bcf onesecupdate
heinrichsweikamp
parents:
diff changeset
169 btfss onesecupdate
heinrichsweikamp
parents:
diff changeset
170 bra $-2
heinrichsweikamp
parents:
diff changeset
171 ; Wait 1 second
heinrichsweikamp
parents:
diff changeset
172 bcf onesecupdate
heinrichsweikamp
parents:
diff changeset
173 btfss onesecupdate
heinrichsweikamp
parents:
diff changeset
174 bra $-2
heinrichsweikamp
parents:
diff changeset
175
heinrichsweikamp
parents:
diff changeset
176 call disable_rs232
heinrichsweikamp
parents:
diff changeset
177 bcf LEDr
heinrichsweikamp
parents:
diff changeset
178 goto restart
heinrichsweikamp
parents:
diff changeset
179
heinrichsweikamp
parents:
diff changeset
180 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
181
heinrichsweikamp
parents:
diff changeset
182 comm_service_ll_bootloader:
heinrichsweikamp
parents:
diff changeset
183 bsf LEDr
heinrichsweikamp
parents:
diff changeset
184 WIN_SMALL comm_status3_column, comm_status3_row
heinrichsweikamp
parents:
diff changeset
185 STRCPY_TEXT_PRINT tUsbLlBld ; Low Level Bootloader started
heinrichsweikamp
parents:
diff changeset
186 WIN_TOP comm_warning_row
heinrichsweikamp
parents:
diff changeset
187 WIN_LEFT comm_warning_column
heinrichsweikamp
parents:
diff changeset
188 TFT_WRITE_PROM_IMAGE dive_warning_block ; Show Warning icon
heinrichsweikamp
parents:
diff changeset
189 goto 0x1FF0C
heinrichsweikamp
parents:
diff changeset
190
heinrichsweikamp
parents:
diff changeset
191 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
192 ; Sends external flash from 0x3E0000 to 0x3FD000 (118784bytes) via comm
heinrichsweikamp
parents:
diff changeset
193 ;
heinrichsweikamp
parents:
diff changeset
194 comm_send_firmware:
heinrichsweikamp
parents:
diff changeset
195 movlw 0x50 ; send echo
heinrichsweikamp
parents:
diff changeset
196 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
197 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
198
heinrichsweikamp
parents:
diff changeset
199 ; Read 5 bytes into buffer.
heinrichsweikamp
parents:
diff changeset
200 lfsr FSR2,buffer
heinrichsweikamp
parents:
diff changeset
201 movlw .5 ; counter
heinrichsweikamp
parents:
diff changeset
202 movwf lo
heinrichsweikamp
parents:
diff changeset
203 movlw 0x55 ; 5'ft byte checksum.
heinrichsweikamp
parents:
diff changeset
204 movwf hi
heinrichsweikamp
parents:
diff changeset
205
heinrichsweikamp
parents:
diff changeset
206 comm_send_firmware_loop:
heinrichsweikamp
parents:
diff changeset
207 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
208 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
209 bra comm_send_firmware_abort ; No, abort!
heinrichsweikamp
parents:
diff changeset
210 movf RCREG1,W
heinrichsweikamp
parents:
diff changeset
211 movwf POSTINC2 ; Store checksum byte.
heinrichsweikamp
parents:
diff changeset
212 xorwf hi,F ; Also xor into checksum
heinrichsweikamp
parents:
diff changeset
213 rlncf hi,F ; And rotate it.
heinrichsweikamp
parents:
diff changeset
214 decfsz lo,F
heinrichsweikamp
parents:
diff changeset
215 bra comm_send_firmware_loop
heinrichsweikamp
parents:
diff changeset
216
heinrichsweikamp
parents:
diff changeset
217 ; Check that 5ft byte checksum's checksum
heinrichsweikamp
parents:
diff changeset
218 movf hi,W
heinrichsweikamp
parents:
diff changeset
219 bnz comm_send_firmware_failed
heinrichsweikamp
parents:
diff changeset
220
heinrichsweikamp
parents:
diff changeset
221 movlw 0x4C ; send OK
heinrichsweikamp
parents:
diff changeset
222 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
223 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
224
heinrichsweikamp
parents:
diff changeset
225 ; Passed: goto second stage verification.
heinrichsweikamp
parents:
diff changeset
226 ; NOTE: Bootloader is Bank0. With buffer at address 0x200.
heinrichsweikamp
parents:
diff changeset
227 goto 0x1FDF0 ; And pray...
heinrichsweikamp
parents:
diff changeset
228
heinrichsweikamp
parents:
diff changeset
229 comm_send_firmware_failed:
heinrichsweikamp
parents:
diff changeset
230 WIN_SMALL comm_string_column, comm_string_row
heinrichsweikamp
parents:
diff changeset
231 TFT_WARNINGS_COLOR
heinrichsweikamp
parents:
diff changeset
232 STRCPY_PRINT "Checksum failed"
heinrichsweikamp
parents:
diff changeset
233
heinrichsweikamp
parents:
diff changeset
234 comm_send_firmware_abort:
heinrichsweikamp
parents:
diff changeset
235
heinrichsweikamp
parents:
diff changeset
236 movlw 0xFF ; send ABORTED byte.
heinrichsweikamp
parents:
diff changeset
237 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
238 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
239 bra comm_download_mode0 ; Done.
heinrichsweikamp
parents:
diff changeset
240
heinrichsweikamp
parents:
diff changeset
241 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
242 ; Reset to Dive 1 in logbook
heinrichsweikamp
parents:
diff changeset
243
heinrichsweikamp
parents:
diff changeset
244 comm_reset_logbook_pointers:
heinrichsweikamp
parents:
diff changeset
245 clrf EEADRH ; Make sure to select eeprom bank 0
heinrichsweikamp
parents:
diff changeset
246 clrf EEDATA
heinrichsweikamp
parents:
diff changeset
247 write_int_eeprom .4
heinrichsweikamp
parents:
diff changeset
248 write_int_eeprom .5
heinrichsweikamp
parents:
diff changeset
249 write_int_eeprom .6
heinrichsweikamp
parents:
diff changeset
250 write_int_eeprom .2 ; Also, delete total dive counter
heinrichsweikamp
parents:
diff changeset
251 write_int_eeprom .3
heinrichsweikamp
parents:
diff changeset
252 call ext_flash_erase_logbook ; And complete logbook (!)
heinrichsweikamp
parents:
diff changeset
253 bra comm_download_mode0 ; Done.
heinrichsweikamp
parents:
diff changeset
254
heinrichsweikamp
parents:
diff changeset
255 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
256 comm_reset_battery_gauge: ; Resets battery gauge registers
heinrichsweikamp
parents:
diff changeset
257 call reset_battery_pointer ; Resets battery pointer 0x07-0x0C and battery_gauge:5
heinrichsweikamp
parents:
diff changeset
258 bra comm_download_mode0 ; Done.
heinrichsweikamp
parents:
diff changeset
259
heinrichsweikamp
parents:
diff changeset
260 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
261 ; erases range in 4kB steps
heinrichsweikamp
parents:
diff changeset
262
heinrichsweikamp
parents:
diff changeset
263 comm_erase_range4kb:
heinrichsweikamp
parents:
diff changeset
264 movlw 0x42 ; send echo
heinrichsweikamp
parents:
diff changeset
265 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
266 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
267
heinrichsweikamp
parents:
diff changeset
268 bcf INTCON,GIE ; All interrups off!
heinrichsweikamp
parents:
diff changeset
269
heinrichsweikamp
parents:
diff changeset
270 rcall comm_get_flash_address ; Get three bytes address or return
heinrichsweikamp
parents:
diff changeset
271 btfsc rs232_recieve_overflow ; Got Data?
heinrichsweikamp
parents:
diff changeset
272 bra comm_download_mode0 ; No, Done.
heinrichsweikamp
parents:
diff changeset
273
heinrichsweikamp
parents:
diff changeset
274 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
275 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
276 bra comm_download_mode0 ; No, Done.
heinrichsweikamp
parents:
diff changeset
277 movff RCREG1,lo
heinrichsweikamp
parents:
diff changeset
278 ; Got 4bytes: 3bytes address and 1 bytes (lo) amount of 4kB blocks
heinrichsweikamp
parents:
diff changeset
279
heinrichsweikamp
parents:
diff changeset
280 comm_erase_range4kb1:
heinrichsweikamp
parents:
diff changeset
281 call ext_flash_erase4kB ; Erase block!
heinrichsweikamp
parents:
diff changeset
282
heinrichsweikamp
parents:
diff changeset
283 movlw 0x10
heinrichsweikamp
parents:
diff changeset
284 addwf ext_flash_address+1,F
heinrichsweikamp
parents:
diff changeset
285 movlw .0
heinrichsweikamp
parents:
diff changeset
286 addwfc ext_flash_address+2,F ; Increase address by .4096, or 0x1000
heinrichsweikamp
parents:
diff changeset
287 decfsz lo,F
heinrichsweikamp
parents:
diff changeset
288 bra comm_erase_range4kb1 ; Loop until lo=zero
heinrichsweikamp
parents:
diff changeset
289
heinrichsweikamp
parents:
diff changeset
290 bra comm_download_mode0 ; Done (Sends the 4C OK too).
heinrichsweikamp
parents:
diff changeset
291
heinrichsweikamp
parents:
diff changeset
292 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
293
heinrichsweikamp
parents:
diff changeset
294 comm_erase_4kb: ; Get 3 bytes start address
heinrichsweikamp
parents:
diff changeset
295 bcf INTCON,GIE ; All interrups off!
heinrichsweikamp
parents:
diff changeset
296
heinrichsweikamp
parents:
diff changeset
297 rcall comm_get_flash_address ; Get three bytes address or return
heinrichsweikamp
parents:
diff changeset
298 btfsc rs232_recieve_overflow ; Got Data?
heinrichsweikamp
parents:
diff changeset
299 bra comm_download_mode0 ; No, Done.
heinrichsweikamp
parents:
diff changeset
300
heinrichsweikamp
parents:
diff changeset
301 call ext_flash_erase4kB ; Erase one block
heinrichsweikamp
parents:
diff changeset
302 bra comm_download_mode0 ; Done.
heinrichsweikamp
parents:
diff changeset
303
heinrichsweikamp
parents:
diff changeset
304 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
305
heinrichsweikamp
parents:
diff changeset
306 comm_write_range: ; Get 3 bytes start address
heinrichsweikamp
parents:
diff changeset
307 movlw 0x30 ; send echo
heinrichsweikamp
parents:
diff changeset
308 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
309 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
310
heinrichsweikamp
parents:
diff changeset
311 bcf INTCON,GIE ; All interrups off!
heinrichsweikamp
parents:
diff changeset
312
heinrichsweikamp
parents:
diff changeset
313 rcall comm_get_flash_address ; Get three bytes address or return
heinrichsweikamp
parents:
diff changeset
314 btfsc rs232_recieve_overflow ; Got Data?
heinrichsweikamp
parents:
diff changeset
315 bra comm_download_mode0 ; No, Done.
heinrichsweikamp
parents:
diff changeset
316
heinrichsweikamp
parents:
diff changeset
317 comm_write_range_loop:
heinrichsweikamp
parents:
diff changeset
318 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
319 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
320 bra comm_download_mode0 ; No, Done (and send OK byte too).
heinrichsweikamp
parents:
diff changeset
321 movf RCREG1,W
heinrichsweikamp
parents:
diff changeset
322 call ext_flash_byte_write ; write one byte
heinrichsweikamp
parents:
diff changeset
323 call incf_ext_flash_address_p1 ; increase address+1
heinrichsweikamp
parents:
diff changeset
324 bra comm_write_range_loop
heinrichsweikamp
parents:
diff changeset
325
heinrichsweikamp
parents:
diff changeset
326 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
327
heinrichsweikamp
parents:
diff changeset
328 comm_send_range: ; Get 3 bytes start address and 3 bytes amount
heinrichsweikamp
parents:
diff changeset
329 movlw 0x20 ; send echo
heinrichsweikamp
parents:
diff changeset
330 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
331 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
332
heinrichsweikamp
parents:
diff changeset
333 bcf INTCON,GIE ; All interrups off!
heinrichsweikamp
parents:
diff changeset
334
heinrichsweikamp
parents:
diff changeset
335 rcall comm_get_flash_address ; Get three bytes address or return
heinrichsweikamp
parents:
diff changeset
336 btfsc rs232_recieve_overflow ; Got Data?
heinrichsweikamp
parents:
diff changeset
337 bra comm_download_mode0 ; No, Done.
heinrichsweikamp
parents:
diff changeset
338
heinrichsweikamp
parents:
diff changeset
339 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
340 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
341 bra comm_download_mode0 ; No, Done.
heinrichsweikamp
parents:
diff changeset
342 movff RCREG1,up
heinrichsweikamp
parents:
diff changeset
343 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
344 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
345 bra comm_download_mode0 ; No, Done.
heinrichsweikamp
parents:
diff changeset
346 movff RCREG1,hi
heinrichsweikamp
parents:
diff changeset
347 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
348 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
349 bra comm_download_mode0 ; No, Done.
heinrichsweikamp
parents:
diff changeset
350 movff RCREG1,lo
heinrichsweikamp
parents:
diff changeset
351
heinrichsweikamp
parents:
diff changeset
352 ; If lo==0, we must precondition hi because there is to many bytes send !
heinrichsweikamp
parents:
diff changeset
353 movf lo,W
heinrichsweikamp
parents:
diff changeset
354 bnz $+4
heinrichsweikamp
parents:
diff changeset
355 decf hi,F
heinrichsweikamp
parents:
diff changeset
356
heinrichsweikamp
parents:
diff changeset
357 ; 6bytes received, send data
heinrichsweikamp
parents:
diff changeset
358 comm_send_range2: ; needs ext_flash_address:3 start address and up:hi:lo amount
heinrichsweikamp
parents:
diff changeset
359 call ext_flash_read_block_start
heinrichsweikamp
parents:
diff changeset
360 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
361
heinrichsweikamp
parents:
diff changeset
362 bra comm_send_range24 ; counter 24bit
heinrichsweikamp
parents:
diff changeset
363 comm_send_range24_loop:
heinrichsweikamp
parents:
diff changeset
364 call ext_flash_read_block ; Read one byte
heinrichsweikamp
parents:
diff changeset
365 movwf TXREG1 ; Start new transmit
heinrichsweikamp
parents:
diff changeset
366 comm_send_range24:
heinrichsweikamp
parents:
diff changeset
367 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
368 decfsz lo,F
heinrichsweikamp
parents:
diff changeset
369 bra comm_send_range24_loop
heinrichsweikamp
parents:
diff changeset
370 decf hi,F
heinrichsweikamp
parents:
diff changeset
371 movlw 0xFF
heinrichsweikamp
parents:
diff changeset
372 cpfseq hi
heinrichsweikamp
parents:
diff changeset
373 bra comm_send_range24_loop
heinrichsweikamp
parents:
diff changeset
374 decf up,F
heinrichsweikamp
parents:
diff changeset
375 movlw 0xFF
heinrichsweikamp
parents:
diff changeset
376 cpfseq up
heinrichsweikamp
parents:
diff changeset
377 bra comm_send_range24_loop
heinrichsweikamp
parents:
diff changeset
378 call ext_flash_read_block_stop
heinrichsweikamp
parents:
diff changeset
379
heinrichsweikamp
parents:
diff changeset
380 bra comm_download_mode0 ; Done.
heinrichsweikamp
parents:
diff changeset
381
heinrichsweikamp
parents:
diff changeset
382 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
383
heinrichsweikamp
parents:
diff changeset
384 comm_get_flash_address:
heinrichsweikamp
parents:
diff changeset
385 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
386 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
387 return ; No, return
heinrichsweikamp
parents:
diff changeset
388 movff RCREG1,ext_flash_address+2
heinrichsweikamp
parents:
diff changeset
389 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
390 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
391 return ; No, return
heinrichsweikamp
parents:
diff changeset
392 movff RCREG1,ext_flash_address+1
heinrichsweikamp
parents:
diff changeset
393 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
394 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
395 return ; No, return
heinrichsweikamp
parents:
diff changeset
396 movff RCREG1,ext_flash_address+0
heinrichsweikamp
parents:
diff changeset
397 return
heinrichsweikamp
parents:
diff changeset
398
heinrichsweikamp
parents:
diff changeset
399 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
400
heinrichsweikamp
parents:
diff changeset
401 comm_download_mode:
heinrichsweikamp
parents:
diff changeset
402 ; Enable comm download mode
heinrichsweikamp
parents:
diff changeset
403 WIN_SMALL comm_status2_column, comm_status2_row
heinrichsweikamp
parents:
diff changeset
404 STRCPY_TEXT_PRINT tUsbDownloadMode; Download mode enabled
heinrichsweikamp
parents:
diff changeset
405 bsf INTCON,GIE ; All interrups on
heinrichsweikamp
parents:
diff changeset
406 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
407 movlw 0xBB ; Command Echo
heinrichsweikamp
parents:
diff changeset
408 movwf TXREG1 ; Send Answer
heinrichsweikamp
parents:
diff changeset
409 comm_download_mode0:
heinrichsweikamp
parents:
diff changeset
410 bsf INTCON,GIE ; All interrups on
heinrichsweikamp
parents:
diff changeset
411 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
412 movlw 0x4C ; 4C in service mode
heinrichsweikamp
parents:
diff changeset
413 btfss comm_service_enabled
heinrichsweikamp
parents:
diff changeset
414 movlw 0x4D ; 4D in download mode
heinrichsweikamp
parents:
diff changeset
415 movwf TXREG1 ; Send Answer
heinrichsweikamp
parents:
diff changeset
416 movlw timeout_service_mode
heinrichsweikamp
parents:
diff changeset
417 movwf timeout_counter ; Timeout
heinrichsweikamp
parents:
diff changeset
418 bcf switch_right
heinrichsweikamp
parents:
diff changeset
419 comm_download_mode1:
heinrichsweikamp
parents:
diff changeset
420 bcf onesecupdate
heinrichsweikamp
parents:
diff changeset
421 dcfsnz timeout_counter,F
heinrichsweikamp
parents:
diff changeset
422 bra comm_service_exit ; Timeout -> Exit
heinrichsweikamp
parents:
diff changeset
423 comm_download_mode2:
heinrichsweikamp
parents:
diff changeset
424 call rs232_get_byte ; Check for a byte
heinrichsweikamp
parents:
diff changeset
425 btfsc comm_service_enabled
heinrichsweikamp
parents:
diff changeset
426 btg LEDr ; Blink in Service mode
heinrichsweikamp
parents:
diff changeset
427 btfss vusb_in ; USB plugged in?
heinrichsweikamp
parents:
diff changeset
428 bra comm_service_exit_nousb ; Disconnected -> Exit
heinrichsweikamp
parents:
diff changeset
429 btfsc switch_right ; Abort with right
heinrichsweikamp
parents:
diff changeset
430 bra comm_service_exit
heinrichsweikamp
parents:
diff changeset
431 btfsc onesecupdate
heinrichsweikamp
parents:
diff changeset
432 bra comm_download_mode1
heinrichsweikamp
parents:
diff changeset
433 btfsc rs232_recieve_overflow
heinrichsweikamp
parents:
diff changeset
434 bra comm_download_mode2 ; Wait for command byte
heinrichsweikamp
parents:
diff changeset
435
heinrichsweikamp
parents:
diff changeset
436 ; command received!
heinrichsweikamp
parents:
diff changeset
437 bcf LEDr
heinrichsweikamp
parents:
diff changeset
438 movlw 0xFF
heinrichsweikamp
parents:
diff changeset
439 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
440 bra $+4
heinrichsweikamp
parents:
diff changeset
441 bra comm_service_exit ; exit
heinrichsweikamp
parents:
diff changeset
442 movlw "a"
heinrichsweikamp
parents:
diff changeset
443 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
444 bra $+4
heinrichsweikamp
parents:
diff changeset
445 bra comm_send_headers ; Send all 256 dive headers
heinrichsweikamp
parents:
diff changeset
446 movlw "b"
heinrichsweikamp
parents:
diff changeset
447 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
448 bra $+4
heinrichsweikamp
parents:
diff changeset
449 bra comm_set_time ; Read time and date from the PC and set clock
heinrichsweikamp
parents:
diff changeset
450 movlw "c"
heinrichsweikamp
parents:
diff changeset
451 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
452 bra $+4
heinrichsweikamp
parents:
diff changeset
453 bra comm_set_custom_text ; Send a opt_name_length byte string of custom text.
heinrichsweikamp
parents:
diff changeset
454 movlw "f"
heinrichsweikamp
parents:
diff changeset
455 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
456 bra $+4
heinrichsweikamp
parents:
diff changeset
457 bra comm_send_dive ; Send header and profile for one dive
heinrichsweikamp
parents:
diff changeset
458 movlw "i"
heinrichsweikamp
parents:
diff changeset
459 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
460 bra $+4
heinrichsweikamp
parents:
diff changeset
461 bra comm_identify ; Send firmware, serial, etc.
heinrichsweikamp
parents:
diff changeset
462 movlw "n"
heinrichsweikamp
parents:
diff changeset
463 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
464 bra $+4
heinrichsweikamp
parents:
diff changeset
465 bra comm_send_string ; Send a 15byte string to the screen
heinrichsweikamp
parents:
diff changeset
466 movlw "l"
heinrichsweikamp
parents:
diff changeset
467 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
468 bra $+4
heinrichsweikamp
parents:
diff changeset
469 call TFT_dump_screen ; Dump the screen contents
heinrichsweikamp
parents:
diff changeset
470
heinrichsweikamp
parents:
diff changeset
471 btfss comm_service_enabled ; Done for Download mode
heinrichsweikamp
parents:
diff changeset
472 bra comm_download_mode0 ; Loop with timeout reset
heinrichsweikamp
parents:
diff changeset
473
heinrichsweikamp
parents:
diff changeset
474 movlw 0x20
heinrichsweikamp
parents:
diff changeset
475 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
476 bra $+4
heinrichsweikamp
parents:
diff changeset
477 bra comm_send_range ; send hi:lo:temp1 bytes starting from ext_flash_address:3
heinrichsweikamp
parents:
diff changeset
478 movlw 0x22
heinrichsweikamp
parents:
diff changeset
479 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
480 bra $+4
heinrichsweikamp
parents:
diff changeset
481 bra comm_reset_logbook_pointers ; Resets all logbook pointers and the logbook (!)
heinrichsweikamp
parents:
diff changeset
482 movlw 0x23
heinrichsweikamp
parents:
diff changeset
483 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
484 bra $+4
heinrichsweikamp
parents:
diff changeset
485 bra comm_reset_battery_gauge ; Resets battery gauge registers
heinrichsweikamp
parents:
diff changeset
486 movlw 0x30
heinrichsweikamp
parents:
diff changeset
487 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
488 bra $+4
heinrichsweikamp
parents:
diff changeset
489 bra comm_write_range ; write bytes starting from ext_flash_address:3 (Stop when timeout)
heinrichsweikamp
parents:
diff changeset
490 movlw 0x40
heinrichsweikamp
parents:
diff changeset
491 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
492 bra $+4
heinrichsweikamp
parents:
diff changeset
493 bra comm_erase_4kb ; erases 4kB block from ext_flash_address:3 (Warning: No confirmation or built-in security here...)
heinrichsweikamp
parents:
diff changeset
494 movlw 0x42
heinrichsweikamp
parents:
diff changeset
495 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
496 bra $+4
heinrichsweikamp
parents:
diff changeset
497 bra comm_erase_range4kb ; erases range in 4kB steps (Get 3 bytes address and 1byte amount of 4kB blocks)
heinrichsweikamp
parents:
diff changeset
498 movlw 0x50
heinrichsweikamp
parents:
diff changeset
499 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
500 bra $+4
heinrichsweikamp
parents:
diff changeset
501 bra comm_send_firmware ; sends firmware from external flash from 0x3E0000 to 0x3FD000 (118784bytes) via comm
heinrichsweikamp
parents:
diff changeset
502 movlw "t"
heinrichsweikamp
parents:
diff changeset
503 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
504 bra $+4
heinrichsweikamp
parents:
diff changeset
505 goto testloop ; Start raw-data testloop
heinrichsweikamp
parents:
diff changeset
506 movlw "r"
heinrichsweikamp
parents:
diff changeset
507 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
508 bra $+4
heinrichsweikamp
parents:
diff changeset
509 call option_reset_all ; Reset all options to factory default.
heinrichsweikamp
parents:
diff changeset
510 movlw 0xC1
heinrichsweikamp
parents:
diff changeset
511 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
512 bra $+4
heinrichsweikamp
parents:
diff changeset
513 bra comm_service_ll_bootloader ; Start low-level bootloader
heinrichsweikamp
parents:
diff changeset
514 bra comm_download_mode0 ; Loop with timeout reset
heinrichsweikamp
parents:
diff changeset
515
heinrichsweikamp
parents:
diff changeset
516 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
517
heinrichsweikamp
parents:
diff changeset
518 comm_send_headers:
heinrichsweikamp
parents:
diff changeset
519 movlw "a" ; send echo
heinrichsweikamp
parents:
diff changeset
520 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
521 ; Send 256 bytes/dive (Header)
heinrichsweikamp
parents:
diff changeset
522 ; 1st: 200000h-2000FFh
heinrichsweikamp
parents:
diff changeset
523 ; 2nd: 201000h-2010FFh
heinrichsweikamp
parents:
diff changeset
524 ; 3rd: 202000h-2020FFh
heinrichsweikamp
parents:
diff changeset
525 ; 100: 264000h-2640FFh
heinrichsweikamp
parents:
diff changeset
526 ; 256: 2FF000h-2FF0FFh
heinrichsweikamp
parents:
diff changeset
527 movlw 0x1F
heinrichsweikamp
parents:
diff changeset
528 movwf ext_flash_address+2
heinrichsweikamp
parents:
diff changeset
529 movlw 0xF0
heinrichsweikamp
parents:
diff changeset
530 movwf ext_flash_address+1
heinrichsweikamp
parents:
diff changeset
531
heinrichsweikamp
parents:
diff changeset
532 comm_send_headers2:
heinrichsweikamp
parents:
diff changeset
533 movlw 0x00
heinrichsweikamp
parents:
diff changeset
534 movwf ext_flash_address+0
heinrichsweikamp
parents:
diff changeset
535 ; Adjust address for next dive
heinrichsweikamp
parents:
diff changeset
536 movlw 0x10
heinrichsweikamp
parents:
diff changeset
537 addwf ext_flash_address+1
heinrichsweikamp
parents:
diff changeset
538 movlw 0x00
heinrichsweikamp
parents:
diff changeset
539 addwfc ext_flash_address+2
heinrichsweikamp
parents:
diff changeset
540
heinrichsweikamp
parents:
diff changeset
541 movlw 0x30
heinrichsweikamp
parents:
diff changeset
542 cpfseq ext_flash_address+2 ; All 256 dive send?
heinrichsweikamp
parents:
diff changeset
543 bra comm_send_headers4 ; No, continue
heinrichsweikamp
parents:
diff changeset
544 bra comm_download_mode0 ; Done. Loop with timeout reset
heinrichsweikamp
parents:
diff changeset
545
heinrichsweikamp
parents:
diff changeset
546 comm_send_headers4:
heinrichsweikamp
parents:
diff changeset
547 clrf lo ; Counter
heinrichsweikamp
parents:
diff changeset
548 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
549 call ext_flash_read_block_start ; 1st byte
heinrichsweikamp
parents:
diff changeset
550 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
551 bra comm_send_headers3 ; counter 24bit
heinrichsweikamp
parents:
diff changeset
552 comm_send_headers_loop:
heinrichsweikamp
parents:
diff changeset
553 call ext_flash_read_block ; Read one byte
heinrichsweikamp
parents:
diff changeset
554 movwf TXREG1 ; Start new transmit
heinrichsweikamp
parents:
diff changeset
555 comm_send_headers3:
heinrichsweikamp
parents:
diff changeset
556 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
557 decfsz lo,F
heinrichsweikamp
parents:
diff changeset
558 bra comm_send_headers_loop
heinrichsweikamp
parents:
diff changeset
559 call ext_flash_read_block_stop
heinrichsweikamp
parents:
diff changeset
560 bra comm_send_headers2 ; continue
heinrichsweikamp
parents:
diff changeset
561
heinrichsweikamp
parents:
diff changeset
562 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
563 ;
heinrichsweikamp
parents:
diff changeset
564
heinrichsweikamp
parents:
diff changeset
565 comm_set_time:
heinrichsweikamp
parents:
diff changeset
566 movlw "b" ; send echo
heinrichsweikamp
parents:
diff changeset
567 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
568
heinrichsweikamp
parents:
diff changeset
569 call rs232_wait_tx ; wait for UART
heinrichsweikamp
parents:
diff changeset
570 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
571 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
572 return ; No, abort!
heinrichsweikamp
parents:
diff changeset
573 movff RCREG1, hours
heinrichsweikamp
parents:
diff changeset
574 movlw d'24'
heinrichsweikamp
parents:
diff changeset
575 cpfslt hours
heinrichsweikamp
parents:
diff changeset
576 clrf hours
heinrichsweikamp
parents:
diff changeset
577 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
578 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
579 return ; No, abort!
heinrichsweikamp
parents:
diff changeset
580 movff RCREG1, mins
heinrichsweikamp
parents:
diff changeset
581 movlw d'60'
heinrichsweikamp
parents:
diff changeset
582 cpfslt mins
heinrichsweikamp
parents:
diff changeset
583 clrf mins
heinrichsweikamp
parents:
diff changeset
584 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
585 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
586 return ; No, abort!
heinrichsweikamp
parents:
diff changeset
587 movff RCREG1, secs
heinrichsweikamp
parents:
diff changeset
588 movlw d'60'
heinrichsweikamp
parents:
diff changeset
589 cpfslt secs
heinrichsweikamp
parents:
diff changeset
590 clrf secs
heinrichsweikamp
parents:
diff changeset
591 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
592 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
593 return ; No, abort!
heinrichsweikamp
parents:
diff changeset
594 movff RCREG1, month
heinrichsweikamp
parents:
diff changeset
595 movlw d'13'
heinrichsweikamp
parents:
diff changeset
596 cpfslt month
heinrichsweikamp
parents:
diff changeset
597 movwf month
heinrichsweikamp
parents:
diff changeset
598 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
599 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
600 return ; No, abort!
heinrichsweikamp
parents:
diff changeset
601 rcall comm_check_day ; Check day
heinrichsweikamp
parents:
diff changeset
602 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
603 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
604 return ; No, abort!
heinrichsweikamp
parents:
diff changeset
605 movff RCREG1, year
heinrichsweikamp
parents:
diff changeset
606 movlw d'100'
heinrichsweikamp
parents:
diff changeset
607 cpfslt year
heinrichsweikamp
parents:
diff changeset
608 clrf year
heinrichsweikamp
parents:
diff changeset
609 ; All ok, set RTCC
heinrichsweikamp
parents:
diff changeset
610 call rtc_set_rtc ; writes mins,sec,hours,day,month and year to rtc module
heinrichsweikamp
parents:
diff changeset
611 bra comm_download_mode0 ; Done. back to loop with timeout reset
heinrichsweikamp
parents:
diff changeset
612
heinrichsweikamp
parents:
diff changeset
613 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
614 ; Set OSTC3 custom text string (opt_name_length ascii chars).
heinrichsweikamp
parents:
diff changeset
615 ;
heinrichsweikamp
parents:
diff changeset
616
heinrichsweikamp
parents:
diff changeset
617 comm_set_custom_text:
heinrichsweikamp
parents:
diff changeset
618 movlw "c" ; send echo
heinrichsweikamp
parents:
diff changeset
619 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
620 call rs232_wait_tx ; wait for UART
heinrichsweikamp
parents:
diff changeset
621 lfsr FSR2,opt_name
heinrichsweikamp
parents:
diff changeset
622 movlw opt_name_length
heinrichsweikamp
parents:
diff changeset
623 movwf lo ; counter
heinrichsweikamp
parents:
diff changeset
624 comm_set_ctext_loop:
heinrichsweikamp
parents:
diff changeset
625 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
626 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
627 return ; No, abort!
heinrichsweikamp
parents:
diff changeset
628 movff RCREG1,POSTINC2 ; Store character
heinrichsweikamp
parents:
diff changeset
629 decfsz lo,F
heinrichsweikamp
parents:
diff changeset
630 bra comm_set_ctext_loop
heinrichsweikamp
parents:
diff changeset
631 bra comm_download_mode0 ; Done. Loop with timeout reset
heinrichsweikamp
parents:
diff changeset
632
heinrichsweikamp
parents:
diff changeset
633 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
634 ; Reply Serial (2 bytes low:high), firmware (major.minor) and custom text.
heinrichsweikamp
parents:
diff changeset
635 ;
heinrichsweikamp
parents:
diff changeset
636
heinrichsweikamp
parents:
diff changeset
637 comm_identify:
heinrichsweikamp
parents:
diff changeset
638 movlw "i" ; send echo
heinrichsweikamp
parents:
diff changeset
639 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
640 call rs232_wait_tx ; wait for UART
heinrichsweikamp
parents:
diff changeset
641
heinrichsweikamp
parents:
diff changeset
642 ;---- Read serial from internal EEPROM address 0000
heinrichsweikamp
parents:
diff changeset
643 clrf EEADRH
heinrichsweikamp
parents:
diff changeset
644 clrf EEADR ; Get Serial number LOW
heinrichsweikamp
parents:
diff changeset
645 call read_eeprom ; read byte
heinrichsweikamp
parents:
diff changeset
646 movff EEDATA,lo
heinrichsweikamp
parents:
diff changeset
647 incf EEADR,F ; Get Serial number HIGH
heinrichsweikamp
parents:
diff changeset
648 call read_eeprom ; read byte
heinrichsweikamp
parents:
diff changeset
649 movff EEDATA,hi
heinrichsweikamp
parents:
diff changeset
650
heinrichsweikamp
parents:
diff changeset
651 ;---- Emit serial number
heinrichsweikamp
parents:
diff changeset
652 movff lo,TXREG1
heinrichsweikamp
parents:
diff changeset
653 call rs232_wait_tx
heinrichsweikamp
parents:
diff changeset
654 movff hi,TXREG1
heinrichsweikamp
parents:
diff changeset
655 call rs232_wait_tx
heinrichsweikamp
parents:
diff changeset
656
heinrichsweikamp
parents:
diff changeset
657 ;---- Emit fiwmware hi.lo
heinrichsweikamp
parents:
diff changeset
658 movlw softwareversion_x
heinrichsweikamp
parents:
diff changeset
659 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
660 call rs232_wait_tx
heinrichsweikamp
parents:
diff changeset
661 movlw softwareversion_y
heinrichsweikamp
parents:
diff changeset
662 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
663 call rs232_wait_tx
heinrichsweikamp
parents:
diff changeset
664
heinrichsweikamp
parents:
diff changeset
665 ;---- Emit custom text
heinrichsweikamp
parents:
diff changeset
666 movlw opt_name_length
heinrichsweikamp
parents:
diff changeset
667 movwf hi
heinrichsweikamp
parents:
diff changeset
668 lfsr FSR2,opt_name
heinrichsweikamp
parents:
diff changeset
669
heinrichsweikamp
parents:
diff changeset
670 common_identify_loop:
heinrichsweikamp
parents:
diff changeset
671 movff POSTINC2,TXREG1
heinrichsweikamp
parents:
diff changeset
672 call rs232_wait_tx
heinrichsweikamp
parents:
diff changeset
673 decfsz hi,F
heinrichsweikamp
parents:
diff changeset
674 bra common_identify_loop
heinrichsweikamp
parents:
diff changeset
675
heinrichsweikamp
parents:
diff changeset
676 bra comm_download_mode0 ; Done.
heinrichsweikamp
parents:
diff changeset
677
heinrichsweikamp
parents:
diff changeset
678
heinrichsweikamp
parents:
diff changeset
679 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
680
heinrichsweikamp
parents:
diff changeset
681 comm_send_dive:
heinrichsweikamp
parents:
diff changeset
682 movlw "f" ; send echo
heinrichsweikamp
parents:
diff changeset
683 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
684
heinrichsweikamp
parents:
diff changeset
685 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
686 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
687 bra comm_download_mode0 ; No, abort!
heinrichsweikamp
parents:
diff changeset
688 movff RCREG1,lo ; Store dive number (0-255)
heinrichsweikamp
parents:
diff changeset
689 ; First, send the header (again)
heinrichsweikamp
parents:
diff changeset
690 ; Set ext_flash_address:3 to TOC entry of this dive
heinrichsweikamp
parents:
diff changeset
691 ; 1st: 200000h-200FFFh -> lo=0
heinrichsweikamp
parents:
diff changeset
692 ; 2nd: 201000h-201FFFh -> lo=1
heinrichsweikamp
parents:
diff changeset
693 ; 3rd: 202000h-202FFFh -> lo=2
heinrichsweikamp
parents:
diff changeset
694 ; 256: 2FF000h-2FFFFFh -> lo=255
heinrichsweikamp
parents:
diff changeset
695 clrf ext_flash_address+0
heinrichsweikamp
parents:
diff changeset
696 clrf ext_flash_address+1
heinrichsweikamp
parents:
diff changeset
697 movlw 0x20
heinrichsweikamp
parents:
diff changeset
698 movwf ext_flash_address+2
heinrichsweikamp
parents:
diff changeset
699 movlw .16
heinrichsweikamp
parents:
diff changeset
700 mulwf lo ; lo*16 = offset to 0x2000 (up:hi)
heinrichsweikamp
parents:
diff changeset
701 movf PRODL,W
heinrichsweikamp
parents:
diff changeset
702 addwf ext_flash_address+1,F
heinrichsweikamp
parents:
diff changeset
703 movf PRODH,W
heinrichsweikamp
parents:
diff changeset
704 addwfc ext_flash_address+2,F
heinrichsweikamp
parents:
diff changeset
705
heinrichsweikamp
parents:
diff changeset
706 incf_ext_flash_address d'2' ; Skip 0xFA, 0xFA
heinrichsweikamp
parents:
diff changeset
707 call ext_flash_byte_read_plus ; Read start address of profile
heinrichsweikamp
parents:
diff changeset
708 movff temp1,ext_flash_log_pointer+0
heinrichsweikamp
parents:
diff changeset
709 call ext_flash_byte_read_plus ; Read start address of profile
heinrichsweikamp
parents:
diff changeset
710 movff temp1,ext_flash_log_pointer+1
heinrichsweikamp
parents:
diff changeset
711 call ext_flash_byte_read_plus ; Read start address of profile
heinrichsweikamp
parents:
diff changeset
712 movff temp1,ext_flash_log_pointer+2
heinrichsweikamp
parents:
diff changeset
713 call ext_flash_byte_read_plus ; Read end address of profile
heinrichsweikamp
parents:
diff changeset
714 movff temp1,convert_value_temp+0
heinrichsweikamp
parents:
diff changeset
715 call ext_flash_byte_read_plus ; Read end address of profile
heinrichsweikamp
parents:
diff changeset
716 movff temp1,convert_value_temp+1
heinrichsweikamp
parents:
diff changeset
717 call ext_flash_byte_read_plus ; Read end address of profile
heinrichsweikamp
parents:
diff changeset
718 movff temp1,convert_value_temp+2
heinrichsweikamp
parents:
diff changeset
719 decf_ext_flash_address d'8' ; Back again to first 0xFA in header
heinrichsweikamp
parents:
diff changeset
720
heinrichsweikamp
parents:
diff changeset
721 movf ext_flash_log_pointer+0,W
heinrichsweikamp
parents:
diff changeset
722 cpfseq convert_value_temp+0 ; Equal?
heinrichsweikamp
parents:
diff changeset
723 bra comm_send_dive1 ; No, Send header
heinrichsweikamp
parents:
diff changeset
724
heinrichsweikamp
parents:
diff changeset
725 movf ext_flash_log_pointer+1,W
heinrichsweikamp
parents:
diff changeset
726 cpfseq convert_value_temp+1 ; Equal?
heinrichsweikamp
parents:
diff changeset
727 bra comm_send_dive1 ; No, Send header
heinrichsweikamp
parents:
diff changeset
728
heinrichsweikamp
parents:
diff changeset
729 movf ext_flash_log_pointer+2,W
heinrichsweikamp
parents:
diff changeset
730 cpfseq convert_value_temp+2 ; Equal?
heinrichsweikamp
parents:
diff changeset
731 bra comm_send_dive1 ; No, Send header
heinrichsweikamp
parents:
diff changeset
732
heinrichsweikamp
parents:
diff changeset
733 ; Start=End -> Not good, abort
heinrichsweikamp
parents:
diff changeset
734 bra comm_download_mode0 ; Done. Loop with timeout reset
heinrichsweikamp
parents:
diff changeset
735
heinrichsweikamp
parents:
diff changeset
736 comm_send_dive1:
heinrichsweikamp
parents:
diff changeset
737 ; Send header
heinrichsweikamp
parents:
diff changeset
738 clrf hi ; Counter
heinrichsweikamp
parents:
diff changeset
739 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
740 call ext_flash_read_block_start ; 1st byte
heinrichsweikamp
parents:
diff changeset
741 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
742 bra comm_send_dive_header
heinrichsweikamp
parents:
diff changeset
743 comm_send_dive_header2:
heinrichsweikamp
parents:
diff changeset
744 call ext_flash_read_block ; Read one byte
heinrichsweikamp
parents:
diff changeset
745 movwf TXREG1 ; Start new transmit
heinrichsweikamp
parents:
diff changeset
746 comm_send_dive_header:
heinrichsweikamp
parents:
diff changeset
747 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
748 decfsz hi,F
heinrichsweikamp
parents:
diff changeset
749 bra comm_send_dive_header2
heinrichsweikamp
parents:
diff changeset
750 call ext_flash_read_block_stop
heinrichsweikamp
parents:
diff changeset
751
heinrichsweikamp
parents:
diff changeset
752 ; Set address for profile
heinrichsweikamp
parents:
diff changeset
753 movff ext_flash_log_pointer+0,ext_flash_address+0
heinrichsweikamp
parents:
diff changeset
754 movff ext_flash_log_pointer+1,ext_flash_address+1
heinrichsweikamp
parents:
diff changeset
755 movff ext_flash_log_pointer+2,ext_flash_address+2
heinrichsweikamp
parents:
diff changeset
756
heinrichsweikamp
parents:
diff changeset
757 movlw .6 ; Skip 6byte short header in profile - only for internal use
heinrichsweikamp
parents:
diff changeset
758 call incf_ext_flash_address0_0x20 ; increases bytes in ext_flash_address:3 with 0x200000 bank switching
heinrichsweikamp
parents:
diff changeset
759
heinrichsweikamp
parents:
diff changeset
760 comm_send_dive_profile:
heinrichsweikamp
parents:
diff changeset
761 call ext_flash_byte_read_plus_0x20 ; Read one byte into temp1, takes care of banking at 0x200000
heinrichsweikamp
parents:
diff changeset
762 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
763 movff temp1,TXREG1 ; Send a byte
heinrichsweikamp
parents:
diff changeset
764
heinrichsweikamp
parents:
diff changeset
765 ; 24bit compare with end address
heinrichsweikamp
parents:
diff changeset
766 movff convert_value_temp+0,WREG
heinrichsweikamp
parents:
diff changeset
767 cpfseq ext_flash_address+0
heinrichsweikamp
parents:
diff changeset
768 bra comm_send_dive_profile
heinrichsweikamp
parents:
diff changeset
769 movff convert_value_temp+1,WREG
heinrichsweikamp
parents:
diff changeset
770 cpfseq ext_flash_address+1
heinrichsweikamp
parents:
diff changeset
771 bra comm_send_dive_profile
heinrichsweikamp
parents:
diff changeset
772 movff convert_value_temp+2,WREG
heinrichsweikamp
parents:
diff changeset
773 cpfseq ext_flash_address+2
heinrichsweikamp
parents:
diff changeset
774 bra comm_send_dive_profile
heinrichsweikamp
parents:
diff changeset
775
heinrichsweikamp
parents:
diff changeset
776 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
777 bra comm_download_mode0 ; Done. Loop with timeout reset
heinrichsweikamp
parents:
diff changeset
778
heinrichsweikamp
parents:
diff changeset
779 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
780
heinrichsweikamp
parents:
diff changeset
781 comm_send_string:
heinrichsweikamp
parents:
diff changeset
782 movlw "n" ; send echo
heinrichsweikamp
parents:
diff changeset
783 movwf TXREG1
heinrichsweikamp
parents:
diff changeset
784 call rs232_wait_tx ; Wait for UART
heinrichsweikamp
parents:
diff changeset
785 WIN_SMALL comm_string_column, comm_string_row
heinrichsweikamp
parents:
diff changeset
786 lfsr FSR2,buffer
heinrichsweikamp
parents:
diff changeset
787 movlw .16
heinrichsweikamp
parents:
diff changeset
788 movwf lo ; counter
heinrichsweikamp
parents:
diff changeset
789 comm_send_string_loop:
heinrichsweikamp
parents:
diff changeset
790 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
791 btfsc rs232_recieve_overflow ; Got byte?
heinrichsweikamp
parents:
diff changeset
792 bra comm_send_string_abort ; No, abort!
heinrichsweikamp
parents:
diff changeset
793 movff RCREG1,POSTINC2 ; Store character
heinrichsweikamp
parents:
diff changeset
794 decfsz lo,F
heinrichsweikamp
parents:
diff changeset
795 bra comm_send_string_loop
heinrichsweikamp
parents:
diff changeset
796 comm_send_string_abort:
heinrichsweikamp
parents:
diff changeset
797 STRCAT_PRINT "" ; Show the text
heinrichsweikamp
parents:
diff changeset
798 bra comm_download_mode0 ; Done. Loop with timeout reset
heinrichsweikamp
parents:
diff changeset
799
heinrichsweikamp
parents:
diff changeset
800 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
801
heinrichsweikamp
parents:
diff changeset
802 comm_check_day:
heinrichsweikamp
parents:
diff changeset
803 movff RCREG1, day
heinrichsweikamp
parents:
diff changeset
804 movff month,lo ; new month
heinrichsweikamp
parents:
diff changeset
805 dcfsnz lo,F
heinrichsweikamp
parents:
diff changeset
806 movlw .31
heinrichsweikamp
parents:
diff changeset
807 dcfsnz lo,F
heinrichsweikamp
parents:
diff changeset
808 movlw .28
heinrichsweikamp
parents:
diff changeset
809 dcfsnz lo,F
heinrichsweikamp
parents:
diff changeset
810 movlw .31
heinrichsweikamp
parents:
diff changeset
811 dcfsnz lo,F
heinrichsweikamp
parents:
diff changeset
812 movlw .30
heinrichsweikamp
parents:
diff changeset
813 dcfsnz lo,F
heinrichsweikamp
parents:
diff changeset
814 movlw .31
heinrichsweikamp
parents:
diff changeset
815 dcfsnz lo,F
heinrichsweikamp
parents:
diff changeset
816 movlw .30
heinrichsweikamp
parents:
diff changeset
817 dcfsnz lo,F
heinrichsweikamp
parents:
diff changeset
818 movlw .31
heinrichsweikamp
parents:
diff changeset
819 dcfsnz lo,F
heinrichsweikamp
parents:
diff changeset
820 movlw .31
heinrichsweikamp
parents:
diff changeset
821 dcfsnz lo,F
heinrichsweikamp
parents:
diff changeset
822 movlw .30
heinrichsweikamp
parents:
diff changeset
823 dcfsnz lo,F
heinrichsweikamp
parents:
diff changeset
824 movlw .31
heinrichsweikamp
parents:
diff changeset
825 dcfsnz lo,F
heinrichsweikamp
parents:
diff changeset
826 movlw .30
heinrichsweikamp
parents:
diff changeset
827 dcfsnz lo,F
heinrichsweikamp
parents:
diff changeset
828 movlw .31
heinrichsweikamp
parents:
diff changeset
829 cpfsgt day ; day ok?
heinrichsweikamp
parents:
diff changeset
830 return ; OK
heinrichsweikamp
parents:
diff changeset
831 movlw .1 ; not OK, set to 1st
heinrichsweikamp
parents:
diff changeset
832 movwf day
heinrichsweikamp
parents:
diff changeset
833 return
heinrichsweikamp
parents:
diff changeset
834
heinrichsweikamp
parents:
diff changeset
835 ;----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
836 END