// +FHDR------------------------------------------------------------
//                 Copyright (c) 2022 SmartLogic.
//                       ALL RIGHTS RESERVED
// -----------------------------------------------------------------
// Filename      : ucp_handshake.c
// Author        : xianfeng.du
// Created On    : 2022-06-25
// Last Modified :
// -----------------------------------------------------------------
// Description:
//
//
// -FHDR------------------------------------------------------------

#include "ucp_printf.h"
#include "ucp_utility.h"
#include "ucp_handshake.h"
#include "msg_transfer_mem.h"
#include "pet_sm_mgt.h"

//master is the core which controlled the handshake flow
void ucp_handshake(void)
{
	uint32_t core_id = NPU_CORE_ID;
	uint32_t request= (core_id + HANDSHKAE_REQ_VALUE);
	volatile uint32_t response;

	PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt();
	UcpHandshake_t*	pHandshake = pPetSmLocalMgt->pHandshake;

	pHandshake->request[core_id] = request;
	UCP_PRINT_DEBUG("core[0x%08x] sent handshake request message,value[0x%08x].",core_id,request);

	while(1) {
		response = pHandshake->response[core_id];
		if (response == (core_id + HANDSHKAE_RESP_VALUE)) {
			UCP_PRINT_DEBUG("core[0x%08x] recieved handshake response message,value[0x%08x].",core_id,response);
			break;
		}
	}

	return;
}

