From: ceb Date: Tue, 4 Jan 2005 23:16:13 +0000 (+0000) Subject: adding debugging stuff... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=e080941852737ed5dd1b9fa3d9fbb8e3bfa7a81e;p=trains.git adding debugging stuff... --- diff --git a/cebpic/Makefile b/cebpic/Makefile index 11620f4..127ee2a 100644 --- a/cebpic/Makefile +++ b/cebpic/Makefile @@ -1,4 +1,4 @@ -PROGRAMS= led-flash send-serial reply-serial nmra-stream +PROGRAMS= led-flash send-serial reply-serial nmra-stream booster-output-low include ../pic.make diff --git a/cebpic/nmra-stream.asm b/cebpic/nmra-stream.asm index 39bbb4a..f6a3471 100644 --- a/cebpic/nmra-stream.asm +++ b/cebpic/nmra-stream.asm @@ -47,14 +47,14 @@ macros debug macro debugvalue movlw debugvalue call debug_serial_transmit -waitfortsr - btfss TXSTA,1,0 - bra waitfortsr endm debug_serial_transmit movwf TXREG,0 ; move contents of W (i.e. debugvalue) ; to TXREG for transmission +waitfortsr + btfss TXSTA,1,0 + bra waitfortsr return ;**************************************************************************** @@ -79,6 +79,8 @@ initialise bsf SPBRG,7,0 bsf SPBRG,0,0 + + debug 'a' ; write 'a' to serial port ;---------------------------------------------------------------------------- @@ -100,6 +102,7 @@ initialise bcf T0CON,1,0 ; } prescale value 1:32 bsf T0CON,0,0 ; } (testing) + debug 'b' ; write 'b' to serial port ;---------------------------------------------------------------------------- ; initialise buffers (for BSR5, for nmra from-serial/to-track buffers) @@ -113,6 +116,7 @@ initialise ; all in access bank + debug 'c' ; write 'c' to serial port ;---------------------------------------------------------------------------- @@ -125,14 +129,15 @@ initialise movwf TOTRACKBIT,0 ; make bit mask be 1000 0000 ; initialise booster direction - bsf TRISC,0,0 ; make pin 0 (booster direction) output + bcf TRISC,0,0 ; make pin 0 (booster direction) output bcf PORTC,0,0 ; set low initially ; set booster pwm high - bsf TRISC,1,0 ; make pin 1 (booster pwm) output + bcf TRISC,1,0 ; make pin 1 (booster pwm) output bsf PORTC,1,0 ; booster pwm high + debug 'd' ; write 'd' to serial port ;---------------------------------------------------------------------------- ; interrupt set-up @@ -151,6 +156,7 @@ initialise bsf INTCON,5,0 ; enable timer0 interrupts + debug 'e' ; write 'e' to serial port ;**************************************************************************** call led_green @@ -169,8 +175,10 @@ interrupt_low ; check which interrupt. Branch to serial_receive or timer or return + debug 146 ; write 'f' to serial port btfss PIR1,5,0 ; check whether serial recv interrupt bit set goto serial_receive + debug 147 ; write 'g' to serial port btfss INTCON,2,0 ; check whether timer0 interrupt set goto timer0_interrupt goto panic @@ -183,6 +191,7 @@ interrupt_low ;**************************************************************************** serial_receive + debug 148 ; 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 @@ -199,6 +208,7 @@ serial_receive advance_write_buffer + debug 149 ; write 'i' to serial port ; check if on 1st byte of new buffer anyway (i.e. last 4 bits = 0) movf FROMSERIAL,0,0 ; copy FROMSERIAL pointer location to W andlw 0xF ; investigate last 4 bits @@ -225,12 +235,14 @@ fromserial_overflow timer0_interrupt + debug 150 ; write 'j' to serial port bcf INTCON,2,0 ; clear interrupt-set bit movlw 0x01 ; (testing) ; movlw 0x6E ; (not-testing) movwf TMR0L,0 ; set timer0 to 0x6E (so interrupt takes 58us) + debug 151 ; write 'k' to serial port ; check next action - if 0, change to 1 and return btfsc NMRACTRL,NEXTACTION,0 goto toggle_output @@ -241,6 +253,7 @@ timer0_interrupt ; if next action = 1, then toggle output toggle_output + debug 152 ; write 'l' to serial port btg PORTC,0,0 ; toggle booster output pin btfss PORTC,0,0 goto decide_next_bit @@ -251,6 +264,7 @@ toggle_output ; nextaction in preparation for 2nd half of bit and then return mid_bit + debug 153 ; write 'm' to serial port btfsc NMRACTRL,TRANSMITBIT,0 bsf NMRACTRL,NEXTACTION,0 btfss NMRACTRL,TRANSMITBIT,0 @@ -260,6 +274,7 @@ mid_bit decide_next_bit + debug 154 ; write 'n' to serial port ; check whether current to-track buffer = current from-serial buffer ; if yes, transmit 1s (set transmitbit=1, nextaction=1 and return) @@ -273,6 +288,7 @@ decide_next_bit read_from_buffer + debug 155 ; write 'o' to serial port ; if currently on bit 7, want to skip to bit 6 ;*** wouldn't it be easier to start on bit 6 ? :-) -iwj @@ -284,6 +300,7 @@ read_from_buffer ; set na=cb=bit value, advance bit (i.e. rotate TRANSMITBIT right), ; check if bit7, if so, advance byte, return + debug 156 ; write 'p' to serial port movff TOTRACK,FSR1L ; set low byte of IND1 pointer movlw 5 movwf FSR1H,0 ; set high byte of IND1 pointer @@ -298,11 +315,13 @@ read_from_buffer bra one_bit_to_track zero_bit_to_track + debug 157 ; write 'q' to serial port bcf NMRACTRL,TRANSMITBIT,0 bcf NMRACTRL,NEXTACTION,0 goto advance_bit one_bit_to_track + debug 158 ; write 'r' to serial port bsf NMRACTRL,TRANSMITBIT,0 bsf NMRACTRL,NEXTACTION,0 goto advance_bit @@ -312,6 +331,7 @@ one_bit_to_track advance_bit ; rotate transmitbit to next position + debug 159 ; write 's' to serial port rrncf TOTRACKBIT,1,0 ; rotate mask right ;*** surely rrnc (`rotate right not through carry' I assume) ;*** will leave a copy of the top bit in the N flag ? Then you @@ -325,6 +345,7 @@ advance_bit advance_pointer + debug 160 ; write 't' to serial port ; currently on bit 7 of the byte, after having read rest of byte to ; track; check whether it is 1 or 0 @@ -341,6 +362,7 @@ advance_pointer advance_read_buffer + debug 161 ; write 'u' to serial port ;*** I suggest swapping this and advance_read_byte round, since ;*** advance_read_byte is a more `inner' bit of the `loop' -iwj @@ -373,6 +395,7 @@ totrack_overflow advance_read_byte + debug 'v' ; write 'v' to serial port ; advance to next byte of buffer (increment TOTRACK) ; (will be on bit 7 at this point anyway so no need to change TOTRACKBIT) diff --git a/detpic/nmra-stream.asm b/detpic/nmra-stream.asm index 39bbb4a..f6a3471 100644 --- a/detpic/nmra-stream.asm +++ b/detpic/nmra-stream.asm @@ -47,14 +47,14 @@ macros debug macro debugvalue movlw debugvalue call debug_serial_transmit -waitfortsr - btfss TXSTA,1,0 - bra waitfortsr endm debug_serial_transmit movwf TXREG,0 ; move contents of W (i.e. debugvalue) ; to TXREG for transmission +waitfortsr + btfss TXSTA,1,0 + bra waitfortsr return ;**************************************************************************** @@ -79,6 +79,8 @@ initialise bsf SPBRG,7,0 bsf SPBRG,0,0 + + debug 'a' ; write 'a' to serial port ;---------------------------------------------------------------------------- @@ -100,6 +102,7 @@ initialise bcf T0CON,1,0 ; } prescale value 1:32 bsf T0CON,0,0 ; } (testing) + debug 'b' ; write 'b' to serial port ;---------------------------------------------------------------------------- ; initialise buffers (for BSR5, for nmra from-serial/to-track buffers) @@ -113,6 +116,7 @@ initialise ; all in access bank + debug 'c' ; write 'c' to serial port ;---------------------------------------------------------------------------- @@ -125,14 +129,15 @@ initialise movwf TOTRACKBIT,0 ; make bit mask be 1000 0000 ; initialise booster direction - bsf TRISC,0,0 ; make pin 0 (booster direction) output + bcf TRISC,0,0 ; make pin 0 (booster direction) output bcf PORTC,0,0 ; set low initially ; set booster pwm high - bsf TRISC,1,0 ; make pin 1 (booster pwm) output + bcf TRISC,1,0 ; make pin 1 (booster pwm) output bsf PORTC,1,0 ; booster pwm high + debug 'd' ; write 'd' to serial port ;---------------------------------------------------------------------------- ; interrupt set-up @@ -151,6 +156,7 @@ initialise bsf INTCON,5,0 ; enable timer0 interrupts + debug 'e' ; write 'e' to serial port ;**************************************************************************** call led_green @@ -169,8 +175,10 @@ interrupt_low ; check which interrupt. Branch to serial_receive or timer or return + debug 146 ; write 'f' to serial port btfss PIR1,5,0 ; check whether serial recv interrupt bit set goto serial_receive + debug 147 ; write 'g' to serial port btfss INTCON,2,0 ; check whether timer0 interrupt set goto timer0_interrupt goto panic @@ -183,6 +191,7 @@ interrupt_low ;**************************************************************************** serial_receive + debug 148 ; 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 @@ -199,6 +208,7 @@ serial_receive advance_write_buffer + debug 149 ; write 'i' to serial port ; check if on 1st byte of new buffer anyway (i.e. last 4 bits = 0) movf FROMSERIAL,0,0 ; copy FROMSERIAL pointer location to W andlw 0xF ; investigate last 4 bits @@ -225,12 +235,14 @@ fromserial_overflow timer0_interrupt + debug 150 ; write 'j' to serial port bcf INTCON,2,0 ; clear interrupt-set bit movlw 0x01 ; (testing) ; movlw 0x6E ; (not-testing) movwf TMR0L,0 ; set timer0 to 0x6E (so interrupt takes 58us) + debug 151 ; write 'k' to serial port ; check next action - if 0, change to 1 and return btfsc NMRACTRL,NEXTACTION,0 goto toggle_output @@ -241,6 +253,7 @@ timer0_interrupt ; if next action = 1, then toggle output toggle_output + debug 152 ; write 'l' to serial port btg PORTC,0,0 ; toggle booster output pin btfss PORTC,0,0 goto decide_next_bit @@ -251,6 +264,7 @@ toggle_output ; nextaction in preparation for 2nd half of bit and then return mid_bit + debug 153 ; write 'm' to serial port btfsc NMRACTRL,TRANSMITBIT,0 bsf NMRACTRL,NEXTACTION,0 btfss NMRACTRL,TRANSMITBIT,0 @@ -260,6 +274,7 @@ mid_bit decide_next_bit + debug 154 ; write 'n' to serial port ; check whether current to-track buffer = current from-serial buffer ; if yes, transmit 1s (set transmitbit=1, nextaction=1 and return) @@ -273,6 +288,7 @@ decide_next_bit read_from_buffer + debug 155 ; write 'o' to serial port ; if currently on bit 7, want to skip to bit 6 ;*** wouldn't it be easier to start on bit 6 ? :-) -iwj @@ -284,6 +300,7 @@ read_from_buffer ; set na=cb=bit value, advance bit (i.e. rotate TRANSMITBIT right), ; check if bit7, if so, advance byte, return + debug 156 ; write 'p' to serial port movff TOTRACK,FSR1L ; set low byte of IND1 pointer movlw 5 movwf FSR1H,0 ; set high byte of IND1 pointer @@ -298,11 +315,13 @@ read_from_buffer bra one_bit_to_track zero_bit_to_track + debug 157 ; write 'q' to serial port bcf NMRACTRL,TRANSMITBIT,0 bcf NMRACTRL,NEXTACTION,0 goto advance_bit one_bit_to_track + debug 158 ; write 'r' to serial port bsf NMRACTRL,TRANSMITBIT,0 bsf NMRACTRL,NEXTACTION,0 goto advance_bit @@ -312,6 +331,7 @@ one_bit_to_track advance_bit ; rotate transmitbit to next position + debug 159 ; write 's' to serial port rrncf TOTRACKBIT,1,0 ; rotate mask right ;*** surely rrnc (`rotate right not through carry' I assume) ;*** will leave a copy of the top bit in the N flag ? Then you @@ -325,6 +345,7 @@ advance_bit advance_pointer + debug 160 ; write 't' to serial port ; currently on bit 7 of the byte, after having read rest of byte to ; track; check whether it is 1 or 0 @@ -341,6 +362,7 @@ advance_pointer advance_read_buffer + debug 161 ; write 'u' to serial port ;*** I suggest swapping this and advance_read_byte round, since ;*** advance_read_byte is a more `inner' bit of the `loop' -iwj @@ -373,6 +395,7 @@ totrack_overflow advance_read_byte + debug 'v' ; write 'v' to serial port ; advance to next byte of buffer (increment TOTRACK) ; (will be on bit 7 at this point anyway so no need to change TOTRACKBIT)