📄 func_auto_configuration_detection.c
字号:
/******************************************************************************
*
* Purpose: Automatic Configuration Detection Functions
*
* Creator: Rob Lansbergen
*
* Version: $Revision: 11 $
*
* File Name: $Workfile: Func_Auto_Configuration_Detection.c $
*
* Author: Rob Lansbergen
*
* Check in: $Author: Chong.cheeleong $
*
* The information is provided 揳s is?without any express or implied warranty
* of any kind, * including warranties of merchantability, noninfringement of
* intellectual property, or fitness for any particular purpose. In no event sha
* Wireless Sound Solutions and/or its affiliate companies, or its suppliers be
* liable for any damages whatsoever arising out of the use of or inability to
* use the information or the materials. Wireless Sound Solutions, its affiliate
* companies, and its suppliers further do not warrant the accuracy or
* completeness of information, text, graphics, or other items contained within
* materials. Wireless Sound Solutions, Inc., may make changes to materials, or
* the products described within, at any time, without notice.
* ?007 Wireless Sound Solutions. All rights reserved. Wireless Sound Solutions
* STS and STS-wireless are trademarks of Wireless Sound Solutions.
******************************************************************************/
/*
** Include files
** -------------
*/
#include <stdio.h>
#include <ina90.h>
#include "defines.h"
#ifdef Target_MU
static const unsigned char DT_Speaker_En[6] =
{
0x01 //1NACK
,0x03 //2NACK
,0x07 //3NACK
,0x0F //4NACK
,0x11 //1Headset
,0x33 //2Headset
};
#endif /*Target_MU*/
unsigned char Auto_Configuration_State = 0;
volatile unsigned int AutoConfig_NoSync_Delay_Cntr = 0;
volatile unsigned char AutoConfig_InSync_Leadtime = 0;
volatile unsigned char AutoConfig_PDDC_Disable_Cntr = 0;
extern unsigned char InSync_Detected;
unsigned char I2C_Write_Byte(unsigned char map, unsigned char data);
/* Local Functions */
void Change_MU_Config(void);
/******************************************************************************
*
* Function Name : Handle_Auto_Config_Detection_MainLoop
*
* Purpose : Automatic Configuration Detection by MU
*
* Arguments : none
*
* Return value : none
*
******************************************************************************/
void Handle_Auto_Config_Detection_MainLoop(void)
{
#ifdef Target_MU
if(Use_Auto_Config == 0) return;
switch(Auto_Configuration_State)
{
case Init_Process:
if(InSync_Detected == 0)
{
if(Use_Application < No_Application_Use) Use_Application++; //No_Application_Use=5
else Use_Application = 0;
/* set CU config */
Config_Byte1 &= 0xE0; /* clear Bit 4~0, Application Number */
Config_Byte1 |= Use_Application & 0x1F; /* reset Bit 4~0, Application Number */
Config_Byte2 &= 0xF0; /* clear Bit 3~0, Stereo Stream */
Config_Byte2 |= DT_Speaker_En[Use_Application] & 0x0F; /* reset Bit 4~0, Stereo Stream */
Use_Speaker_Enable_Bits = Config_Byte2 & 0x0F;
if ((Use_Application == 4)||(Use_Application == 5))
{
ApplicType = APPL_TYPE_HEADSET; /*For Headset application*/
Data_Free_Up = 0;
}
else
{
ApplicType = APPL_TYPE_NACK;
Data_Free_Up = 1;
}
/* Initialise DARR80 again */
if (Init_DARR() != 0) //Init_DARR ERROR
{
#ifdef DEBUG
putstring("Init_DARR ERROR\r");
#endif
Sync_Led_Status = LED_INIT_ERROR;
Error_Code = 1; /* blink one's every 4 seconds */
while(1){}; /* init error */
}
// //-------------//Allan add-------------------*/
#ifdef Target_MU
Wait_For_mSec(100);
/* Configure Codec */
if (Config_Codec() != 0)
{
Sync_Led_Status = LED_INIT_ERROR;
Error_Code = 2; /* blink twice's every 4 seconds */
while(1){}; /* init error */
}
#else
#endif
// //-------------//Allan add-------------------*/
/* read connect code from Eeprom */
Connection_Code = Get_ConnectCode();
/* write COCO register in DARR80 */
I2C_Write_Byte(COCO_ADDR, Connection_Code & 0x0FF);
I2C_Write_Byte(COCO_ADDR + 1, (Connection_Code >> 8) & 0xFF);
if(AutoConfig_PDDC_Disable_Cntr < LOW_POWER_SEARCH_60SEC) //Disable time = 1 min
{
I2C_Write_Byte(PDDC_ADDR, 0); // disable PDDC to get faster Sync
}
else
{
AutoConfig_PDDC_Disable_Cntr = 60; //Set the counter to 1 min
}
AutoConfig_InSync_Leadtime = 0;
Auto_Configuration_State = InSync_Leadtime;
#ifndef NO_GUI
Show_Config_Status();
#endif /*NO_GUI*/
}
else
{
Auto_Configuration_State = Auto_Config_Check;
}
break;
case InSync_Leadtime:
/* Search time to sync up with a applicaitons */
if(AutoConfig_InSync_Leadtime >= CONFIG_SCAN_TIME_300MS) //Wait time = 300ms
{
Auto_Configuration_State = Sync_State;
}
break;
case Sync_State:
if (InSync_Detected == 1)
{
/* Found Application */
/*** insync ***/
Auto_Configuration_State = Auto_Config_Check;
if(AutoConfig_PDDC_Disable_Cntr < LOW_POWER_SEARCH_60SEC)
I2C_Write_Byte(PDDC_ADDR, PDDC_SETTING); /* set fast Power down duty cycle mode */
}else
{
/* Not found application init next application*/
/*** No Sync ***/
Auto_Configuration_State = Init_Process;
}
break;
case Debounce_Sync:
/* Only start scanning for application when no Insync was detected for 5 seconds */
if(InSync_Detected == 1)
{
Auto_Configuration_State = Auto_Config_Check;
}else
{
if(AutoConfig_NoSync_Delay_Cntr >=CONFIG_SCAN_TIME_5SEC) //Waiting Time 5 sec
{
Auto_Configuration_State = Init_Process;
AutoConfig_PDDC_Disable_Cntr = 0;
}
}
break;
case Auto_Config_Check:
if(InSync_Detected == 0)
{
Auto_Configuration_State = Debounce_Sync;
AutoConfig_NoSync_Delay_Cntr = 0;
}
break;
default:
// Auto_Configuration_State = Auto_Config_Check;
break;
}
#endif /*Target_MU*/
}
/******************************************************************************
*
* Function Name : Handle_MU_Change_Config_RXMsg
*
* Purpose : Handle the MU CU Change Procedure.
*
* Arguments : none
*
* Return value : none
*
******************************************************************************/
void Handle_MU_Change_Config_RXMsg(void)
{
#ifdef Target_MU
if ((Use_ModuleMode == MU)&&(Use_Continuous_RX_TX == 0)&&(Use_MU_CU_Swap ==0))
{
/* Change Request from CU */
if (RX_Data_recv_array[0] == MSG_TYPE_APPLICATION_CHANGE_REQ)
{
DATA_LED_ON;
/* Change the config of MU */
Change_MU_Config();
DATA_LED_OFF;
}
}
#endif /*Target_MU*/
}
/******************************************************************************
*
* Function Name : Change_MU_Config
*
* Purpose : Change MU configuration strings.
*
* Arguments : none
*
* Return value : none
*
******************************************************************************/
void Change_MU_Config(void)
{
#ifdef Target_MU
Use_Application = RX_Data_recv_array[1]; /*Change to new application*/
/* set MU config */
Config_Byte1 &= 0xE0; /* clear Bit 4~0, Application Number */
Config_Byte1 |= Use_Application & 0x1F; /* reset Bit 4~0, Application Number */
Config_Byte2 &= 0xF0; /* clear Bit 3~0, Stereo Stream */
Config_Byte2 |= DT_Speaker_En[Use_Application] & 0x0F; /* reset Bit 4~0, Stereo Stream */
Use_Speaker_Enable_Bits = Config_Byte2 & 0x0F;
if ((Use_Application == 4)||(Use_Application == 5))
{
ApplicType = APPL_TYPE_HEADSET; /*For Headset application*/
Data_Free_Up = 0;
}
else
{
ApplicType = APPL_TYPE_NACK;
Data_Free_Up = 1;
}
/* Initialise DARR80 again */
if (Init_DARR() != 0)
{
#ifdef DEBUG
putstring("Init_DARR ERROR\r");
#endif
Sync_Led_Status = LED_INIT_ERROR;
Error_Code = 1; /* blink one's every 4 seconds */
while(1){}; /* init error */
}
// //-------------//Allan add-------------------*/
Wait_For_mSec(100);
/* Configure Codec */
if (Config_Codec() != 0)
{
Sync_Led_Status = LED_INIT_ERROR;
Error_Code = 2; /* blink twice's every 4 seconds */
while(1){}; /* init error */
}
// //-------------//Allan add-------------------*/
Auto_Configuration_State = Auto_Config_Check;
#endif /*Target_MU*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -