/***************************************************************************** * FUNCTION * gdi_mutex_unlock * DESCRIPTION * * PARAMETERS * M [?] * RETURNS * void *****************************************************************************/ void gdi_mutex_unlock(gdi_mutex_struct *M) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ U32 save_irq_mask; kal_taskid gdi_current_thread_id = kal_get_current_thread_ID(); /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ if (INT_Exception_Enter) { return; } save_irq_mask = SaveAndSetIRQMask(); if (gdi_current_thread_id != NULL) { GDI_DEBUG_ASSERT(M->tid == gdi_current_thread_id); if (--M->cnt == 0) { M->tid = NULL; } } RestoreIRQMask(save_irq_mask); }
void * RTFAPI RTFSYSGetTLS(int Index) { kal_uint8 task_indx; #ifndef __FS_CARD_DOWNLOAD__ kal_taskid current_task; fs_assert_local(Index < MAX_TLS_INDEX); current_task = kal_get_current_thread_ID(); for (task_indx=0; task_indx<FS_TCT_Index+1; task_indx++) { if (gFS_TaskList[task_indx] == current_task) break; } //fs_assert_local(task_indx != FS_TCT_Index); if(task_indx == FS_TCT_Index+1) { _fs_int_missed_task = current_task; return (void*)FS_TLS_DEFAULT; } #else task_indx = 0; #endif return(void*)gFS_TaskData[ task_indx ][ Index ]; }
/************************************************************************* * FUNCTION * mdci_deinit * * DESCRIPTION * This function de-initializes the logical channel. * * PARAMETERS * channel - logical channel * * RETURNS * MDIF error code. * *************************************************************************/ kal_int32 mdci_deinit(MDCI_CHANNEL_T channel) { kal_uint32 owner, mask; kal_int32 ret; /* error checking */ if (channel >= MDCI_MAX_CHANNEL) return MDCI_INVALID_PARAM; if (kal_if_lisr()) return MDCI_IN_LISR; /* get the current task */ owner = (kal_uint32)kal_get_current_thread_ID(); /* check owner */ if (mdci_ctrl_pool[channel].owner != owner) { return MDCI_NOT_OWNER; } ret = MDCI_SUCCESS; /* check state */ mask = SaveAndSetIRQMask(); if (mdci_ctrl_pool[channel].state != MDCI_IDLE) { ret = MDCI_IN_USE; } else { /* free the channel */ mdci_ctrl_pool[channel].owner = 0; } RestoreIRQMask(mask); return ret; }
void L1sim_PowerOff_All(SIM_ICC_APPLICATION application) { sim_ctrlDriver *simDriver; kal_uint32 simInterface; sim_HW_cb *hw_cb; simInterface = sim_get_logicalNum_from_app(application); hw_cb = (sim_HW_cb *)(hwCbArray[simInterface]); #if defined (LPWR_SLIM) L1SM_SleepDisable(hw_cb->smHandler); //lock sleep mode #endif if(DRV_SIM_MAX_LOGICAL_INTERFACE <= simInterface) ASSERT(0); if(KAL_TRUE == sim_physicalSlotChanged) simInterface = 1-simInterface; /*find out the hooked function table*/ simDriver = sim_driverTable[simInterface]; ASSERT(0 != simDriver); simDriver->addMessage(SIM_AL_ACTION_POWOFF, simInterface, (kal_uint32)kal_get_current_thread_ID(), 0); simDriver->powerOff((sim_HW_cb *)(hwCbArray[simInterface])); simDriver->addMessage(SIM_AL_ACTION_EOC, simInterface, 0, 0); simDriver->EOC((sim_HW_cb *)(hwCbArray[simInterface])); #if defined (LPWR_SLIM) L1SM_SleepEnable(hw_cb->smHandler); //unlock sleep mode #endif }
/************************************************************************* * FUNCTION * RTFSYSLockMutex * * DESCRIPTION * This function implements to take mutex during dedicated time period * * PARAMETERS * * RETURNS * * GLOBALS AFFECTED * *************************************************************************/ int RTFAPI RTFSYSLockMutex(RTFMutex * Mutex, UINT Timeout) { /* XXX!!!. Timeout lock is not support by Nucleus Plus =>wrong*/ kal_uint32 lr; kal_taskid current_task; int ret_val = RTF_NO_ERROR; FS_GET_RETURN_ADDRESS(lr); #ifdef __P_PROPRIETARY_COPYRIGHT__ /* under construction !*/ /* under construction !*/ #endif current_task = kal_get_current_thread_ID(); // task not ready if (current_task == KAL_NILTASK_ID) return RTF_NO_ERROR; /* * Bypass all FS lock operations in exception mode to avoid unexpected suspend behavior. (W10.37) * * NOTE 1. If a "HISR" triggers an exception, bypass lock operation to avoid another fatal error * because only "task" can get semaphore (kal_take_sem) successfully. * * NOTE 2. HISR should NOT use FS in normal mode. It only walks here when an exception is triggerred in HISR. */ else if (INT_QueryExceptionStatus() == KAL_TRUE) return RTF_NO_ERROR; if (Mutex->rtf_sem_owner == current_task) { Mutex->rtf_lock_count++; return (ret_val); } #if defined(__AUDIO_DSP_LOWPOWER__) AUDMA_LOCK(AUDMA_ID_FS); #endif ret_val = ((kal_take_sem(Mutex->rtf_sem, (kal_wait_mode)Timeout) == KAL_SUCCESS) ? RTF_NO_ERROR : MT_LOCK_MUTEX_FAIL); if (ret_val != RTF_NO_ERROR) { #if defined(__AUDIO_DSP_LOWPOWER__) AUDMA_UNLOCK(AUDMA_ID_FS); #endif return ret_val; } /* Update owner and lock count */ Mutex->rtf_sem_owner = current_task; Mutex->rtf_sem_owner_lr = lr; Mutex->rtf_lock_count = 1; return (ret_val); }
BOOL gdi_fast_mutex_is_owner(void) { BOOL ret; U32 save_irq_mask; save_irq_mask = SaveAndSetIRQMask(); ret = (gdi_mutex.tid == kal_get_current_thread_ID()); RestoreIRQMask(save_irq_mask); return ret; }
/************************************************************************* * FUNCTION * mdci_init * * DESCRIPTION * This function initializes the logical channel. * * PARAMETERS * channel - logical channel * funp - ISR callback function * * RETURNS * MDIF error code. * *************************************************************************/ kal_int32 mdci_init(MDCI_CHANNEL_T channel, MDCI_CALLBACK funp) { kal_taskid task; /* get the current task */ task = kal_get_current_thread_ID(); return mdci_owner_init(channel, task, funp); }
/************************************************************************* * FUNCTION * RTFSYSOwnMutex * * DESCRIPTION * This function implements to get filesystem mutex * * PARAMETERS * * RETURNS * * GLOBALS AFFECTED * *************************************************************************/ int RTFAPI RTFSYSOwnMutex(RTFMutex * Mutex) { kal_taskid current_task; current_task = kal_get_current_thread_ID(); if (Mutex->rtf_sem_owner == current_task) return (int)(KAL_TRUE); else return (int)(KAL_FALSE); }
/************************************************************************* * FUNCTION * DclSD_Initialize * * DESCRIPTION * This function is to get SD DCL handler. * * PARAMETERS * eDev - only valid for DCL_SD. * flags -following bit stand for specific meaning. * DCL_SD_FLAGS_CARD1: to get a handle for card 1 * DCL_SD_FLAGS_CARD2: to get a handle for card 2 * DCL_SD_FLAGS_SIMPLUS: to get a handle for sim plus * Other values are prohibited * RETURNS * DCL_HANDLE_INVALID - Open failed. * other value - a valid handle * *************************************************************************/ DCL_HANDLE DclSIM_Open(DCL_DEV dev, DCL_FLAGS flags) { kal_uint32 retAddr = 0; kal_uint32 thdId; kal_uint32 loopIndex; if (dev != DCL_SIM) { ASSERT(0); return DCL_HANDLE_INVALID; } #if defined(__RVCT__) /* RVCT doesn't support inline assemlber; bypass temporarily */ retAddr = 0; #elif defined(__GCC__) /* GCC has function to support this */ retAddr = (kal_uint32) __builtin_return_address (0); #else /* __RVCT__ */ /* GCC has function to support this */ retAddr = (kal_uint32) __builtin_return_address (0); // /* get the return address */ // __asm { // MOV retAddr,lr // } #endif /* __RVCT__ */ thdId = (kal_uint32)kal_get_current_thread_ID(); /* In SIM DCL open, we only mark control block as assigned and return handle to user. We don't support one resource used by multiple applications, so the control block will be not re-assigned. Every time this function is called, we just find an unused control block, mark it assigned, and return the handle. */ kal_take_sem(dclSimArb, KAL_INFINITE_WAIT); for(loopIndex = 0; DCL_SIM_MAX_INTERFACE > loopIndex; loopIndex ++) { if (KAL_FALSE == simResource[loopIndex].assigned) { simResource[loopIndex].assigned = KAL_TRUE; simResource[loopIndex].thdId = thdId; simResource[loopIndex].allocatedPoint = retAddr; kal_give_sem(dclSimArb); return (DCL_HANDLE)(&simResource[loopIndex]); } } kal_give_sem(dclSimArb); return DCL_HANDLE_NONE; }
/************************************************************************* * FUNCTION * RTFSYSFreeMutex * * DESCRIPTION * This function implements to release filesystem mutex * * PARAMETERS * * RETURNS * * GLOBALS AFFECTED * *************************************************************************/ void RTFAPI RTFSYSFreeMutex(RTFMutex * Mutex) { kal_taskid current_task; #ifdef __P_PROPRIETARY_COPYRIGHT__ /* under construction !*/ /* under construction !*/ #endif current_task = kal_get_current_thread_ID(); // task not ready if(current_task == KAL_NILTASK_ID) return; /* * Bypass all FS lock operations in exception mode to avoid unexpected suspend behavior. (W10.37) * * NOTE 1. If a "HISR" triggers an exception, bypass lock operation to avoid another fatal error * because only "task" can get semaphore (kal_take_sem) successfully. * * NOTE 2. HISR should NOT use FS in normal mode. It only walks here when an exception is triggerred in HISR. */ else if (INT_QueryExceptionStatus() == KAL_TRUE) return; #ifndef WIN32 if (INT_QueryExceptionStatus() == KAL_FALSE) /* Should only be possible for exception cases */ fs_assert_local(Mutex->rtf_sem_owner == current_task); #else fs_assert_local(Mutex->rtf_sem_owner == current_task); #endif Mutex->rtf_lock_count--; if (Mutex->rtf_lock_count == 0) { Mutex->rtf_sem_owner = KAL_NILTASK_ID; /* Solve MMI hang for waiting lock, Karen Hsu, 2004/04/23, ADD START */ Mutex->DeviceNum_1 = 0; Mutex->DeviceNum_2 = 0; /* Solve MMI hang for waiting lock, Karen Hsu, 2004/04/23, ADD END */ kal_give_sem(Mutex->rtf_sem); #if defined(__AUDIO_DSP_LOWPOWER__) AUDMA_UNLOCK(AUDMA_ID_FS); #endif } }
/************************************************************************* * FUNCTION * stack_config * * DESCRIPTION * This function implements to config Protocol Stack's configuration * * PARAMETERS * * RETURNS * * GLOBALS AFFECTED * *************************************************************************/ void RTFAPI RTFSYSSetTLS(int Index, void * Value) { kal_uint8 task_indx; #ifndef __FS_CARD_DOWNLOAD__ kal_taskid current_task; fs_assert_local(Index <= FS_TLS_Index); current_task = kal_get_current_thread_ID(); /* Find current task id is registered or not */ for (task_indx=0; task_indx<FS_TCT_Index+1; task_indx++) { if (gFS_TaskList[task_indx] == current_task) break; } /* Not found */ if (task_indx == FS_TCT_Index+1) { if (FS_TCT_Index >= FS_MAX_THREAD) { fs_err_internal_fatal(FS_ERR_TLS_02, (void*)FS_MAX_THREAD); return; } /* Register current task id as new one */ gFS_TaskList[FS_TCT_Index] = current_task; gFS_TaskData[FS_TCT_Index][Index] = (_XData*)Value; FS_TCT_Index++; return; } #else task_indx = 0; #endif gFS_TaskData[task_indx][Index] = (_XData*)Value; return; }
sim_status L1sim_Cmd_All(kal_uint8 *txData,kal_uint32 *txSize,kal_uint8 *rxData, kal_uint32 *rxSize, SIM_ICC_APPLICATION application) { sim_ctrlDriver *simDriver; sim_status status; kal_uint32 simInterface; sim_HW_cb *hw_cb; simInterface = sim_get_logicalNum_from_app(application); hw_cb = (sim_HW_cb *)(hwCbArray[simInterface]); #if defined (LPWR_SLIM) L1SM_SleepDisable(hw_cb->smHandler); //lock sleep mode #endif if(DRV_SIM_MAX_LOGICAL_INTERFACE <= simInterface) ASSERT(0); if(KAL_TRUE == sim_physicalSlotChanged) simInterface = 1-simInterface; if(0x0 == txData || 0x0 == txSize || 0x0 == rxSize) ASSERT(0); /*find out the hooked function table*/ simDriver = sim_driverTable[simInterface]; ASSERT(0 != simDriver); simDriver->addMessage(SIM_AL_ACTION_COMMAND, simInterface, (kal_uint32)kal_get_current_thread_ID(), 0); status = simDriver->command(txData, txSize, rxData, rxSize, (sim_HW_cb *)(hwCbArray[simInterface])); simDriver->addMessage(SIM_AL_ACTION_EOC, simInterface, 0, 0); simDriver->EOC((sim_HW_cb *)(hwCbArray[simInterface])); #if defined (LPWR_SLIM) L1SM_SleepEnable(hw_cb->smHandler); //unlock sleep mode #endif return status; }
kal_uint8 RTFAPI RTFSYSGetTaskIndex() { #ifndef __FS_CARD_DOWNLOAD__ kal_uint8 task_indx; kal_taskid current_task; current_task = kal_get_current_thread_ID(); for (task_indx = 0; task_indx <= FS_TCT_Index; task_indx++) if (gFS_TaskList[task_indx] == current_task) return task_indx; if (FS_TCT_Index >= FS_MAX_THREAD) { fs_err_internal_fatal(FS_ERR_TLS_02, (void*)FS_MAX_THREAD); } // Register current task id as new one gFS_TaskList[FS_TCT_Index++] = current_task; return (FS_TCT_Index - 1); #else return 0; #endif }
/***************************************************************************** * FUNCTION * gdi_fast_mutex_unlock * DESCRIPTION * * PARAMETERS * void * RETURNS * void *****************************************************************************/ void gdi_fast_mutex_unlock(void) { kal_taskid gdi_current_thread_id; U32 save_irq_mask; /* kal_taskid gdi_current_thread_id = kal_get_current_thread_ID(); */ if (INT_Exception_Enter) return; save_irq_mask = SaveAndSetIRQMask(); gdi_current_thread_id = kal_get_current_thread_ID(); if (gdi_current_thread_id != NULL) { GDI_DEBUG_ASSERT(gdi_mutex.tid == gdi_current_thread_id); if (--gdi_mutex.cnt == 0) { gdi_mutex.tid = NULL; } } RestoreIRQMask(save_irq_mask); }
kal_int32 idp_add_traced_begin(IdpTracedAPI const api) { kal_uint32 savedMask; kal_int32 my_idx; #if defined(ENABLE_LOGGING_FOR_IS_BUSY) kal_int32 my_idx_minus_1; kal_int32 my_idx_minus_2; #endif #if !defined(ENABLE_LOGGING_FOR_IS_BUSY) switch (api) { case IDP_TRACED_API_camera_preview_IS_BUSY: case IDP_TRACED_API_camera_preview_with_face_detection_IS_BUSY: case IDP_TRACED_API_camera_capture_to_jpeg_IS_BUSY: case IDP_TRACED_API_camera_capture_to_mem_IS_BUSY: case IDP_TRACED_API_camera_capture_to_barcode_IS_BUSY: case IDP_TRACED_API_jpeg_decode_IS_BUSY: case IDP_TRACED_API_jpeg_encode_IS_BUSY: case IDP_TRACED_API_jpeg_resize_IS_BUSY: case IDP_TRACED_API_image_resize_IS_BUSY: case IDP_TRACED_API_rgb2yuv_IS_BUSY: case IDP_TRACED_API_video_editor_decode_IS_BUSY: case IDP_TRACED_API_video_editor_encode_IS_BUSY: case IDP_TRACED_API_video_decode_IS_BUSY: case IDP_TRACED_API_video_encode_IS_BUSY: case IDP_TRACED_API_webcam_IS_BUSY: case IDP_TRACED_API_video_call_decode_IS_BUSY: case IDP_TRACED_API_video_call_encode_IS_BUSY: case IDP_TRACED_API_simple_display_with_rotate_IS_BUSY: case IDP_TRACED_API_image_effect_pixel_IS_BUSY: return -1; //break; default: break; } #endif savedMask = SaveAndSetIRQMask(); { my_idx = g_idp_traced_curr_idx; #if defined(ENABLE_LOGGING_FOR_IS_BUSY) // I don't want the same xxx_IS_BUSY fill out of my // g_idp_traced space. switch (my_idx) { case 0: my_idx_minus_1 = (IDP_TRACED_BUFFER_SIZE - 1); my_idx_minus_2 = (IDP_TRACED_BUFFER_SIZE - 2); break; case 1: my_idx_minus_1 = 0; my_idx_minus_2 = (IDP_TRACED_BUFFER_SIZE - 1); break; default: my_idx_minus_1 = (my_idx - 1); my_idx_minus_2 = (my_idx - 2); break; } switch (api) { case IDP_TRACED_API_camera_preview_IS_BUSY: case IDP_TRACED_API_camera_preview_with_face_detection_IS_BUSY: case IDP_TRACED_API_camera_capture_to_jpeg_IS_BUSY: case IDP_TRACED_API_camera_capture_to_mem_IS_BUSY: case IDP_TRACED_API_camera_capture_to_barcode_IS_BUSY: case IDP_TRACED_API_camera_capture_to_ybuffer_IS_BUSY: case IDP_TRACED_API_jpeg_decode_IS_BUSY: case IDP_TRACED_API_jpeg_encode_IS_BUSY: case IDP_TRACED_API_jpeg_resize_IS_BUSY: case IDP_TRACED_API_image_resize_IS_BUSY: case IDP_TRACED_API_rgb2yuv_IS_BUSY: case IDP_TRACED_API_video_editor_decode_IS_BUSY: case IDP_TRACED_API_video_editor_encode_IS_BUSY: case IDP_TRACED_API_video_decode_IS_BUSY: case IDP_TRACED_API_video_encode_IS_BUSY: case IDP_TRACED_API_webcam_IS_BUSY: case IDP_TRACED_API_video_call_decode_IS_BUSY: case IDP_TRACED_API_video_call_encode_IS_BUSY: case IDP_TRACED_API_simple_display_with_rotate_IS_BUSY: case IDP_TRACED_API_image_effect_pixel_IS_BUSY: if ((api == g_idp_traced[my_idx_minus_1].m_api) && (api == g_idp_traced[my_idx_minus_2].m_api)) { RestoreIRQMask(savedMask); return my_idx_minus_1; } break; default: break; } #endif ++g_idp_traced_curr_idx; g_idp_traced_curr_idx &= (IDP_TRACED_BUFFER_SIZE - 1); } RestoreIRQMask(savedMask); g_idp_traced[my_idx].m_api = api; g_idp_traced[my_idx].m_who = kal_get_current_thread_ID(); if (kal_if_hisr()) { g_idp_traced[my_idx].m_call_by_which_level = IDP_CALL_BY_HISR; } else if (kal_if_lisr()) { g_idp_traced[my_idx].m_call_by_which_level = IDP_CALL_BY_LISR; } else { g_idp_traced[my_idx].m_call_by_which_level = IDP_CALL_BY_TASK; } g_idp_traced[my_idx].m_done = KAL_FALSE; g_idp_traced[my_idx].m_start_time_drv = drv_get_current_time(); return my_idx; }
usim_status_enum L1sim_Reset_All(sim_power_enum ExpectVolt, sim_power_enum *ResultVolt, kal_bool warm, SIM_ICC_APPLICATION application) { sim_ctrlDriver *simDriver; usim_status_enum status; kal_uint32 simInterface; #ifdef __SIM_HOT_SWAP_SUPPORT__ kal_int32 ipcStatus; #if defined (__MD1__) || defined (__SIM_HOT_PLUG_SINGLE_MD_QUERY_STR__) kal_uint8 *query, querystring[25] = "MD1_SIM1_HOT_PLUG_EINT"; #elif defined (__MD2__) kal_uint8 *query, querystring[25] = "MD2_SIM1_HOT_PLUG_EINT"; #else kal_uint8 *query, querystring[20] = "SIM1_HOT_PLUG_EINT"; #endif SIM_ICC_HOT_PLUG iccHotPlug = {KAL_FALSE, KAL_FALSE, KAL_FALSE, 0, 0, 0, 0, 0, 0, NULL, NULL}; query = &querystring[0]; #endif #ifdef SIM_4_CARD_SMT_TEST SIM_ICC_APPLICATION anotherApplication; kal_uint32 anotherSimInterface; sim_power_enum anotherResultVolt; sim_ctrlDriver *anotherSimDriver; usim_status_enum anotherStatus; #endif sim_HW_cb *hw_cb; simInterface = sim_get_logicalNum_from_app(application); hw_cb = (sim_HW_cb *)(hwCbArray[simInterface]); #ifdef SIM_4_CARD_SMT_TEST if(SIM_ICC_APPLICATION_PHONE1 == application) anotherApplication = SIM_ICC_APPLICATION_PHONE3; else if(SIM_ICC_APPLICATION_PHONE2 == application) anotherApplication = SIM_ICC_APPLICATION_PHONE4; else ASSERT(0); anotherSimInterface = sim_get_logicalNum_from_app(anotherApplication); #endif if(DRV_SIM_MAX_LOGICAL_INTERFACE <= simInterface) ASSERT(0); #ifdef SIM_4_CARD_SMT_TEST if(DRV_SIM_MAX_LOGICAL_INTERFACE <= anotherSimInterface) ASSERT(0); #endif if(KAL_TRUE == sim_physicalSlotChanged){ #if !defined( __MAUI_BASIC__) tst_sys_trace("[SIM]:sim interface inversed!!"); #else dbg_print("[SIM]:sim interface inversed!!"); #endif simInterface = 1-simInterface; application = 1-application; // need to switch to get correct hwcb and SIMIF number } if(0x0 == ResultVolt) ASSERT(0); #if defined (LPWR_SLIM) L1SM_SleepDisable(hw_cb->smHandler); //lock sleep mode #endif #ifdef __CUSTOMER_HW_VERIFICATION__ simInterface = 0; /*find out the hooked function table*/ simDriver = sim_driverTable[simInterface]; ASSERT(0 != simDriver); sim_MT6302_addMsg(SIM_MT6302_ACTION_RESET, simInterface, 0, 0); status = simDriver->reset(ExpectVolt, ResultVolt, warm, (sim_HW_cb *)(hwCbArray[simInterface])); sim_MT6302_addMsg(SIM_MT6302_ACTION_EOC, simInterface, drv_get_current_time(), 0); simDriver->EOC((sim_HW_cb *)(hwCbArray[simInterface])); simInterface = 1; /*find out the hooked function table*/ simDriver = sim_driverTable[simInterface]; ASSERT(0 != simDriver); sim_MT6302_addMsg(SIM_MT6302_ACTION_RESET, simInterface, 0, 0); /*when we release single SIM MMI, we only release SIM1 MMI, cusrtomer won't get SIM2 MMI, SIM1 is what MMI need*/ //status = simDriver->reset(ExpectVolt, ResultVolt, warm, simInterface); sim_MT6302_addMsg(SIM_MT6302_ACTION_EOC, simInterface, drv_get_current_time(), 0); simDriver->EOC(simInterface); #else /*find out the hooked function table*/ simDriver = sim_driverTable[simInterface]; ASSERT(0 != simDriver); simDriver->addMessage(SIM_AL_ACTION_RESET, simInterface, (kal_uint32)kal_get_current_thread_ID(), 0); status = simDriver->reset(ExpectVolt, ResultVolt, warm, (sim_HW_cb *)(hwCbArray[simInterface])); #ifdef __SIM_HOT_SWAP_SUPPORT__ /* we should always register eint. If we bootup without plugin simcard, status will display NO_CARD. we will never get insert event because eint is not registered */ #if defined (__MD1__) || defined (__SIM_HOT_PLUG_SINGLE_MD_QUERY_STR__) if (application == SIM_ICC_APPLICATION_PHONE2) query = (kal_uint8 *)"MD1_SIM2_HOT_PLUG_EINT"; #elif defined (__MD2__) if (application == SIM_ICC_APPLICATION_PHONE2) query = (kal_uint8 *)"MD2_SIM2_HOT_PLUG_EINT"; #else if (application == SIM_ICC_APPLICATION_PHONE2) query = (kal_uint8 *)"SIM2_HOT_PLUG_EINT"; #endif /* if any rpc error happens, we should leave register eint */ #if defined (__MD1__) || defined (__MD2__) || defined (__SIM_HOT_PLUG_SINGLE_MD_QUERY_STR__) ipcStatus = IPC_RPC_EINT_GetAttribute(query, 23, SIM_HOT_PLUG_EINT_NUMBER, (void *)&iccHotPlug.eintNo, 4); #else ipcStatus = IPC_RPC_EINT_GetAttribute(query, 19, SIM_HOT_PLUG_EINT_NUMBER, (void *)&iccHotPlug.eintNo, 4); #endif if (ipcStatus < 0) { kal_sprintf(sim_dbg_str,"get eint no fail %d %d, please request HW to check ALPS DWS setting.", ipcStatus, iccHotPlug.eintNo); #if !defined( __MAUI_BASIC__) tst_sys_trace(sim_dbg_str); #else dbg_print(sim_dbg_str); #endif goto LEAVE_REG_EINT; } #if defined (__MD1__) || defined (__MD2__) || defined (__SIM_HOT_PLUG_SINGLE_MD_QUERY_STR__) ipcStatus = IPC_RPC_EINT_GetAttribute(query, 23, SIM_HOT_PLUG_EINT_DEBOUNCETIME, (void *)&iccHotPlug.debounceTime, 4); #else ipcStatus = IPC_RPC_EINT_GetAttribute(query, 19, SIM_HOT_PLUG_EINT_DEBOUNCETIME, (void *)&iccHotPlug.debounceTime, 4); #endif if (ipcStatus < 0) { kal_sprintf(sim_dbg_str,"get debounce fail %d %d, please request HW to check ALPS DWS setting.", ipcStatus, iccHotPlug.debounceTime); #if !defined( __MAUI_BASIC__) tst_sys_trace(sim_dbg_str); #else dbg_print(sim_dbg_str); #endif goto LEAVE_REG_EINT; } #if defined (__MD1__) || defined (__MD2__) || defined (__SIM_HOT_PLUG_SINGLE_MD_QUERY_STR__) ipcStatus = IPC_RPC_EINT_GetAttribute(query, 23, SIM_HOT_PLUG_EINT_POLARITY, (void *)&iccHotPlug.polarity, 4); #else ipcStatus = IPC_RPC_EINT_GetAttribute(query, 19, SIM_HOT_PLUG_EINT_POLARITY, (void *)&iccHotPlug.polarity, 4); #endif if (ipcStatus < 0) { kal_sprintf(sim_dbg_str,"get polarity fail %d %d, please request HW to check ALPS DWS setting.", ipcStatus, iccHotPlug.polarity); #if !defined( __MAUI_BASIC__) tst_sys_trace(sim_dbg_str); #else dbg_print(sim_dbg_str); #endif goto LEAVE_REG_EINT; } #if defined (__MD1__) || defined (__MD2__) || defined (__SIM_HOT_PLUG_SINGLE_MD_QUERY_STR__) ipcStatus = IPC_RPC_EINT_GetAttribute(query, 23, SIM_HOT_PLUG_EINT_SENSITIVITY, (void *)&iccHotPlug.sensitivity, 4); #else ipcStatus = IPC_RPC_EINT_GetAttribute(query, 19, SIM_HOT_PLUG_EINT_SENSITIVITY, (void *)&iccHotPlug.sensitivity, 4); #endif if (ipcStatus < 0) { kal_sprintf(sim_dbg_str,"get sensitivity fail %d %d, please request HW to check ALPS DWS setting.", ipcStatus, iccHotPlug.sensitivity); #if !defined( __MAUI_BASIC__) tst_sys_trace(sim_dbg_str); #else dbg_print(sim_dbg_str); #endif goto LEAVE_REG_EINT; } #if defined (__MD1__) || defined (__MD2__) || defined (__SIM_HOT_PLUG_SINGLE_MD_QUERY_STR__) ipcStatus = IPC_RPC_EINT_GetAttribute(query, 23, SIM_HOT_PLUG_EINT_SOCKETTYPE, (void *)&iccHotPlug.socketType, 4); #else ipcStatus = IPC_RPC_EINT_GetAttribute(query, 19, SIM_HOT_PLUG_EINT_SOCKETTYPE, (void *)&iccHotPlug.socketType, 4); #endif if (ipcStatus < 0) { kal_sprintf(sim_dbg_str,"get socket fail %d %d, please request HW to check ALPS DWS setting.", ipcStatus, iccHotPlug.socketType); #if !defined( __MAUI_BASIC__) tst_sys_trace(sim_dbg_str); #else dbg_print(sim_dbg_str); #endif goto LEAVE_REG_EINT; } sim_reg_hot_plug_eint(application, iccHotPlug.eintNo, iccHotPlug.debounceTime, iccHotPlug.polarity, iccHotPlug.sensitivity, iccHotPlug.socketType); LEAVE_REG_EINT: kal_sprintf(sim_dbg_str,"[SIM_DRV]EINT: %d, %d %d %d %d %d %d", application, ipcStatus, iccHotPlug.eintNo, iccHotPlug.debounceTime, iccHotPlug.polarity, iccHotPlug.sensitivity, iccHotPlug.socketType); #if !defined( __MAUI_BASIC__) tst_sys_trace(sim_dbg_str); #else dbg_print(sim_dbg_str); #endif kal_sprintf(sim_dbg_str,"[SIM_DRV]EINT: %s", query); #if !defined( __MAUI_BASIC__) tst_sys_trace(sim_dbg_str); #else dbg_print(sim_dbg_str); #endif #endif /* End of #ifdef __SIM_HOT_SWAP_SUPPORT__ */ simDriver->addMessage(SIM_AL_ACTION_EOC, simInterface, 0, 0); simDriver->EOC((sim_HW_cb *)(hwCbArray[simInterface])); #ifdef SIM_4_CARD_SMT_TEST /*find out the hooked function table*/ anotherSimDriver = sim_driverTable[anotherSimInterface]; ASSERT(0 != anotherSimDriver); anotherSimDriver->addMessage(SIM_AL_ACTION_RESET, anotherSimInterface, (kal_uint32)kal_get_current_thread_ID(), 0); anotherStatus = anotherSimDriver->reset(UNKNOWN_POWER_CLASS, &anotherResultVolt, warm, (sim_HW_cb *)(hwCbArray[anotherSimInterface])); if(USIM_NO_ERROR == anotherStatus) { #if !defined( __MAUI_BASIC__) tst_sys_trace("another SIM card found!!"); #else dbg_print("another SIM card found!!"); #endif } else { #if !defined( __MAUI_BASIC__) tst_sys_trace("another SIM card not found!!"); #else dbg_print("another SIM card not found!!"); #endif } anotherSimDriver->addMessage(SIM_AL_ACTION_EOC, anotherSimInterface, 0, 0); anotherSimDriver->EOC((sim_HW_cb *)(hwCbArray[anotherSimInterface])); #endif #endif #if defined (LPWR_SLIM) L1SM_SleepEnable(hw_cb->smHandler); //unlock sleep mode #endif return status; }
/***************************************************************************** * FUNCTION * gdi_mutex_lock * DESCRIPTION * * PARAMETERS * M [?] * RETURNS * void *****************************************************************************/ void gdi_mutex_lock(gdi_mutex_struct *M) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ U32 save_irq_mask; kal_taskid gdi_current_thread_id = kal_get_current_thread_ID(); /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ if (INT_Exception_Enter) { return; } if (gdi_current_thread_id == NULL) { #if 0 /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ #endif /* DEMO_PROJECT */ return; } if (gdi_current_thread_id != M->tid) { /* wait gdi mutex free */ while (1) { save_irq_mask = SaveAndSetIRQMask(); if (M->cnt == 0) { M->cnt = 1; RestoreIRQMask(save_irq_mask); break; } RestoreIRQMask(save_irq_mask); kal_sleep_task(1); /* waiting */ } /* get gdi mutex */ M->tid = gdi_current_thread_id; gdi_mutex_serial++; #ifdef GDI_MUTEX_DEBUG_DUMP_STACK /* Store Stack Status when gdi mutex lock */ INT_ExceptionDumpStack(gdi_mutex_stack_backup, (long*)gdi_current_thread_id); #endif /* GDI_MUTEX_DEBUG */ } else { save_irq_mask = SaveAndSetIRQMask(); ++(M->cnt); RestoreIRQMask(save_irq_mask); } }
/***************************************************************************** * FUNCTION * gdi_fast_mutex_lock * DESCRIPTION * * PARAMETERS * void * RETURNS * void *****************************************************************************/ void gdi_fast_mutex_lock(void) { kal_taskid gdi_current_thread_id; U32 save_irq_mask; #ifdef DEMO_PROJECT GDI_ASSERT(gdi_mutex.front_guard == GDI_MUTEX_GUARD_PATTERN); GDI_ASSERT(gdi_mutex.rear_guard == GDI_MUTEX_GUARD_PATTERN); #endif /* DEMO_PROJECT */ if (INT_Exception_Enter) return; #if 0 /* under construction !*/ /* under construction !*/ #if 0 /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ #endif /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ #ifdef GDI_MUTEX_DEBUG_DUMP_STACK /* under construction !*/ /* under construction !*/ #endif // GDI_MUTEX_DEBUG /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ #endif /* 0 */ save_irq_mask = SaveAndSetIRQMask(); if ((gdi_current_thread_id = kal_get_current_thread_ID()) != NULL) { if (gdi_current_thread_id != gdi_mutex.tid) { if(gdi_mutex.tid == gdc_thread_id) // Is current GDI user GDC task ( non-blocking task ) ? if(!gdi_nb_is_high_priority()) // Should we wait non-blocking finish ? gdi_image_set_abort(TRUE); // Force abort non-blocking job /* wait gdi mutex free */ while (gdi_mutex.cnt) { RestoreIRQMask(save_irq_mask); kal_sleep_task(1); /* waiting */ save_irq_mask = SaveAndSetIRQMask(); } gdi_mutex.cnt = 1; gdi_mutex.tid = gdi_current_thread_id; gdi_mutex_serial++; gdi_image_set_abort(FALSE); // disable force abort, because we had got the mutex #ifdef GDI_MUTEX_DEBUG_DUMP_STACK //Store Stack Status when gdi mutex lock INT_ExceptionDumpStack(gdi_mutex_stack_backup,(long*)gdi_current_thread_id); #endif // GDI_MUTEX_DEBUG } else { ++(gdi_mutex.cnt); } } RestoreIRQMask(save_irq_mask); }
sim_status L1sim_Cmd_All(kal_uint8 *txData,kal_uint32 *txSize,kal_uint8 *rxData, kal_uint32 *rxSize, SIM_ICC_APPLICATION application) { sim_ctrlDriver *simDriver; sim_status status; kal_uint32 simInterface; sim_HW_cb *hw_cb; #if defined(__SIM_HOT_SWAP_POLL_TIMER__) && defined(__SIM_HOT_SWAP_SUPPORT__) Sim_Card *SimCard; usim_dcb_struct *usim_dcb; #endif simInterface = sim_get_logicalNum_from_app(application); hw_cb = (sim_HW_cb *)(hwCbArray[simInterface]); #if defined (LPWR_SLIM) L1SM_SleepDisable(hw_cb->smHandler); //lock sleep mode #endif if(DRV_SIM_MAX_LOGICAL_INTERFACE <= simInterface) ASSERT(0); if(KAL_TRUE == sim_physicalSlotChanged) simInterface = 1-simInterface; if(0x0 == txData || 0x0 == txSize || 0x0 == rxSize) ASSERT(0); /*find out the hooked function table*/ simDriver = sim_driverTable[simInterface]; ASSERT(0 != simDriver); simDriver->addMessage(SIM_AL_ACTION_COMMAND, simInterface, (kal_uint32)kal_get_current_thread_ID(), 0); status = simDriver->command(txData, txSize, rxData, rxSize, (sim_HW_cb *)(hwCbArray[simInterface])); simDriver->addMessage(SIM_AL_ACTION_EOC, simInterface, 0, 0); simDriver->EOC((sim_HW_cb *)(hwCbArray[simInterface])); #if defined (LPWR_SLIM) L1SM_SleepEnable(hw_cb->smHandler); //unlock sleep mode #endif #if defined(__SIM_HOT_SWAP_POLL_TIMER__) && defined(__SIM_HOT_SWAP_SUPPORT__) SimCard = GET_SIM_CB(hw_cb->simInterface); usim_dcb = GET_USIM_CB(hw_cb->simInterface); if(SimCard->poll_sim_2s || usim_dcb->poll_sim_2s) { sim_hot_swap_poll_timer_rollback(application); SimCard->poll_sim_2s = KAL_FALSE; usim_dcb->poll_sim_2s = KAL_FALSE; #if !defined( __MAUI_BASIC__) tst_sys_trace("[SIM DRV]stop timer\n\r"); #else dbg_print("[SIM DRV]stop timer\n\r"); #endif if(status == 0x0000) { #ifdef __SIM_HOT_SWAP_SUPPORT__ iccHotPlugTable[simInterface].plugOutcb(simInterface); #endif #if !defined( __MAUI_BASIC__) tst_sys_trace("[SIM DRV]real hot plug\n\r"); #else dbg_print("[SIM DRV]real hot plug\n\r"); #endif } } #endif return status; }
kal_bool idp_find_empty_and_register( kal_uint32 * const key, idp_owner_t ** const owner) { kal_uint32 i; kal_bool result = KAL_FALSE; if (NULL == owner) { //ASSERT(0); return KAL_FALSE; } /* Because I need to call semaphore API, I have to ensure * this function will not be called from HISR & LISR. */ if (kal_if_hisr()) { //ASSERT(0); return KAL_FALSE; } if (kal_if_lisr()) { //ASSERT(0); return KAL_FALSE; } kal_take_sem(idp_owners_sem, KAL_INFINITE_WAIT); for (i = 0; i < MAX_CONCURRENT_DP; ++i) { //kal_bool find_one = KAL_FALSE; if (0 == owners[i].key) { kal_uint32 local_key; while (1) { kal_bool cal_again = KAL_FALSE; local_key = 0; while (0 == local_key) { local_key = rand(); } { int j; for (j = 0; j < MAX_CONCURRENT_DP; ++j) { if (j != i) { if (owners[j].key == local_key) { cal_again = KAL_TRUE; } if (KAL_TRUE == cal_again) { break; } } } } if (KAL_FALSE == cal_again) { break; } } owners[i].key = local_key; (*key) = local_key; owners[i].task = kal_get_current_thread_ID(); (*owner) = &(owners[i]); result = KAL_TRUE; //find_one = KAL_TRUE; break; } //if (KAL_TRUE == find_one) //{ // break; //} } kal_give_sem(idp_owners_sem); return result; }
/************************************************************************* * FUNCTION * mdci_read * * DESCRIPTION * This function reads data through either mailbox channel or stream * channel. * * PARAMETERS * channel - logical channel * buff - pointer to channel buffer * * RETURNS * MDIF error code. * *************************************************************************/ kal_int32 mdci_read(MDCI_CHANNEL_T channel, MDCI_BUFF_T *buff) { kal_uint32 owner, mask, ret, event; kal_char event_name[20]; #ifdef __IVP__ dbg_print("Error.... can not use mdci_read in IVP\n\r"); while(1); #endif /* check if a LISR is running */ if (kal_if_lisr()) return MDCI_IN_LISR; /* check parameters */ if (channel >= MDCI_MAX_CHANNEL) return MDCI_INVALID_PARAM; if (buff == NULL) return MDCI_INVALID_PARAM; /* get the current task */ owner = (kal_uint32)kal_get_current_thread_ID(); /* check owner */ if (mdci_ctrl_pool[channel].owner != owner && mdci_is_chanel_need_check_owner(channel)) { return MDCI_NOT_OWNER; } /* create an event for the first use */ if (mdci_ctrl_pool[channel].event == NULL) { sprintf(event_name, "MDIF%d event", channel); mdci_ctrl_pool[channel].event = kal_create_event_group(event_name); if (mdci_ctrl_pool[channel].event == NULL) ASSERT(0); } /* check state */ ret = MDCI_SUCCESS; mask = SaveAndSetIRQMask(); if (mdci_ctrl_pool[channel].state != MDCI_IDLE) { ret = MDCI_IN_USE; } else { /* set ACTIVE_WRITE */ mdci_ctrl_pool[channel].state = MDCI_ACTIVE_READ; } RestoreIRQMask(mask); if (ret != MDCI_SUCCESS) return ret; #ifndef __IVP__ /* wait for the event */ kal_retrieve_eg_events(mdci_ctrl_pool[channel].event, 1, KAL_OR_CONSUME, &event, KAL_SUSPEND); #endif if (event != 1) { ASSERT(0); } /* read channel buffer */ memcpy(buff, &(mdci_ctrl_pool[channel].buff), sizeof(MDCI_BUFF_T)); /* set ACTIVE_IDLE */ mdci_ctrl_pool[channel].state = MDCI_IDLE; return MDCI_SUCCESS; }
__attribute__((section ("INTSRAM_ROCODE"))) kal_int32 mdci_write_internal(MDCI_CHANNEL_T channel, MDCI_BUFF_T *buff,kal_bool check_lisr) { kal_uint32 owner, mask, mdci_busy, phy_chann, saveaddr = 0; kal_int32 ret; MDCI_BUFF_T *chdata; /* check if a LISR is running */ if (1 == check_lisr) { if (kal_if_lisr()) { mask = SaveAndSetIRQMask(); mdci_err_log[log_index].return_tick = kal_get_systicks(); mdci_err_log[log_index].return_value = MDCI_IN_LISR; log_index++; log_index %= DebugEntryNo; RestoreIRQMask(mask); return MDCI_IN_LISR; } } /* check parameters */ if (channel >= MDCI_MAX_CHANNEL) { mask = SaveAndSetIRQMask(); mdci_err_log[log_index].return_tick = kal_get_systicks(); mdci_err_log[log_index].return_value = MDCI_INVALID_PARAM; log_index++; log_index %= DebugEntryNo; RestoreIRQMask(mask); return MDCI_INVALID_PARAM; } if (buff == NULL) { mask = SaveAndSetIRQMask(); mdci_err_log[log_index].return_tick = kal_get_systicks(); mdci_err_log[log_index].return_value = MDCI_INVALID_PARAM; log_index++; log_index %= DebugEntryNo; RestoreIRQMask(mask); return MDCI_INVALID_PARAM; } /* get the current task */ owner = (kal_uint32)kal_get_current_thread_ID(); /* check owner */ if (mdci_ctrl_pool[channel].owner != owner && mdci_is_chanel_need_check_owner(channel) ) { mask = SaveAndSetIRQMask(); mdci_err_log[log_index].return_tick = kal_get_systicks(); mdci_err_log[log_index].return_value = MDCI_NOT_OWNER; log_index++; log_index %= DebugEntryNo; RestoreIRQMask(mask); return MDCI_NOT_OWNER; } /* check state */ ret = MDCI_SUCCESS; mask = SaveAndSetIRQMask(); if (mdci_ctrl_pool[channel].state != MDCI_IDLE) { ret = MDCI_IN_USE; } else { /* set ACTIVE_WRITE */ mdci_ctrl_pool[channel].state = MDCI_ACTIVE_WRITE; } RestoreIRQMask(mask); if (ret != MDCI_SUCCESS) { mask = SaveAndSetIRQMask(); mdci_err_log[log_index].return_tick = kal_get_systicks(); mdci_err_log[log_index].return_value = ret; log_index++; log_index %= DebugEntryNo; RestoreIRQMask(mask); return ret; } /* get one physical channel */ mask = SaveAndSetIRQMask(); mdci_busy = *MDIF_BUSY; //for (phy_chann = 0; phy_chann < MDIF_MAX_PHY; phy_chann++) { for (phy_chann = mdci_writeindx_for_FC ; phy_chann < (mdci_writeindx_for_FC + MDIF_MAX_PHY); phy_chann++) { phy_chann %= MDIF_MAX_PHY; if (mdci_busy & (1 << phy_chann)) { //continue; mdci_err_log[log_index].return_tick = kal_get_systicks(); mdci_err_log[log_index].return_value = MDCI_NO_PHY_CHANNEL; mdci_err_log[log_index].return_busy = mdci_busy; mdci_err_log[log_index].return_write_index = mdci_writeindx_for_FC; log_index++; log_index %= DebugEntryNo; RestoreIRQMask(mask); mdci_ctrl_pool[channel].state = MDCI_IDLE; return MDCI_NO_PHY_CHANNEL; //break; } else { /* set BUSY bit */ *MDIF_BUSY = (1 << phy_chann); mdci_writeindx_for_FC = (phy_chann + 1)%MDIF_MAX_PHY; break; } } /* set logical channel number */ buff->channel = channel; #ifndef __IVP__ mdci_trans_log_pool[channel][mdci_trans_log_index[channel]].tick = kal_get_systicks(); #endif /* __IVP__ */ /* add a MD offset for the stream buffer address */ if (!MDCI_IS_MAILBOX(buff)) { saveaddr = MDCI_STREAM_ADDR(buff); #if defined(MDIF_FOR_AP_SIDE) MDCI_STREAM_ADDR(buff) |= mdci_md_offset; #else /* MDIF_FOR_AP_SIDE */ MDCI_STREAM_ADDR(buff) &= ~mdci_md_offset; #endif /* MDIF_FOR_AP_SIDE */ } /* copy channel buffer */ chdata = (MDCI_BUFF_T *)MDIF_TXCHDATA + phy_chann; kal_mem_cpy(chdata, buff, sizeof(MDCI_BUFF_T)); /* restore the stream buffer address */ if (!MDCI_IS_MAILBOX(buff)) { MDCI_STREAM_ADDR(buff) = saveaddr; } /* start MDIF */ *MDIF_TCHNUM = phy_chann; /* set ACTIVE_IDLE */ mdci_ctrl_pool[channel].state = MDCI_IDLE; RestoreIRQMask(mask); /* do transaction log */ kal_mem_cpy(&(mdci_ctrl_pool[channel].buff), buff, sizeof(MDCI_BUFF_T)); kal_mem_cpy(&(mdci_trans_log_pool[channel][mdci_trans_log_index[channel]].ct), &mdci_ctrl_pool[channel], sizeof(MDCI_CTRL_T)); mdci_trans_log_index[channel]++; mdci_trans_log_index[channel]%=(DebugEntryNo); return MDCI_SUCCESS; }