📄 flsocket.c
字号:
/***********************************************************************************/
/* M-Systems Confidential */
/* Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2003 */
/* All Rights Reserved */
/***********************************************************************************/
/* NOTICE OF M-SYSTEMS OEM */
/* SOFTWARE LICENSE AGREEMENT */
/* */
/* THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE */
/* AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT */
/* FOR THE SPECIFIC TERMS AND CONDITIONS OF USE, */
/* OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE: */
/* E-MAIL = info@m-sys.com */
/***********************************************************************************/
/*
* $Log: V:/PVCSDB/DiskOnChip/archives/general storage/TrueFFS/src/core/flsocket.c-arc $
*
* Rev 1.1 Sep 01 2003 19:07:38 oris
* - Removed warnings
*
* Rev 1.0 Apr 09 2003 12:16:04 OriS
* Initial revision.
*
*/
#include "flsocket.h"
FLByte noOfSockets = 0; /* No. of drives actually registered */
static FLSocket vols[SOCKETS];
#ifdef FL_MALLOC
static FLBuffer *volBuffers[SOCKETS];
#if (defined(VERIFY_WRITE) || defined(VERIFY_ERASE) || defined(MTD_RECONSTRUCT_BBT) || defined(VERIFY_VOLUME))
static FLByte* readBackBuffer[SOCKETS];
#endif /* VERIFY_WRITE || VERIFY_ERASE || VERIFY_VOLUME || MTD_RECONSTRUCT_BBT */
#else
static FLBuffer volBuffers[SOCKETS];
#if (defined(VERIFY_WRITE) || defined(VERIFY_ERASE) || defined(MTD_RECONSTRUCT_BBT) || defined(VERIFY_VOLUME))
static FLByte readBackBuffer[SOCKETS][READ_BACK_BUFFER_SIZE];
#endif /* VERIFY_WRITE || VERIFY_ERASE || VERIFY_VOLUME || MTD_RECONSTRUCT_BBT */
#endif /* FL_MALLOC */
/*----------------------------------------------------------------------*/
/* f l S o c k e t N o O f */
/* */
/* Gets the volume no. connected to a socket */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* */
/* Returns: */
/* volume no. of socket */
/*----------------------------------------------------------------------*/
FLByte flSocketNoOf(const FLSocket vol)
{
return (FLByte)vol.volNo;
}
/*----------------------------------------------------------------------*/
/* f l S o c k e t O f */
/* */
/* Gets the socket connected to a volume no. */
/* */
/* Parameters: */
/* volNo : Volume no. for which to get socket */
/* */
/* Returns: */
/* socket of volume no. */
/*----------------------------------------------------------------------*/
FLSocket *flSocketOf(unsigned volNo)
{
return &vols[volNo];
}
/*----------------------------------------------------------------------*/
/* f l B u f f e r O f */
/* */
/* Gets the buffer connected to a volume no. */
/* */
/* Parameters: */
/* volNo : Volume no. for which to get socket */
/* */
/* Returns: */
/* buffer of volume no. */
/*----------------------------------------------------------------------*/
FLBuffer *flBufferOf(unsigned volNo)
{
#ifdef FL_MALLOC
return volBuffers[volNo];
#else
return &volBuffers[volNo];
#endif
}
#if (defined(VERIFY_WRITE) || defined(VERIFY_ERASE) || defined(MTD_RECONSTRUCT_BBT) || defined(VERIFY_VOLUME))
/*----------------------------------------------------------------------*/
/* f l R e a d B a c k B u f f e r O f */
/* */
/* Gets the read back buffer connected to a volume no. */
/* */
/* Parameters: */
/* volNo : Volume no. for which to get socket */
/* */
/* Returns: */
/* buffer of volume no. */
/*----------------------------------------------------------------------*/
FLByte * flReadBackBufferOf(unsigned volNo)
{
#ifdef FL_MALLOC
return readBackBuffer[volNo];
#else
return &(readBackBuffer[volNo][0]);
#endif
}
#endif /* VERIFY_WRITE || VERIFY_ERASE || VERIFY_VOLUME || MTD_RECONSTRUCT_BBT */
/*----------------------------------------------------------------------*/
/* f l W r i t e P r o t e c t e d */
/* */
/* Returns the write-protect state of the media */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* */
/* Returns: */
/* 0 = not write-protected, other = write-protected */
/*----------------------------------------------------------------------*/
FLBoolean flWriteProtected(FLSocket vol)
{
return vol.writeProtected(&vol);
}
#ifndef FIXED_MEDIA
/*----------------------------------------------------------------------*/
/* f l R e s e t C a r d C h a n g e d */
/* */
/* Acknowledges a media-change condition and turns off the condition. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* */
/*----------------------------------------------------------------------*/
void flResetCardChanged(FLSocket vol)
{
if (vol.getAndClearCardChangeIndicator)
vol.getAndClearCardChangeIndicator(&vol); /* turn off the indicator */
vol.cardChanged = FALSE;
}
/*----------------------------------------------------------------------*/
/* f l M e d i a C h e c k */
/* */
/* Checks the presence and change status of the media */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* */
/* Returns: */
/* flOK -> Media present and not changed */
/* driveNotReady -> Media not present */
/* diskChange -> Media present but changed */
/*----------------------------------------------------------------------*/
FLStatus flMediaCheck(FLSocket vol)
{
if (!vol.cardDetected(&vol)) {
vol.cardChanged = TRUE;
return flDriveNotReady;
}
if (vol.getAndClearCardChangeIndicator &&
vol.getAndClearCardChangeIndicator(&vol))
vol.cardChanged = TRUE;
return vol.cardChanged ? flDiskChange : flOK;
}
#endif
/*----------------------------------------------------------------------*/
/* f l G e t M a p p i n g C o n t e x t */
/* */
/* Returns the currently mapped window page (in 4KB units) */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* */
/* Returns: */
/* unsigned int : Current mapped page no. */
/*----------------------------------------------------------------------*/
unsigned flGetMappingContext(FLSocket vol)
{
return vol.window.currentPage;
}
/*----------------------------------------------------------------------*/
/* f l M a p */
/* */
/* Maps the window to a specified card address and returns a pointer to */
/* that location (some offset within the window). */
/* */
/* NOTE: Addresses over 128M are attribute memory. On PCMCIA adapters, */
/* subtract 128M from the address and map to attribute memory. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* address : Byte-address on card. NOT necessarily on a */
/* full-window boundary. */
/* If above 128MB, address is in attribute space. */
/* */
/* Returns: */
/* Pointer to a location within the window mapping the address. */
/*----------------------------------------------------------------------*/
void FAR0 *flMap(FLSocket vol, CardAddress address)
{
unsigned pageToMap;
if (vol.window.currentPage == UNDEFINED_MAPPING)
vol.setWindow(&vol);
pageToMap = (unsigned) ((address & -vol.window.size) >> 12);
if (vol.window.currentPage != pageToMap) {
vol.setMappingContext(&vol, pageToMap);
vol.window.currentPage = pageToMap;
vol.remapped = TRUE; /* indicate remapping done */
}
return addToFarPointer(vol.window.base,address & (vol.window.size - 1));
}
/*----------------------------------------------------------------------*/
/* f l S e t W i n d o w B u s W i d t h */
/* */
/* Requests to set the window bus width to 8 or 16 bits. */
/* Whether the request is filled depends on hardware capabilities. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* width : Requested bus width */
/* */
/*----------------------------------------------------------------------*/
void flSetWindowBusWidth(FLSocket vol, unsigned width)
{
vol.window.busWidth = width;
vol.window.currentPage = UNDEFINED_MAPPING; /* force remapping */
}
/*----------------------------------------------------------------------*/
/* f l S e t W i n d o w S p e e d */
/* */
/* Requests to set the window speed to a specified value. */
/* The window speed is set to a speed equal or slower than requested, */
/* if possible in hardware. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* nsec : Requested window speed in nanosec. */
/* */
/*----------------------------------------------------------------------*/
void flSetWindowSpeed(FLSocket vol, unsigned nsec)
{
vol.window.speed = nsec;
vol.window.currentPage = UNDEFINED_MAPPING; /* force remapping */
}
/*----------------------------------------------------------------------*/
/* f l S e t W i n d o w S i z e */
/* */
/* Requests to set the window size to a specified value (power of 2). */
/* The window size is set to a size equal or greater than requested, */
/* if possible in hardware. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* sizeIn4KBUnits : Requested window size in 4 KByte units. */
/* MUST be a power of 2. */
/* */
/*----------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -