summaryrefslogtreecommitdiff
path: root/software/idm
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2011-12-09 13:22:10 +0000
committerChristian Pointner <equinox@mur.at>2011-12-09 13:22:10 +0000
commita6225cc1b045246f7a83a92df7b9b2cbb45d7a09 (patch)
tree70e5594cf4d474e82ea81830c4908d82db2a81a1 /software/idm
parentadded write ring buffer (diff)
read write buf ptr handling
git-svn-id: https://svn.spreadspace.org/mur.sat@210 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software/idm')
-rw-r--r--software/idm/idm.asm122
1 files changed, 108 insertions, 14 deletions
diff --git a/software/idm/idm.asm b/software/idm/idm.asm
index c1a3ed3..a4fd653 100644
--- a/software/idm/idm.asm
+++ b/software/idm/idm.asm
@@ -41,7 +41,11 @@
BUF_PAGE_LEN EQU H'0050'
BUF_PAGE_CNT EQU H'0004'
BUF_OFFSET EQU H'0020'
-
+
+ ;; FLAGS
+UNDERRUN EQU .0
+OVERRUN EQU .1
+
;; I/O Pins
;; PortA
MPU_INT EQU .4
@@ -55,7 +59,8 @@ MPU_INT EQU .4
;; all pages
TMP EQU H'0070'
WAIT_CNT EQU H'0071'
-
+FLAGS EQU H'0072'
+
WBUF_PAGE_PTR EQU H'0074'
WBUF_PAGE_NUM EQU H'0075'
RBUF_PAGE_PTR EQU H'0076'
@@ -99,10 +104,13 @@ int_tmr2_adcon
goto int_tmr2_adcon
call wbuf_next
+ btfsc FLAGS,OVERRUN
+ goto int_tmr2_end
movf ADRESH,w
- movwf IND
-; movwf TXREG
-
+ movwf INDF
+ movwf TXREG
+
+int_tmr2_end
bcf PIR1,TMR2IF
goto interrupt_end
@@ -173,8 +181,8 @@ init
movwf PIE1
clrf PIE2
; movlw .250 ;; 8kHz
-; movlw .200 ;; 5kHz
- movlw .156 ;; ~50Hz
+ movlw .200 ;; 5kHz
+; movlw .156 ;; ~50Hz
movwf PR2
clrf ADCON1
@@ -184,8 +192,8 @@ init
movlw b'10010000'
movwf RCSTA
; movlw b'00000100' ;; 8kHz
-; movlw b'00001100' ;; 5kHz
- movlw b'01111110' ;; ~50Hz
+ movlw b'00001100' ;; 5kHz
+; movlw b'01111110' ;; ~50Hz
movwf T2CON
movlw b'01000000'
movwf INTCON
@@ -195,11 +203,8 @@ init
; bcf PORTA,MPU_INT
- movlw BUF_PAGE_LEN - 1
- movwf WBUF_PAGE_PTR
- movlw BUF_PAGE_CNT - 1
- movwf WBUF_PAGE_NUM
-
+ call wbuf_reset
+ call rbuf_reset
clrf TMP
bsf INTCON,GIE
@@ -256,7 +261,33 @@ uart_rx_fe
return
;; -------------------
+wbuf_reset
+ movlw BUF_PAGE_LEN - 1
+ movwf WBUF_PAGE_PTR
+ movlw BUF_PAGE_CNT - 1
+ movwf WBUF_PAGE_NUM
+ bcf FLAGS,OVERRUN
+
+ ;; -------------------
wbuf_next
+ btfsc FLAGS,UNDERRUN
+ goto wbuf_move_ptr
+
+ movf RBUF_PAGE_NUM,w
+ xorwf WBUF_PAGE_NUM,w
+ btfss STATUS,Z
+ goto wbuf_move_ptr
+
+ movf RBUF_PAGE_PTR,w
+ xorwf WBUF_PAGE_PTR,w
+ btfss STATUS,Z
+ goto wbuf_move_ptr
+
+ bsf FLAGS,OVERRUN
+ return
+
+wbuf_move_ptr
+ bcf FLAGS,UNDERRUN
movf WBUF_PAGE_PTR,f
btfsc STATUS,Z
goto wbuf_next_page
@@ -291,6 +322,69 @@ wbuf_fill_fsr
bsf STATUS,IRP
return
+ ;; -------------------
+rbuf_reset
+ movlw BUF_PAGE_LEN - 1
+ movwf RBUF_PAGE_PTR
+ movlw BUF_PAGE_CNT - 1
+ movwf RBUF_PAGE_NUM
+ bsf FLAGS,UNDERRUN
+
+ ;; -------------------
+rbuf_next
+ btfsc FLAGS,OVERRUN
+ goto rbuf_move_ptr
+
+ movf WBUF_PAGE_NUM,w
+ xorwf RBUF_PAGE_NUM,w
+ btfss STATUS,Z
+ goto rbuf_move_ptr
+
+ movf WBUF_PAGE_PTR,w
+ xorwf RBUF_PAGE_PTR,w
+ btfss STATUS,Z
+ goto rbuf_move_ptr
+
+ bsf FLAGS,UNDERRUN
+ return
+
+rbuf_move_ptr
+ bcf FLAGS,OVERRUN
+ movf RBUF_PAGE_PTR,f
+ btfsc STATUS,Z
+ goto rbuf_next_page
+ decf RBUF_PAGE_PTR,f
+ goto rbuf_fill_fsr
+
+rbuf_next_page
+ movlw BUF_PAGE_LEN - 1
+ movwf RBUF_PAGE_PTR
+ movf RBUF_PAGE_NUM,f
+ btfsc STATUS,Z
+ goto rbuf_next_cycle
+ decf RBUF_PAGE_NUM,f
+ goto rbuf_fill_fsr
+
+rbuf_next_cycle
+ movlw BUF_PAGE_CNT - 1
+ movwf RBUF_PAGE_NUM
+
+rbuf_fill_fsr
+ movlw BUF_OFFSET
+ addwf RBUF_PAGE_PTR,w
+ movwf FSR
+
+ btfss RBUF_PAGE_NUM,0
+ bcf FSR,7
+ btfsc RBUF_PAGE_NUM,0
+ bsf FSR,7
+ btfss RBUF_PAGE_NUM,1
+ bcf STATUS,IRP
+ btfsc RBUF_PAGE_NUM,1
+ bsf STATUS,IRP
+ return
+
+
;; -------------------------------------
;; MAINLOOP
main