void borFifoPop(bor_fifo_t *fifo) { bor_fifo_segm_t *next; if (!fifo->front) return; // Notice that we are not really removing an element we just move the // pointer and remove only the whole segment if necessary fifo->front_el += fifo->el_size; // Remove the front segment if no more elements can fit it or if have // pop'ed the last element. if (fifo->front_el + fifo->el_size > fifo->front_end || (fifo->front == fifo->back && fifo->front_el >= fifo->back_el)){ // Remember the next segment next = fifo->front->next; // free the whole segment BOR_FREE(fifo->front); // Use the remembered segment and initialize front_el and front_end fifo->front = next; if (fifo->front != NULL){ fifoInitElPtrs(fifo, fifo->front, &fifo->front_el, &fifo->front_end); }else{ fifoReset(fifo); } } }
void borFifoClear(bor_fifo_t *fifo) { bor_fifo_segm_t *next; while (fifo->front){ next = fifo->front->next; BOR_FREE(fifo->front); fifo->front = next; } fifoReset(fifo); }
void borFifoInitSize(bor_fifo_t *fifo, size_t el_size, size_t buf_size) { fifo->segm_size = buf_size; fifo->el_size = el_size; fifoReset(fifo); }
static void reset2SafeState( int why ) /* argument is the type of exception */ { int pTmpId, TmpPrior; int tuneactive = 0; DPRINT(1,"reset2SafeState"); DPRINT(1,"stopAPint"); pcsAbortSort(); /* parallel channel sort to stop and return to APint() */ abortAPint(); /* like stopAPint() but also cause the Parser to suspend itself */ /* stopAPint(); */ DPRINT(1,"stop downLinker"); setDwnLkAbort(); /* like stop downLinker and set to dump further download to bit bucket */ DPRINT(1,"reset2SafeState"); DPRINT(0,"fifoSetNoStuff\n"); fifoSetNoStuff(pTheFifoObject); /* stop the stuffer in it's tracks */ DPRINT(0,"Disable STM Intrps"); stmItrpDisable(pTheStmObject, STM_ALLITRPS); /* reset fifo Object not to use parallel channels */ fifoClearPChanId(pTheFifoObject); DPRINT(0,"fifoReset"); /* Keep the MTS gradient amp disabled whenever possible! */ gpaTuneSet(pTheAutoObject, SET_GPAENABLE, GPA_DISABLE_DELAY); /* if an interactive abort do not reset the apbus, thus preventing the all amplifier from going to Pulse Mode, thus amps that are in CW will stay that way. This is/was a lockdisplay/shimming issue. Where exiting lock display set all the amps to Pulse Mode or blanked!, then one shimmed and obtain a certain lock level. After su command then amps would go back to CW thus injecting noise and lowing the lock level, If use wht directly to shimming they could neer re-attain the lock level they had before. But when enter and exit lock display the level would jump back up. Thus causing no end of confusion.... Thus for INTERACTIVE_ABORT the reset apbus bit is left out when reseting the FIFO. Oooops, but wait, we found an exception (of course), when exiting qtune the reset of the apbus reset all the tune relays back to noraml, now of course this does not happen thus leaving the console in tuning mode. Thus we added the following test isTuneActive() and if it is then a full reset including the apbus is done. */ tuneactive = isTuneActive(); /* DPRINT1(-3,"Is Tune active: %d\n",tuneactive); */ if ((why != INTERACTIVE_ABORT) || (tuneactive == 1)) fifoReset(pTheFifoObject, RESETFIFOBRD); /* this now also clear the Fifo Buffer & restart the Stuffer */ else fifoReset(pTheFifoObject, RESETFIFO | RESETSTATEMACH | RESETTAGFIFO | RESETAPRDBKFIFO ); /* no apbus reset */ /* set initial value of parallel channel free buffer pointer to null */ clearParallelFreeBufs(); DPRINT(0,"Stuff FIFO DIRECTLY with Safe State & Run fifo"); fifoLoadHsl(pTheFifoObject, STD_HS_LINES, pTheFifoObject->SafeHSLines); fifoLoadHsl(pTheFifoObject, EXT_HS_LINES, pTheFifoObject->SafeHSLinesExt); /* Each SafeState Code is actually two long words */ if (numSafeStatCodes > 0) { /* WARNING: Does not pend for FF Almost Full, BEWARE !! */ /* Should only be used in phandler's reset2SafeState() */ fifoStuffCode(pTheFifoObject, pSafeStateCodes, numSafeStatCodes); fifoStuffCode(pTheFifoObject, pTurnOffSshaCodes, numTurnOffSshaCodes); fifoStuffCode(pTheFifoObject, pHaltOpCodes, numHaltOpCodes); DPRINT(1,"Ready to start FIFO in reset to safe state\n" ); fifoStart(pTheFifoObject); /* fifoWait4Stop(pTheFifoObject); /* use BusyWait don't what any other lower priority tasks to run ! */ fifoBusyWait4Stop(pTheFifoObject); /* use BusyWait don't what any other lower priority tasks to run ! */ DPRINT(1,"FIFO wait for stop completes in reset to safe state\n" ); } activate_ssha(); DPRINT(0,"getnGiveShimMutex\n"); /* allow any pending serial Shim commands to finish */ getnGiveShimMutex(); DPRINT(0,"getnGiveVTMutex\n"); /* allow any pending serial VT commands to finish */ getnGiveVTMutex(); /* Now Bump Priority of DownLiner so that it can Dump the remaining Data that SendProc wants to send it */ /* If we lost the connection to the host computer, the downlinker is is not going to get any more data; nor should this task (problem handler) wait for the downlinker to become ready. April 1997 */ DPRINT(0,"dlbFreeAllNotLoading Dyn"); dlbFreeAllNotLoading(pDlbDynBufs); DPRINT(0,"dlbFreeAllNotLoading Fix"); dlbFreeAllNotLoading(pDlbFixBufs); if (why != LOST_CONN) { pTmpId = taskNameToId("tDownLink"); taskPriorityGet(pTmpId,&TmpPrior); taskPrioritySet(pTmpId,(pHandlerPriority-1)); /* downLinker has now A. ran and is suspended, B. Done and in READY state or C. still waiting in a read of a socket */ /* start wdog timeout of 20 seconds */ wdStart(pHandlerWdTimeout,sysClkRateGet() * 20, pHandlerWdISR, 0); /* if it is busy and not suspend then wait till /* it is Ready or Suspended, or Time-Out */ while (downLinkerIsActive() && !taskIsSuspended(pTmpId) && !pHandlerTimeout) taskDelay(1); /* wait one tick , 16msec */ wdCancel(pHandlerWdTimeout); if (taskIsSuspended(pTmpId)) { taskResume(pTmpId); wait4DownLinkerReady(); } taskPrioritySet(pTmpId,TmpPrior); DPRINT(0,"downlinker resynchronized\n"); } DPRINT(0,"dlbFreeAll Dyn"); dlbFreeAll(pDlbDynBufs); DPRINT(0,"dlbFreeAll Fix"); dlbFreeAll(pDlbFixBufs); /* Now Bump Priority of Parser so that it can Finish Up We don't have to worry as much about the state of the parser since it will completely restarted very soon. */ pTmpId = taskNameToId("tParser"); taskPriorityGet(pTmpId,&TmpPrior); taskPrioritySet(pTmpId,(pHandlerPriority-1)); if (taskIsSuspended(pTmpId)) { taskResume(pTmpId); wait4ParserReady(); } taskPrioritySet(pTmpId,TmpPrior); resetAPint(); DPRINT(0,"A-code parser resynchronized\n"); /* Parser might of made a buffer ready to stuff, so better clear it just incase */ if (why != INTERACTIVE_ABORT) fifoReset(pTheFifoObject, RESETFIFOBRD); /* this now also clear the Fifo Buffer & restart the Stuffer */ else fifoReset(pTheFifoObject, RESETFIFO | RESETSTATEMACH | RESETTAGFIFO | RESETAPRDBKFIFO ); /* no apbus reset */ return; }