⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ram_driver.c

📁 flash AM29LV160 的驱动程序
💻 C
字号:
/*
 * File       : RamDrv.c
 * Description: This file contains the RAM driver for use in ZiLOG File System
 * Author     : 
 * Created on : 30-APR-2003
 *
 * Copyright 2004 ZiLOG Inc.  ALL RIGHTS RESERVED.
 *
 * This file contains unpublished confidential and proprietary information
 * of ZiLOG, Inc.
 * NO PART OF THIS WORK MAY BE DUPLICATED, STORED, PUBLISHED OR DISCLOSED 
 * IN ANY FORM WITHOUT THE PRIOR WRITTEN CONSENT OF ZiLOG, INC.
 * This is not a license and no use of any kind of this work is authorized
 * in the absence of a written license granted by ZiLOG, Inc. in ZiLOG's 
 * sole discretion 
 */

#include "Ram_Driver.h"
#include "ZSysgen.h"
#include "ZThread.h"

UINT8 g_ram_driver_initialized ;

INT RamDrv_Init(  void *paddr, UINT32 num_bytes  )
{
	RZK_STATE_t preempt_status ;
	INT status = SUCCESS ;

	if( g_ram_driver_initialized == RZK_TRUE )
		return -1 ;
	
	preempt_status = RZKDisablePreemption() ;

	g_ram_driver_initialized = RZK_TRUE ;

//	status = RamDrv_Erase( paddr, num_bytes ) ;

	RZKRestorePreemption( preempt_status ) ;

	return status ;
}

INT32 RamDrv_Read( void *paddr, void *pbuf, UINT num_bytes )
{

	UINT8 *src_addr = (UINT8*) paddr ;
	UINT8 *dest_addr = (UINT8*) pbuf ;
	UINT num_bytes_to_read = num_bytes ;

	if( g_ram_driver_initialized == RZK_FALSE )
		return -1 ;

	while( num_bytes_to_read > 0 )
		{
		*dest_addr++ = *src_addr++ ;
		num_bytes_to_read -- ;
		}
	return (num_bytes - num_bytes_to_read ) ;
}

INT32 RamDrv_Write( void *paddr, void *pbuf, UINT num_bytes )
{
	UINT8 *src_addr = (UINT8*) pbuf ;
	UINT8 *dest_addr = (UINT8*) paddr ;
	UINT num_bytes_to_write = num_bytes ;

	if( g_ram_driver_initialized == RZK_FALSE )
		return -1 ;

	while( num_bytes_to_write > 0 )
		{
		*dest_addr++ = *src_addr++ ;
		num_bytes_to_write -- ;
		}

	return (num_bytes - num_bytes_to_write ) ;
}

INT RamDrv_Erase( void *paddr, UINT32 num_bytes )
{
	UINT8 *src_addr = (UINT8*) paddr ;
	volatile UINT32 num_bytes_to_erase = num_bytes ;

	if( g_ram_driver_initialized == RZK_FALSE )
		return -1 ;

	while( num_bytes_to_erase != 0 )
		{
		*src_addr++ = 0xFF ;
		num_bytes_to_erase -- ;
		}

	return SUCCESS ;
}

INT RamDrv_Close( void )
{
	RZK_STATE_t preempt_status ;

	if( g_ram_driver_initialized == RZK_FALSE )
		return -1 ;
	
	preempt_status = RZKDisablePreemption() ;

	g_ram_driver_initialized = RZK_FALSE ;

	RZKRestorePreemption( preempt_status ) ;

	return SUCCESS ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -