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