/*******************************************************************************
** Document: FW_lt_api.c
** Copyright (c) 2005 R&D Center, Tailyn Communication Company, Ltd.  
** Created by: Chien Chung Lo
** Date: Jan. 14, 2005
** Description: Line card Firmware interface API.
** Version: 0.1
*******************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>

#include <FW_lt/FW_lt_api.h>

#include <umap_type.h>

//----------------------------------------------------------------------
UMAP_S32 FW_ReadLT(void* buf, UMAP_U32 addr, UMAP_U32 size)
{
	UMAP_S32 LT_file;
	UMAP_S32 result;

	LT_file = open(LT_DEVICE_FILE_NAME, O_RDWR);
	if(LT_file < 0)
	{
		result = LT_file;
		perror("open");
		return result; // open fail!!
	}
	
	result = lseek(LT_file, addr, SEEK_SET);
	if(result < 0)
	{
		close(LT_file);
		perror("lseek");
		return result; // lseek fail!!
	}
	
	result = read(LT_file, buf, size);	
	if(result < 0)
	{
		close(LT_file);
		perror("read");
		return result; // read fail!!
	}
	
	result = close(LT_file);
	
	return result; // succes
}

//----------------------------------------------------------------------
UMAP_S32 FW_WriteLT(void* buf, UMAP_U32 addr, UMAP_U32 size)
{
	UMAP_S32 LT_file;
	UMAP_S32 result;
	
	LT_file = open(LT_DEVICE_FILE_NAME, O_RDWR);
	if(LT_file < 0)
	{
		result = LT_file;
		perror("open");
		return result; // open fail!!
	}
	
	result = lseek(LT_file, addr, SEEK_SET);
	if(result < 0)
	{
		close(LT_file);
		perror("lseek");
		return result; // lseek fail!!
	}
	
	result = write(LT_file, buf, size);
	if(result < 0)
	{
		close(LT_file);
		perror("write");
		return result; // read fail!!
	}
	
	result = close(LT_file);
	
	return 0; // succes
}



