That seems like a lot to keep track of. Simply checking each pointer when it is incremented to see if it equals the other seems much simpler. Allen > -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist- > bounces@mit.edu] On Behalf Of Isaac M. Bavaresco > Sent: Wednesday, August 9, 2017 8:23 AM > To: Microcontroller discussion list - Public. > Subject: Re: [PIC] pic16f628a memory bank switching in a > large circular buffer. > > I don't like the head+tail method because the conditions for > full and > empty queues are the same, that is head=3D=3Dtail, unless you > always leave > one position unused. > If the queue element's size is small (say, one byte) and the > queue is > long then this wasted position may be acceptable. > One could use a flag to differentiate the full from empty > conditions, > but that is one more variable. > > I prefer the head+used positions or tail+used positions > instead. > > Empty: used =3D=3D 0 > Full: used =3D=3D length > If using head+used: tail =3D ( head - used ) mod length. > If using tail+used: head =3D ( tail + used ) mod length. > > Note: you don't need to actually use 'mod' operator: > if(( tail =3D head - used ) < 0 ) tail +=3D length; > if(( head =3D tail + used ) >=3D length ) tail -=3D length; > > Cheers, > Isaac > > > Em 08/08/2017 20:50, smplx escreveu: > > I agree with Bob, use two offsets pointer_in and > pointer_out (or as I > > like to call them "head" and "tail") > > > > The only complicated bit is to then map these offsets into > your real > > RAM. But as Bob has shown this simply means loading the > offset, > > mapping it (with his 4 instruction code) and saving this > address into > > the FSR before loading a byte from the buffer or saving a > byte to the > > buffer (using INDF). The rest of FIFO read and write then > becomes > > trivial. > > > > Just remember: DON'T update "head" and "tail" until after > you've read > > or written the byte to or from the buffer. > > > > Regards > > Sergio Masci > > > > > > On Tue, 8 Aug 2017, Bob Ammerman wrote: > > > >> Why are you keeping an offset from pointer_in, instead of > just keeping > >> pointer_out as a virtual pointer in its own right? > >> > >> ~ Bob Ammerman > >> RAm Systems > >> > >>> -----Original Message----- > >>> From: piclist-bounces@mit.edu [mailto:piclist- > bounces@mit.edu] On > >>> Behalf > >>> Of noname > >>> Sent: Tuesday, August 08, 2017 3:55 PM > >>> To: Microcontroller discussion list - Public. > > >>> Subject: Re: [PIC] pic16f628a memory bank switching in a > large circular > >> buffer. > >>> > >>> Follow up question: > >>> > >>> > >>> Following the same method as outlined by Bob, is it > possible to map the > >>> (absolute) pointer_out directly from (abs) pointer_in? I > have tried > >> several > >>> ways on paper, but I do not get to a simple solution. > >>> > >>> > >>> So starting with a valid (abs) pointer_in (mapped in the > range > >>> 0x20-0x6F > >> or > >>> 0xA0-0xEF) > >>> > >>> I need to add the offset that can be anything between 0 > and 0xA0, > >>> and then > >>> account for =B4bankgaps=B4 and finally land in the same range > 0x20-0x6F and > >>> 0xA0-0xEF . I tried something by adding 0xB0 to the offset > (is it > >>> smaller > >> or > >>> larger than 50?) but I diverge in such bookkeeping I > cannot oversee. > >>> > >>> > >>> My current code utilises the virtual pointer_in as > reference, but I > >>> think > >> I can > >>> go even faster if I took the absolute pointer_in as > reference. > >>> > >>> Nonetheless my code is some 30% smaller now: > >>> > >>> > >>> Current code: > >>> > >>> > >>> getpointers_table160 > >>> decfsz virt_pointer_in, w ; if > >>> 0 then > >> point to top of the > >>> buffer again > >>> goto > >>> _skipifset ; if > >> not 0 then skip next line > >>> addlw CIRCULAR_BUFFER_LENGTH ; + 0xA0 > >>> _skipifset > >>> movwf virt_pointer_in ; wreg > >> holds the current > >>> virt_pointer_in minus 1 > >>> > >>> addlw h'B0'-1 ; > >> carry set if bank1 > >>> btfsc STATUS,C > >>> addlw h'30' > >>> addlw > >>> h'70' ; > >> bank set 0x20-6F or 0xA0-EF > >>> movwf pointer_in ; > >>> now > >> wreg holds the abs value of > >>> pointer_in > >>> > >>> > >> ; calc the pointer out > >>> movf pointer_offset, w ; > >>> offset > >> from 0 to 0xA0 > >>> addwf virt_pointer_in, w ; > >> virt_pointer_in is used as ref > >>> here > >>> btfsc STATUS, C > >>> addlw h'60' > >>> addlw h'60' - > >>> 1 ; > >> Carry is set if >0xff > >>> btfss STATUS, C > >>> addlw h'A0' > >>> > >>> > >> ; At this point wreg =3D virtual > >>> pointer_out > >>> addlw h'B0' ; carry set if bank1 > >>> btfsc STATUS,C > >>> addlw h'30' > >>> addlw h'70' ; bank set 0x20-6F or 0x80-EF > >>> movwf pointer_out > >>> return > >>> > >>> > >>> > >>> > >>> > >>> ________________________________ > >>> Van: piclist-bounces@mit.edu bounces@mit.edu> namens Bob > >>> Ammerman > >>> Verzonden: maandag 7 augustus 2017 19:52 > >>> Aan: 'Microcontroller discussion list - Public.' > >>> Onderwerp: RE: [PIC] pic16f628a memory bank switching > in a large > >>> circular > >>> buffer. > >>> > >>> NOTE: all numbers are in HEX below. The trick below > >>> works because we are working MODULO 100 hex. > >>> > >>> Input: W is a pointer ranging from 00h thru 9Fh > >>> Output: W points to the correct register in bank 0 or 1 > >>> > >>> ; At entry, the value of W is as follows: > >>> ; 00..4F - we want to map to page 0 addresses 20..6F ; > 50..9F - we > >>> want > >> to > >>> map to page 1 addresses A0..EF > >>> > >>> ; We start by adding B0. This will set STATUS,C to 1, ; if we > have a > >>> page > >> 1 > >>> address, and to 0 if we have a ; page 0 address. After this > add, we > >>> will > >> have: > >>> ; B0..FF - which we want to map to page 0 addresses > 20..6F ; 00..4F - > >> which > >>> we want to map to page 1 addresses A0..EF > >>> > >>> ADDLW 0B0h > >>> > >>> ; Now, if carry is set, we add 30. After this conditional ; > add, we > >>> will > >> have: > >>> ; B0..FF - which we want to map to page 0 addresses > 20..6F ; 30..7F - > >> which > >>> we want to map to page 1 addresses A0..EF > >>> > >>> BTFSC STATUS,C > >>> ADDLW 030h > >>> > >>> ; One more add gives us our answer. By adding 70 we > get: > >>> ; 20..6F for page 0 addresses > >>> ; A0..EF for page 1 addresses > >>> > >>> ADDLW 070h > >>> > >>> -- Problem solved in 4 instructions! > >>> > >>> ~ Bob Ammerman > >>> RAm Systems > >>> > >>> -- > >>> http://www.piclist.com/techref/piclist PIC/SX FAQ & list > archive > >>> PIClist, > >>> Microchip PIC > >>> www.piclist.com > >>> The PICList is a collection of people interested in the > Microchip PIC > >> processor. > >>> > >>> > >>> View/change your membership options at > >>> http://mailman.mit.edu/mailman/listinfo/piclist > >>> -- > >>> http://www.piclist.com/techref/piclist PIC/SX FAQ & list > archive > >>> View/change your membership options at > >>> http://mailman.mit.edu/mailman/listinfo/piclist > >> > >> > >> -- > >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list > archive > >> View/change your membership options at > >> http://mailman.mit.edu/mailman/listinfo/piclist > >> > > > > > > > > --- > Este email foi escaneado pelo Avast antiv=EDrus. > https://www.avast.com/antivirus > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list > archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .