📄 flsocket.c
字号:
/* f l N e e d V p p */
/* */
/* Turns on Vpp, if not on already */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* */
/* Returns: */
/* FLStatus : 0 on success, failed otherwise */
/*----------------------------------------------------------------------*/
FLStatus flNeedVpp(FLSocket vol)
{
vol.VppUsers++;
if (vol.VppState == PowerOff)
checkStatus(vol.VppOn(&vol));
vol.VppState = PowerOn;
return flOK;
}
/*----------------------------------------------------------------------*/
/* f l D o n t N e e d V p p */
/* */
/* Notifies that Vpp is no longer needed, allowing it to be turned off. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* */
/*----------------------------------------------------------------------*/
void flDontNeedVpp(FLSocket vol)
{
if (vol.VppUsers > 0)
vol.VppUsers--;
}
#endif /* SOCKET_12_VOLTS */
/*----------------------------------------------------------------------*/
/* f l S e t P o w e r O n C a l l b a c k */
/* */
/* Sets a routine address to call when powering on the socket. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* routine : Routine to call when turning on power */
/* flash : Flash object of routine */
/* */
/*----------------------------------------------------------------------*/
void flSetPowerOnCallback(FLSocket vol, void (*routine)(void *flash), void *flash)
{
vol.powerOnCallback = routine;
vol.flash = flash;
}
/*----------------------------------------------------------------------*/
/* f l I n t e r v a l R o u t i n e */
/* */
/* Performs periodic socket actions: Checks card presence, and handles */
/* the Vcc & Vpp turn off mechanisms. */
/* */
/* The routine may be called from the interval timer or sunchronously. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* */
/*----------------------------------------------------------------------*/
void flIntervalRoutine(FLSocket vol)
{
#ifndef FIXED_MEDIA
if (vol.getAndClearCardChangeIndicator == NULL &&
!vol.cardChanged)
if (!vol.cardDetected(&vol)) /* Check that the card is still there */
vol.cardChanged = TRUE;
#endif
if (vol.VppUsers == 0) {
if (vol.VppState == PowerOn)
vol.VppState = PowerGoingOff;
else if (vol.VppState == PowerGoingOff) {
vol.VppState = PowerOff;
#ifdef SOCKET_12_VOLTS
vol.VppOff(&vol);
#endif
}
if (vol.VccUsers == 0) {
if (vol.VccState == PowerOn)
vol.VccState = PowerGoingOff;
else if (vol.VccState == PowerGoingOff) {
vol.VccState = PowerOff;
vol.VccOff(&vol);
}
}
}
}
/*----------------------------------------------------------------------*/
/* u d a t e S o c k e t P a r a m e t e r s */
/* */
/* Pass socket parameters to the socket interface layer. */
/* This function should be called after the socket parameters (like */
/* size and base) are known. If these parameters are known at */
/* registration time then there is no need to use this function, and */
/* the parameters can be passed to the registration routine. */
/* The structure passed in irData is specific for each socket interface.*/
/* */
/* Note : When using DiskOnChip this routine returns the socekt */
/* parameters instead of initialiaing them. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* params : Record returning (or sending) the flsocket record */
/* */
/* Returns: */
/* FLStatus : 0 on success */
/*----------------------------------------------------------------------*/
FLStatus updateSocketParameters(FLSocket vol, void FAR1 *params)
{
if (vol.updateSocketParams)
vol.updateSocketParams(&vol, params);
return flOK;
}
#ifdef EXIT
/*----------------------------------------------------------------------*/
/* f l E x i t S o c k e t */
/* */
/* Reset the socket and free resources that were allocated for this */
/* socket. */
/* This function is called when FLite exits. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* */
/*----------------------------------------------------------------------*/
void flExitSocket(FLSocket vol)
{
flMap(&vol, 0); /* reset the mapping register */
flDontNeedVcc(&vol);
flSocketSetBusy(&vol,FL_OFF);
vol.freeSocket(&vol); /* free allocated resources */
#ifdef FL_MALLOC
FL_FREE(volBuffers[vol.volNo]);
#if (defined(VERIFY_WRITE) || defined(VERIFY_ERASE) || defined(MTD_RECONSTRUCT_BBT) || defined(VERIFY_VOLUME) || defined(VERIFY_ERASED_SECTOR))
FL_FREE(readBackBuffer[vol.volNo]);
#endif /* VERIFY_WRITE || VERIFY_ERASE || VERIFY_VOLUME || MTD_RECONSTRUCT_BBT || VERIFY_ERASED_SECTOR */
#endif /* FL_MALLOC */
}
#endif /* EXIT */
/*-----------------------------------------------------------------------*/
/* 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 < noOfSockets; volNo++, pVol++) {
flSetWindowSpeed(&vol, 250);
flSetWindowBusWidth(&vol, 16);
flSetWindowSize(&vol, 2); /* make it 8 KBytes */
vol.cardChanged = FALSE;
#ifdef FL_MALLOC
/* allocate buffer for this socket */
volBuffers[volNo] = (FLBuffer *)FL_MALLOC(sizeof(FLBuffer));
if (volBuffers[volNo] == NULL) {
DEBUG_PRINT(("Debug: failed allocating sector buffer.\r\n"));
return flNotEnoughMemory;
}
#if (defined(VERIFY_WRITE) || defined(VERIFY_ERASE) || defined(MTD_RECONSTRUCT_BBT) || defined(VERIFY_VOLUME) || defined(VERIFY_ERASED_SECTOR))
/* allocate read back buffer for this socket */
readBackBuffer[volNo] = (byte *)FL_MALLOC(READ_BACK_BUFFER_SIZE);
if (readBackBuffer[volNo] == NULL) {
DEBUG_PRINT(("Debug: failed allocating readBack buffer.\r\n"));
return flNotEnoughMemory;
}
#endif /* VERIFY_WRITE || VERIFY_ERASE || MTD_READ_BBT || VERIFY_VOLUME || VERIFY_ERASED_SECTOR */
#endif /* FL_MALLOC */
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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -