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

#include <string.h>
#include "typedef.h"
#include "typedef.h"
#include "ucp_sfr_c.h"
#include "ucp_utility.h"

void palladium_ddr2file(char * fileName, uint32_t ddrFNAddr, uint32_t ddrSrcAddr, uint32_t dataLength)
{
	SYSCTRL_REG3 = ddrFNAddr / 4;
	memcpy_ext((char *)ddrFNAddr, fileName, strlen(fileName) + 1);
	SYSCTRL_REG1 = ddrSrcAddr / 4;
	SYSCTRL_REG2 = dataLength;
	__ucps2_synch(f_SMW);
	SYSCTRL_REG0 = 2;
	SYSCTRL_REG0 = 2;
	SYSCTRL_REG0 = 2;
	SYSCTRL_REG0 = 0;
	__ucps2_synch(f_SMW);
}

void palladium_file2ddr(const char * fileName, uint32_t ddrFNAddr, uint32_t ddrDstAddr)
{
	SYSCTRL_REG3 = ddrFNAddr / 4;
	memcpy_ext((char *)ddrFNAddr, fileName, strlen(fileName) + 1);
	SYSCTRL_REG1 = ddrDstAddr / 4;
	__ucps2_synch(f_SMW);
	SYSCTRL_REG0 = 4;
	SYSCTRL_REG0 = 4;
	SYSCTRL_REG0 = 4;
	SYSCTRL_REG0 = 0;
	__ucps2_synch(f_SMW);
}

#define DUMP_DDR_BASE_ADDR 0xB7FFF000
void vec_dump(char* filename, uint32_t address, uint32_t length)
{
	uint32_t core_id = get_core_id();
	uint32_t fileNameAddr = DUMP_DDR_BASE_ADDR + (core_id * 64);
	palladium_ddr2file(filename, fileNameAddr, address, length);
	
	return;
}

#define READ_DDR_BASE_ADDR 0xB7FFF800
void vec_read(char* filename, uint32_t address)
{
	uint32_t core_id = get_core_id();
	uint32_t fileNameAddr = READ_DDR_BASE_ADDR + (core_id * 64);
	palladium_file2ddr(filename, fileNameAddr, address);
	
	return;
}
