FB_DataFifo.TcPOU 2.41 KB
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.11">
  <POU Name="FB_DataFifo" Id="{d56a36d5-a9e2-464d-82c2-924a10cada6f}" SpecialFunc="None">
    <Declaration><![CDATA[FUNCTION_BLOCK FB_DataFifo
VAR_INPUT
	bPutData	:	BOOL;
	bGetData	:	BOOL;
	bClearFifo	:	BOOL;
	pPutData	:	pvoid;
	pGetData	:	pvoid;
	nDataLen	:	UDINT;
	pFifoMemory	:	pvoid;
	nFifoSize	:	DINT;

END_VAR
VAR_OUTPUT
	bFifoEmpty	:	BOOL;
	bFifoFull	:	BOOL;
	iFifoSizeLeft	: DINT;
END_VAR
VAR
	fbGetTaskId	: GETCURTASKINDEX;
	nTaskId		: BYTE;
	
	iPutIndex	:	DINT;
	iGetIndex	:	DINT;

	pPutIndex	:	DINT;
	pGetIndex	:	DINT;
	bIs1Sec : BOOL;

END_VAR]]></Declaration>
    <Implementation>
      <ST><![CDATA[
IF bClearFifo THEN
	iPutIndex := 0; iGetIndex := 0;
	iFifoSizeLeft := nFifoSize;
	bFifoEmpty := TRUE;
	RETURN;
END_IF

IF NOT(bFifoFull) THEN
	IF bPutData THEN
		IF iPutIndex >= nFifoSize THEN
			iPutIndex := 0;
		END_IF
		pPutIndex := iPutIndex * nDataLen;
		MEMCPY(pFifoMemory + pPutIndex, pPutData, nDataLen);
		iPutIndex := iPutIndex + 1;
		iFifoSizeLeft := iFifoSizeLeft - 1;
	END_IF
END_IF;

IF NOT(bFifoEmpty) THEN
	IF bGetData THEN
		bIs1Sec := iGetIndex >= nFifoSize;
		
		IF bIs1Sec THEN
			iGetIndex := 0;
		END_IF
		pGetIndex := iGetIndex * nDataLen;
		MEMCPY(pGetData, pFifoMemory + pGetIndex , nDataLen);
		iGetIndex := iGetIndex + 1;
		iFifoSizeLeft := iFifoSizeLeft + 1;
	END_IF
END_IF;


(*
 _TaskInfo[GETCURTASKINDEX()].FirstCycle;
SystemTaskInfoArr[SystemInfo.RuntimeNo].firstCycle
*)


fbGetTaskId();	
IF _TaskInfo[fbGetTaskId.index].FirstCycle THEN
	iFifoSizeLeft  := nFifoSize;
END_IF

IF iFifoSizeLeft = 0 THEN
	bFifoFull := TRUE;
ELSE
	bFifoFull := FALSE;
END_IF

IF iFifoSizeLeft >= nFifoSize THEN
	bFifoEmpty := TRUE;
ELSE
	bFifoEmpty := FALSE;
END_IF
]]></ST>
    </Implementation>
    <LineIds Name="FB_DataFifo">
      <LineId Id="117" Count="1" />
      <LineId Id="122" Count="1" />
      <LineId Id="126" Count="0" />
      <LineId Id="124" Count="0" />
      <LineId Id="121" Count="0" />
      <LineId Id="36" Count="14" />
      <LineId Id="155" Count="1" />
      <LineId Id="51" Count="8" />
      <LineId Id="77" Count="0" />
      <LineId Id="84" Count="1" />
      <LineId Id="60" Count="0" />
      <LineId Id="81" Count="0" />
      <LineId Id="79" Count="0" />
      <LineId Id="87" Count="1" />
      <LineId Id="61" Count="15" />
      <LineId Id="9" Count="0" />
    </LineIds>
  </POU>
</TcPlcObject>