comparison src/eeprom_rs232.asm @ 656:8af5aefbcdaf default tip

Update to 3.31 beta
author heinrichsweikamp
date Thu, 27 Nov 2025 18:32:58 +0100
parents 75e90cd0c2c3
children
comparison
equal deleted inserted replaced
655:c7b7b8a358cd 656:8af5aefbcdaf
12 #include "hwos.inc" 12 #include "hwos.inc"
13 #include "wait.inc" 13 #include "wait.inc"
14 #include "shared_definitions.h" 14 #include "shared_definitions.h"
15 #include "rtc.inc" 15 #include "rtc.inc"
16 #include "external_flash.inc" 16 #include "external_flash.inc"
17 #include "convert.inc"
17 18
18 #DEFINE INSIDE_EEPROM_RS232 19 #DEFINE INSIDE_EEPROM_RS232
19 #include "eeprom_rs232.inc" 20 #include "eeprom_rs232.inc"
20 21
21 22
366 call request_speed_normal ; request CPU speed change to normal speed 367 call request_speed_normal ; request CPU speed change to normal speed
367 enable_rs232_1: 368 enable_rs232_1:
368 btfss speed_is_normal ; speed = normal? 369 btfss speed_is_normal ; speed = normal?
369 bra enable_rs232_1 ; NO - loop waiting for ISR to have adjusted the speed 370 bra enable_rs232_1 ; NO - loop waiting for ISR to have adjusted the speed
370 bsf TRISC,7 371 bsf TRISC,7
372 btfss aux_flag ; use Bluetooth?
371 bcf ble_npower ; YES - switch port to comm 373 bcf ble_npower ; YES - switch port to comm
372 bsf PORTJ,2 ; - /Reset (required for very old OSTC sport) 374 bsf PORTJ,2 ; - /Reset (required for very old OSTC sport)
373 movlw b'00100100' ; - TX configuration: TX enabled, async, high speed 375 movlw b'00100100' ; - TX configuration: TX enabled, async, high speed
374 movwf TXSTA1 ; - ... 376 movwf TXSTA1 ; - ...
375 movlw b'10010000' ; - RX configuration: port enabled, RX enabled 377 movlw b'10010000' ; - RX configuration: port enabled, RX enabled
505 bra serial_rx_stream_tmr_loop ; NO - continue waiting 507 bra serial_rx_stream_tmr_loop ; NO - continue waiting
506 bra serial_rx_timeout ; YES - timeout 508 bra serial_rx_timeout ; YES - timeout
507 509
508 ;----------------------------------------------------------------------------- 510 ;-----------------------------------------------------------------------------
509 511
510 ;----------------------------------------------------------------------------- 512 ;------------------------------------------
511 ; Add new services and characteristics to new BLE (type 2) module 513 ; Setup BLE name to new BLE (type 2) module
512 ;----------------------------------------------------------------------------- 514 ;------------------------------------------
513 global ble2_configure 515 global ble2_configure_name
514 ble2_configure: 516 ble2_configure_name:
515 rcall enable_rs232 517 btfss dn_flag ; dn mode?
518 return ; no, return
519 ;rcall enable_rs232
516 bcf NCTS ; Clear to send 520 bcf NCTS ; Clear to send
517 call wait_1s 521 call wait_1s
518 call wait_1s 522 call wait_1s
519 call wait_1s 523 call wait_1s
520 call wait_1s 524 call wait_1s
521 bcf PORTB,6 525 bcf PORTB,6
522 nop 526 nop
523 bsf PORTB,6 ; rising edge -> Command mode 527 bsf PORTB,6 ; rising edge -> Command mode
524
525 ; point to config table 528 ; point to config table
526 movlw LOW ble_AT1 529 movlw LOW ble_AT2
527 movwf TBLPTRL 530 movwf TBLPTRL
528 movlw HIGH ble_AT1 531 movlw HIGH ble_AT2
529 movwf TBLPTRH 532 movwf TBLPTRH
530 movlw UPPER ble_AT1 533 movlw UPPER ble_AT2
531 movwf TBLPTRU 534 movwf TBLPTRU
532 rcall ble_init_loop 535 rcall ble_init_loop
536 ; Read serial from EEPROM
537 call eeprom_serial_number_read ; read OSTC serial number
538 movff mpr+0, lo
539 movff mpr+1, hi
540 lfsr FSR2,buffer+0
541 output_65535 ; lo:hi converted to ascii into POSTINC2
542 SERIAL_CC_SEND buffer+0
543 SERIAL_CC_SEND buffer+1
544 SERIAL_CC_SEND buffer+2
545 SERIAL_CC_SEND buffer+3
546 SERIAL_CC_SEND buffer+4
547 SERIAL_LC_SEND .13 ; CR
548 WAITMS d'200'
549 bcf PORTB,6 ; falling edge -> Data mode
550 movlw LOW ble_AT3
551 movwf TBLPTRL
552 movlw HIGH ble_AT3
553 movwf TBLPTRH
554 movlw UPPER ble_AT3
555 movwf TBLPTRU
556 rcall ble_init_loop
557 return
558
533 559
534 rcall disable_rs232 560
535 bcf PORTB,6 ; keep low for min. current consumption 561 ;-----------------------------------------------------------------------------
562 ; Add new services and characteristics to new BLE (type 2) module
563 ;-----------------------------------------------------------------------------
564 global ble2_configure
565 ble2_configure:
566 bcf aux_flag ; needed for enable_rs232
567 rcall enable_rs232
568 bcf NCTS ; Clear to send
569 call wait_1s
570 call wait_1s
571 call wait_1s
572 call wait_1s
573 bcf PORTB,6
574 nop
575 bsf PORTB,6 ; rising edge -> Command mode
576
577 ; point to config table
578 movlw LOW ble_AT1
579 movwf TBLPTRL
580 movlw HIGH ble_AT1
581 movwf TBLPTRH
582 movlw UPPER ble_AT1
583 movwf TBLPTRU
584
585 btfsc dual_comm ; dual-comm hardware?
586 rcall ble2_configure_at4 ; YES - BLE-only module in dual-comm hardware, overwrite TBLPTRx!
587
588 rcall ble_init_loop
589 rcall disable_rs232
590 bcf PORTB,6 ; keep low for min. current consumption
536 return ; done. 591 return ; done.
537 592
593 ble2_configure_at4:
594 ; point to config table
595 movlw LOW ble_AT4
596 movwf TBLPTRL
597 movlw HIGH ble_AT4
598 movwf TBLPTRH
599 movlw UPPER ble_AT4
600 movwf TBLPTRU
601 return
602
538 ble_init_loop: 603 ble_init_loop:
539 TBLRD*+ 604 TBLRD*+
540 movlw 0xFF ; end 605 movlw 0xFF ; end
541 cpfseq TABLAT 606 cpfseq TABLAT
542 bra ble_init_loop1 ; not end 607 bra ble_init_loop1 ; not end
557 ble_init_loop3: 622 ble_init_loop3:
558 movf TABLAT,W 623 movf TABLAT,W
559 SERIAL_CC_SEND WREG 624 SERIAL_CC_SEND WREG
560 bra ble_init_loop 625 bra ble_init_loop
561 626
627 ble_AT4: ; config table
628 ; 0xFF at the end
629 ; 0xFE: 20ms delay
630 ; 0xFD: 1s delay
631 ; .13: cr character
632 db "AT+UBTLN=OSTC nano",.13,0xFE ; "name command"
633 ;db "AT+UFACTORY",.13,0xFE,0xFE ; Set to factory defined configuration
634 db "AT+UMSM=1",.13,0xFE,0xFE ; start in Data mode
635 db "AT+UBTLE=2",.13,0xFE ; Bluetooth low energy Peripheral
636 db "AT+UDSC=0,0",.13,0xFE,0xFE ; Disable SPS Server on ID0 (and wait 40ms)
637 db "AT+UDSC=0,6",.13,0xFE,0xFE ; SPs Server on ID0 (and wait 40ms)
638 db "AT+UDSC=1,0",.13,0xFE,0xFE ; Disable SPP Server on ID1 (and wait 40ms)
639 db "AT+UDSC=1,3",.13,0xFE,0xFE ; SPP Server on ID1 (and wait 40ms)
640 db "AT&W",.13,0xFE ; write settings into eeprom
641 db "AT+CPWROFF",.13 ; save and reboot
642 db 0xFD, 0xFD, 0xFF
643
562 ble_AT1: ; config table 644 ble_AT1: ; config table
563 ; 0xFF at the end 645 ; 0xFF at the end
564 ; 0xFE: 20ms delay 646 ; 0xFE: 20ms delay
565 ; 0xFD: 1s delay 647 ; 0xFD: 1s delay
566 ; .13: cr character 648 ; .13: cr character
567 db 0xFD,0xFD,0xFD,0xFD ; Wait 4 seconds 649 db 0xFD,0xFD,0xFD,0xFD ; Wait 4 seconds
568 db "AT+UDSC=0,0",.13,0xFE,0xFE ; Disable SPP Server on ID0 (and wait 40ms) 650 db "AT+UDSC=0,0",.13,0xFE,0xFE ; Disable SPS Server on ID0 (and wait 40ms)
569 db "AT+UDSC=0,3",.13,0xFE,0xFE ; SPP Server on ID0 (and wait 40ms) 651 db "AT+UDSC=0,6",.13,0xFE,0xFE ; SPs Server on ID0 (and wait 40ms)
570 db "AT+UDSC=1,0",.13,0xFE,0xFE ; Disable SPS Server on ID1 (and wait 40ms) 652 db "AT+UDSC=1,0",.13,0xFE,0xFE ; Disable SPP Server on ID1 (and wait 40ms)
571 db "AT+UDSC=1,6",.13,0xFE,0xFE ; SPS Server on ID1 (and wait 40ms) 653 db "AT+UDSC=1,3",.13,0xFE,0xFE ; SPP Server on ID1 (and wait 40ms)
572 db "AT&W",.13,0xFE ; write settings into eeprom (and wait 20ms) 654 db "AT&W",.13,0xFE ; write settings into eeprom (and wait 20ms)
573 db "AT+CPWROFF",.13,0xFD,0xFD,0xFF ; save and reboot (and wait 2 seconds) 655 db "AT+CPWROFF",.13,0xFD,0xFD,0xFF ; save and reboot (and wait 2 seconds)
574 656 ble_AT2: ; config table
575 657 db 0xFD,0xFD,0xFD,0xFD ; Wait 4 seconds
658 db "AT+UBTLN=OSTC+ ",0xFF ; Start of "name command"
659 ble_AT3: ; config table
660 db "ATO1",.13,0xFF ; Enable Data mode
661
576 END 662 END