void TIMER32_0_IRQHandler() { static unsigned int duty_counter_r = 0; static unsigned int duty_counter_g = 0; static unsigned int duty_counter_b = 0; static unsigned int bl_duty_counter = 0; static unsigned int period_counter = 0; static int activity_counter = 0; CoEnterISR(); TIM_ClearIntPending(LPC_TMR32B0, TIM_MR0_INT); // 39.0625us activity indicator (for calibration) GPIO_ToggleBits(TIMER_ACTIVITY_PORT, TIMER_ACTIVITY_PIN); if( period_counter -- > 0 ) { if( duty_counter_r -- == 0 ) GPIO_ResetBits(RED_PORT, RED_PIN); if( duty_counter_g -- == 0 ) GPIO_ResetBits(GREEN_PORT, GREEN_PIN); if( duty_counter_b -- == 0 ) GPIO_ResetBits(BLUE_PORT, BLUE_PIN); if (bl_duty_counter-- == 0) GPIO_ResetBits(LCD_BACKLITE_PORT, LCD_BACKLITE_PIN); } else { if( activity_counter ++ >= TICKS_PER_SECOND ) { activity_counter = 0; GPIO_ToggleBits(TIMER_ACTIVITY_PORT, TIMER_ACTIVITY_PIN); //if( device_mode == AMBIENT_TEMPERATURE ) // PLUGIN_Temperature_Update(); } SEQ_Tick(); duty_counter_r = SEQ_CurrentRed(); duty_counter_r == 0 ? GPIO_ResetBits(RED_PORT, RED_PIN) : GPIO_SetBits(RED_PORT, RED_PIN); duty_counter_g = SEQ_CurrentGreen(); duty_counter_g == 0 ? GPIO_ResetBits(GREEN_PORT, GREEN_PIN ) : GPIO_SetBits(GREEN_PORT, GREEN_PIN ); duty_counter_b = SEQ_CurrentBlue(); duty_counter_b == 0 ? GPIO_ResetBits(BLUE_PORT, BLUE_PIN ) : GPIO_SetBits(BLUE_PORT, BLUE_PIN ); bl_duty_counter = backlite_power; bl_duty_counter == 0 ? GPIO_ResetBits(LCD_BACKLITE_PORT, LCD_BACKLITE_PIN) : GPIO_SetBits(LCD_BACKLITE_PORT, LCD_BACKLITE_PIN); period_counter = 255; } CoExitISR(); }
///////////////////////////////////////////////////////////////////////////// // this sequencer handler is called periodically to check for new requests // from BPM generator ///////////////////////////////////////////////////////////////////////////// s32 SEQ_Handler(void) { // a lower priority task requested to play the next file if( next_file_req ) { SEQ_PlayFile(next_file_req-1); next_file_req = 0; }; // handle BPM requests u8 num_loops = 0; u8 again = 0; do { ++num_loops; // note: don't remove any request check - clocks won't be propagated // so long any Stop/Cont/Start/SongPos event hasn't been flagged to the sequencer if( SEQ_BPM_ChkReqStop() ) { SEQ_PlayOffEvents(); } if( SEQ_BPM_ChkReqCont() ) { // release pause mode seq_pause = 0; } if( SEQ_BPM_ChkReqStart() ) { SEQ_Reset(1); SEQ_SongPos(0); } u16 new_song_pos; if( SEQ_BPM_ChkReqSongPos(&new_song_pos) ) { SEQ_SongPos(new_song_pos); } u32 bpm_tick; if( SEQ_BPM_ChkReqClk(&bpm_tick) > 0 ) { again = 1; // check all requests again after execution of this part SEQ_Tick(bpm_tick); } } while( again && num_loops < 10 ); return 0; // no error }