📄 mt28f008_driver_fswrapper.c
字号:
/*
* File : MT28F008_Driver_FSWrapper.c
* Description: This file contains the Flash driver for use in ZiLOG File System
* Author :
* Created on : 04-OCT-2004
*
* 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
*/
/* Revision History
* CR #6089: MKC, 05/30/2005
* Semaphore is not being deleted when the driver is closed after
* 20 successive driver open-close calls are made.
*/
#include <stdio.h>
#include <string.h>
#include "MT28F008_Driver.h"
#include "ZSysgen.h"
#include "ZThread.h"
#include "ZSemaphore.h"
// External Flash driver wrapper that will call the actual flash driver routines
RZK_SEMAPHOREHANDLE_t g_mt_flash_sem_Handle ;
UINT8 g_mt_flash_initialized ;
INT FS_MT28F008_Init( void *paddr, UINT32 num_bytes )
{
RZK_STATE_t preempt_status ;
INT status ;
if( g_mt_flash_initialized == RZK_TRUE )
return -1 ;
preempt_status = RZKDisablePreemption() ;
// create a sempahore to control the access to the device
g_mt_flash_sem_Handle = RZKCreateSemaphore( (RZK_NAME_t*) "MICFLASH", 1, RECV_ORDER_PRIORITY ) ;
if( g_mt_flash_sem_Handle == NULL )
status = -1 ;
else
{
g_mt_flash_initialized = RZK_TRUE ;
status = SUCCESS ;
}
if( status == SUCCESS )
{
// execute the driver init
status = MT28F008_Init( paddr, num_bytes ) ;
}
RZKRestorePreemption( preempt_status ) ;
return status ;
}
INT32 FS_MT28F008_Read( void *paddr, void *pbuf, UINT num_bytes )
{
INT status ;
INT32 num_bytes_read ;
if( g_mt_flash_initialized == RZK_FALSE )
return -1 ;
// create a sempahore to control the access to the device
status = RZKAcquireSemaphore( g_mt_flash_sem_Handle, MAX_INFINITE_SUSPEND ) ;
if( status != RZKERR_SUCCESS )
return -1 ;
// now call the flash driver read routine
num_bytes_read = MT28F008_Read( paddr, pbuf, num_bytes ) ;
RZKReleaseSemaphore( g_mt_flash_sem_Handle ) ;
return num_bytes_read ;
}
INT32 FS_MT28F008_Write( void *paddr, void *pbuf, UINT num_bytes )
{
INT status ;
INT32 num_bytes_written ;
if( g_mt_flash_initialized == RZK_FALSE )
return -1 ;
// create a sempahore to control the access to the device
status = RZKAcquireSemaphore( g_mt_flash_sem_Handle, MAX_INFINITE_SUSPEND ) ;
if( status != RZKERR_SUCCESS )
return -1 ;
// now call the flash driver read routine
num_bytes_written = MT28F008_Write( paddr, pbuf, num_bytes ) ;
RZKReleaseSemaphore( g_mt_flash_sem_Handle ) ;
return num_bytes_written ;
}
INT FS_MT28F008_Erase( void *paddr, UINT32 num_bytes )
{
INT status ;
if( g_mt_flash_initialized == RZK_FALSE )
return -1 ;
// create a sempahore to control the access to the device
status = RZKAcquireSemaphore( g_mt_flash_sem_Handle, MAX_INFINITE_SUSPEND ) ;
if( status != RZKERR_SUCCESS )
return -1 ;
// now call the flash driver read routine
status = MT28F008_Erase( paddr, num_bytes ) ;
RZKReleaseSemaphore( g_mt_flash_sem_Handle ) ;
return status ;
}
INT FS_MT28F008_Close( void )
{
RZK_STATE_t preempt_status ;
INT status ;
if( g_mt_flash_initialized == RZK_FALSE )
return -1 ;
preempt_status = RZKDisablePreemption() ;
g_mt_flash_initialized = RZK_FALSE;
status = MT28F008_Close() ;
// CR#6089
// Delete the semaphore
RZKDeleteSemaphore( g_mt_flash_sem_Handle ) ;
RZKRestorePreemption( preempt_status ) ;
return status ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -