/* GPT timer handler for Escape character detect */ void USB2UART_Timeout(void *parameter) { UARTStruct *UARTData=(UARTStruct *)parameter; GPTI_StopItem(UARTData->handle); switch(UARTData->Rec_state) { case UART_Get3EscChar: /* escape detect */ UARTData->EscFound = KAL_TRUE; UARTData->Rec_state = UART_RecNormal; UARTData->EscCount = 0; USB2UART_Sendilm(MSG_ID_UART_ESCAPE_DETECTED_IND); break; case UART_RecNormal: /* first timeout, start to check escape character */ UARTData->Rec_state = UART_StartCheckESC; UARTData->EscCount = 0; break; case UART_StartCheckESC: UARTData->Rec_state = UART_RecNormal; UARTData->EscCount = 0; break; } }
void noke_drv_horse_race_keyenter_round_light_on_timer_handler(void * index) { kal_uint8 horse_race_tmr_handle = HORSE_RASE_TMR_HANDLE; kal_bool ret = KAL_FALSE; int lights = enter_key_style_array[*((int *)index)]; kal_uint16 horse_race_tmr_repeat = 10; /*30ms : 1s = 100ticks, 0.1s = 10ticks */ GPTI_StopItem(horse_race_tmr_handle); noke_drv_horse_race_keyenter_backlight( lights ); f_lights_index++; if( f_lights_index >= sizeof(enter_key_style_array)/sizeof(int) ) { f_lights_index = 0; return; } do{ ret = GPTI_StartItem(horse_race_tmr_handle, horse_race_tmr_repeat, noke_drv_horse_race_keyenter_round_light_on_timer_handler, (void *)(&f_lights_index)); }while( ret== KAL_FALSE ); }
/************************************************************************* * FUNCTION * EINT_LISR * * DESCRIPTION * Entry function of External Interrupt Service Routine * * CALLS * * PARAMETERS * * RETURNS * No return * * GLOBALS AFFECTE * *************************************************************************/ void EINT_LISR(void) { kal_uint8 index; kal_uint16 status; status = *EINT_STATUS; // for conventional external interrupt! for(index=0;index<EINT_MAX_CHANNEL;index++) { if (status & EINT_STATUS_EINT(index)) { GPTI_StopItem(eint_sw_debounce[index].eint_sw_debounce_handle); if ( (eint_sw_debounce[index].eint_intr_allow == KAL_FALSE) && (eint_sw_debounce_time_delay[index] > 0) ) { GPTI_StartItem(eint_sw_debounce[index].eint_sw_debounce_handle, eint_sw_debounce_time_delay[index], EINT_TIMER_CALLBACK, &eint_sw_debounce[index]); EINT_Mask(index); } else { eint_sw_debounce[index].eint_intr_allow = KAL_FALSE; // disable interrupt EINT_Mask(index); ASSERT(EINT_FUNC.eint_func[index]!=NULL); if ( EINT_FUNC.eint_func[index] ) { EINT_FUNC.eint_active[index] = KAL_TRUE; drv_active_hisr(DRV_EINT_HISR_ID); } } *EINT_INTACK = EINT_INTACK_EINT(index); } } // for external interrupt without hardware debounce and always edge sensitive for (index=EINT_MAX_CHANNEL; index<EINT_TOTAL_CHANNEL; index++) { if (status & EINT_STATUS_EINT(index)) { EINT_Mask(index); ASSERT(EINT_FUNC.eint_func[index]!=NULL); if ( EINT_FUNC.eint_func[index] ) { EINT_FUNC.eint_active[index] = KAL_TRUE; drv_active_hisr(DRV_EINT_HISR_ID); } *EINT_INTACK = EINT_INTACK_EINT(index); } } }
/* close USB2UART port */ static void USB2UART_close(UART_PORT port, module_type ownerid) { #ifndef __USB_ENABLE__ ASSERT(0); #endif #ifndef __PRODUCTION_RELEASE__ if(ownerid != USB2UARTPort.ownerid) { EXT_ASSERT( 0, (kal_uint32) ownerid, USB2UARTPort.ownerid, 0); } #endif if(INT_Exception_Enter != 0) { drv_trace1(TRACE_FUNC, USBACM_CLOSE, ownerid); // kal_prompt_trace(MOD_USB, "USB Close %d", ownerid); } g_UsbACM.send_Txilm = KAL_FALSE; g_UsbACM.config_send_Txilm = KAL_FALSE; USB2UARTPort.initialized = KAL_FALSE; USB2UARTPort.ownerid = MOD_DRV_HISR; g_UsbACM.threshold_enable = KAL_FALSE; if ((gUsbDevice.device_type == USB_CDC_ACM)&&(gUsbDevice.nDevState==DEVSTATE_CONFIG)) { /* disable endpoint interrupt */ USB_TxEPDis(g_UsbACM.txpipe->byEP, KAL_TRUE); USB_RxEPDis(g_UsbACM.rxpipe->byEP, KAL_FALSE); } Buf_init(&(USB2UARTPort.Rx_Buffer),(kal_uint8 *)(USB2UARTPort.RingBuffers.rx_buffer), g_UsbACM.acm_param->rx_ringbuff_size); Buf_init(&(USB2UARTPort.Tx_Buffer),(kal_uint8 *)(USB2UARTPort.RingBuffers.tx_buffer), g_UsbACM.acm_param->tx_ringbuff_size); Buf_init(&(USB2UARTPort.Tx_Buffer_ISR),(kal_uint8 *)(USB2UARTPort.RingBuffers.txISR_buffer), g_UsbACM.acm_param->txisr_ringbuff_size); if(g_UsbACM.ring_buffer_timer_counting == KAL_TRUE) { GPTI_StopItem(g_UsbACM.ring_buffer_handle); g_UsbACM.ring_buffer_timer_counting = KAL_FALSE; } USB2UART_ConfigEscape(port, 0xff, 0, MOD_DRV_HISR); }
static void e_compass_enable_driver(kal_bool enable) { if (KAL_TRUE == enable) { e_compass_sensor_custom_fp->ec_take_measurement(); /* we have different GPT timer for different state */ if (E_COMPASS_SENSOR_START_CALI != e_compass_sensor_data.cali_state) GPTI_StartItem(e_compass_sensor_data.sample_handle,e_compass_sensor_custom_dp->normal_sample_dura,e_compass_sample_cb,NULL); else GPTI_StartItem(e_compass_sensor_data.sample_handle,e_compass_sensor_custom_dp->calibration_sample_dura,e_compass_sample_cb,NULL); } else { GPTI_StopItem(e_compass_sensor_data.sample_handle); } }
void Direction_Sensor_state_Filter() { kal_uint8 direction_sensor_tmr_handle = DIRECTION_SENSOR_TMR_HANDLE; kal_uint16 direction_sensor_tmr_repeat = 50; /* 1s = 100ticks, 0.1s = 10ticks */ kal_bool ret = KAL_FALSE; //noke_dbg_printf("\rHongzhe.Liu : Direction_Sensor_state_Filter ... \n"); GPTI_StopItem(direction_sensor_tmr_handle); kal_sleep_task(100); do{ ret = GPTI_StartItem(direction_sensor_tmr_handle, direction_sensor_tmr_repeat, Direct_Sensor_Set_Sensor_State, NULL); //noke_dbg_printf("\rHongzhe.Liu : Direction_Sensor_state_Filter : start ret=%d... \n", ret); }while( ret== KAL_FALSE ); }
/***************************************************************************** * FUNCTION * GMI_Stop * DESCRIPTION * This function is used to stop melody playing. *****************************************************************************/ void GMI_Stop( void ) { int16 I; if( !L1Audio_CheckFlag( gmi.aud_id ) ) return; if( gmi.state == GMI_STATE_IDLE ) return; GPTI_StopItem( gmi.gpt ); QTMF_CONTROL = 0; for( I = 0; I < MAX_DPRAM_BUFFER; I++ ) QTMF_DURA(I) = 0; AM_MelodyOff(); gmi.state = GMI_STATE_IDLE; L1Audio_ClearFlag( gmi.aud_id ); }
/************************************************************************* * FUNCTION * EINT_TIMER_CALLBACK * * DESCRIPTION * This function implements main external interrupt LISR registered in * global ISR jump table. * * CALLS * * PARAMETERS * * RETURNS * No return * * GLOBALS AFFECTED * *************************************************************************/ void EINT_TIMER_CALLBACK(void *data) { EINT_SW_DEBOUNCE_STRUCT *sw_debounce = (EINT_SW_DEBOUNCE_STRUCT *)data; GPTI_StopItem(sw_debounce->eint_sw_debounce_handle); sw_debounce->eint_intr_allow = (sw_debounce->eint_intr_allow == KAL_TRUE)? KAL_FALSE: KAL_TRUE; /* * This timer is to avoid if interrupt status is changed but * sw_debounce->eint_intr_allow is still in KAL_TRUE state * because of no interrupt */ if (sw_debounce->eint_intr_allow) { GPTI_StartItem(sw_debounce->eint_sw_debounce_handle, eint_sw_debounce_time_delay[sw_debounce->eint_no], /*0.5 second*/ EINT_TIMER_CALLBACK, data); } EINT_UnMask(sw_debounce->eint_no); }
/* Disable decode interrupt * @param None. * @return None */ void video_dec_disable_irq(DECODE_TYPE decode_type) { kal_uint32 savedMask; if((decode_type == DECODE_TYPE_MPEG4) || (decode_type == DECODE_TYPE_H263)) { savedMask = SaveAndSetIRQMask(); #ifdef DRV_MP4_V1 IRQMask(IRQ_MPEG4_CODE); #else /*!DRV_MP4_V1*/ IRQMask(IRQ_MPEG4_DEC_CODE); #endif /*DRV_MP4_V1*/ if(g_mpeg4_dec_isr_param.gpt_exception_protect_handle!=0) g_mpeg4_dec_isr_param.b_gpt_active = KAL_FALSE; RestoreIRQMask(savedMask); if(g_mpeg4_dec_isr_param.gpt_exception_protect_handle!=0) GPTI_StopItem(g_mpeg4_dec_isr_param.gpt_exception_protect_handle); //video_dec_stop_av(); video_dec_set_av_callback(NULL); } }
/* open USB2UART port , actually port is no use because only support one USB port */ static kal_bool USB2UART_open(UART_PORT port, module_type owner) { #ifndef __USB_ENABLE__ ASSERT(0); #endif if(g_UsbACM.acm_owner == USB_ACM_OWNER_DSP) { ASSERT(0); } if(g_UsbACM.acm_owner == USB_ACM_OWNER_FT) { #ifdef __USB_DOWNLOAD__ if(gUsbDevice.is_usb_download_mode == KAL_FALSE) ASSERT(0); #else ASSERT(0); #endif } /* It cannot be opened if uart owner did not close it before */ if(USB2UARTPort.ownerid != MOD_DRV_HISR) { return KAL_FALSE; } #ifndef __PRODUCTION_RELEASE__ if(INT_Exception_Enter != 0) { drv_trace0(TRACE_FUNC, USBACM_OPEN); // kal_prompt_trace(MOD_USB, "USB Open"); } #endif /* __PRODUCTION_RELEASE__ */ USB2UARTPort.initialized = KAL_TRUE; USB2UARTPort.ownerid = owner; g_UsbACM.send_Txilm = KAL_FALSE; g_UsbACM.send_Rxilm = KAL_TRUE; if(INT_Exception_Enter != 0) { drv_trace1(TRACE_FUNC, USBACM_OPEN_READY_TO_READ_FLAG, owner); // kal_prompt_trace(MOD_USB, "open RDY R %d", owner); } g_UsbACM.config_send_Txilm = KAL_FALSE; g_UsbACM.threshold_enable = KAL_FALSE; if( (USB2UARTPort.RingBuffers.rx_buffer==NULL) || (USB2UARTPort.RingBuffers.tx_buffer==NULL) || (USB2UARTPort.RingBuffers.txISR_buffer==NULL) ) { EXT_ASSERT(0, (kal_uint32)USB2UARTPort.RingBuffers.rx_buffer, (kal_uint32)USB2UARTPort.RingBuffers.tx_buffer, (kal_uint32)USB2UARTPort.RingBuffers.txISR_buffer); } Buf_init(&(USB2UARTPort.Rx_Buffer),(kal_uint8 *)(USB2UARTPort.RingBuffers.rx_buffer), g_UsbACM.acm_param->rx_ringbuff_size); Buf_init(&(USB2UARTPort.Tx_Buffer),(kal_uint8 *)(USB2UARTPort.RingBuffers.tx_buffer), g_UsbACM.acm_param->tx_ringbuff_size); Buf_init(&(USB2UARTPort.Tx_Buffer_ISR),(kal_uint8 *)(USB2UARTPort.RingBuffers.txISR_buffer), g_UsbACM.acm_param->txisr_ringbuff_size); if(g_UsbACM.ring_buffer_timer_counting == KAL_TRUE) { GPTI_StopItem(g_UsbACM.ring_buffer_handle); g_UsbACM.ring_buffer_timer_counting = KAL_FALSE; } if ((gUsbDevice.device_type == USB_CDC_ACM)&&(gUsbDevice.nDevState==DEVSTATE_CONFIG)) { /* Only out EP needs to be enabled since IN EP will use DMA polling*/ USB_TxEPEn(g_UsbACM.txpipe->byEP, KAL_TRUE); USB_RxEPEn(g_UsbACM.rxpipe->byEP, KAL_FALSE); USB_Set_UnMask_Irq(KAL_TRUE); } return KAL_TRUE; }
/* Determine transmit data If return value is large than 0, the caller should send the data in parameter. This function and "USB2UART_Update_Transmit_Data" function must be pair. */ static kal_uint32 USB2UART_Check_Transmit_Data(kal_uint32* addr, kal_bool b_check) { kal_uint32 length = 0; kal_uint32 savedMask; // g_UsbACM.force_ISR_buffer = KAL_FALSE; if(g_UsbACM.ring_buffer_timer_counting == KAL_TRUE) { GPTI_StopItem(g_UsbACM.ring_buffer_handle); g_UsbACM.ring_buffer_timer_counting = KAL_FALSE; } /* First, check if TX ISR buffer has "enough" data to send out */ /* The data in the ISR TX buffer must be sent out all at one time. Otherwise, the catcher cannot decode the log correctly */ savedMask = SaveAndSetIRQMask(); if (USB2UARTPort.Tx_Buffer_ISR.Write != USB2UARTPort.Tx_Buffer_ISR.Read) { /* used for callback function to know sent source */ USB2Uart_MemType = USBTRX_MEM_ISR; *addr = (kal_uint32)USB2UARTPort.Tx_Buffer_ISR.CharBuffer+USB2UARTPort.Tx_Buffer_ISR.Read; if (USB2UARTPort.Tx_Buffer_ISR.Write >= USB2UARTPort.Tx_Buffer_ISR.Read) { length = USB2UARTPort.Tx_Buffer_ISR.Write - USB2UARTPort.Tx_Buffer_ISR.Read; if(b_check == KAL_TRUE) { if(length <= (g_UsbACM.acm_param->txisr_ringbuff_size/2)) { length = 0; g_UsbACM.ring_buffer_timer_counting = KAL_TRUE; } } } else { /* ISR TX buffer must have data to send out */ length = USB2UARTPort.Tx_Buffer_ISR.Length - USB2UARTPort.Tx_Buffer_ISR.Read; } } /* check if TX buffer has enough data to send out */ if((USB2UARTPort.Tx_Buffer.Write != USB2UARTPort.Tx_Buffer.Read) && (length == 0)) { g_UsbACM.ring_buffer_timer_counting = KAL_FALSE; /* used for callback function to know sent source */ USB2Uart_MemType = USBTRX_MEM_TASK; *addr = (kal_uint32)USB2UARTPort.Tx_Buffer.CharBuffer+USB2UARTPort.Tx_Buffer.Read; if(USB2UARTPort.Tx_Buffer.Write >= USB2UARTPort.Tx_Buffer.Read) { length = USB2UARTPort.Tx_Buffer.Write - USB2UARTPort.Tx_Buffer.Read; #ifndef __L1_STANDALONE__ if(b_check == KAL_TRUE) { if(length <= (g_UsbACM.acm_param->tx_ringbuff_size/2)) { length = 0; g_UsbACM.ring_buffer_timer_counting = KAL_TRUE; } } #endif } else { length = USB2UARTPort.Tx_Buffer.Length - USB2UARTPort.Tx_Buffer.Read; } } RestoreIRQMask(savedMask); if(g_UsbACM.ring_buffer_timer_counting == KAL_TRUE) { USB2Uart_MemType = USBTRX_MEM_UNKOWN; GPTI_StartItem(g_UsbACM.ring_buffer_handle, USBACM_RING_BUFFER_TIMEOUT, USB_Acm_Ring_Buffer_Timeout, NULL); } /* If the packet size is multiple of 64, make the last one to be less than 64. Otherwise the last packet may not be seen on WinXP */ if(((length&0x3f) == 0) && (length != 0)) USB2Uart_WriteLength = length - 1; else USB2Uart_WriteLength = length; return USB2Uart_WriteLength; }
*************************************************************************/ kal_int32 GIF_DecodeNext(void* dest) { kal_uint8 status; kal_uint8 bg_index; kal_uint16 *gct_ptr; DRV_WriteReg32(GIF_GCE_REG,((gif_dcb.gif_info.transparent_index<< 1)| \ (gif_dcb.gif_info.transparent_flag))); DRV_WriteReg32(GIF_ORGB_BASE_ADDR,dest); gif_dcb.is_timeout = KAL_FALSE; GIF_START(); GPTI_StartItem(gif_dcb.gpt_handle, gif_dcb.timeout_period, GIF_TimeOutHandler, NULL); // busy waiting may be replaced by retreive event group while(1) { volatile kal_bool *timeout = &gif_dcb.is_timeout; status = DRV_Reg(GIF_STATUS_REG); // check if gif decoder is completed or not if(status & ~GIF_STATUS_GCE) { GPTI_StopItem(gif_dcb.gpt_handle); gif_dcb.is_timeout = KAL_FALSE; break; } if(*timeout) { status = DRV_Reg(GIF_STATUS_REG); // check if gif decoder is completed or not if(status & ~GIF_STATUS_GCE) { GPTI_StopItem(gif_dcb.gpt_handle); gif_dcb.is_timeout = KAL_FALSE; break; } break; } } // check if the guard pattern still exists GIF_CheckGuardPatternValid(); // retreive gif info and backgroud color GIF_GetInfo(&gif_dcb.gif_info); bg_index = gif_dcb.gif_info.bg; gct_ptr = (kal_uint16*)gif_resource.GCT; if(bg_index < (1 << (gif_dcb.gif_info.GCT_size+1))) { gif_dcb.gif_info.bg_color = gct_ptr[bg_index]; } else { gif_dcb.gif_info.bg_color = 0xFFFF; //dbg_print("!!!!Background index exceed the size of GCT!!!!\r\n"); } if(status & (GIF_STATUS_FINISH_FRMAE |GIF_STATUS_FINISH_FILE)) // one frame { if(status & GIF_STATUS_FINISH_FILE) { //dbg_print("HW file finish!\r\n"); return GIF_LAST_FRAME; } else { //dbg_print("HW frame finish!\r\n"); return GIF_FINISH_FRAME; } } else if(status & GIF_STATUS_END) // truncated gif file { //ASSERT(0); return GIF_TRUNCATED_FILE; } else if(gif_dcb.is_timeout) // hw decoder failed to decode the gif file { //ASSERT(0); return GIF_DECODE_TIMEOUT; } //ASSERT(0); return GIF_FORMAT_ERROR;
/***************************************************************************** * FUNCTION * gmiWriteToDSP * DESCRIPTION * This function is the call-back function of GPT for playing notes. *****************************************************************************/ static void gmiWriteToDSP( void *data ) { GMI_Note *note; uint16 I; uint32 curtime; uint32 note_time; uint32 next_time; uint16 rb_count_org; rb_count_org = RB_Count(); curtime = (uint32)(QTMF_COUNTER - gmi.start_time); next_time = curtime; while( !RB_Empty() ) { note = RB_Peek(); note_time = gmi.note_time + note->delta_time; if( note_time > next_time ) { next_time = note_time; } else if( note_time < curtime ) { RB_Consume(); gmi.note_time = note_time; continue; } /* search for the first available DSP tone */ for( I = 0; I < MAX_DPRAM_BUFFER; I++ ) { #if defined(MT6205) if( QTMF_DURA(I) == 0 && gmi.dsp_time[I] <= note_time ) { #else if( QTMF_DURA(I) == 0 ) { #endif QTMF_FREQ(I) = Pitch2Frequency[ note->pitch ]; QTMF_AMP(I) = (uint16)note->amplitude; QTMF_DURA(I) = note->duration << 4; /* QTMF_DURA(I) = (note->duration << 4) + ((note->timbre >> 3) & 0x0F ); */ QTMF_TIME(I) = (uint16)note_time + gmi.start_time; gmi.dsp_time[I] = note_time + note->duration; if( gmi.end_time < gmi.dsp_time[I] ) gmi.end_time = gmi.dsp_time[I]; RB_Consume(); gmi.note_time = note_time; break; } } if( I == MAX_DPRAM_BUFFER ) break; } switch( gmi.state ) { case GMI_STATE_INIT: QTMF_CONTROL = 3; gmi.state = GMI_STATE_PLAY; break; case GMI_STATE_PLAY: if( rb_count_org >= GMI_RB_SIZE/2 && RB_Count() < GMI_RB_SIZE/2 ) L1Audio_SetEvent( gmi.aud_id, (void*)GMI_NOTE_REQUEST ); if( gmi.eof_flag ) gmi.state = GMI_STATE_DATA_COMPLETE; break; case GMI_STATE_DATA_COMPLETE: if( RB_Empty() ) { GPTI_StartItem( gmi.gpt, (gmi.end_time - curtime + 5) * 2, gmiTerminate, 0 ); return; } break; } if( next_time > curtime ) next_time = next_time - curtime; else next_time = 1; GPTI_StartItem( gmi.gpt, next_time, gmiWriteToDSP, 0 ); } /***************************************************************************** * FUNCTION * GMI_Play * DESCRIPTION * This function is used to start melody playing. * * PARAMETERS * gmi_handler - a call back function used to be notified an event that * the end of a song is reached. *****************************************************************************/ void GMI_Play( void (*gmi_handler)( GMI_Event event ) ) { int16 I; if( L1Audio_CheckFlag( gmi.aud_id ) ) return; if( gmi_handler == 0 ) return; if( gmi.state != GMI_STATE_IDLE ) return; L1Audio_SetFlag( gmi.aud_id ); GPTI_StopItem( gmi.gpt ); for( I = 0; I < MAX_DPRAM_BUFFER; I++ ) { gmi.dsp_time[I] = 0; QTMF_DURA(I) = 0; } gmi.rb_head = 0; gmi.rb_tail = 0; gmi.mmi_time = 0; gmi.start_time = QTMF_COUNTER; gmi.end_time = 0; gmi.state = GMI_STATE_INIT; gmi.note_time = 0; gmi.eof_flag = false; gmi.gmi_handler = gmi_handler; gmi.gmi_handler( GMI_NOTE_REQUEST ); AM_MelodyOn(); gmiWriteToDSP( 0 ); } /* end of gmiPlay */