Mercurial > public > hwos_code
annotate src/comm.asm @ 636:2737ddc643bb
3.11 release
author | heinrichsweikamp |
---|---|
date | Mon, 25 May 2020 17:35:30 +0200 |
parents | 4050675965ea |
children | 8c1f1f334275 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
636 | 3 ; File comm.asm * combined next generation V3.10.0 |
0 | 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 | |
631 | 11 ; 2012-02-11 : [jDG] Added 0x63 set custom text, and "i" identify |
0 | 12 |
275 | 13 #include "hwos.inc" |
0 | 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" | |
299
6c4800af27ac
Make char_I_bottom_usage and char_I_deco_usage configurable from PC
heinrichsweikamp
parents:
275
diff
changeset
|
24 #include "shared_definitions.h" |
604 | 25 #include "math.inc" |
631 | 26 #include "i2c.inc" |
27 #include "logbook.inc" | |
634 | 28 #include "colorschemes.inc" |
631 | 29 |
0 | 30 |
582 | 31 extern restart |
32 extern option_reset_all | |
631 | 33 extern option_check_and_store_all |
34 extern option_read_serial | |
35 extern option_write_serial | |
582 | 36 extern gaslist_cleanup_list |
631 | 37 extern eeprom_deco_data_write |
634 | 38 extern eeprom_memorize_fw_checksum |
0 | 39 |
40 | |
631 | 41 ; timeouts |
42 #DEFINE timeout_comm_pre_mode .240 ; [sec] timeout before communication is established | |
43 #DEFINE timeout_service_mode .120 ; [sec] timeout when communication is established | |
582 | 44 |
631 | 45 ; positioning of title |
46 #DEFINE comm_title_row .0 | |
623 | 47 #DEFINE comm_title_column_usb .40 |
582 | 48 #DEFINE comm_title_column_ble .25 |
0 | 49 |
631 | 50 ; positioning of host-sent text messages |
51 #DEFINE comm_string_row .30 | |
582 | 52 #DEFINE comm_string_column .40 |
53 | |
631 | 54 ; positioning of COMM mode status messages |
55 #DEFINE comm_status1_row .70 | |
582 | 56 #DEFINE comm_status1_column .10 |
57 #DEFINE comm_status2_row .100 | |
58 #DEFINE comm_status2_column comm_status1_column | |
59 #DEFINE comm_status3_row .130 | |
60 #DEFINE comm_status3_column comm_status1_column | |
604 | 61 #DEFINE comm_status4_row .160 |
62 #DEFINE comm_status4_column comm_status1_column | |
634 | 63 #DEFINE comm_status5_row .190 |
64 #DEFINE comm_status5_column comm_status1_column | |
65 | |
604 | 66 |
631 | 67 ; positioning of COMM mode warning icon |
68 #DEFINE comm_warning_row .160 | |
623 | 69 #DEFINE comm_warning_column .65 |
582 | 70 |
0 | 71 |
631 | 72 ;#DEFINE testloop_avail ; uncomment if testloop code is available |
73 | |
634 | 74 ;============================================================================= |
604 | 75 comm CODE |
76 ;============================================================================= | |
0 | 77 |
634 | 78 ;----------------------------------------------------------------------------- |
79 ; Entry Point for Comm Mode / USB | |
80 ; | |
623 | 81 global comm_mode_usb |
82 comm_mode_usb: ; entry point for comm mode via USB | |
83 WAITMS d'1' ; wait 1 ms | |
84 btfss vusb_in ; USB still plugged in? | |
85 return ; NO - it was only a glitch, abort | |
631 | 86 WAITMS d'1' ; YES - wait 1 ms |
87 btfss vusb_in ; - USB still plugged in? | |
88 return ; NO - it was only a glitch, abort | |
89 bsf aux_flag ; YES - remember to show USB title | |
90 bra comm_mode_common ; - continue with common part | |
623 | 91 |
634 | 92 |
93 ;----------------------------------------------------------------------------- | |
94 ; Entry Point for Comm Mode / BT | |
95 ; | |
96 global comm_mode_bt | |
97 comm_mode_bt: ; entry point for comm mode via BT | |
623 | 98 bcf aux_flag ; remember to show BLE title |
99 ;bra comm_mode_common ; continue with common part | |
100 | |
634 | 101 |
102 ;----------------------------------------------------------------------------- | |
103 ; Common Part of Comm Mode Entry | |
104 ; | |
623 | 105 comm_mode_common: |
631 | 106 clrf STKPTR ; reset addresses stack |
623 | 107 call TFT_ClearScreen ; clear screen |
634 | 108 FONT_COLOR color_greenish ; set color |
631 | 109 |
623 | 110 btfss aux_flag ; shall show USB title? |
634 | 111 bra comm_mode_common_bt ; NO - show BT title |
112 ;bra comm_mode_common_usb ; YES - show USB title | |
631 | 113 |
634 | 114 comm_mode_common_usb: |
115 WIN_SMALL comm_title_column_usb, comm_title_row ; set USB title position | |
116 STRCPY_TEXT_PRINT tUsbTitle ; print USB title text | |
117 bra comm_mode_common_logo ; continue with logo | |
631 | 118 |
634 | 119 comm_mode_common_bt: |
120 WIN_SMALL comm_title_column_ble, comm_title_row ; set BT title position | |
121 STRCPY_TEXT_PRINT tBleTitle ; print BT title text | |
122 ;bra comm_mode_common_logo ; continue with logo | |
123 | |
124 comm_mode_common_logo: | |
631 | 125 WIN_TOP .10 ; set position of USB/BLE logo, row |
126 WIN_LEFT .1 ; set position of USB/BLE logo, column | |
634 | 127 btfss battery_gauge_available ; "+" bootloader ? |
128 bra comm_mode_common_logo2 ; YES - show logo type 2 | |
129 ;bra comm_mode_common_logo1 ; NO - show logo type 1 | |
130 | |
131 comm_mode_common_logo1: | |
132 TFT_WRITE_PROM_IMAGE_BY_ADDR comm_logo_1 ; show USB/BT logo | |
133 bra comm_mode_common_start ; continue with starting message | |
631 | 134 |
634 | 135 comm_mode_common_logo2: |
136 TFT_WRITE_PROM_IMAGE_BY_ADDR comm_logo_2 ; show BT logo / OSTC+ | |
137 ;bra comm_mode_common_start ; continue with starting message | |
631 | 138 |
634 | 139 comm_mode_common_start: |
140 WIN_SMALL comm_status1_column,comm_status1_row ; set position | |
141 FONT_COLOR_MEMO ; set standard color | |
142 STRCPY_TEXT_PRINT tUsbStarting ; print status message "starting..." | |
631 | 143 |
623 | 144 WIN_TINY .40,.240-.16 ; set output position to bottom line |
634 | 145 call TFT_print_serial_and_firmware ; show serial number and firmware version |
604 | 146 |
147 IFDEF _screendump | |
631 | 148 bcf screen_dump_avail ; disable screen dump function |
604 | 149 ENDIF |
150 | |
631 | 151 bcf switch_right ; clear potential left-over right button event |
152 call enable_rs232 ; enable serial comm, also sets CPU to normal speed | |
153 | |
634 | 154 WIN_SMALL comm_status1_column+.80,comm_status1_row ; set position after starting message |
155 FONT_COLOR_MEMO ; set standard color | |
156 STRCPY_TEXT_PRINT tUsbStartDone ; print (adding to status message) "done..." | |
631 | 157 |
158 movlw timeout_comm_pre_mode ; get timeout for phase without communication established yet | |
159 movwf comm_timeout_timer ; initialize timeout counter | |
634 | 160 ;bra comm_mode_selection_loop ; continue with mode selection loop |
0 | 161 |
634 | 162 |
163 ;----------------------------------------------------------------------------- | |
164 ; Mode Selection Loop: Download Mode or Service Mode | |
165 ; | |
631 | 166 comm_mode_selection_loop: |
167 bcf trigger_full_second ; clear 'one second elapsed' flag | |
168 bcf LEDr ; switch off red LED / power down TR co-processor | |
169 dcfsnz comm_timeout_timer,F ; decrement timeout, reached zero? | |
170 bra comm_service_exit ; YES - timeout, exit comm mode | |
171 ;bra comm_mode_selection_loop_1 ; NO - try to receive a byte | |
172 comm_mode_selection_loop_1: | |
173 SERIAL_CC_RECEIVE lo ; (try to) receive 1 byte | |
174 btfsc rs232_rx_timeout ; timeout? | |
175 bra comm_mode_selection_loop_2 ; YES - check for comm mode termination | |
176 movf lo,W ; NO - copy received byte to lo | |
177 xorlw 0xAA ; - service mode start byte received? | |
178 bz comm_service_mode_check ; YES - check if correct key will be send | |
179 movf lo,W ; NO - copy received byte to lo again | |
180 xorlw 0xBB ; - download mode start byte received? | |
634 | 181 bz comm_download_mode ; YES - enter command loop |
182 ;bra comm_mode_selection_loop_2 ; NO - check for comm mode termination | |
631 | 183 comm_mode_selection_loop_2: |
634 | 184 btfsc ble_available ; BT available? |
631 | 185 bra comm_mode_selection_loop_3 ; YES - skip USB check check (required for very old OSTC sport) |
186 btfss vusb_in ; NO - USB plugged in? | |
187 bra comm_service_exit_nousb_delay ; NO - disconnected, check for vusb_in glitch | |
188 ;bra comm_mode_selection_loop_3 ; YES - check for exit button or continue looping | |
189 comm_mode_selection_loop_3: | |
190 btfsc switch_right ; right button pressed? | |
191 bra comm_service_exit ; YES - exit comm mode | |
192 btfsc trigger_full_second ; NO - did 1 second elapsed meanwhile? | |
193 bra comm_mode_selection_loop ; YES - loop with clocking down timeout counter | |
194 bra comm_mode_selection_loop_1 ; NO - loop without clocking down timeout counter | |
0 | 195 |
196 | |
197 ;----------------------------------------------------------------------------- | |
634 | 198 ; Check Service Mode Pass-Key and notify Service Mode on Success |
0 | 199 ; |
631 | 200 comm_service_mode_check: |
201 SERIAL_LC_SEND 0x4B ; request peer to send service key | |
202 | |
203 ; receive a 3 byte service key transmitted in big-endian, echo each byte | |
204 | |
205 clrf WREG ; clear WREG | |
206 | |
207 SERIAL_CC_RECEIVE lo ; receive 1st byte, store in lo | |
208 xorwf lo,W ; exclusive-or received byte into WREG | |
209 xorlw UPPER (comm_service_key) ; exclusive-or expected byte into WREG | |
210 SERIAL_CC_SEND lo ; echo 1st byte | |
0 | 211 |
631 | 212 SERIAL_CC_RECEIVE lo ; receive 2nd byte, store in lo |
213 xorwf lo,W ; exclusive-or received byte into WREG | |
214 xorlw HIGH (comm_service_key & 0xFFFF) ; exclusive-or expected byte into WREG | |
215 SERIAL_CC_SEND lo ; echo 2nd byte | |
216 | |
217 SERIAL_CC_RECEIVE lo ; receive 3rd byte, store in lo | |
218 xorwf lo,W ; exclusive-or received byte into WREG | |
219 xorlw LOW (comm_service_key & 0xFFFF) ; exclusive-or expected byte into WREG | |
220 SERIAL_CC_SEND lo ; echo 3rd byte | |
221 | |
222 ; check for correct service key | |
223 tstfsz WREG ; received expected service key? | |
224 bra comm_mode_selection_loop ; NO - back to mode selection loop | |
225 WIN_SMALL comm_status2_column, comm_status2_row ; YES - print service mode enabled message | |
634 | 226 FONT_COLOR_MEMO ; - set standard color |
631 | 227 STRCPY_TEXT_PRINT tUsbServiceMode ; - ... |
228 bsf comm_service_mode ; - enable service mode commands | |
229 bra comm_command_loop ; - enter command loop | |
0 | 230 |
623 | 231 |
0 | 232 ;----------------------------------------------------------------------------- |
634 | 233 ; Notify RX Timeout occurred |
234 ; | |
235 comm_command_timeout: | |
236 WIN_SMALL comm_status4_column, comm_status4_row ; select font and output position | |
237 FONT_COLOR_WARNING ; set warning color | |
238 STRCPY_PRINT "Data Rx Timeout" ; print failure message | |
239 FONT_COLOR_MEMO ; back to standard color | |
240 bra comm_drain_rx_queue ; continue with draining the RX queue | |
241 | |
242 | |
243 ;----------------------------------------------------------------------------- | |
244 ; Notify Error in Parameters | |
245 ; | |
246 comm_command_error: | |
247 WIN_SMALL comm_status4_column, comm_status4_row ; select font and output position | |
248 FONT_COLOR_WARNING ; set warning color | |
249 STRCPY_PRINT "Parameter Error" ; print failure message | |
250 FONT_COLOR_MEMO ; back to standard color | |
251 ;bra comm_drain_rx_queue ; continue with draining the RX queue | |
252 | |
253 | |
254 ;----------------------------------------------------------------------------- | |
255 ; Drain the RX Queue until next Timeout | |
256 ; | |
257 comm_drain_rx_queue: | |
258 bsf INTCON,GIE ; re-enable all interrupts | |
259 comm_drain_rx_queue_loop: | |
260 btfsc switch_right ; right button (abort) pressed? | |
261 bra comm_service_exit ; YES - exit comm mode | |
262 SERIAL_CC_RECEIVE WREG ; NO - (try to) receive one byte | |
263 btfss rs232_rx_timeout ; - got a byte? | |
264 bra comm_drain_rx_queue_loop ; YES - try to drain more bytes | |
265 bra comm_command_loop ; NO - re-enter command loop | |
266 | |
267 | |
268 ;----------------------------------------------------------------------------- | |
269 ; Debug Code - show Number of Bytes received | |
270 ; | |
271 IFDEF _comm_debug | |
272 comm_command_debug: | |
273 WIN_SMALL comm_status5_column, comm_status5_row ; select font and output position | |
274 FONT_COLOR_MEMO ; set standard color | |
275 STRCPY "last RX: " ; print label | |
276 output_9999 ; print number of bytes received (0-9999) | |
277 STRCAT_PRINT " Byte" ; finalize output | |
278 bra comm_command_loop ; re-enter command loop | |
279 ENDIF | |
280 | |
281 | |
282 ;----------------------------------------------------------------------------- | |
283 ; Notify Download Mode selected | |
623 | 284 ; |
631 | 285 comm_download_mode: |
286 SERIAL_LC_SEND 0xBB ; inform peer download mode will be started | |
0 | 287 |
634 | 288 WIN_SMALL comm_status2_column, comm_status2_row ; set position |
289 FONT_COLOR_MEMO ; set standard color | |
290 STRCPY_TEXT_PRINT tUsbDownloadMode ; print download mode enabled message | |
631 | 291 bcf comm_service_mode ; disable service mode commands |
634 | 292 ;bra comm_command_loop ; enter command loop |
631 | 293 |
0 | 294 |
295 ;----------------------------------------------------------------------------- | |
634 | 296 ; Command Loop: await, decode and execute Commands |
623 | 297 ; |
631 | 298 comm_command_loop: |
299 bsf INTCON,GIE ; re-enable all interrupts | |
634 | 300 |
301 ; restart command timeout | |
631 | 302 movlw timeout_service_mode ; get timeout value |
303 movwf comm_timeout_timer ; reload timeout timer | |
0 | 304 |
631 | 305 ; request peer to send a command |
306 movlw 0x4D ; default request code is 0x4D for download mode active | |
307 btfsc comm_service_mode ; service mode enabled? | |
308 movlw 0x4C ; YES - change request to 0x4C for service mode active | |
309 SERIAL_CC_SEND WREG ; send request | |
0 | 310 |
631 | 311 ; wait for peer to send a command |
312 comm_command_loop_wait: | |
313 SERIAL_CC_RECEIVE lo ; (try to) receive a command byte | |
314 btfss rs232_rx_timeout ; timeout? | |
315 bra comm_command_decode ; NO - decode and execute the command | |
316 btfsc comm_service_mode ; YES - service mode enabled? | |
317 btg LEDr ; YES - blink in service mode | |
634 | 318 btfsc ble_available ; - BT available? |
631 | 319 bra comm_command_loop_wait_1 ; YES - skip USB check (required for very old OSTC sport) |
320 btfss vusb_in ; NO - USB still plugged in? | |
321 bra comm_service_exit_nousb ; NO - disconnected -> exit comm mode | |
634 | 322 ;bra comm_command_loop_wait_1 ; YES - proceed |
323 | |
631 | 324 comm_command_loop_wait_1: |
325 btfsc switch_right ; right button (abort) pressed? | |
326 bra comm_service_exit ; YES - exit comm mode | |
327 btfss trigger_full_second ; NO - did 1 second elapsed meanwhile? | |
328 bra comm_command_loop_wait ; NO - loop | |
329 dcfsnz comm_timeout_timer,F ; YES - decrement the timeout timer, reached zero? | |
330 bra comm_service_exit ; YES - exit comm mode | |
331 bcf trigger_full_second ; NO - clear 'one second elapsed' flag | |
332 bra comm_command_loop_wait ; - loop | |
346
cf9ce6053dee
New option to download "Compact Headers". Improved BLE support (OSTC 2 and OSTC 3+), updated OSTC interface documentation
heinrichsweikamp
parents:
337
diff
changeset
|
333 |
cf9ce6053dee
New option to download "Compact Headers". Improved BLE support (OSTC 2 and OSTC 3+), updated OSTC interface documentation
heinrichsweikamp
parents:
337
diff
changeset
|
334 |
cf9ce6053dee
New option to download "Compact Headers". Improved BLE support (OSTC 2 and OSTC 3+), updated OSTC interface documentation
heinrichsweikamp
parents:
337
diff
changeset
|
335 ;----------------------------------------------------------------------------- |
634 | 336 ; Macro for easier writing of Command Decoding Rules |
631 | 337 ; |
338 command_decode macro command_id,command_function | |
634 | 339 movf lo,W ; copy received command to WREG |
340 xorlw command_id ; exclusive-or with command ID | |
341 btfsc STATUS,Z ; received command = command ID ? | |
342 goto command_function ; YES - execute command | |
631 | 343 endm |
0 | 344 |
634 | 345 |
0 | 346 ;----------------------------------------------------------------------------- |
634 | 347 ; Decode and execute a Command |
631 | 348 ; |
349 comm_command_decode: | |
350 bcf LEDr ; switch off red led | |
80 | 351 |
631 | 352 ; decode and execute standard commands |
353 command_decode 0x6E,comm_show_text ; n show a text on the screen | |
354 command_decode 0x69,comm_identify ; i send ID: serial, firmware, and custom text | |
355 command_decode 0x6A,comm_hardware_descriptor ; j send ID: hardware descriptor byte | |
356 command_decode 0x60,comm_feature_and_hardware ; ' send ID: more detailed information | |
357 command_decode 0x6D,comm_send_headers_short ; m send all headers in compact format | |
358 command_decode 0x61,comm_send_headers_full ; a send all headers is full format | |
359 command_decode 0x66,comm_send_dive ; f send header and profile for one dive | |
360 command_decode 0x62,comm_set_time ; b set the real time clock | |
361 command_decode 0x63,comm_set_custom_text ; c write a new custom text | |
362 command_decode 0x72,comm_read_option ; r read an option value | |
363 command_decode 0x77,comm_write_option ; w write an option value (into RAM) | |
364 command_decode 0x78,comm_option_reset_all ; x reset all option values to their factory default | |
365 command_decode 0xFF,comm_service_exit ; exit comm mode | |
366 IFDEF _screendump | |
636 | 367 command_decode 0x6C,TFT_dump_screen_comm ; l dump the screen contents |
631 | 368 ENDIF |
369 | |
370 btfss comm_service_mode ; service mode enabled? | |
371 bra comm_command_loop ; NO - ignore unrecognized command, back to command loop | |
372 | |
373 ; decode and execute additional service mode commands | |
374 command_decode 0x23,comm_reset_battery_gauge ; # reset the battery gauge registers | |
375 command_decode 0x22,comm_erase_complete_logbook ; " reset all logbook pointers and the logbook | |
634 | 376 command_decode 0x20,comm_read_range ;' ' read a memory range from the external FLASH |
377 command_decode 0x40,comm_erase_single_4kb ; @ erase a single 4 kB block - Warning: no confirmation or built-in safety here... | |
378 command_decode 0x42,comm_erase_range_4kb ; B erase a range of 4 kB blocks - Warning: no confirmation or built-in safety here... | |
631 | 379 command_decode 0x30,comm_write_range_stream ; 0 write a stream of bytes starting at ext_flash_address:3 until timeout |
380 command_decode 0x31,comm_write_range_block ; 1 write a block of 256 bytes starting at ext_flash_address:3 | |
381 command_decode 0x50,comm_firmware_update ; P initiate firmware update | |
382 command_decode 0xC1,comm_cold_start ; start low-level bootloader | |
383 IFDEF testloop_avail | |
384 command_decode 0x74,testloop ; t start raw-data test loop | |
385 ENDIF | |
386 | |
387 bra comm_command_loop ; ignore unrecognized command, back to command loop | |
388 | |
80 | 389 |
390 ;----------------------------------------------------------------------------- | |
636 | 391 ; Screendump |
392 ; | |
393 IFDEF _screendump | |
394 TFT_dump_screen_comm: | |
395 call TFT_dump_screen ; dump the screen contents and set screen_dump_avail | |
396 ;bra comm_service_exit ; exit comm mode | |
397 ENDIF | |
398 | |
399 | |
400 ;----------------------------------------------------------------------------- | |
634 | 401 ; Exit Comm Mode |
631 | 402 ; |
403 comm_service_exit: | |
404 WIN_SMALL comm_status3_column, comm_status3_row ; print "Exited" message | |
634 | 405 FONT_COLOR_MEMO ; set standard color |
631 | 406 STRCPY_TEXT_PRINT tUsbExit ; ... |
407 bra comm_service_exit_common ; acknowledge exit command and restart | |
0 | 408 |
631 | 409 comm_service_exit_nousb_delay: |
410 WAITMS d'200' ; wait 200 ms | |
411 btfsc vusb_in ; USB sensed again? | |
412 bra comm_mode_selection_loop_3 ; YES - was just a glitch, continue | |
413 ;bra comm_service_exit_nousb ; NO - proceed exiting | |
0 | 414 |
631 | 415 comm_service_exit_nousb: |
416 WIN_SMALL comm_status3_column, comm_status3_row ; print "Port closed" message | |
634 | 417 FONT_COLOR_MEMO ; set standard color |
631 | 418 STRCPY_TEXT_PRINT tUsbClosed ; ... |
419 ;bra comm_service_exit_common ; proceed exiting | |
420 | |
421 comm_service_exit_common: | |
422 SERIAL_LC_SEND 0xFF ; acknowledge exit command | |
634 | 423 WAITS .1 ; wait 1 second to give the serial I/F time |
424 ; to send the 0xFF before it gets shut down | |
631 | 425 call disable_rs232 ; shut down comm port |
426 bcf LEDr ; switch off red LED | |
634 | 427 WAITS .1 ; wait 1 second for BT module supply to drain |
631 | 428 goto restart ; restart |
429 | |
0 | 430 |
431 ;----------------------------------------------------------------------------- | |
631 | 432 ; Set Real-Time-Clock |
0 | 433 ; |
631 | 434 comm_set_time: |
634 | 435 bcf INTCON,GIE ; disable all interrupts |
631 | 436 SERIAL_LC_SEND 0x62 ; acknowledge command |
634 | 437 SERIAL_RR_RECEIVE mpr,.6 ; (try to) receive 6 bytes: hour, minute, second, month, day, year |
438 bsf INTCON,GIE ; re-enable all interrupts | |
631 | 439 |
634 | 440 btfsc rs232_rx_timeout ; got all 6 bytes? |
441 bra comm_command_timeout ; NO - show rx timeout message and back to command loop | |
631 | 442 |
634 | 443 movff mpr+0,rtc_latched_hour ; map the received bytes onto the rtc_latched variables |
444 movff mpr+1,rtc_latched_mins ; ... | |
445 movff mpr+2,rtc_latched_secs ; ... | |
446 movff mpr+3,rtc_latched_month ; ... | |
447 movff mpr+4,rtc_latched_day ; ... | |
448 movff mpr+5,rtc_latched_year ; ... | |
631 | 449 call rtc_set_rtc ; write time and date to RTC module |
450 bra comm_command_loop ; done, back to command loop | |
451 | |
452 | |
453 ;----------------------------------------------------------------------------- | |
634 | 454 ; Write a 15 char Text to the OSTC Display |
631 | 455 ; |
456 comm_show_text: | |
634 | 457 ; set font and output position (needs to be done before SERIAL_RR_RECEIVE) |
631 | 458 WIN_SMALL comm_string_column, comm_string_row |
634 | 459 FONT_COLOR_MEMO ; set standard color |
631 | 460 |
634 | 461 bcf INTCON,GIE ; disable all interrupts |
631 | 462 SERIAL_LC_SEND 0x6E ; acknowledge command |
634 | 463 SERIAL_RR_RECEIVE buffer,.16 ; (try to) receive 16 chars into the string buffer |
464 bsf INTCON,GIE ; re-enable all interrupts | |
631 | 465 |
634 | 466 movlw .15 ; set maximum text length |
467 call TFT_buffer_trim_length ; fill or trim the text to correct length | |
468 PRINT ; print text to screen | |
469 bra comm_command_loop ; done, back to command loop | |
470 | |
471 | |
472 ;----------------------------------------------------------------------------- | |
473 ; Send Serial (2 bytes low:high), Firmware (major.minor) and Custom Text | |
474 ; | |
475 comm_identify: | |
476 SERIAL_LC_SEND 0x69 ; acknowledge command | |
477 | |
478 ; send OSTC serial number | |
479 call eeprom_serial_number_read ; read OSTC serial number | |
480 SERIAL_CC_SEND mpr+0 ; send serial number, low byte | |
481 SERIAL_CC_SEND mpr+1 ; send serial number, high byte | |
482 | |
483 ; send firmware version | |
484 SERIAL_LC_SEND fw_version_major ; send firmware version, major | |
485 SERIAL_LC_SEND fw_version_minor ; send firmware version, minor | |
486 | |
487 ; send custom text | |
488 SERIAL_RR_SEND opt_name,opt_name_length | |
631 | 489 |
490 bra comm_command_loop ; done, back to command loop | |
491 | |
0 | 492 |
493 ;----------------------------------------------------------------------------- | |
634 | 494 ; Send short Hardware Descriptor |
0 | 495 ; |
634 | 496 comm_hardware_descriptor: |
497 SERIAL_LC_SEND 0x6A ; acknowledge command | |
498 rcall comm_helper_hw_descriptor ; send hardware descriptor | |
631 | 499 bra comm_command_loop ; done, back to command loop |
0 | 500 |
623 | 501 |
235
23311219dacc
under construction: new hardware_flag to configure different hardware versions
heinrichsweikamp
parents:
223
diff
changeset
|
502 ;----------------------------------------------------------------------------- |
634 | 503 ; Helper Function for sending Hardware Descriptor |
235
23311219dacc
under construction: new hardware_flag to configure different hardware versions
heinrichsweikamp
parents:
223
diff
changeset
|
504 ; |
634 | 505 comm_helper_hw_descriptor: |
623 | 506 movf HW_descriptor,W ; get hardware descriptor |
507 bcf WREG,6 ; clear bit 6 for reason of compatibility with 3rd party software | |
508 bcf WREG,7 ; clear bit 7 for reason of compatibility with 3rd party software | |
631 | 509 SERIAL_CC_SEND WREG ; send modified hardware descriptor |
634 | 510 return |
623 | 511 |
0 | 512 |
631 | 513 ;----------------------------------------------------------------------------- |
634 | 514 ; Send detailed Hardware Descriptor |
631 | 515 ; |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
426
diff
changeset
|
516 comm_feature_and_hardware: |
631 | 517 SERIAL_LC_SEND 0x60 ; acknowledge command |
623 | 518 |
634 | 519 SERIAL_LC_SEND 0x00 ; send hardware high byte (fixed zero) |
520 rcall comm_helper_hw_descriptor ; send hardware descriptor | |
521 SERIAL_LC_SEND 0x00 ; send feature high byte (fixed zero) | |
522 SERIAL_LC_SEND 0x00 ; send feature low byte (fixed zero) | |
631 | 523 SERIAL_LC_SEND 0x00 ; send model descriptor byte (fixed zero) |
623 | 524 |
631 | 525 bra comm_command_loop ; done, back to command loop |
623 | 526 |
604 | 527 |
528 ;----------------------------------------------------------------------------- | |
634 | 529 ; Helper Function to retrieve a Header, hide the internal Profile Version, |
530 ; and to check if the Header is empty | |
531 ; | |
532 comm_helper_read_header: | |
533 ; copy header from FLASH into memory | |
534 call log_header_addr_by_index ; compute header start address from index in WREG | |
535 FLASH_RR_READ header_buffer,.256 ; copy from FLASH to header buffer | |
0 | 536 |
634 | 537 ; hide internal profile version ID from the outside |
538 movff header_buffer+index_profile_version,WREG ; get byte at the profile version position | |
539 infsnz WREG,W ; was the byte = 0xFF (i.e. empty header) ? | |
540 return ; YES - leave it as it is (WREG now 0) | |
541 decf WREG,W ; NO - restore the profile version | |
542 andlw b'00111111' ; - keep only the external part | |
543 movff WREG,header_buffer+index_profile_version ; - write back the cleaned byte | |
544 return ; - done (WREG now ext. profile version) | |
582 | 545 |
0 | 546 |
547 ;----------------------------------------------------------------------------- | |
634 | 548 ; Send Dive Headers in short or full Format |
549 ; | |
550 comm_send_headers_short: | |
551 SERIAL_LC_SEND 0x6D ; acknowledge command | |
552 bcf aux_flag ; send short headers | |
553 bra comm_send_headers_common ; continue with common part | |
0 | 554 |
631 | 555 comm_send_headers_full: |
556 SERIAL_LC_SEND 0x61 ; acknowledge command | |
634 | 557 bsf aux_flag ; send full headers |
558 ;bra comm_send_headers_common ; continue with common part | |
631 | 559 |
634 | 560 comm_send_headers_common: |
561 clrf ex ; start with dive having index 0 | |
562 | |
563 comm_send_headers_loop: | |
564 movf ex,W ; get index into WREG | |
565 rcall comm_helper_read_header ; get header into header_buffer | |
566 | |
567 btfss aux_flag ; shall send full headers? | |
568 bra comm_send_headers_loop_short; NO - send short headers | |
569 ;bra comm_send_headers_loop_full ; YES - send full headers | |
631 | 570 |
634 | 571 comm_send_headers_loop_full: |
572 SERIAL_RR_SEND header_buffer,.256 ; send the full header | |
573 bra comm_send_headers_loop_com ; continue with common part | |
574 | |
575 comm_send_headers_loop_short: | |
576 ; send the fractions of the short header (16 byte/dive) | |
577 SERIAL_RR_SEND header_buffer+index_profile_byte_count,.13 | |
578 SERIAL_RR_SEND header_buffer+index_total_dives, .2 | |
579 SERIAL_CC_SEND header_buffer+index_profile_version ; .1 | |
580 ;bra comm_send_headers_loop_com ; continue with common part | |
581 | |
582 comm_send_headers_loop_com: | |
583 incfsz ex ; increment index, wrap-around. i.e. all dives done ? | |
584 bra comm_send_headers_loop ; NO - loop | |
585 bra comm_command_loop ; YES - done, back to command loop | |
631 | 586 |
587 | |
588 ;----------------------------------------------------------------------------- | |
634 | 589 ; Send one full Dive |
631 | 590 ; |
591 comm_send_dive: | |
592 SERIAL_LC_SEND 0x66 ; acknowledge command | |
593 | |
634 | 594 SERIAL_CC_RECEIVE WREG ; (try to) receive the dive index |
631 | 595 btfsc rs232_rx_timeout ; got dive index? |
634 | 596 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
631 | 597 |
634 | 598 rcall comm_helper_read_header ; read header into header_buffer |
599 bz comm_send_dive_exit ; abort if header contains no dive | |
631 | 600 |
634 | 601 ; get the start and end address of the profile data |
631 | 602 MOVTT header_buffer+index_profile_start_address,ext_flash_address |
603 MOVTT header_buffer+index_profile_end_address, ext_flash_end_pointer | |
634 | 604 |
605 ; header start code sequence present? | |
606 bcf aux_flag ; default to no profile available | |
631 | 607 |
634 | 608 FLASH_CW_READ_0x20 ; get the 1st byte of profile data |
609 xorlw 0xFA ; 1st byte = header start byte? | |
610 bnz comm_send_dive_modify_header; NO - no profile data available | |
611 | |
612 FLASH_CW_READ_0x20 ; get the 2nd byte of profile data | |
613 xorlw 0xFA ; 2nd byte = header start byte? | |
614 bnz comm_send_dive_modify_header; NO - no profile data available | |
615 | |
616 EXT_FLASH_INC_ADDRESS_0x20 .2 ; skip the 3rd and 4th byte (dive number) | |
631 | 617 |
634 | 618 FLASH_CW_READ_0x20 ; get the 5th byte of profile data |
619 xorlw 0xFA ; 5th byte = header start byte? | |
620 bnz comm_send_dive_modify_header; NO - no profile data available | |
621 | |
622 FLASH_CW_READ_0x20 ; get the 6th byte of profile data | |
623 xorlw 0xFA ; 6th byte = header start byte? | |
624 bnz comm_send_dive_modify_header; NO - no profile data available | |
631 | 625 |
634 | 626 bsf aux_flag ; memorize profile data available |
627 bra comm_send_dive_header ; continue with sending header | |
631 | 628 |
634 | 629 comm_send_dive_modify_header: |
630 ; set profile data start and end address to 0x000000 | |
631 CLRR header_buffer+index_profile_start_address,.6 | |
632 | |
633 ; set hi = 0x00, lo = 0x08 | |
634 MOVLI 0x0008,mpr | |
604 | 635 |
634 | 636 ; set byte count to 0x000008 |
637 movff lo,header_buffer+index_profile_byte_count+0 ; = 0x08 | |
638 movff hi,header_buffer+index_profile_byte_count+1 ; = 0x00 | |
639 movff hi,header_buffer+index_profile_byte_count+2 ; = 0x00 | |
640 | |
641 comm_send_dive_header: | |
642 SERIAL_RR_SEND header_buffer,.256 ; send the header from the buffer | |
643 | |
644 btfss aux_flag ; profile data available? | |
645 bra comm_send_dive_empty_profile; NO - send empty profile | |
646 | |
647 comm_send_dive_profile: | |
648 FLASH_CW_READ_0x20 ; read one byte and increment address with rollover at 0x200000 | |
649 SERIAL_CC_SEND WREG ; transmit the byte | |
650 | |
651 ; 24 bit compare of current address with end address | |
652 movf ext_flash_end_pointer+0,W ; check low byte of addresses | |
653 cpfseq ext_flash_address+0 ; current address = end address ? | |
654 bra comm_send_dive_profile ; NO - more bytes to do, loop | |
631 | 655 |
634 | 656 movf ext_flash_end_pointer+1,W ; check high byte of addresses |
657 cpfseq ext_flash_address+1 ; current address = end address ? | |
658 bra comm_send_dive_profile ; NO - more bytes to do, loop | |
659 | |
660 movf ext_flash_end_pointer+2,W ; check upper byte of addresses | |
661 cpfseq ext_flash_address+2 ; current address = end address ? | |
662 bra comm_send_dive_profile ; NO - more bytes to do, loop | |
663 | |
664 comm_send_dive_exit: | |
665 bra comm_command_loop ; done, back to command loop | |
666 | |
667 comm_send_dive_empty_profile: | |
668 | |
669 ; send profile length | |
670 SERIAL_RR_SEND header_buffer+index_profile_byte_count,.3 | |
671 | |
672 SERIAL_LC_SEND 0xFD ; send end-of-profile sequence, byte 1 | |
673 SERIAL_LC_SEND 0xFD ; send end-of-profile sequence, byte 2 | |
674 | |
675 bra comm_command_loop ; done, back to command loop | |
631 | 676 |
604 | 677 |
631 | 678 ;----------------------------------------------------------------------------- |
679 ; Reset all Options to Factory Default | |
680 ; | |
681 comm_option_reset_all: | |
682 SERIAL_LC_SEND 0x78 ; acknowledge command | |
683 call option_reset_all ; reset all options to factory default | |
684 bra comm_command_loop ; done, back to command loop | |
685 | |
686 | |
687 ;----------------------------------------------------------------------------- | |
634 | 688 ; Set Custom Text (opt_name_length ASCII chars) |
631 | 689 ; |
690 comm_set_custom_text: | |
634 | 691 CLRR opt_name,opt_name_length ; clear old custom text |
631 | 692 |
634 | 693 bcf INTCON,GIE ; disable all interrupts |
694 SERIAL_LC_SEND 0x63 ; acknowledge command | |
695 SERIAL_RR_RECEIVE opt_name,opt_name_length ; receive new custom text | |
696 bsf INTCON,GIE ; re-enable all interrupts | |
697 bsf option_changed ; flag that EEPROM needs to be updated | |
631 | 698 |
634 | 699 bra comm_command_loop ; done, back to command loop |
631 | 700 |
701 | |
702 ;----------------------------------------------------------------------------- | |
703 ; Reset Battery Gauge | |
704 ; | |
705 comm_reset_battery_gauge: | |
706 ; SERIAL_LC_SEND 0x23 ; acknowledge command (not done) | |
707 call reset_battery_gauge_and_lt2942 ; reset battery registers and battery gauge chip | |
708 bra comm_command_loop ; done, back to command loop | |
709 | |
604 | 710 |
631 | 711 ;----------------------------------------------------------------------------- |
712 ; Erase complete Logbook | |
713 ; | |
714 comm_erase_complete_logbook: | |
634 | 715 ; SERIAL_LC_SEND 0x22 ; acknowledge command (not done) |
716 call erase_complete_logbook ; erase complete logbook | |
717 bra comm_command_loop ; done, back to command loop | |
631 | 718 |
719 | |
720 ;----------------------------------------------------------------------------- | |
721 ; Start Bootloader (aka perform cold start) | |
722 ; | |
723 comm_cold_start: | |
724 ; SERIAL_LC_SEND 0xC1 ; acknowledge command (not done) | |
725 | |
634 | 726 WIN_SMALL comm_status3_column, comm_status3_row ; set position |
727 FONT_COLOR_MEMO ; set standard color | |
728 STRCPY_TEXT_PRINT tUsbLlBld ; print "Low-level Bootloader" message | |
631 | 729 |
730 WIN_TOP comm_warning_row ; set row for icon | |
731 WIN_LEFT comm_warning_column ; set column for icon | |
732 TFT_WRITE_PROM_IMAGE_BY_LABEL dive_warning2_block ; show a warning icon | |
733 | |
734 bsf LEDr ; switch on red LED | |
735 | |
736 call eeprom_deco_data_write ; update deco data in EEPROM | |
737 call eeprom_battery_gauge_write ; update battery gauge in EEPROM | |
634 | 738 btfsc option_changed ; do the options need to be stored to EEPROM ? |
631 | 739 call option_check_and_store_all ; YES - check and store all option values in EEPROM |
740 | |
634 | 741 ; WAITS .1 ; wait 1 second to give the serial I/F time |
742 ; ; to send the ackn before it gets shut down | |
743 | |
744 goto 0x1FF0C ; jump into the bootloader code for cold start | |
631 | 745 |
746 | |
747 ;----------------------------------------------------------------------------- | |
634 | 748 ; Send Firmware to Bootloader (aka initiate Firmware Update) |
631 | 749 ; |
750 comm_firmware_update: | |
634 | 751 bcf INTCON,GIE ; disable all interrupts |
631 | 752 SERIAL_LC_SEND 0x50 ; acknowledge command |
634 | 753 SERIAL_RR_RECEIVE buffer,.5 ; (try to) receive 5 byte checksum |
754 bsf INTCON,GIE ; re-enable all interrupts | |
631 | 755 |
756 btfsc rs232_rx_timeout ; got all 5 bytes? | |
757 bra comm_send_firmware_abort ; NO - abort | |
582 | 758 |
631 | 759 ; check the checksum |
760 movlw 0x55 ; initialize checksum check-byte | |
761 movwf hi ; store in hi | |
634 | 762 INIT_BUFFER ; go back to start of the buffer |
631 | 763 movlw .5 ; 5 bytes to process |
764 movwf lo ; initialize loop counter | |
765 comm_firmware_update_loop: | |
766 movf POSTINC2,W ; get a checksum byte | |
767 xorwf hi,F ; xor checksum byte with check-byte | |
768 rlncf hi,F ; rotate check-byte | |
769 decfsz lo,F ; decrement loop counter, done? | |
770 bra comm_firmware_update_loop ; NO - loop | |
771 tstfsz hi ; YES - check-byte zero? | |
772 bra comm_send_firmware_failed ; NO - checksum not valid | |
773 | |
774 ; checksum is valid | |
775 SERIAL_LC_SEND 0x4C ; inform checksum is ok | |
634 | 776 WAITS .1 ; wait 1 second to give the serial I/F time |
777 ; to send the 0x4C before it gets shut down | |
778 ;bra comm_firmware_update_exec ; execute update | |
631 | 779 |
634 | 780 global comm_firmware_update_exec |
781 comm_firmware_update_exec: | |
782 call eeprom_memorize_fw_checksum ; memorize fw checksum in EEPROM | |
631 | 783 call eeprom_deco_data_write ; update deco data in EEPROM |
784 call eeprom_battery_gauge_write ; update battery gauge in EEPROM | |
634 | 785 btfsc option_changed ; do the options need to be stored to EEPROM ? |
631 | 786 call option_check_and_store_all ; YES - check and store all option values in EEPROM |
634 | 787 goto 0x1FDF0 ; jump into the bootloader code for firmware update |
631 | 788 |
789 | |
790 comm_send_firmware_failed: | |
791 ; select font and output position | |
792 WIN_SMALL comm_string_column, comm_string_row | |
634 | 793 FONT_COLOR_WARNING ; set warning color |
631 | 794 STRCPY_PRINT "Checksum failed" ; print failure message (fill to 15 chars) |
795 ;bra comm_send_firmware_abort ; abort | |
796 | |
797 comm_send_firmware_abort: | |
634 | 798 SERIAL_LC_SEND 0xFF ; send checksum failure message |
799 bra comm_command_loop ; done, back to command loop | |
800 | |
801 | |
802 ;----------------------------------------------------------------------------- | |
803 ; Erase a single Block or a Range of Blocks | |
804 ; | |
805 comm_erase_single_4kb: | |
806 bcf INTCON,GIE ; disable all interrupts | |
807 bcf aux_flag ; do a single block only | |
808 ; SERIAL_LC_SEND 0x40 ; acknowledge command (not done) | |
809 bra comm_erase_get_start ; continue with getting start address | |
810 | |
811 comm_erase_range_4kb: | |
812 bcf INTCON,GIE ; disable all interrupts | |
813 bsf aux_flag ; do a range of blocks | |
814 SERIAL_LC_SEND 0x42 ; acknowledge command | |
815 ;bra comm_erase_get_start ; continue with getting start address | |
816 | |
817 comm_erase_get_start: | |
818 rcall comm_get_start_address ; (try to) get the start address | |
819 btfsc rs232_rx_timeout ; got start address? | |
820 bra comm_command_timeout ; NO - show rx timeout message and back to command loop | |
821 btfsc aux_flag ; YES - shall erase a range of blocks? | |
822 bra comm_erase_get_count ; YES - get the block count | |
823 movlw .1 ; NO - set 1 block to do | |
824 movwf WREG ; - ... | |
825 bra comm_erase_common ; - start the erasing | |
826 | |
827 comm_erase_get_count: | |
828 SERIAL_CC_RECEIVE WREG ; (try to) receive the block count | |
829 btfsc rs232_rx_timeout ; got block count? | |
830 bra comm_command_timeout ; NO - show rx timeout message and back to command loop | |
831 tstfsz WREG ; YES - block count = 0 ? | |
832 bra comm_erase_common ; NO - start the erasing | |
833 bra comm_command_error ; YES - invalid, show error message and back to command loop | |
834 | |
835 comm_erase_common: | |
836 bsf INTCON,GIE ; re-enable all interrupts | |
837 call ext_flash_erase_range ; erase #WREG 4kB blocks starting at ext_flash_address | |
631 | 838 bra comm_command_loop ; done, back to command loop |
839 | |
840 | |
841 ;----------------------------------------------------------------------------- | |
634 | 842 ; Write a Stream of Bytes to the FLASH beginning at given Start Address, finish on Timeout |
631 | 843 ; |
634 | 844 comm_write_range_stream: |
845 bcf INTCON,GIE ; disable all interrupts | |
846 SERIAL_LC_SEND 0x30 ; acknowledge command | |
631 | 847 |
634 | 848 rcall comm_get_start_address ; (try to) get the start address |
849 btfsc rs232_rx_timeout ; got a complete start address? | |
850 bra comm_command_timeout ; NO - show rx timeout message and back to command loop | |
851 | |
852 IFDEF _comm_debug | |
853 CLRI mpr ; clear mpr to be used as a 16 bit counter | |
854 ENDIF | |
631 | 855 |
634 | 856 comm_write_range_stream_loop: |
857 SERIAL_CC_RECEIVE WREG ; (try to) receive one byte | |
858 btfsc rs232_rx_timeout ; got a byte? | |
859 IFNDEF _comm_debug | |
860 bra comm_command_loop ; NO - timeout, done, back to command loop | |
861 ELSE | |
862 bra comm_command_debug ; NO - timeout, done, show number of bytes received | |
863 ENDIF | |
864 ; bsf NCTS ; YES - hold Bluetooth chip (requires PC/Android/iOS side to use flow control...) | |
865 call ext_flash_write_byte_0x40_nowait; - write byte to FLASH, increase address with rollover at 0x400000, does not wait on FLASH | |
866 ; bcf NCTS ; - release Bluetooth chip (requires PC/Android/iOS side to use flow control...) | |
867 IFDEF _comm_debug | |
868 INCI mpr ; increment counter | |
869 ENDIF | |
870 bra comm_write_range_stream_loop ; - loop | |
157
5ee76921e359
make new parameters configurable through pc
heinrichsweikamp
parents:
150
diff
changeset
|
871 |
631 | 872 |
873 ;----------------------------------------------------------------------------- | |
634 | 874 ; Write a Block of 256 Bytes to the FLASH beginning at given Start Address (low byte needs to be zero) |
631 | 875 ; |
634 | 876 comm_write_range_block: |
877 bcf INTCON,GIE ; disable all interrupts | |
878 SERIAL_LC_SEND 0x31 ; acknowledge command | |
879 | |
880 rcall comm_get_start_address ; (try to) get the start address | |
881 btfsc rs232_rx_timeout ; got a complete start address? | |
882 bra comm_command_timeout ; NO - show rx timeout message and back to command loop | |
631 | 883 |
634 | 884 tstfsz ext_flash_address+0 ; low byte of start address = 0 ? |
885 bra comm_command_error ; NO - show error message and back to command loop | |
886 | |
887 SERIAL_RR_RECEIVE buffer,.256 ; (try to) receive 256 byte and buffer them in memory | |
888 bsf INTCON,GIE ; re-enable all interrupts | |
889 btfsc rs232_rx_timeout ; got all 256 bytes? | |
890 bra comm_command_timeout ; NO - show rx timeout message and back to command loop | |
891 | |
892 FLASH_RR_WRITE buffer,.256 ; copy from memory to FLASH | |
893 bra comm_command_loop ; done, back to command loop | |
631 | 894 |
895 | |
896 ;----------------------------------------------------------------------------- | |
634 | 897 ; Read a Memory Range from FLASH given by Start Address and Byte Count |
631 | 898 ; |
899 comm_read_range: | |
634 | 900 bcf INTCON,GIE ; disable all interrupts |
631 | 901 SERIAL_LC_SEND 0x20 ; acknowledge command |
902 | |
903 ; receive start address | |
904 rcall comm_get_start_address ; (try to) get the start address | |
905 btfsc rs232_rx_timeout ; got a complete start address? | |
634 | 906 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
907 | |
908 ; receive byte count | |
909 rcall comm_get_length ; (try to) get the byte count | |
910 btfsc rs232_rx_timeout ; got a complete byte count? | |
911 bra comm_command_timeout ; NO - show rx timeout message and back to command loop | |
631 | 912 |
634 | 913 bsf INTCON,GIE ; re-enable all interrupts |
914 | |
915 ; decrement byte counter by 1 so that all bytes will be done when the counter wraps around to 0xFFFFFF | |
916 EXT_FLASH_DEC_LENGTH | |
917 | |
918 ; check validity of the byte count | |
919 movlw 0x40 ; now the byte count is allowed to be 0x3FFFFF at max | |
920 cpfslt ext_flash_length_counter+2 ; length count < 0x40(0000) ? | |
921 bra comm_command_error ; NO - show error message and back to command loop | |
631 | 922 |
923 ; stream bytes from FLASH | |
634 | 924 call ext_flash_read_block_start ; read first byte from FLASH into WREG |
925 bra comm_read_range_loop_start ; jump into transmit loop | |
631 | 926 comm_read_range_loop: |
927 call ext_flash_read_block_0x40 ; read next byte into WREG | |
928 comm_read_range_loop_start: | |
929 SERIAL_CC_SEND WREG ; transmit byte | |
634 | 930 EXT_FLASH_DEC_LENGTH ; decrement byte counter |
631 | 931 btfss ext_flash_length_counter+2,7; under-run? |
932 bra comm_read_range_loop ; NO - continue loop | |
933 call ext_flash_read_block_stop ; YES - end reading from FLASH | |
934 bra comm_command_loop ; - done, back to command loop | |
935 | |
936 | |
937 ;----------------------------------------------------------------------------- | |
938 ; Receive a 3 byte FLASH address (on serial: big-endian, in memory: little-endian) | |
939 ; | |
940 comm_get_start_address: | |
634 | 941 SERIAL_RR_RECEIVE ext_flash_address,.3 ; (try to) receive 3 bytes |
942 btfsc rs232_rx_timeout ; timeout? | |
943 return ; YES - abort, no usable address available | |
631 | 944 |
945 ; remap address from network byte format (big endian) to host format (little-endian) | |
946 movf ext_flash_address+0,W | |
947 movff ext_flash_address+2,ext_flash_address+0 | |
948 movwf ext_flash_address+2 | |
949 | |
634 | 950 return ; done, complete start address available |
631 | 951 |
952 | |
953 ;----------------------------------------------------------------------------- | |
954 ; Receive a 3 byte length (on serial: big-endian, in memory: little-endian) | |
955 ; | |
956 comm_get_length: | |
634 | 957 SERIAL_RR_RECEIVE ext_flash_length_counter,.3 ; receive 3 bytes |
958 btfsc rs232_rx_timeout ; timeout? | |
959 return ; YES - abort, no usable address available | |
631 | 960 |
961 ; remap address from network byte format (big endian) to host format (little-endian) | |
962 movf ext_flash_length_counter+0,W | |
963 movff ext_flash_length_counter+2,ext_flash_length_counter+0 | |
964 movwf ext_flash_length_counter+2 | |
965 | |
634 | 966 return ; done, complete start address available |
631 | 967 |
968 | |
969 ;----------------------------------------------------------------------------- | |
970 ; Read an Option Value | |
971 ; | |
972 comm_read_option: | |
973 SERIAL_LC_SEND 0x72 ; acknowledge command | |
974 SERIAL_CC_RECEIVE lo ; (try to) receive option index | |
975 btfsc rs232_rx_timeout ; received option index? | |
634 | 976 bra comm_command_loop ; NO - show rx timeout message and back to command loop |
631 | 977 |
978 ; option index 0x00 - 0x0F: unused | |
979 movlw 0x0F ; last option index of the unused range | |
980 cpfsgt lo ; received option index > end of unused range ? | |
634 | 981 bra comm_command_error ; NO - show error message and back to command loop |
631 | 982 |
983 ; option index 0x10 - 0x19: gases & diluents | |
984 movlw 0x19 ; last option index for gases / diluents | |
985 cpfsgt lo ; received option index > end of gas/dil range ? | |
986 bra comm_read_gas_dil ; NO - process gas/dil read | |
987 | |
988 ; option index 0x1A - 0x1E: setpoints | |
989 movlw 0x1E ; last option index for setpoint | |
990 cpfsgt lo ; received option index > end of setpoint range ? | |
991 bra comm_read_sp ; NO - process setpoint read | |
992 | |
993 ; option index = 0x49 - special handling button polarity | |
994 movf lo,W ; copy option index to WREG | |
995 iorlw 0x49 ; received option index for button polarity ? | |
996 bz comm_read_button_polarity ; YES - process button polarity read | |
997 | |
634 | 998 ; option index 0x1F - 0xF9: options managed by option table |
999 movlw 0xF9 ; last option index for options | |
1000 cpfsgt lo ; received option index > end of options range? | |
1001 bra comm_read_option_index ; YES - process option value read via index | |
631 | 1002 |
634 | 1003 bra comm_command_error ; NO - illegal option index |
631 | 1004 |
1005 | |
1006 ;----------------------------------------------------------------------------- | |
1007 ; Write an Option Value | |
1008 ; | |
1009 comm_write_option: | |
634 | 1010 bcf INTCON,GIE ; disable all interrupts |
631 | 1011 SERIAL_LC_SEND 0x77 ; acknowledge command |
1012 SERIAL_CC_RECEIVE lo ; (try to) receive option index | |
1013 btfsc rs232_rx_timeout ; got a byte? | |
634 | 1014 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
631 | 1015 |
1016 ; option index 0x00 - 0x0F: unused | |
1017 movlw 0x0F ; last option index of the unused range | |
1018 cpfsgt lo ; received option index > end of unused range ? | |
1019 bra comm_write_unused ; NO - but need to consume the option value | |
1020 | |
1021 ; option index 0x10 - 0x19: gases & diluents | |
1022 movlw 0x19 ; last option index for gases / diluents | |
1023 cpfsgt lo ; received option index > end of gas/dil range ? | |
1024 bra comm_write_gas_dil ; NO - process gas/dil write | |
1025 | |
1026 ; option index 0x1A - 0x1E: setpoints | |
1027 movlw 0x1E ; last option index for setpoint | |
1028 cpfsgt lo ; received option index > end of setpoint range ? | |
1029 bra comm_write_sp ; NO - process setpoint write | |
1030 | |
1031 ; option index = 0x49 - special handling button polarity | |
1032 movf lo,W ; copy option index to WREG | |
1033 iorlw 0x49 ; received option index for button polarity ? | |
1034 bz comm_write_button_polarity ; YES - process button polarity write | |
1035 | |
634 | 1036 ; option index 0x1F - 0xF9: options managed by option table |
1037 movlw 0xF9 ; last option index for options | |
1038 cpfsgt lo ; received option index > end of options range? | |
1039 bra comm_write_option_index ; YES - process option value write via index | |
1040 | |
1041 bra comm_write_unused ; NO - illegal option index | |
1042 | |
1043 | |
1044 ;----------------------------------------------------------------------------- | |
1045 ; Read an Option Value via its Serial Index | |
1046 ; | |
1047 comm_read_option_index: | |
1048 call option_read_serial ; try to find the option and read its value | |
1049 tstfsz WREG ; option found? | |
1050 bra comm_read_setting_fail ; NO - send dummy value | |
1051 SERIAL_CC_SEND hi ; YES - send read value | |
1052 bra comm_command_loop ; - done, back to command loop | |
1053 | |
1054 comm_read_setting_fail: | |
1055 SERIAL_LC_SEND 0x00 ; send a dummy value | |
1056 bra comm_command_error ; back to command loop with failure message | |
1057 | |
1058 | |
1059 ;----------------------------------------------------------------------------- | |
1060 ; Write an Option Value via its Serial Index | |
1061 ; | |
1062 comm_write_option_index: | |
631 | 1063 SERIAL_CC_RECEIVE hi ; (try to) receive option value |
1064 btfsc rs232_rx_timeout ; got a byte? | |
1065 bra comm_command_timeout ; NO - abort | |
1066 call option_write_serial ; YES - try to find the option and write new value | |
1067 tstfsz WREG ; - option found and new value valid ? | |
1068 bra comm_command_error ; NO - back to command loop with failure message | |
1069 bra comm_command_loop ; YES - done, back to command loop | |
1070 | |
1071 comm_write_unused: | |
1072 SERIAL_CC_RECEIVE WREG ; consume unused option value | |
1073 bra comm_command_error ; done, back to command loop | |
1074 | |
1075 | |
1076 ;----------------------------------------------------------------------------- | |
634 | 1077 ; Read Button Polarity |
631 | 1078 ; |
1079 comm_read_button_polarity: | |
1080 SERIAL_CC_SEND button_polarity ; send current button polarity setting | |
1081 bra comm_command_loop ; done, back to command loop | |
1082 | |
1083 | |
1084 ;----------------------------------------------------------------------------- | |
634 | 1085 ; Write Button Polarity |
631 | 1086 ; |
1087 comm_write_button_polarity: | |
1088 SERIAL_CC_RECEIVE hi ; (try to) receive configuration value | |
1089 btfsc rs232_rx_timeout ; got configuration value? | |
634 | 1090 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
631 | 1091 movff hi,button_polarity ; YES - store button polarity in memory and EEPROM |
1092 EEPROM_CC_WRITE button_polarity,eeprom_button_polarity | |
1093 bra comm_command_loop ; - done, back to command loop | |
1094 | |
1095 | |
1096 ;----------------------------------------------------------------------------- | |
634 | 1097 ; Read a Gas/Diluent Dataset |
631 | 1098 ; |
634 | 1099 ; memory map is as follows: |
604 | 1100 ; ------------------------- |
1101 ; opt_gas_O2_ratio res 5 ; O2 ratios of OC/bailout gases | |
1102 ; opt_dil_O2_ratio res 5 ; O2 ratios of diluents | |
1103 ; opt_gas_He_ratio res 5 ; He ratios of OC/bailout gases | |
1104 ; opt_dil_He_ratio res 5 ; He ratios of diluents | |
1105 ; opt_gas_type res 5 ; OC/bailout gas type | |
1106 ; opt_dil_type res 5 ; dil type | |
1107 ; opt_gas_change res 5 ; change depths for OC/Bailout gases | |
1108 ; opt_dil_change res 5 ; change depths for diluents | |
631 | 1109 ; |
604 | 1110 comm_read_gas_dil: |
1111 lfsr FSR0,opt_gas_O2_ratio ; load base address of gas data arrays | |
631 | 1112 movlw 0x10 ; compute gas index from option index... |
1113 subwf lo,W ; ...making WREG point to O2 ratio | |
1114 SERIAL_CC_SEND PLUSW0 ; send O2 ratio | |
1115 addlw .10 ; increment WREG by 10 to point to He ratio | |
1116 SERIAL_CC_SEND PLUSW0 ; send He ratio | |
1117 addlw .10 ; increment WREG by 10 to point to gas/diluent type | |
1118 SERIAL_CC_SEND PLUSW0 ; send gas/diluent type | |
1119 addlw .10 ; increment WREG by 10 to point to change depth | |
1120 SERIAL_CC_SEND PLUSW0 ; send change depth | |
1121 bra comm_command_loop ; done, back to command loop | |
110 | 1122 |
79
0fc8113ddf6d
new command in download mode: "r" - read setting
mh@mh-THINK.localdomain
parents:
69
diff
changeset
|
1123 |
631 | 1124 ; ---------------------------------------------------------------------------- |
634 | 1125 ; Write a Gas/Diluent Dataset |
631 | 1126 ; |
634 | 1127 ; memory map is as follows: |
604 | 1128 ; ------------------------- |
1129 ; opt_gas_O2_ratio res 5 ; O2 ratios of OC/bailout gases | |
1130 ; opt_dil_O2_ratio res 5 ; O2 ratios of diluents | |
1131 ; opt_gas_He_ratio res 5 ; He ratios of OC/bailout gases | |
1132 ; opt_dil_He_ratio res 5 ; He ratios of diluents | |
1133 ; opt_gas_type res 5 ; OC/bailout gas type | |
1134 ; opt_dil_type res 5 ; dil type | |
1135 ; opt_gas_change res 5 ; change depths for OC/Bailout gases | |
1136 ; opt_dil_change res 5 ; change depths for diluents | |
631 | 1137 ; |
1138 comm_write_gas_dil: | |
634 | 1139 SERIAL_RR_RECEIVE hi,.4 ; (try to) receive 4 option values |
631 | 1140 btfsc rs232_rx_timeout ; got all 4 bytes? |
634 | 1141 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
80 | 1142 |
631 | 1143 ; check validity of O2 value |
1144 movlw gaslist_min_o2-.1 ; get min value minus 1 | |
1145 cpfsgt hi ; received O2% >= min ? | |
634 | 1146 bra comm_command_error ; NO - show error message and back to command loop |
631 | 1147 movlw gaslist_max_o2+.1 ; get max value plus 1 |
1148 cpfslt hi ; received O2% <= max ? | |
634 | 1149 bra comm_command_error ; NO - show error message and back to command loop |
631 | 1150 |
1151 ; check validity of He value | |
1152 movlw gaslist_max_He+.1 ; get max value plus 1 | |
1153 cpfslt up ; received O2% <= max ? | |
634 | 1154 bra comm_command_error ; NO - show error message and back to command loop |
631 | 1155 |
634 | 1156 IFDEF _helium |
631 | 1157 ; check O2% + He% <= 100% |
634 | 1158 movlw .100 ; load WREG with 100% |
631 | 1159 bsf STATUS,C ; set carry = clear borrow |
634 | 1160 subfwb hi,W ; subtract O2% from WREG |
1161 subfwb up,W ; subtract He% from WREG | |
631 | 1162 btfss STATUS,C ; result negative? |
634 | 1163 bra comm_command_error ; YES - show error message and back to command loop |
1164 ENDIF ; _helium | |
631 | 1165 |
1166 ; check validity of type | |
1167 movlw 0x14 ; last option index for gases | |
1168 cpfsgt lo ; received option index > end of gas range ? | |
636 | 1169 bra comm_write_check_gas ; NO - check type for gases |
1170 ;bra comm_write_check_dil ; YES - check type for diluents | |
1171 | |
1172 comm_write_check_dil: | |
1173 ; check validity of type for a diluent | |
1174 movlw num_dil_types ; load number of diluent types | |
1175 bra comm_write_check_com ; continue with common part | |
631 | 1176 |
634 | 1177 comm_write_check_gas: |
631 | 1178 ; check validity of type for a gas |
1179 movlw num_gas_types ; load number of gas types | |
634 | 1180 ;bra comm_write_check_com ; continue with common part |
631 | 1181 |
634 | 1182 comm_write_check_com: |
631 | 1183 cpfslt ex ; received type < max ? |
634 | 1184 bra comm_command_error ; NO - show error message and back to command loop |
631 | 1185 |
1186 ; check validity of change depth | |
1187 movlw gaslist_max_change_depth+.1 ; get max value plus 1 | |
1188 cpfslt ul ; received change depth <= max ? | |
634 | 1189 bra comm_command_error ; NO - show error message and back to command loop |
631 | 1190 |
1191 ; all values ok, can finally be written | |
604 | 1192 lfsr FSR0,opt_gas_O2_ratio ; load base address of gas data arrays |
631 | 1193 movlw 0x10 ; compute gas index from option index... |
1194 subwf lo,W ; ...making WREG point to O2 ratio | |
634 | 1195 |
631 | 1196 movff hi,PLUSW0 ; set O2 ratio |
1197 addlw .10 ; increment WREG by 10 to point to He ratio | |
1198 movff up,PLUSW0 ; set He ratio | |
1199 addlw .10 ; increment WREG by 10 to point to gas/dil type | |
1200 movff ex,PLUSW0 ; set gas/dil type | |
1201 addlw .10 ; increment WREG by 10 to point to change depth | |
1202 movff ul,PLUSW0 ; set change depth | |
1203 | |
634 | 1204 bsf option_changed ; flag that EEPROM needs to be updated |
631 | 1205 bra comm_command_loop ; done, back to command loop |
80 | 1206 |
604 | 1207 |
631 | 1208 ;----------------------------------------------------------------------------- |
634 | 1209 ; Read a Setpoint Dataset |
631 | 1210 ; |
634 | 1211 ; memory map is as follows: |
604 | 1212 ; ------------------------- |
623 | 1213 ; opt_setpoint_cbar res 5 ; setpoints in cbar |
1214 ; opt_setpoint_change res 5 ; change depth for the setpoints in meter | |
631 | 1215 ; |
1216 comm_read_sp: | |
623 | 1217 lfsr FSR0,opt_setpoint_cbar ; load base address of setpoint cbar values |
631 | 1218 movlw 0x1A ; compute SP index from option index... |
1219 subwf lo,W ; ...making WREG point to cbar value | |
1220 SERIAL_CC_SEND PLUSW0 ; send setpoint cbar value | |
1221 addlw .5 ; increment WREG by 5 to point to change depth | |
1222 SERIAL_CC_SEND PLUSW0 ; send change depth | |
1223 bra comm_command_loop ; done, back to command loop | |
1224 | |
1225 | |
1226 ;----------------------------------------------------------------------------- | |
634 | 1227 ; Write a Setpoint Dataset |
631 | 1228 ; |
634 | 1229 ; memory map is as follows: |
631 | 1230 ; ------------------------- |
1231 ; opt_setpoint_cbar res 5 ; setpoints in cbar | |
1232 ; opt_setpoint_change res 5 ; change depths in meter | |
1233 ; | |
1234 comm_write_sp: | |
634 | 1235 SERIAL_RR_RECEIVE hi,.2 ; (try to) receive 2 option values |
631 | 1236 btfsc rs232_rx_timeout ; got both bytes? |
634 | 1237 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
631 | 1238 |
1239 ; check validity of setpoint value | |
1240 movlw gaslist_sp_min-.1 ; get min value minus 1 | |
1241 cpfsgt hi ; received O2% >= min ? | |
634 | 1242 bra comm_command_error ; NO - show error message and back to command loop |
631 | 1243 movlw gaslist_sp_max+.1 ; get max value plus 1 |
1244 cpfslt hi ; received O2% <= max ? | |
634 | 1245 bra comm_command_error ; NO - show error message and back to command loop |
631 | 1246 |
1247 ; check validity of change depth | |
634 | 1248 movlw gaslist_sp_max_depth+.1 ; get max value plus 1 |
631 | 1249 cpfslt up ; received change depth <= max ? |
634 | 1250 bra comm_command_error ; NO - show error message and back to command loop |
631 | 1251 |
1252 lfsr FSR0,opt_setpoint_cbar ; load base address of setpoint cbar values | |
1253 movlw 0x1A ; compute SP index from option index... | |
1254 subwf lo,W ; ...making WREG point to cbar value | |
634 | 1255 |
1256 bnz comm_write_sp_exec ; selected SP is 2...5 -> execute write | |
1257 tstfsz up ; SP1: change depth = 0 ? | |
1258 bra comm_command_error ; NO - show error message and back to command loop | |
1259 | |
1260 comm_write_sp_exec: | |
631 | 1261 movff hi,PLUSW0 ; set cbar value |
1262 addlw .5 ; increment WREG by 5 to point to change depth | |
1263 movff up,PLUSW0 ; set change depth | |
1264 | |
634 | 1265 bsf option_changed ; flag that EEPROM needs to be updated |
631 | 1266 bra comm_command_loop ; done, back to command loop |
80 | 1267 |
79
0fc8113ddf6d
new command in download mode: "r" - read setting
mh@mh-THINK.localdomain
parents:
69
diff
changeset
|
1268 ;----------------------------------------------------------------------------- |
0fc8113ddf6d
new command in download mode: "r" - read setting
mh@mh-THINK.localdomain
parents:
69
diff
changeset
|
1269 |
582 | 1270 END |