;**************************************************************************************** ; Mega 128 Scope Controller Program ; (c) Martin Cibulski ; ; Monitor/Debugging routines ;**************************************************************************************** ;**************************************************************************************** ; Labels .EQU LABEL_LEN = 10 ;characters (+ ptr + type + nullbyte) .EQU L_TYPE_BYTE = 0b00000000 ;1 byte .EQU L_TYPE_WORD = 0b00000001 ;2 byte .EQU L_TYPE_LONG = 0b00000010 ;4 byte .EQU L_TYPE_FLOAT = 0b00000011 ;8 byte .EQU L_TYPE_CMD = 0b00000100 ;small subroutine .EQU L_TYPE_XCMD = 0b00000101 ;large subroutine .EQU L_TYPES = 0b00000111 ;mask for compares .EQU L_LOC_REG = 0b10000000 ;cpu/io register (offset 0x20) .EQU L_LOC_RAM = 0b01000000 ;RAM .EQU L_LOC_EEP = 0b00100000 ;EEPROM .EQU L_LOC_PGM = 0b00010000 ;Flash ROM .EQU L_LOC_SEP = 0b00001000 ;external serial EEPROM .EQU L_LOCATIONS = 0b11111000 ;mask for compares .EQU L_BREG = L_TYPE_BYTE |L_LOC_REG ;cpu byte register name (r0 - r31) .EQU L_WREG = L_TYPE_WORD |L_LOC_REG ;cpu word register name (x,y,z) .EQU L_BRAM = L_TYPE_BYTE |L_LOC_RAM ;RAM address (variable) .EQU L_WRAM = L_TYPE_WORD |L_LOC_RAM ;RAM address (variable) .EQU L_LRAM = L_TYPE_LONG |L_LOC_RAM ;RAM address (variable) .EQU L_FRAM = L_TYPE_FLOAT|L_LOC_RAM ;RAM address (variable) .EQU L_BEEP = L_TYPE_BYTE |L_LOC_EEP ;EEPROM address (variable) .EQU L_WEEP = L_TYPE_WORD |L_LOC_EEP ;EEPROM address (variable) .EQU L_LEEP = L_TYPE_LONG |L_LOC_EEP ;EEPROM address (variable) .EQU L_FEEP = L_TYPE_FLOAT|L_LOC_EEP ;EEPROM address (variable) .EQU L_CMD = L_TYPE_CMD |L_LOC_PGM ;subroutine adress .EQU L_XCMD = L_TYPE_XCMD |L_LOC_PGM ;subroutine adress .EQU L_END = 0 ;end of table .EQU IO_BASE = 0x20 ;**************************************************************************************** ;standard functions monitor_label_tab: .dw twi_test .db L_CMD ,"TWITEST " .dw mon_help .db L_CMD ,"? " .dw mon_help .db L_CMD ,"HELP " .dw mon_list_labels .db L_CMD ,"LABELS " .dw monitor_da .db L_CMD ,"DA " .dw monitor_db .db L_CMD ,"DB " .dw monitor_dw .db L_CMD ,"DW " .dw monitor_dl .db L_CMD ,"DL " .dw monitor_dq .db L_CMD ,"DQ " .dw monitor_df .db L_XCMD ,"DF " .dw monitor_dbe .db L_CMD ,"DBE " .dw monitor_dwe .db L_CMD ,"DWE " .dw monitor_dle .db L_CMD ,"DLE " .dw monitor_dqe .db L_CMD ,"DQE " .dw monitor_dfe .db L_XCMD ,"DFE " .dw monitor_dbs .db L_CMD ,"DBS " .dw monitor_dws .db L_CMD ,"DWS " .dw monitor_dls .db L_CMD ,"DLS " .dw monitor_dqs .db L_CMD ,"DQS " .dw monitor_dfs .db L_XCMD ,"DFS " .dw monitor_mb .db L_CMD ,"MB " .dw monitor_mw .db L_CMD ,"MW " .dw monitor_ml .db L_CMD ,"ML " .dw monitor_mf .db L_XCMD ,"MF " .dw monitor_mq .db L_CMD ,"MQ " .dw monitor_mbe .db L_CMD ,"MBE " .dw monitor_mwe .db L_CMD ,"MWE " .dw monitor_mle .db L_CMD ,"MLE " .dw monitor_mfe .db L_XCMD ,"MFE " .dw monitor_mbs .db L_CMD ,"MBS " .dw monitor_mws .db L_CMD ,"MWS " .dw monitor_mls .db L_CMD ,"MLS " .dw monitor_mfs .db L_XCMD ,"MFS " .dw monitor_ports .db L_CMD ,"PORTS " .dw 0x0000 .db L_CMD ,"RESET " ;**************************************************************************************** ;special functions .dw mon_eep_load_profile .db L_CMD ,"LOADPROF " .dw mon_eep_save_profile .db L_CMD ,"SAVEPROF " .dw main_op_mode .db L_BRAM ,"MAINOPMODE " ;**************************************************************************************** ;standard registers .dw GIMSK + IO_BASE .db L_BRAM ,"GIMSK " .dw GIFR + IO_BASE .db L_BRAM ,"GIFR " .dw TIMSK + IO_BASE .db L_BRAM ,"TIMSK " .dw TIFR + IO_BASE .db L_BRAM ,"TIFR " .dw MCUCR + IO_BASE .db L_BRAM ,"MCUCR " .dw PORTA + IO_BASE .db L_BRAM ,"PORTA " .dw DDRA + IO_BASE .db L_BRAM ,"DDRA " .dw PINA + IO_BASE .db L_BRAM ,"PINA " .dw PORTB + IO_BASE .db L_BRAM ,"PORTB " .dw DDRB + IO_BASE .db L_BRAM ,"DDRB " .dw PINB + IO_BASE .db L_BRAM ,"PINB " .dw PORTC + IO_BASE .db L_BRAM ,"PORTC " .dw DDRC + IO_BASE .db L_BRAM ,"DDRC " .dw PINC + IO_BASE .db L_BRAM ,"PINC " .dw PORTD + IO_BASE .db L_BRAM ,"PORTD " .dw DDRD + IO_BASE .db L_BRAM ,"DDRD " .dw PIND + IO_BASE .db L_BRAM ,"PIND " .dw 0 .db L_END , 0 ;**************************************************************************************** ; find label ; xh:xl : pointer to label name ; r16 : type of label ; ; xh:xl :adress ; t-flag :1=found ;************************************************************ mon_master_label_tab: .dw lx200_label_tab .dw monitor_label_tab .dw xyz_label_tab .dw hbx_label_tab .dw lcd_label_tab .dw flt_label_tab .dw mco_label_tab .dw tgo_label_tab .dw cor_label_tab .dw alg_label_tab .dw mot_label_tab .dw a39_label_tab .dw util_label_tab .dw 0x0000 find_label: push yl push yh push zl push zh ldi zl ,low(mon_master_label_tab<<1) ldi zh ,high(mon_master_label_tab<<1) clt find_label_loop: lpm yl ,Z+ lpm yh ,Z+ cpi yl ,0 cpc yl ,yh breq find_label_end lsl yl rol yh rcall find_label_sub brtc find_label_loop find_label_end: pop zh pop zl pop yh pop yl ret ;**************************************************************************************** ; Test .DSEG monitor_inptr: .byte 1 .CSEG monitor_test: ldi r24 ,low(uart_ibuf) ;store character as uart_ibuf [uart_iput] ldi r25 ,high(uart_ibuf) lds r16 ,uart_iput clr r17 lds r18 ,uart_iget ldi zl ,low((monitor_test_command<<1)) ldi zh ,high((monitor_test_command<<1)) monitor_test_loop: cp r16 ,r18 ;check if buffer full breq monitor_test_full lpm r0 ,Z+ movw xh:xl ,r25:r24 add xl ,r16 adc xh ,r17 st X ,r0 inc r16 ;uart_iput ++ (post increment) andi r16 ,UART_ISIZE-1 sts uart_iput ,r16 tst r0 brne monitor_test_loop monitor_test_full: rjmp monitor ;**************************************************************************************** ; Check for Commands monitor: lds r16 ,monitor_inptr tst r16 brpl monitor_no_prompt ;ldi zl ,low(monitor_msg_prompt<<1) ;ldi zh ,high(monitor_msg_prompt<<1) ;call puts_rom_func ldi r16 ,0 sts monitor_inptr ,r16 monitor_no_prompt: call gets brtc monitor_exit rcall next_word brtc monitor_error ldi r16 ,L_XCMD rcall find_label brtc monitor_error mov zl ,xl mov zh ,xh icall brts monitor_init monitor_error: ldi zl ,low(msg_monitor_error<<1) ldi zh ,high(msg_monitor_error<<1) call puts_rom_func rjmp monitor_init monitor_init: ldi r16 ,low(uart_cmd) sts cmd_ptr ,r16 ldi r16 ,high(uart_cmd) sts cmd_ptr+1 ,r16 ldi r16 ,-1 sts monitor_inptr ,r16 monitor_exit: ret monitor_msg_prompt: .db 62, 0 ;**************************************************************************************** ; mon_help: PUTS_ROM msg_monitor_help set ret ;**************************************************************************************** ; mon_list_labels: rcall next_int_value brtc mon_llb_exit ldi zl ,low(mon_master_label_tab<<1) ldi zh ,high(mon_master_label_tab<<1) clt mon_llb_01: lpm r16 ,Z+ lpm r17 ,Z+ cpi r16 ,0 cpc r16 ,r17 breq mon_llb_exit dec AKKU_8 brne mon_llb_01 movw zh:zl ,r17:r16 lsl zl rol zh set mon_llb_02: lpm r16 ,Z+ ;label adress lpm r17 ,Z+ cpi r16 ,0 cpc r16 ,r17 breq mon_llb_exit lpm r16 ,Z+ ;label type ldi r17 ,11 ;11 characters label name mon_llb_03: lpm r16 ,Z+ call putc_func dec r17 brne mon_llb_03 ldi r16 ,13 call putc_func rjmp mon_llb_02 mon_llb_exit: ret ;**************************************************************************************** ; mon_eep_save_profile: rcall next_int_value brtc mon_esp_exit mov r16 ,AKKU_8 dec r16 call eep_save_profile mon_esp_exit: ret ;**************************************************************************************** ; mon_eep_load_profile: rcall next_int_value brtc mon_elp_exit mov r16 ,AKKU_8 dec r16 call eep_load_profile mon_elp_exit: ret ;************************************************************ ; Monitor Command DA ; Display Adress ; ; DA