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