/*  keapiStorage.c - KEAPI BSP support for storage at Kontron nanoETXsp board
  *
  *  KEAPI v1.2.0.3 implementation.
  *  
  *  Initialization.
  */

/*
 * Copyright 2011 Kontron KGSC.
 */

/*
 modification history
 --------------------
 01b,12may11,ivo update for nanoETXsp
 01a,07apr11,ivo initial version
*/

/*
DESCRIPTION:
    KEAPI BSP support for storage at Kontron nanoETXsp board
    KEAPI v1.2.0.3 implementation. Initialization.
*/

#include <vxWorks.h>
#include <config.h>

#include "keapi/keapiBSPCommon.h"

#define KEAPI_BSP_STORAGE
#include "keapi/keapiBSP.h"
#undef  KEAPI_BSP_STORAGE   

KEAPI_RETVAL keapiGetStorageCount (
        KEAPI_PINT32 pStorageCount
	)
	{
	*pStorageCount = STORAGE_COUNT;
	return KEAPI_RET_SUCCESS;
	}

KEAPI_RETVAL keapiGetStorageSize (
		KEAPI_INT32	 storageNr,
        KEAPI_PINT32 pStorageSize
	)
	{
	if ((UINT32)storageNr >= STORAGE_COUNT)
		return KEAPI_RET_PARAM_ERROR;
	
	*pStorageSize = STORAGE_SIZE(storageNr);
	
	return KEAPI_RET_SUCCESS;
	}

KEAPI_RETVAL keapiStorageRead (
		KEAPI_INT32	 storageNr,
		KEAPI_INT32	 offset,
        KEAPI_PUINT8 pData8,
        KEAPI_INT32	 length
	)
	{
	KEAPI_RETVAL result;
	
	if ((UINT32)storageNr >= STORAGE_COUNT)
		return KEAPI_RET_PARAM_ERROR;
	
	STORAGE_READ(storageNr, offset, pData8, length, result);
	
	return result;
	}

KEAPI_RETVAL keapiStorageWrite (
		KEAPI_INT32	 storageNr,
		KEAPI_INT32	 offset,
        KEAPI_PUINT8 pData8,
        KEAPI_INT32	 length
	)
	{
	UINT32 uoffset = offset;
	UINT32 ulength = length;
	KEAPI_RETVAL result;
	
	if ((UINT32)storageNr >= STORAGE_COUNT)
		return KEAPI_RET_PARAM_ERROR;
	
	STORAGE_WRITE(storageNr, uoffset, pData8, ulength, result);
	
	return result;
	}
