lib/sw_services/xilplmi/src/xplmi_generic.c
static int XPlmi_Proc(XPlmi_Cmd *Cmd)
{
	int Status = XST_FAILURE;
	u32 ProcId;
	u8 Index = 0U;
	u32 SrcAddr;
	u32 LenDiff = 0U;
	u32 CmdLenInBytes = (Cmd->Len - 1U) * XPLMI_WORD_LEN;
	u32 CurrPayloadLen;
	XPlmi_ProcList *ProcList = NULL;

	if (Cmd->ProcessedLen == 0U) {
		/*
		 * Check if LPD is initialized as we are using PSM RAM to store
		 * Proc data
		 */
		if ((LpdInitialized & LPD_INITIALIZED) != LPD_INITIALIZED) {
			XPlmi_Printf(DEBUG_GENERAL, "LPD is not initialized, "
					"Proc commands cannot be stored\r\n");
			Status = (int)XPLMI_ERR_PROC_LPD_NOT_INITIALIZED;
			goto END;
		}

		ProcId = Cmd->Payload[0U];
		/* Get the proc list */
		ProcList = XPlmi_GetProcList();
		/* Check if received ProcId is already in memory */
		ProcList->ProcData[ProcList->ProcCount].Id = ProcId;
		while (ProcList->ProcData[Index].Id != ProcId) {
			Index++;
		}
		if (Index < ProcList->ProcCount) {
			/*
			 * Get Length difference if received proc length is greater than
			 * length of the proc in memory
			 * This is to check if new proc fits in available memory
			 */
			if (CmdLenInBytes > (ProcList->ProcData[Index + 1U].Addr -
					ProcList->ProcData[Index].Addr)) {
				LenDiff = CmdLenInBytes - (ProcList->ProcData[Index + 1U].Addr -
						ProcList->ProcData[Index].Addr);
			}
			/* Check if new proc length fits in the proc allocated memory */
			if ((LenDiff + (ProcList->ProcData[ProcList->ProcCount].Addr -
					ProcList->ProcData[ProcList->ProcCount - 1U].Addr)) >
					XPLMI_PROC_LOCATION_LENGTH) {
				Status = (int)XPLMI_UNSUPPORTED_PROC_LENGTH;
				goto END;
			}

			/*
			 * If proc command is received for existing proc,
			 * move other procs
			 */
			Status = XPlmi_MoveProc(Index, ProcList);
			if (Status != XST_SUCCESS) {
				goto END;
			}
			--ProcList->ProcCount;
		} else {
			/* Check if proc list is full */
			if (ProcList->ProcCount == XPLMI_MAX_PROCS_SUPPORTED) {
				Status = (int)XPLMI_MAX_PROC_COMMANDS_RECEIVED;
				goto END;
			}
		}

		/* New proc address where the proc data need to be copied */
		Cmd->ResumeData[0U] = ProcList->ProcData[ProcList->ProcCount].Addr;

		/* Check if new proc length fits in the proc allocated memory */
		if ((Cmd->ResumeData[0U] + CmdLenInBytes) > (XPLMI_PROC_LOCATION_ADDRESS +
				XPLMI_PROC_LOCATION_LENGTH)) {
			Status = (int)XPLMI_UNSUPPORTED_PROC_LENGTH;
			goto END;
		}
		SrcAddr = (u32)(&Cmd->Payload[1U]);
		CurrPayloadLen = Cmd->PayloadLen - 1U;

		/* Add an entry in ProcList */
		ProcList->ProcData[ProcList->ProcCount].Id = ProcId;
		ProcList->ProcCount++;
		ProcList->ProcData[ProcList->ProcCount].Addr =
				ProcList->ProcData[ProcList->ProcCount - 1U].Addr + CmdLenInBytes;
	} else {
		/* Handle command resume for proc data */
		SrcAddr = (u32)(&Cmd->Payload[0U]);
		CurrPayloadLen = Cmd->PayloadLen;
	}

	/* Copy the received proc to proc memory */
	Status = XPlmi_DmaTransfer(Cmd->ResumeData[0U], SrcAddr, CurrPayloadLen,
			XPLMI_PMCDMA_0);
	if (Status != XST_SUCCESS) {
		goto END;
	}
	/* Update destination address to handle resume case */
	Cmd->ResumeData[0U] += CurrPayloadLen * XPLMI_WORD_LEN;

END:
	return Status;
}
/*****************************************************************************/
/**
 * @brief	This function copies the proc data to reserved PSM RAM when proc
 *          command is received.
 *
 * @param	Cmd is pointer to the command structure
 *              Command payload parameters are
 *              - ProcId
 *              - Data
 *
 * @return	XST_SUCCESS on success and error code on failure
 *
 *****************************************************************************/
@brief       This function copies the proc data to reserved PSM RAM when proc
command is received.

@param       Cmd is pointer to the command structure
Command payload parameters are
- ProcId
- Data

@return      XST_SUCCESS on success and error code on failure
@brief This function copies the proc data to reserved PSM RAM when proc command is received . @param Cmd is pointer to the command structure Command payload parameters are - ProcId - Data @return XST_SUCCESS on success and error code on failure
static int XPlmi_Proc(XPlmi_Cmd *Cmd)
{
	int Status = XST_FAILURE;
	u32 ProcId;
	u8 Index = 0U;
	u32 SrcAddr;
	u32 LenDiff = 0U;
	u32 CmdLenInBytes = (Cmd->Len - 1U) * XPLMI_WORD_LEN;
	u32 CurrPayloadLen;
	XPlmi_ProcList *ProcList = NULL;
	if (Cmd->ProcessedLen == 0U) {
		if ((LpdInitialized & LPD_INITIALIZED) != LPD_INITIALIZED) {
			XPlmi_Printf(DEBUG_GENERAL, "LPD is not initialized, "
					"Proc commands cannot be stored\r\n");
			Status = (int)XPLMI_ERR_PROC_LPD_NOT_INITIALIZED;
			goto END;
		}
		ProcId = Cmd->Payload[0U];
		ProcList = XPlmi_GetProcList();
		ProcList->ProcData[ProcList->ProcCount].Id = ProcId;
		while (ProcList->ProcData[Index].Id != ProcId) {
			Index++;
		}
		if (Index < ProcList->ProcCount) {
			if (CmdLenInBytes > (ProcList->ProcData[Index + 1U].Addr -
					ProcList->ProcData[Index].Addr)) {
				LenDiff = CmdLenInBytes - (ProcList->ProcData[Index + 1U].Addr -
						ProcList->ProcData[Index].Addr);
			}
			if ((LenDiff + (ProcList->ProcData[ProcList->ProcCount].Addr -
					ProcList->ProcData[ProcList->ProcCount - 1U].Addr)) >
					XPLMI_PROC_LOCATION_LENGTH) {
				Status = (int)XPLMI_UNSUPPORTED_PROC_LENGTH;
				goto END;
			}
			Status = XPlmi_MoveProc(Index, ProcList);
			if (Status != XST_SUCCESS) {
				goto END;
			}
			--ProcList->ProcCount;
		} else {
			if (ProcList->ProcCount == XPLMI_MAX_PROCS_SUPPORTED) {
				Status = (int)XPLMI_MAX_PROC_COMMANDS_RECEIVED;
				goto END;
			}
		}
		Cmd->ResumeData[0U] = ProcList->ProcData[ProcList->ProcCount].Addr;
		if ((Cmd->ResumeData[0U] + CmdLenInBytes) > (XPLMI_PROC_LOCATION_ADDRESS +
				XPLMI_PROC_LOCATION_LENGTH)) {
			Status = (int)XPLMI_UNSUPPORTED_PROC_LENGTH;
			goto END;
		}
		SrcAddr = (u32)(&Cmd->Payload[1U]);
		CurrPayloadLen = Cmd->PayloadLen - 1U;
		ProcList->ProcData[ProcList->ProcCount].Id = ProcId;
		ProcList->ProcCount++;
		ProcList->ProcData[ProcList->ProcCount].Addr =
				ProcList->ProcData[ProcList->ProcCount - 1U].Addr + CmdLenInBytes;
	} else {
		SrcAddr = (u32)(&Cmd->Payload[0U]);
		CurrPayloadLen = Cmd->PayloadLen;
	}
	Status = XPlmi_DmaTransfer(Cmd->ResumeData[0U], SrcAddr, CurrPayloadLen,
			XPLMI_PMCDMA_0);
	if (Status != XST_SUCCESS) {
		goto END;
	}
	Cmd->ResumeData[0U] += CurrPayloadLen * XPLMI_WORD_LEN;
END:
	return Status;
}
static int XPlmi_Proc ( XPlmi_Cmd * Cmd ) { int Status = XST_FAILURE ; u32 ProcId ; u8 Index = 0U ; u32 SrcAddr ; u32 LenDiff = 0U ; u32 CmdLenInBytes = ( Cmd -> Len - 1U ) * XPLMI_WORD_LEN ; u32 CurrPayloadLen ; XPlmi_ProcList * ProcList = NULL ; if ( Cmd -> ProcessedLen == 0U ) { if ( ( LpdInitialized & LPD_INITIALIZED ) != LPD_INITIALIZED ) { XPlmi_Printf ( DEBUG_GENERAL , " " " \r \n " ) ; Status = ( int ) XPLMI_ERR_PROC_LPD_NOT_INITIALIZED ; goto END ; } ProcId = Cmd -> Payload [ 0U ] ; ProcList = XPlmi_GetProcList ( ) ; ProcList -> ProcData [ ProcList -> ProcCount ] . Id = ProcId ; while ( ProcList -> ProcData [ Index ] . Id != ProcId ) { Index ++ ; } if ( Index < ProcList -> ProcCount ) { if ( CmdLenInBytes > ( ProcList -> ProcData [ Index + 1U ] . Addr - ProcList -> ProcData [ Index ] . Addr ) ) { LenDiff = CmdLenInBytes - ( ProcList -> ProcData [ Index + 1U ] . Addr - ProcList -> ProcData [ Index ] . Addr ) ; } if ( ( LenDiff + ( ProcList -> ProcData [ ProcList -> ProcCount ] . Addr - ProcList -> ProcData [ ProcList -> ProcCount - 1U ] . Addr ) ) > XPLMI_PROC_LOCATION_LENGTH ) { Status = ( int ) XPLMI_UNSUPPORTED_PROC_LENGTH ; goto END ; } Status = XPlmi_MoveProc ( Index , ProcList ) ; if ( Status != XST_SUCCESS ) { goto END ; } -- ProcList -> ProcCount ; } else { if ( ProcList -> ProcCount == XPLMI_MAX_PROCS_SUPPORTED ) { Status = ( int ) XPLMI_MAX_PROC_COMMANDS_RECEIVED ; goto END ; } } Cmd -> ResumeData [ 0U ] = ProcList -> ProcData [ ProcList -> ProcCount ] . Addr ; if ( ( Cmd -> ResumeData [ 0U ] + CmdLenInBytes ) > ( XPLMI_PROC_LOCATION_ADDRESS + XPLMI_PROC_LOCATION_LENGTH ) ) { Status = ( int ) XPLMI_UNSUPPORTED_PROC_LENGTH ; goto END ; } SrcAddr = ( u32 ) ( & Cmd -> Payload [ 1U ] ) ; CurrPayloadLen = Cmd -> PayloadLen - 1U ; ProcList -> ProcData [ ProcList -> ProcCount ] . Id = ProcId ; ProcList -> ProcCount ++ ; ProcList -> ProcData [ ProcList -> ProcCount ] . Addr = ProcList -> ProcData [ ProcList -> ProcCount - 1U ] . Addr + CmdLenInBytes ; } else { SrcAddr = ( u32 ) ( & Cmd -> Payload [ 0U ] ) ; CurrPayloadLen = Cmd -> PayloadLen ; } Status = XPlmi_DmaTransfer ( Cmd -> ResumeData [ 0U ] , SrcAddr , CurrPayloadLen , XPLMI_PMCDMA_0 ) ; if ( Status != XST_SUCCESS ) { goto END ; } Cmd -> ResumeData [ 0U ] += CurrPayloadLen * XPLMI_WORD_LEN ; END : return Status ; }
@brief       This function copies the proc data to reserved PSM RAM when proc
          command is received.
@brief This function copies the proc data to reserved PSM RAM when proc command is received .
/*
		 * Check if LPD is initialized as we are using PSM RAM to store
		 * Proc data
		 */ /* Get the proc list */ /* Check if received ProcId is already in memory */ /*
			 * Get Length difference if received proc length is greater than
			 * length of the proc in memory
			 * This is to check if new proc fits in available memory
			 */ /* Check if new proc length fits in the proc allocated memory */ /*
			 * If proc command is received for existing proc,
			 * move other procs
			 */ /* Check if proc list is full */ /* New proc address where the proc data need to be copied */ /* Check if new proc length fits in the proc allocated memory */ /* Add an entry in ProcList */ /* Handle command resume for proc data */ /* Copy the received proc to proc memory */ /* Update destination address to handle resume case */