/************************************************************************ Name: ata_ctrl_HardReset Description: Does a hard reset, then waits for BSY to clear Parameter: Ata_p : Pointer to the ATA control block ************************************************************************/ BOOL ata_ctrl_HardReset(ata_ControlBlock_t *Ata_p) { /* Preload the value */ volatile U8 Dummy = BSY_BIT_MASK; clock_t timeout; U32 TimeoutTicks; TimeoutTicks = HARD_RESET_TIMEOUT_SECONDS * ST_GetClocksPerSecond(); /* If hardreset fails, return TRUE for error */ if (hal_HardReset(Ata_p->HalHndl) == TRUE) return TRUE; timeout = time_plus(time_now(), TimeoutTicks); /* Wait for BSY=0 or timeout */ while(TRUE) { WAIT400NS; Dummy = hal_RegInByte(Ata_p->HalHndl,ATA_REG_STATUS); if ((Dummy & BSY_BIT_MASK) == 0) break; /* Returns 1 if first time is after the second */ if (time_after(time_now(), timeout) == 1) break; } /* Check */ if ((Dummy & BSY_BIT_MASK) == 0) return FALSE; else return TRUE; }
/* * Block forever waiting for EVENT to be signalled, * or timeout after timeout (ms) have expired * set timeout to EMBX_TIMEOUT_INFINITE to wait forever * * Returns EMBX_SUCCESS if signalled, EMBX_SYSTEM_TIMEOUT otherwise */ EMBX_ERROR EMBX_OS_EventWaitTimeout(EMBX_EVENT ev, unsigned long timeout) { int res; osclock_t time; EMBX_Assert(ev); if (timeout != EMBX_TIMEOUT_INFINITE) { /* OS21 semaphore timeout takes an absolute time value * so we calculate that here */ time = time_plus(time_now(), (timeout*time_ticks_per_sec())/1000); res = semaphore_wait_timeout(ev->event, &time); } else /* Infinite wait */ res = semaphore_wait(ev->event); if (res == OS21_FAILURE) return EMBX_SYSTEM_TIMEOUT; return EMBX_SUCCESS; }
void current_time_plus(struct timespec *ts, int ms) { current_time(ts); time_plus(ts, ms); }
/******************************************************************************* Name : STDVMi_ServiceTask() Description : STDVM service task Parameters : void *NULL_p NOT USED Return Value : *******************************************************************************/ static void STDVMi_ServiceTask(void *NULL_p) { ST_ErrorCode_t ErrorCode; STDVMi_Handle_t *Handle_p; STDVMi_Handle_t **MsgReceived; clock_t Time2Wait; U32 StartTimeInMs, CurrentTimeInMs, EndTimeInMs; S32 RemainingTime; S32 AudioTrickTime; U32 i; while(STDVMi_ServiceTaskState == TASK_RUNNING) { /* wait on message queue to receive message otherwise check end of file for audio trick mode */ Time2Wait = time_plus(time_now(), ST_GetClocksPerSecond()/10); MsgReceived = message_receive_timeout(STDVMi_ServiceTaskMQ_p, &Time2Wait); if(STDVMi_ServiceTaskState != TASK_RUNNING) { if(MsgReceived != NULL) { message_release(STDVMi_ServiceTaskMQ_p, MsgReceived); } break; } if(MsgReceived != NULL) { Handle_p = *MsgReceived; message_release(STDVMi_ServiceTaskMQ_p, MsgReceived); if(Handle_p->PidChangeState == PID_CHANGE_CHANGING) { /* TODO: Get a copy of the PIDs list or protect Handle_p, since it may be invalid when we reach here */ ErrorCode = STDVM_PlayChangePids((STDVM_Handle_t)Handle_p, Handle_p->StreamInfo_p->ProgramInfo->NbOfPids, Handle_p->StreamInfo_p->ProgramInfo->Pids); if(ErrorCode != ST_NO_ERROR) { STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "STDVMi_ServiceTask: STDVM_PlayChangePids()=%08X\n", ErrorCode)); } Handle_p->PidChangeState = PID_CHANGE_IDLE; } } else /* Audio trick mode */ { for(i = 0; i < STDVMi_NbOfHandles; i++) { Handle_p = &STDVMi_Handles_p[i]; if((Handle_p->HandleInUse == TRUE) && (Handle_p->ObjectType == STDVM_OBJECT_PLAYBACK) && (Handle_p->AudioOnlyProg == TRUE) && (Handle_p->AudioInTrickMode == TRUE) && (Handle_p->AudioInPause == FALSE) && (Handle_p->AudioTrickEndOfFile == FALSE)) { ErrorCode = STPRM_PlayGetTime(Handle_p->PRM_Handle, &StartTimeInMs, &CurrentTimeInMs, &EndTimeInMs); if(ErrorCode != ST_NO_ERROR) { STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "STPRM_PlayGetTime : %08X\n", ErrorCode)); continue; } AUDIO_TRICK_ACCESS_MUTEX_LOCK(Handle_p); if(Handle_p->AudioTrickStartTime != 0) { AudioTrickTime = (S32)(((float)time_minus(time_now(), Handle_p->AudioTrickStartTime) * \ Handle_p->CurrentSpeed * 10) / ST_GetClocksPerSecond()); } else { AudioTrickTime = 0; } CurrentTimeInMs = Handle_p->CurrentTime + AudioTrickTime; RemainingTime = (Handle_p->CurrentSpeed > 0) ? (EndTimeInMs - CurrentTimeInMs) : (CurrentTimeInMs - StartTimeInMs); AUDIO_TRICK_ACCESS_MUTEX_RELEASE(Handle_p); if(RemainingTime <= 0) { STPRM_PlayStatus_t PlayStatus; STPRM_RecordStatus_t RecordStatus; U32 HandleIndex; ErrorCode = STPRM_PlayGetStatus(Handle_p->PRM_Handle, &PlayStatus); if(ErrorCode != ST_NO_ERROR) { STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "STPRM_PlayGetStatus : %08X\n", ErrorCode)); break; } for(HandleIndex = 0; HandleIndex < STDVMi_NbOfHandles; HandleIndex++) { if((STDVMi_Handles_p[HandleIndex].HandleInUse == TRUE) && /* handle is allocated */ (STDVMi_Handles_p[HandleIndex].ObjectType == STDVM_OBJECT_RECORD) && (STDVMi_Handles_p[HandleIndex].StreamInfo_p->Signature == STDVMi_SIGNATURE)) /* object type is record */ { ErrorCode = STPRM_RecordGetStatus(STDVMi_Handles_p[HandleIndex].PRM_Handle, &RecordStatus); if(ErrorCode != ST_NO_ERROR) { STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "STPRM_RecordGetStatus : %08X\n", ErrorCode)); continue; } if(!(strcmp(PlayStatus.SourceName,RecordStatus.DestinationName))) { ErrorCode = STPRM_PlaySeek(Handle_p->PRM_Handle, EndTimeInMs, STPRM_PLAY_SEEK_SET); if(ErrorCode != ST_NO_ERROR) { STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "STPRM_PlaySeek : %08X\n", ErrorCode)); break; } ErrorCode = STPRM_PlayResume(Handle_p->PRM_Handle); if(ErrorCode != ST_NO_ERROR) { STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "STPRM_PlayResume : %08X\n", ErrorCode)); break; } Handle_p->CurrentSpeed = STDVM_PLAY_SPEED_ONE; Handle_p->AudioTrickStartTime = 0; Handle_p->AudioInTrickMode = FALSE; break; } } } if(HandleIndex == STDVMi_NbOfHandles) { Handle_p->CurrentTime = (Handle_p->CurrentSpeed > 0) ? EndTimeInMs : StartTimeInMs; Handle_p->AudioTrickStartTime = 0; Handle_p->AudioTrickEndOfFile = TRUE; ErrorCode = STDVMi_NotifyEvent(STDVM_EVT_END_OF_FILE, Handle_p); if(ErrorCode != ST_NO_ERROR) { STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "STDVMi_NotifyEvent : %08X\n", ErrorCode)); } ErrorCode = STDVMi_NotifyEvent(STDVM_EVT_END_OF_PLAYBACK, Handle_p); if(ErrorCode != ST_NO_ERROR) { STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "STDVMi_NotifyEvent : %08X\n", ErrorCode)); } } } } }/* for */ } }/* while */ }