📄 flsocket.c
字号:
/* dosformt.c - True Flash File System *//* Copyright 1984-2004 Wind River Systems, Inc. */#include "copyright_wrs.h"/* FAT-FTL Lite Software Development Kit * Copyright (C) M-Systems Ltd. 1995-1997 *//*modification history--------------------01a,29jul04,alr modified file header, restarted history*/#include "flsocket.h"unsigned noOfDrives = 0; /* No. of drives actually registered */static FLSocket vols[DRIVES];#ifndef SINGLE_BUFFER#ifdef MALLOC_TFFSstatic FLBuffer *volBuffers[DRIVES];#elsestatic FLBuffer volBuffers[DRIVES];#endif#endif/*----------------------------------------------------------------------*//* 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 *//*----------------------------------------------------------------------*/unsigned flSocketNoOf(const FLSocket vol){ return 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];}#ifndef SINGLE_BUFFER/*----------------------------------------------------------------------*//* 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 MALLOC_TFFS return volBuffers[volNo];#else return &volBuffers[volNo];#endif}#endif /* SINGLE_BUFFER *//*----------------------------------------------------------------------*//* 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 I n i t S o c k e t s *//* *//* First call to this module: Initializes the controller and all sockets*//* *//* Parameters: *//* vol : Pointer identifying drive *//* *//* Returns: *//* FLStatus : 0 on success, failed otherwise *//*----------------------------------------------------------------------*/FLStatus flInitSockets(void){ unsigned volNo; FLSocket vol = vols; for (volNo = 0; volNo < noOfDrives; volNo++, pVol++) { flSetWindowSpeed(&vol, 250); flSetWindowBusWidth(&vol, 16); flSetWindowSize(&vol, 2); /* make it 8 KBytes */ vol.cardChanged = FALSE; #ifndef SINGLE_BUFFER #ifdef MALLOC_TFFS /* allocate buffer for this socket */ volBuffers[volNo] = (FLBuffer *)MALLOC_TFFS(sizeof(FLBuffer)); if (volBuffers[volNo] == NULL) { #ifdef DEBUG_PRINT DEBUG_PRINT("Debug: failed allocating sector buffer.\n"); #endif return flNotEnoughMemory; } #endif #endif checkStatus(vol.initSocket(&vol)); #ifdef SOCKET_12_VOLTS vol.VppOff(&vol); vol.VppState = PowerOff; vol.VppUsers = 0; #endif vol.VccOff(&vol); vol.VccState = PowerOff; vol.VccUsers = 0; } return flOK;}/*----------------------------------------------------------------------*//* 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. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -