void I2C_Driver::Cancel( I2C_HAL_XACTION* xAction, bool signal ) { NATIVE_PROFILE_PAL_COM(); ASSERT(xAction); if(xAction == NULL) return; GLOBAL_LOCK(irq); switch(xAction->GetState()) { // only one xAction will efer be in processing for every call to Abort case I2C_HAL_XACTION::c_Status_Processing: I2C_Internal_XActionStop(); // fall through... case I2C_HAL_XACTION::c_Status_Scheduled: case I2C_HAL_XACTION::c_Status_Completed: case I2C_HAL_XACTION::c_Status_Aborted: xAction->Abort(); xAction->SetState(I2C_HAL_XACTION::c_Status_Cancelled); StartNext(); break; case I2C_HAL_XACTION::c_Status_Idle: // do nothing since we aren't enqueued yet break; } }
BOOL Piezo_Driver::Tone( UINT32 Frequency_Hertz, UINT32 Duration_Milliseconds ) { // Not sure why this is neccessary. Calling the Piezo::Tone function from with-in an ISR // should be a valid scenario. Lorenzo and I (Zach) can not determine // why this assert is needed; therefore, it is being commented out (for now). //ASSERT(!SystemState_Query( SYSTEM_STATE_ISR )); GLOBAL_LOCK(irq); // special to clear queue if(Frequency_Hertz == TONE_CLEAR_BUFFER) { // let active note to finish on it's own EmptyQueue(); } else { // 0 length tone isn't wrong persay, but if a NULL op, so drop it gracefully, as a success if(Duration_Milliseconds > 0) { PIEZO_TONE* Tone = g_Piezo_Driver.m_ToneToRelease.ExtractFirstNode(); if(Tone == NULL) { // // Re-enable interrupts when allocating memory. // irq.Release(); Tone = (PIEZO_TONE*)private_malloc( sizeof(PIEZO_TONE) ); Tone->Initialize(); irq.Acquire(); } if(Tone == NULL) { // No memory, just drop this tone and fail the call ASSERT(0); return FALSE; } Tone->Frequency_Hertz = Frequency_Hertz; Tone->Duration_Milliseconds = Duration_Milliseconds; DEBUG_TRACE3(0, "Tone(%4d,%4d)=%d\r\n", Frequency_Hertz, Duration_Milliseconds, g_Piezo_Driver.m_ToneToPlay.NumOfNodes() ); g_Piezo_Driver.m_ToneToPlay.LinkAtBack( Tone ); if(g_Piezo_Driver.m_TonePlaying == NULL) { StartNext(); } } } return TRUE; }
BOOL PolyphonicPiezo_Driver::Tone( const PIEZO_POLY_TONE& ToneRef ) { ASSERT(!SystemState_Query(SYSTEM_STATE_ISR)); GLOBAL_LOCK(irq); // special to clear queue if(ToneRef.Period[0] == TONE_CLEAR_BUFFER) { // let active note to finish on it's own EmptyQueue(); } else { // 0 length tone isn't wrong persay, but if a NULL op, so drop it gracefully, as a success if(ToneRef.Duration_MicroSeconds > 0) { PIEZO_POLY_TONE* Tone = g_PolyphonicPiezo_Driver.m_ToneToRelease.ExtractFirstNode(); if(Tone == NULL) { // // Re-enable interrupts when allocating memory. // irq.Release(); Tone = (PIEZO_POLY_TONE*)private_malloc( sizeof(PIEZO_POLY_TONE) ); irq.Acquire(); } if(Tone == NULL) { // No memory, just drop this tone and fail the call ASSERT(0); return FALSE; } *Tone = ToneRef; Tone->Initialize(); DEBUG_TRACE2( 0, "Tone(%4d)=%d\r\n", ToneRef.Duration_MicroSeconds, g_PolyphonicPiezo_Driver.m_ToneToPlay.NumOfNodes() ); g_PolyphonicPiezo_Driver.m_ToneToPlay.LinkAtBack( Tone ); if(g_PolyphonicPiezo_Driver.m_TonePlaying == NULL) { StartNext(); } } } return TRUE; }
/* Called from interrupt context */ void BusFree (ADAPTER_PTR HA, int StartLevel) { HA->State.Busy = HA->State.DataIn = HA->State.DoingSync = FALSE; HA->CurrDev = NILL; HA->CurrReq = NILL; HA->ReqCurrentCount = 0; HA->ReqCurrentIndex = 0; HA->Service(HA_LED, HA, (long)0); StartNext(HA, StartLevel); /* Called from interrupt, so level = 2 */ }
//************************************************************************ void CCreditsScene::OnSpriteNotify( LPSPRITE lpSprite, SPRITE_NOTIFY Notify ) //************************************************************************ { if (Notify != SN_MOVEDONE) return; lpSprite->Kill(); if ( !m_pContributors ) return; int i = m_nNextContributor; DWORD dwDelay = m_pContributors[i].m_dwDelayTime; if ( (dwDelay == 1) || (!dwDelay && !m_pAnimator->GetNumSprites()) ) StartNext(); }
//************************************************************************ void CCreditsScene::OnTimer(HWND hWnd, UINT id) //************************************************************************ { CGBScene::OnTimer(hWnd, id); if ( !m_pContributors ) return; int i = m_nNextContributor; if ( m_pContributors[i].m_dwDelayTime <= 1 ) return; DWORD dwTime = timeGetTime(); if ((dwTime - m_dwLastTime) > m_pContributors[i].m_dwDelayTime) StartNext(); }
void Piezo_Driver::ToneDone_ISR( void* Param ) { ASSERT_IRQ_MUST_BE_OFF(); PIEZO_TONE* Tone = g_Piezo_Driver.m_TonePlaying; if(Tone) { g_Piezo_Driver.m_ToneToRelease.LinkAtBack( Tone ); if(g_Piezo_Driver.m_ToneRelease.IsLinked() == false) { g_Piezo_Driver.m_ToneRelease.Enqueue(); } } StartNext(); }
void I2C_Driver::CompletedCallback( void* arg ) { NATIVE_PROFILE_PAL_COM(); I2C_HAL_XACTION* xAction = (I2C_HAL_XACTION*)arg; // is the transaction is the last of a series of related // transactions then free the bus for whoever comes next if(( xAction->m_current == (xAction->m_numXActionUnits)) || xAction->CheckState( I2C_HAL_XACTION::c_Status_Aborted | I2C_HAL_XACTION::c_Status_Cancelled )) { // signal the waiting thread; since continuations are executed one at a time for every round // of the scheduler there is no need to check for lost events on the waiting thread Events_Set( SYSTEM_EVENT_I2C_XACTION ); StartNext(); } }
BOOL I2C_Driver::Enqueue( I2C_HAL_XACTION* xAction ) { NATIVE_PROFILE_PAL_COM(); ASSERT(xAction); if(xAction == NULL) return FALSE; GLOBAL_LOCK(irq); xAction->SetCallback( I2C_Driver::CompletedCallback ); xAction->SetState( I2C_HAL_XACTION::c_Status_Scheduled ); g_I2C_Driver.m_xActions.LinkAtBack( xAction ); StartNext(); return TRUE; }
//************************************************************************ void CCreditsScene::ToonInitDone() //************************************************************************ { if ( m_pAnimator ) { m_pAnimator->StopAll(); m_pAnimator->SetClipRect(&m_rGameArea); if (GetSound() && lstrlen(m_szSoundTrack)) { FNAME szFileName; GetPathName(szFileName, m_szSoundTrack); GetSound()->StartFile(szFileName, TRUE, -1); } StartNext(); m_pAnimator->StartAll(); } }
void PolyphonicPiezo_Driver::Uninitialize() { { GLOBAL_LOCK(irq); EmptyQueue(); // // This purges the currently playing tone. // StartNext(); } bool fEnabled = INTERRUPTS_ENABLED_STATE(); if(!fEnabled) ENABLE_INTERRUPTS(); ToneRelease( NULL ); if(!fEnabled) DISABLE_INTERRUPTS(); }
void PolyphonicPiezo_Driver::ToneDone_ISR( void* Param ) { ASSERT_IRQ_MUST_BE_OFF(); Events_Set( SYSTEM_EVENT_FLAG_TONE_COMPLETE ); PIEZO_POLY_TONE* Tone = g_PolyphonicPiezo_Driver.m_TonePlaying; if(Tone) { g_PolyphonicPiezo_Driver.m_ToneToRelease.LinkAtBack( Tone ); if(g_PolyphonicPiezo_Driver.m_ToneRelease.IsLinked() == false) { g_PolyphonicPiezo_Driver.m_ToneRelease.Enqueue(); } } else { Events_Set( SYSTEM_EVENT_FLAG_TONE_BUFFER_EMPTY ); } StartNext(); }
void Piezo_Driver::Uninitialize() { g_Piezo_Driver.m_ToneDone .Abort(); g_Piezo_Driver.m_ToneRelease.Abort(); { GLOBAL_LOCK(irq); EmptyQueue(); // // This purges the currently playing tone. // StartNext(); } bool fEnabled = INTERRUPTS_ENABLED_STATE(); if(!fEnabled) ENABLE_INTERRUPTS(); ToneRelease( NULL ); if(!fEnabled) DISABLE_INTERRUPTS(); // restore the hardware to proper default state for(int i = 0; i < 2; i++) { PWM_CONFIG* PWM_Config = &g_pPIEZO_Config->PWM_Config[i]; if(PWM_Config->PWM_Output.Pin != GPIO_PIN_NONE) { CPU_GPIO_EnableInputPin( PWM_Config->PWM_Output.Pin, FALSE, NULL, GPIO_INT_NONE, RESISTOR_PULLDOWN ); } } }