øõTRiLOGI Ver 5.0 0,Init 1,Enqueue 2,Dequeue ~ ~ 0,MsgFifoEmpty 1,MsgFifoFull ~ ~ ~ $FIFO String 02 - Gary Dickinson 2/15/207þþSimple FIFO mechanism for a single short string þstored in non-volatile memory.þþThe FIFO stores 40-character strings in non-volatile memory.þþThis version discards oldest message if fifo is full.þ %LInitMsgFifo=(1st.Scan+Init) %LEnqueueMsg=Enqueue %LDequeueMsg=Dequeue ~END_CIRCUIT~ È Fn#0,374 ' InitMsgFifo - Initialize FIFO tracking varaibles in DM and RELAY based state flags ' ENQ_Offset = 0 ' 0..SFIFO_Size - 1 offset for enqueue DEQ_Offset = 0 ' 0..SFIFO_Size - 1 offset for dequeue FIFO_Cnt = 0 ' total number of items in the FIFO SetIO MsgFifoEmpty ' RELAY to indicate that FIFO is empty ClrIO MsgFifoFull ' RELAY to indicate that FIFO is 100% full È Fn#1,1226 ' EnqueueMsg - function to enqueue an array of 40 character messages into the Message FIFO ' ' ' On entry A$ holds the string to enqueue ' This FIFO uses the SAVE_EEP$ statement to store data in the non-volatile memory. ' The message length is limited to 40 characters ' ' On exit: The A$ will be written to the FIFO ' The FIFO_FULL and FIFO_EMPTY RELAYS may be affected. ' The DM[] variables ENQ_Offset, DEQ_Offset and FIFO_CNT may be updated. ' If the FIFO is full then the B$ variable will be written with ' the oldest message in the FIFO to make room for the new message ' If the FIFO is FULL, then discard oldest message in the FIFO ' IF TestIO(MsgFifoFull) ' the FIFO is full, but Lorne is OK with overwriting old messages ' so we will discard the oldest to make room for the newest message. ' This action overwrite the value of B$ ' Call DequeueMsg ENDIF SAVE_EEP$ A$,FIFO_StartAddr + ENQ_Offset ' write one entry into the FIFO ' Update FIFO index, counter and flags ' ENQ_Offset = (ENQ_Offset + 1) MOD FIFO_Size FIFO_Cnt = FIFO_Cnt + 1 IF FIFO_Cnt = FIFO_Size SetIO MsgFifoFull ' the FIFO is full and cannot accept more data ENDIF ClrIO MsgFifoEmpty ' FIFO cannot be empty È Fn#2,814 ' DequeueMsg - function to dequeue String data from the String FIFO ' ' On exit: ' B$ will hold the oldest string in the FIFO. ' The FIFO_FULL and FIFO_EMPTY RELAYS may be affected. ' The DM[] variables ENQ_Offset, DEQ_Offset and FIFO_CNT may be updated. ' Return message from FIFO in B$ ' IF TestIO(MsgFifoEmpty) ' the FIFO is empty and there were no values to remove from the FIFO ' Just return a NULL String ' B$ = "" ELSE ' the FIFO was not empty, so return oldest message in B$] ' B$ = LOAD_EEP$(FIFO_StartAddr + DEQ_Offset) ' Update index, FIFO count and flags ' DEQ_Offset = (DEQ_Offset + 1) MOD FIFO_Size FIFO_Cnt = FIFO_Cnt - 1 IF FIFO_Cnt = 0 SetIO MsgFifoEmpty ' the FIFO is empty and there is no more data to remove ENDIF ClrIO MsgFifoFull ' FIFO cannot be full ENDIF ~END_CUSTFN~ 0,InitMsgFifo 1,EnqueueMsg 2,DequeueMsg ~END_CUSTFNLABEL~ 0,0, 1,0, 2,0, 3,0, 4,0, ~END_QUICKTAGS~ 0,ENQ_Offset,DM[1] 1,DEQ_Offset,DM[2] 2,FIFO_Cnt,DM[3] 3,FIFO_Size,5 4,FIFO_StartAddr,1 ~END_DEFINES~ ~END_BREAKPOINTS~ 192.168.1.16:9080 ~END_LASTIPADDR~