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