diff options
author | Christian Pointner <equinox@mur.at> | 2011-07-25 02:04:21 +0000 |
---|---|---|
committer | Christian Pointner <equinox@mur.at> | 2011-07-25 02:04:21 +0000 |
commit | dd52ba2388271d3b646b013ae45efa90564d0cfd (patch) | |
tree | 3f2f1043772b119af85a58acee75af4f833dd09b /software/ttx/ttx.asm | |
parent | switched to 125kHz for TTX (diff) |
first working communication between ihu and ttx
ttx has 2s watchdog now
ttx main timer wakes every second
better input check for sending chars
git-svn-id: https://svn.spreadspace.org/mur.sat@54 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software/ttx/ttx.asm')
-rw-r--r-- | software/ttx/ttx.asm | 318 |
1 files changed, 205 insertions, 113 deletions
diff --git a/software/ttx/ttx.asm b/software/ttx/ttx.asm index 3a9664b..454e10c 100644 --- a/software/ttx/ttx.asm +++ b/software/ttx/ttx.asm @@ -32,21 +32,24 @@ LIST p=12F635 include "p12f635.inc" - __config _WUREN_OFF & _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT + __config _WUREN_OFF & _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_OFF & _WDT_ON & _INTRC_OSC_NOCLKOUT ;; ------------------------------------- ;; DEFINES ;; constants -DOT EQU .256 - .29 -DASH EQU .256 - .87 +DOT EQU .256 - .21 ; .29 +DASH EQU .256 - .63 ; .87 ESPACE EQU DOT CSPACE EQU DASH -WSPACE EQU .256 - .203 +WSPACE EQU .256 - .147 ; .203 ENABLE_TIME EQU DOT -BCONINT_DEF EQU .5 ; *2 = Beacon Interval in seconds -START_CHAR EQU 'A' - ' ' - +BCONINT_DEF EQU .42 +START_CHAR EQU 'A' +ACK_CHAR EQU 'A' +OSC_LOW EQU b'00000000' +OSC_HIGH EQU b'01100000' + ;; I/O Pins CWENABLE EQU GP0 CWOUT EQU GP1 @@ -63,20 +66,28 @@ CHARCNT EQU H'0044' PENTLE0 EQU H'0045' PENTLE1 EQU H'0046' PENTLECNT EQU H'0047' - +ACK_DATA EQU H'0048' + +RX_CNT EQU H'004E' +RX_BYTE EQU H'004F' + BUF EQU H'0050' ;; all pages +STATE EQU H'0078' BEACON_INT EQU H'0079' -STATE EQU H'007A' +NVSTATE EQU H'007A' BEACONCNTH EQU H'007B' BEACONCNTL EQU H'007C' SECCNT EQU H'007D' W_TEMP EQU H'007E' STATUS_TEMP EQU H'007F' - ;; bits STATE + ;; bits NVSTATE safe EQU .0 + + ;; bits STATE +rx EQU .0 ;; ------------------------------------- ;; Reset Vector @@ -91,29 +102,56 @@ safe EQU .0 swapf STATUS,W movwf STATUS_TEMP - bcf STATUS,RP0 - bcf STATUS,RP1 - btfss INTCON,INTF goto tmr1_int ext_int - ;; TODO: read bit from GPIO,SDAT and add to received string + bcf INTCON,INTF + btfsc STATE,rx goto interrupt_end + bsf STATUS,RP0 + movlw OSC_HIGH + movwf OSCCON + bcf STATUS,RP0 + movlw .8 + movwf RX_CNT +ext_int_clk_low + btfsc GPIO,SCLK + goto ext_int_clk_low +ext_int_clk_high + btfss GPIO,SCLK + goto ext_int_clk_high + btfss GPIO,SDAT + bcf RX_BYTE,0 + btfsc GPIO,SDAT + bsf RX_BYTE,0 + decfsz RX_CNT,f + goto ext_int_rx_next + bsf STATE,rx + bsf STATUS,RP0 + movlw OSC_LOW + movwf OSCCON + goto interrupt_end + +ext_int_rx_next + rlf RX_BYTE,f + goto ext_int_clk_low tmr1_int + bcf STATUS,RP0 bcf PIR1,TMR1IF - btfsc STATE,safe ; safe mode -> disable scheduler - goto disable_tmr1 - movf SECCNT,w + bcf T1CON,TMR1ON + clrf TMR1L + movlw b'10000000' + movwf TMR1H + btfsc NVSTATE,safe ; safe mode -> disable scheduler + goto interrupt_end + + bsf T1CON,TMR1ON + movf SECCNT,f btfss STATUS,Z - decf SECCNT,f + decf SECCNT,f goto interrupt_end -disable_tmr1 - bcf T1CON,TMR1ON - movf BEACON_INT,w - movwf SECCNT - interrupt_end ;; restore context swapf STATUS_TEMP,W @@ -123,55 +161,6 @@ interrupt_end retfie ;; ------------------------------------- - ;; INIT -init - ;; bank 1 - bsf STATUS,RP0 - bcf STATUS,RP1 - - movlw b'11000101' - movwf OPTION_REG - movlw b'11111100' - movwf TRISIO - movlw b'00000001' - movwf PIE1 - movlw b'00010000' - movwf OSCCON - - bcf STATUS,RP0 - - ;; bank 0 - clrf TMR1L - clrf TMR1H - movlw b'00000110' - movwf T1CON - movlw b'01000000' ; enable external interrupt bit4 - movwf INTCON - - movlw b'00000111' - movwf CMCON0 - - bcf GPIO,CWOUT - bcf GPIO,CWENABLE - - movf BEACON_INT,w - movwf SECCNT - - clrf STATE ; TODO: read State from EEPROM - movlw .42 - movwf BEACONCNTL ; TODO: read Beaconcnt from EEPROM - movlw .23 - movwf BEACONCNTH - movlw BCONINT_DEF ; TODO: read Beacon Interval from EEPROM - movwf BEACON_INT - - btfss STATE,safe ; safe mode -> disable scheduler - bsf T1CON,TMR1ON - - bsf INTCON,GIE - goto main - - ;; ------------------------------------- ;; TABLES ;; Morse Codes: 0=dot, 1=dash @@ -303,50 +292,103 @@ getcwlen ;; Base32 Code base32 addwf PCL,f - retlw 'A' - ' ' - retlw 'B' - ' ' - retlw 'C' - ' ' - retlw 'D' - ' ' - retlw 'E' - ' ' - retlw 'F' - ' ' - retlw 'G' - ' ' - retlw 'H' - ' ' - retlw 'I' - ' ' - retlw 'J' - ' ' - retlw 'K' - ' ' - retlw 'L' - ' ' - retlw 'M' - ' ' - retlw 'N' - ' ' - retlw 'O' - ' ' - retlw 'P' - ' ' - retlw 'Q' - ' ' - retlw 'R' - ' ' - retlw 'S' - ' ' - retlw 'T' - ' ' - retlw 'U' - ' ' - retlw 'V' - ' ' - retlw 'W' - ' ' - retlw 'X' - ' ' - retlw 'Y' - ' ' - retlw 'Z' - ' ' - retlw '2' - ' ' - retlw '3' - ' ' - retlw '4' - ' ' - retlw '5' - ' ' - retlw '6' - ' ' - retlw '7' - ' ' + retlw 'A' + retlw 'B' + retlw 'C' + retlw 'D' + retlw 'E' + retlw 'F' + retlw 'G' + retlw 'H' + retlw 'I' + retlw 'J' + retlw 'K' + retlw 'L' + retlw 'M' + retlw 'N' + retlw 'O' + retlw 'P' + retlw 'Q' + retlw 'R' + retlw 'S' + retlw 'T' + retlw 'U' + retlw 'V' + retlw 'W' + retlw 'X' + retlw 'Y' + retlw 'Z' + retlw '2' + retlw '3' + retlw '4' + retlw '5' + retlw '6' + retlw '7' ;; fixed strings callsign addwf PCL,f nop - retlw 'R' - ' ' - retlw 'U' - ' ' - retlw 'M' - ' ' - retlw '6' - ' ' - retlw 'E' - ' ' - retlw 'O' - ' ' + retlw 'R' + retlw 'U' + retlw 'M' + retlw '6' + retlw 'E' + retlw 'O' + + ;; ------------------------------------- + ;; INIT +init + ;; bank 1 + bsf STATUS,RP0 + bcf STATUS,RP1 + + movlw b'11000011' + movwf OPTION_REG + movlw b'11111100' + movwf TRISIO + movlw b'00000001' + movwf PIE1 + movlw OSC_LOW + movwf OSCCON + + bcf STATUS,RP0 + + ;; bank 0 + movlw b'00010110' + movwf WDTCON + clrf TMR1L + movlw b'10000000' + movwf TMR1H + movlw b'00000110' + movwf T1CON + movlw b'01010000' + movwf INTCON + + movlw b'00000111' + movwf CMCON0 + + bcf GPIO,CWOUT + bcf GPIO,CWENABLE + + clrf STATE + clrf NVSTATE ; TODO: read State from EEPROM + movlw .42 + movwf BEACONCNTL ; TODO: read Beaconcnt from EEPROM + movlw .23 + movwf BEACONCNTH + movlw BCONINT_DEF ; TODO: read Beacon Interval from EEPROM + movwf BEACON_INT + + movf BEACON_INT,w + movwf SECCNT + + btfss NVSTATE,safe ; safe mode -> disable scheduler + bsf T1CON,TMR1ON + bsf INTCON,GIE + goto main + ;; ------------------------------------- ;; SUBROUTINES dottime @@ -355,11 +397,24 @@ dottime dot_inner btfss INTCON,T0IF goto dot_inner + clrwdt return ;; ------------------------------------- send_char movwf CHAR + movlw 'Z' + 1 + subwf CHAR,w + btfsc STATUS,C + return + movlw ' ' + subwf CHAR,f + btfss STATUS,C + return + btfsc STATUS,Z + return + + movf CHAR,w call getcw movwf ELEMENT movf CHAR,w @@ -368,7 +423,6 @@ send_char movf ELECNT,f btfsc STATUS,Z return - movf CHAR,w xorwf PARITY,f char_next_element @@ -559,6 +613,8 @@ send_parity andlw b'00011111' call base32 call send_char + movlw WSPACE + call dottime return ;; ------------------------------------- @@ -596,18 +652,54 @@ beacon_end return ;; ------------------------------------- +send_ack + movwf ACK_DATA + bsf GPIO,CWENABLE + movlw ENABLE_TIME + call dottime + clrf PARITY + + movlw ACK_CHAR + call send_char + + movlw CSPACE + call dottime + + movf ACK_DATA,w + call send_char + + movlw CSPACE + call dottime + + call send_parity + + bcf GPIO,CWENABLE + return + + ;; ------------------------------------- ;; MAINLOOP main ;; this gets called after reset and whenever a wakeup occured ;; (after TMR1 overrun or interrupt on GP2) movf SECCNT,f - btfss STATUS,Z + btfsc STATUS,Z + goto seccnt_zero + btfsc STATE,rx + goto byte_received goto powerdown - ;; this gets called every 2*BEACON_INT seconds + ;; this gets called every BEACON_INT seconds +seccnt_zero movf BEACON_INT,w movwf SECCNT call send_beacon + goto powerdown + + ;; this gets called whenver a byte was received from ihu +byte_received + movf RX_BYTE,w + bcf STATE,rx + call send_ack powerdown sleep |