From 98c9be07289cd430ce7008c5be8d594af8ac897c Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 15 Jun 2012 18:47:26 +0000 Subject: some c-code translated to asm git-svn-id: https://svn.spreadspace.org/mur.sat@536 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/idm/idm.asm | 147 ++++++++++++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 65 deletions(-) (limited to 'software/idm') diff --git a/software/idm/idm.asm b/software/idm/idm.asm index fb7b893..f1cd094 100644 --- a/software/idm/idm.asm +++ b/software/idm/idm.asm @@ -64,7 +64,7 @@ BUF_ENDL EQU H'00BF' ;; variables ;; all Pages -TMP EQU H'0070' +CMD EQU H'0070' FLAGS EQU H'007F' @@ -72,6 +72,7 @@ FLAGS EQU H'007F' ;; FLAGS #define UNDERRUN FLAGS,0 #define OVERRUN FLAGS,1 +#define CMD_READ FLAGS,7 ;; ------------------------------------- ;; Macros @@ -118,31 +119,51 @@ inc_fsr_end goto int_spi retfie + ;; void timer2Interrupt() + ;; { + ;; static char value = 0; + ;; if (!overrun) { + ;; *writePtr = ++value; + ;; wbuf_next(); + ;; } + ;; } int_tmr2 bcf PIR1,TMR2IF - bsf DBG0 - movlb b'00000001' - bsf ADCON0,GO - call wbuf_next btfsc OVERRUN goto int_end + movlb b'00000001' + bsf ADCON0,GO int_tmr2_adcon btfsc ADCON0,GO goto int_tmr2_adcon movf ADRESH,w movwf INDFW + call wbuf_next goto int_end + ;; void sspInterrupt() + ;; { + ;; if (cmd_read && spiData == 0) { + ;; *readPtr = 0; + ;; rbuf_next(); + ;; spiData = underrun ? -1 : *readPtr; + ;; } else if (spiData == 'r') { + ;; cmd_read = TRUE; + ;; spiData = underrun ? -1 : *readPtr; + ;; } else { + ;; cmd_read = FALSE; + ;; printf("%s\n", "I don't like you!"); + ;; } + ;; } int_spi bcf PIR1,SSP1IF movlb b'00000100' movf SSP1BUF,w - incf TMP,f - movf TMP,w - movwf SSP1BUF - movlb b'00000000' + movwf CMD + movwf SSP1BUF + int_end movlb .31 movf FSR0H,w @@ -157,96 +178,93 @@ int_end ;; ------------------------------------- ;; SUBROUTINES -wbuf_reset + ;; void buf_init() + ;; { + ;; writePtr = bufferStart; + ;; readPtr = bufferStart; + ;; overrun = FALSE; + ;; underrun = TRUE; + ;; cmd_read = FALSE; + ;; } +buf_init movlw BUF_STARTH movwf FSRWH movlw BUF_STARTL movwf FSRWL + movlw BUF_STARTH + movwf FSRRH + movlw BUF_STARTL + movwf FSRRL bcf OVERRUN + bsf UNDERRUN + bcf CMD_READ + movf BSR,w clrf BSR + bsf INT + bsf DBG1 bcf DBG2 movwf BSR return ;; ------------------- + ;; void wbuf_next() + ;; { + ;; if (!overrun) { + ;; writePtr++; + ;; writePtr = writePtr > bufferEnd ? bufferStart : writePtr; + ;; underrun = FALSE; + ;; if(writePtr == readPtr) { + ;; overrun = TRUE; + ;; } + ;; } + ;; } wbuf_next - btfsc UNDERRUN - goto wbuf_move_ptr btfsc OVERRUN return - + + inc_fsr FSRW,FSRWH,FSRWL + bcf UNDERRUN + movf FSRRH,w xorwf FSRWH,w btfss STATUS,Z - goto wbuf_move_ptr + return movf FSRRL,w xorwf FSRWL,w btfss STATUS,Z - goto wbuf_move_ptr - bsf OVERRUN - movf BSR,w - clrf BSR - bsf DBG2 - movwf BSR return - -wbuf_move_ptr - movf BSR,w - clrf BSR - bcf INT - bcf DBG1 - movwf BSR - bcf UNDERRUN - inc_fsr FSRW,FSRWH,FSRWL - return - - - ;; ------------------- -rbuf_reset - movlw BUF_STARTH - movwf FSRRH - movlw BUF_STARTL - movwf FSRRL - bsf UNDERRUN - movf BSR,w - clrf BSR - bsf INT - bsf DBG1 - movwf BSR + bsf OVERRUN return ;; ------------------- + ;; void rbuf_next() + ;; { + ;; if(!underrun) { + ;; readPtr++; + ;; readPtr = readPtr > bufferEnd ? bufferStart : readPtr; + ;; overrun = FALSE; + ;; if(readPtr == writePtr) { + ;; underrun = TRUE; + ;; } + ;; } + ;; } rbuf_next - btfsc OVERRUN - goto rbuf_move_ptr btfsc UNDERRUN return + inc_fsr FSRR,FSRRH,FSRRL + bcf OVERRUN + movf FSRWH,w xorwf FSRRH,w btfss STATUS,Z - goto rbuf_move_ptr + return movf FSRWL,w xorwf FSRRL,w btfss STATUS,Z - goto rbuf_move_ptr - - bsf UNDERRUN - movf BSR,w - clrf BSR - bsf INT - bsf DBG1 - movwf BSR return - -rbuf_move_ptr - movf BSR,w - clrf BSR - bcf DBG2 - movwf BSR - bcf OVERRUN - inc_fsr FSRR,FSRRH,FSRRL + bsf UNDERRUN return ;; ------------------------------------- @@ -298,8 +316,7 @@ init bcf FILTER_EN bsf INT - call wbuf_reset - call rbuf_reset + call buf_init bsf T2CON,TMR2ON bsf INTCON,GIE -- cgit v1.2.3