📄 auxmain.c
字号:
bmt_adc_measure_done_conf_struct *ptr=(bmt_adc_measure_done_conf_struct *)buf;
kal_int32 aux_volt_result;
aux_id_struct *aux_id_data;
ilm_struct *aux_ilm;
AUX_ID aux_id_no=AUX_ID_PLUGOUT;
if(0==aux_timer_open)
return;
aux_volt_result = (kal_int32)ptr->volt;
if ((aux_volt_result > UART_ADC)&&(*pre_id!=AUX_ID_EARPHONE)&&(*pre_id!=AUX_ID_KEY_PRESS)&&(*pre_id!=AUX_ID_KEY_PRESS))
{
#ifdef AUX_DEBUG
dbg_print("UART \n\r");
dbg_print("AUX voltage = %d\n\r",aux_volt_result);
#endif
aux_id_no = AUX_ID_UART;
//GPIO_WriteIO(1,3);/*Turn on UART*/
}
if(aux_id_no!=AUX_ID_UART)
{
if(aux_detect_mode==KAL_FALSE)/*normal mode */
{
#ifdef AUX_DEBUG
dbg_print("Normal mode 2.2V \n\r");
#endif
if(((NORMAL_EARPHONE_ADC_LOW <aux_volt_result)&& (aux_volt_result< NORMAL_EARPHONE_ADC_HIGH) )||(aux_volt_result< SENDKEY_ADC))
{
#ifdef AUX_DEBUG
dbg_print("Earphone \n\r");
dbg_print("AUX voltage = %d\n\r",aux_volt_result);
#endif
//L1SM_SleepEnable(aux_PDNhandle);
if(*pre_id==AUX_ID_EARPHONE||*pre_id==AUX_ID_KEY_PRESS||*pre_id==AUX_ID_KEY_RELEASE)
{
if(aux_volt_result< SENDKEY_ADC)
{
aux_id_no = AUX_ID_KEY_PRESS;
}
else
{
aux_id_no = AUX_ID_KEY_RELEASE;
}
}
else
aux_id_no =AUX_ID_EARPHONE;
}
else
{
#ifdef AUX_DEBUG
dbg_print("Abnormal mode \n\r");
dbg_print("AUX voltage = %d\n\r",aux_volt_result);
#endif
aux_id_no= AUX_ID_PLUGOUT;
}
}
else if(aux_detect_mode==KAL_TRUE) /*Single mode*/
{
#ifdef AUX_DEBUG
dbg_print("Single mode 1.9V \n\r");
#endif
if(((SINGLE_EARPHONE_ADC_LOW <aux_volt_result)&& (aux_volt_result< SINGLE_EARPHONE_ADC_HIGH) )||(aux_volt_result< SENDKEY_ADC))
{
#ifdef AUX_DEBUG
dbg_print("Earphone \n\r");
dbg_print("AUX voltage = %d\n\r",aux_volt_result);
#endif
if(*pre_id==AUX_ID_EARPHONE||*pre_id==AUX_ID_KEY_PRESS||*pre_id==AUX_ID_KEY_RELEASE)
{
if(aux_volt_result< SENDKEY_ADC)
{
aux_id_no = AUX_ID_KEY_PRESS;
}
else
{
aux_id_no = AUX_ID_KEY_RELEASE;
}
}
else
aux_id_no =AUX_ID_EARPHONE;
}
else
{
#ifdef AUX_DEBUG
dbg_print("Abnormal mode \n\r");
dbg_print("AUX voltage = %d\n\r",aux_volt_result);
#endif
aux_id_no= AUX_ID_PLUGOUT;
}
}
}
if ((*pre_id != aux_id_no) )
{
if((aux_id_no!=AUX_ID_KEY_RELEASE)&&(aux_id_no!=AUX_ID_PLUGOUT))
{
#ifdef AUX_DEBUG
dbg_print("Send EARPHONE msg to MMI \n\r");
dbg_print("AUX ID = %d\n\r",aux_id_no);
#endif
aux_id_data = (aux_id_struct*)
construct_local_para(sizeof(aux_id_struct), TD_CTRL);
aux_id_data->aux_id = aux_id_no;
DRV_BuildPrimitive(aux_ilm,
MOD_AUX,
MOD_UEM,
MSG_ID_AUX_ID,
aux_id_data);
msg_send_ext_queue(aux_ilm);
}
if(aux_id_no!=AUX_ID_PLUGOUT)
*pre_id = aux_id_no;
}
/*error state or poll timer on */
if(aux_id_no==AUX_ID_PLUGOUT)
stack_start_timer(&aux_timer, 1, POLLING_INTERVAL);/*start polling timer*/
else if(poll_timer==KAL_TRUE)
stack_start_timer(&aux_timer, 1, POLLING_INTERVAL);/*start polling timer*/
}
#if (defined(__PHONE_CLAMSHELL__) || defined(__PHONE_SLIDE__))
void CLAM_EINT_HISR(void)
{
ilm_struct *clam_ilm;
aux_id_struct *aux_id_data;
if (clam_state == LEVEL_LOW)
{
aux_id_data = (aux_id_struct*)
construct_local_para(sizeof(aux_id_struct), TD_CTRL);
aux_id_data->aux_id = AUX_ID_CLAM_CLOSE;
DRV_BuildPrimitive(clam_ilm,
MOD_EINT_HISR,
MOD_UEM,
MSG_ID_AUX_ID,
aux_id_data);
}
else
{
aux_id_data = (aux_id_struct*)
construct_local_para(sizeof(aux_id_struct), TD_CTRL);
aux_id_data->aux_id = AUX_ID_CLAM_OPEN;
DRV_BuildPrimitive(clam_ilm,
MOD_EINT_HISR,
MOD_UEM,
MSG_ID_AUX_ID,
aux_id_data);
}
msg_send_ext_queue(clam_ilm);
clam_state = !clam_state;
EINT_Set_Polarity(CLAMDET_EINT_NO,clam_state);
}
#endif
/*************************************************************************
* FUNCTION
* aux_task_main
*
* DESCRIPTION
* This function implements xyz task's entry function
*
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void aux_task_main( task_entry_struct * task_entry_ptr )
{
ilm_struct current_ilm;
ilm_struct *aux_ilm ;
aux_id_struct *aux_id_data;
kal_uint8 aux_adc_logic_id;
AUX_ID pre_id = AUX_ID_PLUGOUT;
/*Engineering mode logic id*/
kal_uint8 vbat_adc_logic_id;
kal_uint8 visense_adc_logic_id;
kal_uint8 vcharger_adc_logic_id;
kal_uint8 vbattemp_adc_logic_id;
kal_uint8 vaux_adc_logic_id;
/*Engineering mode result*/
kal_int32 vbat_value;
kal_int32 visense_value;
kal_int32 vcharger_value;
kal_int32 vbattemp_value;
kal_int32 vaux_value;
bmt_adc_measure_done_conf_struct *mea_done_ptr;
adc_all_channel_struct *adc_all_channel_result;
kal_uint16 adc_measure_count=0;
stack_timer_struct *check_timer_index;
stack_init_timer(&aux_timer, "AUX_TIMER", MOD_AUX);
/*40*4.615ms=18ms*/
aux_adc_logic_id = adc_sche_create_object(MOD_AUX, ADC_ACCESSORYID,40,1, KAL_TRUE);
/*Engineering mode*/
vbat_adc_logic_id = adc_sche_create_object(MOD_AUX, ADC_VBAT,40,1, KAL_TRUE);
visense_adc_logic_id = adc_sche_create_object(MOD_AUX, ADC_VISENSE,40,1, KAL_TRUE);
vcharger_adc_logic_id = adc_sche_create_object(MOD_AUX, ADC_VCHARGER,40,1, KAL_TRUE);
vbattemp_adc_logic_id = adc_sche_create_object(MOD_AUX, ADC_VBATTMP,40,1, KAL_TRUE);
vaux_adc_logic_id = adc_sche_create_object(MOD_AUX, ADC_ACCESSORYID,40,1, KAL_TRUE);
/*Enable External interrupt*/
EINT_Registration(AUX_EINT_NO,KAL_TRUE,aux_state,AUX_EINT_HISR, KAL_TRUE);
#if (defined(__PHONE_CLAMSHELL__) || defined(__PHONE_SLIDE__))
EINT_Registration(CLAMDET_EINT_NO,KAL_TRUE,clam_state,CLAM_EINT_HISR, KAL_TRUE);
#endif
while(1)
{
receive_msg_ext_q(task_info_g[task_entry_ptr->task_indx].task_ext_qid, ¤t_ilm);
switch(current_ilm.msg_id)
{
case MSG_ID_AUX_CALL_SETUP_REQ_IND:
poll_timer=KAL_TRUE;
if(aux_timer_open==1)
{
aux_detect_mode=AFE_TurnOnMicBias();/*voltage source*/
stack_start_timer(&aux_timer, 0, TURN_ON_BIAS_INTERVAL);
}
break;
case MSG_ID_AUX_CALL_DISCONNECT_REQ_IND:
poll_timer=KAL_FALSE;
AFE_TurnOffMicBias();/*voltage source*/
break;
case MSG_ID_AUX_PLUGIN:
break;
case MSG_ID_AUX_PLUGOUT:
/*Notify MMI the aux is plugout*/
pre_id = AUX_ID_PLUGOUT;
aux_id_data = (aux_id_struct*)
construct_local_para(sizeof(aux_id_struct), TD_CTRL);
aux_id_data->aux_id = AUX_ID_PLUGOUT;
DRV_BuildPrimitive(aux_ilm,
MOD_AUX,
MOD_UEM,
MSG_ID_AUX_ID,
aux_id_data);
msg_send_ext_queue(aux_ilm);
/*remove the adc item*/
aux_remove_adc_channel(aux_adc_logic_id);
break;
case MSG_ID_READ_ALL_ADC_CHANNEL_REQ:
adc_measure_count=0;
vbat_value = 0;
aux_read_adc_channel(vbat_adc_logic_id);
visense_value = 0;
aux_read_adc_channel(visense_adc_logic_id);
vcharger_value = 0;
aux_read_adc_channel(vcharger_adc_logic_id);
vbattemp_value = 0;
aux_read_adc_channel(vbattemp_adc_logic_id);
vaux_value = 0;
aux_read_adc_channel(vaux_adc_logic_id);
break;
case MSG_ID_BMT_ADC_MEASURE_DONE_CONF:
mea_done_ptr = (bmt_adc_measure_done_conf_struct *)current_ilm.local_para_ptr;
if (mea_done_ptr->adc_sche_id == aux_adc_logic_id) /*normal mode*/
{
aux_remove_adc_channel(aux_adc_logic_id);
if(poll_timer!=KAL_TRUE) /*not turn off microbias when talking*/
AFE_TurnOffMicBias();
aux_read_result(&pre_id,aux_adc_logic_id,current_ilm.local_para_ptr);
}
if (mea_done_ptr->adc_sche_id == vbat_adc_logic_id)
{
adc_measure_count++;
vbat_value = (kal_int32)mea_done_ptr->volt;
aux_remove_adc_channel(vbat_adc_logic_id);
}
else if (mea_done_ptr->adc_sche_id == visense_adc_logic_id)
{
adc_measure_count++;
visense_value = (kal_int32)mea_done_ptr->volt;
aux_remove_adc_channel(visense_adc_logic_id);
}
else if (mea_done_ptr->adc_sche_id == vcharger_adc_logic_id)
{
adc_measure_count++;
vcharger_value = (kal_int32)mea_done_ptr->volt;
aux_remove_adc_channel(vcharger_adc_logic_id);
}
else if (mea_done_ptr->adc_sche_id == vbattemp_adc_logic_id)
{
adc_measure_count++;
vbattemp_value = (kal_int32)mea_done_ptr->volt;
aux_remove_adc_channel(vbattemp_adc_logic_id);
}
else if (mea_done_ptr->adc_sche_id == vaux_adc_logic_id)
{
adc_measure_count++;
vaux_value = (kal_int32)mea_done_ptr->volt;
aux_remove_adc_channel(vaux_adc_logic_id);
}
if(adc_measure_count==5)
{
adc_measure_count=0;
adc_all_channel_result = (adc_all_channel_struct*)
construct_local_para(sizeof(adc_all_channel_struct), TD_CTRL);
adc_all_channel_result->vbat = vbat_value;
adc_all_channel_result->bat_temp=volt2temp(vbattemp_value);
adc_all_channel_result->vaux = vaux_value;
adc_all_channel_result->charge_current = (visense_value - vbat_value)*bmt_custom_chr_def.ADC_ISENSE_RESISTANCE_FACTOR;
adc_all_channel_result->vcharger = vcharger_value;
DRV_BuildPrimitive(aux_ilm,
MOD_AUX,
MOD_UEM,
MSG_ID_ADC_ALL_CHANNEL_CONF,
adc_all_channel_result);
msg_send_ext_queue(aux_ilm);
}
break;
case MSG_ID_TIMER_EXPIRY:/*Timer*/
check_timer_index = (stack_timer_struct *) current_ilm.local_para_ptr;
switch(check_timer_index->timer_indx)
{
case 0:/*20ms timer*/
if((aux_timer_open==1))
aux_read_adc_channel(aux_adc_logic_id);
else
aux_remove_adc_channel(aux_adc_logic_id);
break;
case 1:/*500ms timer*/
aux_detect_mode=AFE_TurnOnMicBias();/*voltage source*/
stack_start_timer(&aux_timer, 0, TURN_ON_BIAS_INTERVAL);
break;
default:
break;
}
break;
default:
break;
}
free_ilm(¤t_ilm);
}
}
/*************************************************************************
* FUNCTION
* aux_task_reset
*
* DESCRIPTION
* This function implements xyz's reset handler
*
* PARAMETERS
* task_index - task's index
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool
aux_task_reset(task_indx_type task_indx)
{
/* Do task's reset here.
* Notice that: shouldn't execute modules reset handler since
* stack_task_reset() will do. */
return KAL_TRUE;
}
/*************************************************************************
* FUNCTION
* aux_task_end
*
* DESCRIPTION
* This function implements xyz's termination handler
*
* PARAMETERS
* task_index - task's index
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool
aux_task_end(task_indx_type task_indx)
{
/* Do task's termination here.
* Notice that: shouldn't execute modules reset handler since
* stack_task_end() will do. */
return KAL_TRUE;
}
/*UART Detection*/
void UART_Detection_Enable(UART_PORT port, kal_bool enable_flag)
{
switch(port)
{
case uart_port1:
check_uart1=enable_flag;
break;
case uart_port2:
check_uart2=enable_flag;
break;
default:
break;
}
}
kal_bool Get_UART_Detection_Status(UART_PORT port)
{
switch(port)
{
case uart_port1:
return check_uart1;
break;
case uart_port2:
return check_uart2;
break;
default:
return KAL_FALSE;
break;
}
}
#endif /*__L1_STANDALONE__*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -