From: ceb Date: Sat, 8 Jan 2005 23:44:28 +0000 (+0000) Subject: debugging X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=6507282c0a12f91c5eebbcc4d9f3053da2283004;p=trains.git debugging also added slow+fast version ifdefs --- diff --git a/cebpic/README.protocol b/cebpic/README.protocol index cbe2672..f97fa8a 100644 --- a/cebpic/README.protocol +++ b/cebpic/README.protocol @@ -7,7 +7,7 @@ The first 14 data bits in the NMRA packet should be 1s. (i.e. the first two complete bytes should be 01111111 01111111) (packets beginning with some other sequence are reserved for non-NMRA messages) -Maximum NMRA message length = 16 bytes (i.e. 112 bits). +Maximum NMRA message length = 15 bytes (i.e. 105 bits). Messages longer than this will cause things to get confused at the moment. baud rate 9600 diff --git a/cebpic/nmra-stream.asm b/cebpic/nmra-stream.asm index 4b0aeee..5909e56 100644 --- a/cebpic/nmra-stream.asm +++ b/cebpic/nmra-stream.asm @@ -55,11 +55,18 @@ macros ; macro to call subroutine to transmit over serial port for debugging ; takes 8-bit value, puts in W, invokes debug_serial_transmit + + ifndef SLOW_VERSION +debug macro debugvalue + endm + endif + ifdef SLOW_VERSION debug macro debugvalue movlw debugvalue call debug_serial_transmit endm + endif debug_serial_transmit movwf TXREG,0 ; move contents of W (i.e. debugvalue) @@ -103,17 +110,29 @@ initialise ; timer0 initial config for NMRA timer + + ifdef SLOW_VERSION bcf T0CON,6,0 ; p107 Timer0 -> 16bit mode (testing) -; bsf T0CON,6,0 ; p107 Timer0 -> 8bit mode (not-testing) + endif + + ifndef SLOW_VERSION + bsf T0CON,6,0 ; p107 Timer0 -> 8bit mode (not-testing) + endif + bcf T0CON,5,0 ; timer0 use internal clock bcf T0CON,3,0 ; use prescaler -; bcf T0CON,2,0 ; } -; bcf T0CON,1,0 ; } prescale value 1:2 -; bcf T0CON,0,0 ; } (not-testing) + ifndef SLOW_VERSION + bcf T0CON,2,0 ; } + bcf T0CON,1,0 ; } prescale value 1:2 + bcf T0CON,0,0 ; } (not-testing) + endif + + ifdef SLOW_VERSION bsf T0CON,2,0 ; } bcf T0CON,1,0 ; } prescale value 1:16 bcf T0CON,0,0 ; } (testing) + endif debug 'b' ; write 'b' to serial port ;---------------------------------------------------------------------------- @@ -206,19 +225,23 @@ interrupt_low ;**************************************************************************** serial_receive - debug 'h' ; write 'h' to serial port +; debug 'h' ; write 'h' to serial port movff FROMSERIAL,FSR0L ; set low byte of INDF0 pointer movlw 5 movwf FSR0H,0 ; set high byte of INDF0 pointer - debug '1' ; write 'h' to serial port +; debug '1' ; write 'h' to serial port movff RCREG,INDF0 ; copy to received register - debug '2' ; write 'h' to serial port - incf FROMSERIAL,1,0 ; advance FROMSERIAL pointer by 1 byte - debug '3' ; write 'h' to serial port -; *** check for overrun and do something sensible +; debug '2' ; write 'h' to serial port + +; check whether bit 7 is set. If so, move to next buffer. btfsc INDF0,7,0 ; check if bit 7 is set call advance_write_buffer ; if so, move to next buffer - debug '4' ; write 'h' to serial port +; debug '3' ; write 'h' to serial port + +; If not, move to next byte + btfss INDF0,7,0 ; check if bit 7 is set + incf FROMSERIAL,1,0 ; advance FROMSERIAL pointer by 1 byte +; debug '4' ; write 'h' to serial port retfie 1 ; *** I *think* the interrupt bit is cleared by reading out of RCREG @@ -250,8 +273,15 @@ timer0_interrupt debug ',' ; write 'j' to serial port bcf INTCON,2,0 ; clear interrupt-set bit + + ifdef SLOW_VERSION movlw 0x01 ; (testing) -; movlw 0x6E ; (not-testing) + endif + + ifndef SLOW_VERSION + movlw 0x6E ; (not-testing) + endif + movwf TMR0L,0 ; set timer0 to 0x6E (so interrupt takes 58us) @@ -309,8 +339,6 @@ read_from_buffer ; if currently on bit 7, want to skip to bit 6 ;*** wouldn't it be easier to start on bit 6 ? :-) -iwj - btfsc TOTRACKBIT,7,0 - debug '4' btfsc TOTRACKBIT,7,0 rrncf TOTRACKBIT,1,0 ; rotate mask right @@ -329,13 +357,17 @@ read_from_buffer bra one_bit_to_track zero_bit_to_track - debug 'q' ; write 'q' to serial port + debug '_' ; write 'q' to serial port + debug '0' ; write 'q' to serial port + debug '_' ; write 'q' to serial port bcf NMRACTRL,TRANSMITBIT,0 bcf NMRACTRL,NEXTACTION,0 goto advance_bit one_bit_to_track - debug 'r' ; write 'r' to serial port + debug '_' ; write 'q' to serial port + debug '1' ; write 'r' to serial port + debug '_' ; write 'q' to serial port bsf NMRACTRL,TRANSMITBIT,0 bsf NMRACTRL,NEXTACTION,0 goto advance_bit @@ -369,15 +401,11 @@ advance_pointer movwf FSR1H,0 ; if set, move to next buffer - btfsc INDF1,7,0 - debug 'F' btfsc INDF1,7,0 call advance_read_buffer ; if not set, move to next byte of samebuffer (increment TOTRACK) ; (will be on bit 7 at this point anyway so no need to change TOTRACKBIT) - btfss INDF1,7,0 - debug 'Y' btfss INDF1,7,0 incf TOTRACK,1,0 return diff --git a/detpic/nmra-stream.asm b/detpic/nmra-stream.asm index 4b0aeee..5909e56 100644 --- a/detpic/nmra-stream.asm +++ b/detpic/nmra-stream.asm @@ -55,11 +55,18 @@ macros ; macro to call subroutine to transmit over serial port for debugging ; takes 8-bit value, puts in W, invokes debug_serial_transmit + + ifndef SLOW_VERSION +debug macro debugvalue + endm + endif + ifdef SLOW_VERSION debug macro debugvalue movlw debugvalue call debug_serial_transmit endm + endif debug_serial_transmit movwf TXREG,0 ; move contents of W (i.e. debugvalue) @@ -103,17 +110,29 @@ initialise ; timer0 initial config for NMRA timer + + ifdef SLOW_VERSION bcf T0CON,6,0 ; p107 Timer0 -> 16bit mode (testing) -; bsf T0CON,6,0 ; p107 Timer0 -> 8bit mode (not-testing) + endif + + ifndef SLOW_VERSION + bsf T0CON,6,0 ; p107 Timer0 -> 8bit mode (not-testing) + endif + bcf T0CON,5,0 ; timer0 use internal clock bcf T0CON,3,0 ; use prescaler -; bcf T0CON,2,0 ; } -; bcf T0CON,1,0 ; } prescale value 1:2 -; bcf T0CON,0,0 ; } (not-testing) + ifndef SLOW_VERSION + bcf T0CON,2,0 ; } + bcf T0CON,1,0 ; } prescale value 1:2 + bcf T0CON,0,0 ; } (not-testing) + endif + + ifdef SLOW_VERSION bsf T0CON,2,0 ; } bcf T0CON,1,0 ; } prescale value 1:16 bcf T0CON,0,0 ; } (testing) + endif debug 'b' ; write 'b' to serial port ;---------------------------------------------------------------------------- @@ -206,19 +225,23 @@ interrupt_low ;**************************************************************************** serial_receive - debug 'h' ; write 'h' to serial port +; debug 'h' ; write 'h' to serial port movff FROMSERIAL,FSR0L ; set low byte of INDF0 pointer movlw 5 movwf FSR0H,0 ; set high byte of INDF0 pointer - debug '1' ; write 'h' to serial port +; debug '1' ; write 'h' to serial port movff RCREG,INDF0 ; copy to received register - debug '2' ; write 'h' to serial port - incf FROMSERIAL,1,0 ; advance FROMSERIAL pointer by 1 byte - debug '3' ; write 'h' to serial port -; *** check for overrun and do something sensible +; debug '2' ; write 'h' to serial port + +; check whether bit 7 is set. If so, move to next buffer. btfsc INDF0,7,0 ; check if bit 7 is set call advance_write_buffer ; if so, move to next buffer - debug '4' ; write 'h' to serial port +; debug '3' ; write 'h' to serial port + +; If not, move to next byte + btfss INDF0,7,0 ; check if bit 7 is set + incf FROMSERIAL,1,0 ; advance FROMSERIAL pointer by 1 byte +; debug '4' ; write 'h' to serial port retfie 1 ; *** I *think* the interrupt bit is cleared by reading out of RCREG @@ -250,8 +273,15 @@ timer0_interrupt debug ',' ; write 'j' to serial port bcf INTCON,2,0 ; clear interrupt-set bit + + ifdef SLOW_VERSION movlw 0x01 ; (testing) -; movlw 0x6E ; (not-testing) + endif + + ifndef SLOW_VERSION + movlw 0x6E ; (not-testing) + endif + movwf TMR0L,0 ; set timer0 to 0x6E (so interrupt takes 58us) @@ -309,8 +339,6 @@ read_from_buffer ; if currently on bit 7, want to skip to bit 6 ;*** wouldn't it be easier to start on bit 6 ? :-) -iwj - btfsc TOTRACKBIT,7,0 - debug '4' btfsc TOTRACKBIT,7,0 rrncf TOTRACKBIT,1,0 ; rotate mask right @@ -329,13 +357,17 @@ read_from_buffer bra one_bit_to_track zero_bit_to_track - debug 'q' ; write 'q' to serial port + debug '_' ; write 'q' to serial port + debug '0' ; write 'q' to serial port + debug '_' ; write 'q' to serial port bcf NMRACTRL,TRANSMITBIT,0 bcf NMRACTRL,NEXTACTION,0 goto advance_bit one_bit_to_track - debug 'r' ; write 'r' to serial port + debug '_' ; write 'q' to serial port + debug '1' ; write 'r' to serial port + debug '_' ; write 'q' to serial port bsf NMRACTRL,TRANSMITBIT,0 bsf NMRACTRL,NEXTACTION,0 goto advance_bit @@ -369,15 +401,11 @@ advance_pointer movwf FSR1H,0 ; if set, move to next buffer - btfsc INDF1,7,0 - debug 'F' btfsc INDF1,7,0 call advance_read_buffer ; if not set, move to next byte of samebuffer (increment TOTRACK) ; (will be on bit 7 at this point anyway so no need to change TOTRACKBIT) - btfss INDF1,7,0 - debug 'Y' btfss INDF1,7,0 incf TOTRACK,1,0 return