Index: core/yc3121.h
===================================================================
--- /YC3121_SDK/fw/core/yc3121.h	(revision 788)
+++ /YC3121_SDK/fw/core/yc3121.h	(working copy)
@@ -16,8 +16,9 @@
 
 #define NO_BT           0
 #define EXIST_BT        1
+#define NO_XTAL         2
 
-#define VERSIONS		EXIST_BT //无蓝牙版本采用NO_BT
+#define VERSIONS		EXIST_BT
 
 #define M0_FPGA     1
 #define POS_FPGA    2
Index: sdk/yc_bt.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_bt.h	(revision 788)
+++ /YC3121_SDK/fw/sdk/yc_bt.h	(working copy)
@@ -21,20 +21,20 @@
 #define HCI_EVENT                         0x02
 #define MAX_BLUETOOTH_DATA_LEN            255
 #define MAX_TCP_DATA_LEN                  235
-#define MAX_BIG_DATA_LEN                  1452
+#define MAX_BIG_DATA_LEN                  1360
 
 
 
 /*BIT judge*/
-#define BIT_SET_BT_ADDR                   0 
-#define BIT_SET_BLE_ADDR                  1 
-#define BIT_SET_VISIBILITY                2 
-#define BIT_SET_BT_NAME                   3 
-#define BIT_SET_BLE_NAME                  4 
-#define BIT_SEND_SPP_DATA                 5 
-#define BIT_SEND_BLE_DATA                 6 
-#define BIT_STATUS_REQUEST                7 
-#define BIT_SET_PAIRING_MODE              8 
+#define BIT_SET_BT_ADDR                   0
+#define BIT_SET_BLE_ADDR                  1
+#define BIT_SET_VISIBILITY                2
+#define BIT_SET_BT_NAME                   3
+#define BIT_SET_BLE_NAME                  4
+#define BIT_SEND_SPP_DATA                 5
+#define BIT_SEND_BLE_DATA                 6
+#define BIT_STATUS_REQUEST                7
+#define BIT_SET_PAIRING_MODE              8
 #define BIT_SET_PINCODE                   9
 #define BIT_GET_VERSION                   10
 #define BIT_BT_DISCONNECT                 11
@@ -68,6 +68,7 @@
 #define BIT_BNEP_SEND_TCP_BIG_DATA        39
 #define BIT_BNEP_SEND_TCP_BIG_DATA_FINISH 40
 #define BIT_BNEP_SEND_TCP_BIG_DATA_STATUS 41
+#define BIT_SET_LPM_MODE                  42
 /*CMD*/
 #define HCI_CMD_SET_BT_ADDR               0x00  //设置 BT3.0 地址
 #define HCI_CMD_SET_BLE_ADDR              0x01  //设置 BLE 地址
@@ -106,6 +107,7 @@
 #define HCI_CMD_DNS_REQ                   0x82 //域名解析指令
 #define HCI_CMD_SEND_UDP_DATA             0x84 //发送UDP数据
 #define HCI_CMD_SEND_BIG_DATA             0x85 //发送TCP大包数据
+#define HCI_CMD_SET_LPM_MODE              0xff //开关低功耗
 
 
 /*EVENT*/
@@ -143,9 +145,9 @@
 #define HCI_EVENT_BIG_DATA_STATUS         0x3b  /*大数据分包发送状态*/
 
 
-/** 
-  * @brief  event code enum definition  
-  */ 
+/**
+  * @brief  event code enum definition
+  */
 typedef enum
 {
 	BT_CONNECTED        		=HCI_EVENT_BT_CONNECTED,
@@ -173,12 +175,12 @@
 	BT_NAME              		=HCI_EVENT_BT_NAME,
 	UDP_INFO             		=HCI_EVENT_UDP_INFO,
 	BNEP_RECEIVE_UDP_DATA		=HCI_EVENT_BNEP_RECEIVE_UDP_DATA
-	
+
 }BT_EventCodeEnum;
 
 
 
-typedef struct 
+typedef struct
 {
 	uint8_t* pBuf;
     	int BufSize;
@@ -238,7 +240,7 @@
 
 /**
   * @brief  Bt send spp(bt3.0) data
-  * @param  spp_data: pointer to  spp data 
+  * @param  spp_data: pointer to  spp data
   *         len: spp data length(max len is 255)
   * @retval TRUE:send spp data success.
   *         FALSE:send spp data failed
@@ -297,7 +299,7 @@
   * @brief  get the bluetooth module firmware version number
   * @param  none
   * @retval firmware version number(the value is 1~65535),0 is fail
-  *                  
+  *
   */
 uint32_t BT_GetVersion(void);
 
@@ -321,7 +323,7 @@
 
 
 /**
-  * @brief  Bt Enter Sleep mode
+  * @brief  Bt Enter Sleep mode(enter_hibernate)
   * @param  none
   * @retval TRUE:enter sleep mode success
   *
@@ -329,6 +331,15 @@
 Boolean BT_EnterSleepMode(void);
 
 
+/**
+  * @brief  Bt set LPM mode
+  * @param  mode:0x00-close LPM mode; 0x01-open LPM mode
+  * @retval TRUE or FALSE
+  *
+  */
+Boolean BT_SetLpmMode(uint8_t mode);
+
+
 
 /**
   * @brief  Numeric Comparison key matching in paring mode
@@ -351,8 +362,8 @@
 
 
 /**
-  * @brief  Comparison of keys in  PASSKEY paring 
-  * @param  key_data: point to key data,length is 4 bytes,(data in hexadecimal form, 
+  * @brief  Comparison of keys in  PASSKEY paring
+  * @param  key_data: point to key data,length is 4 bytes,(data in hexadecimal form,
   *                   starting with high bytes;for example ,218372(10) = 0x35504 ->key_data[]={0x00,0x03,0x55,0x04})
   * @retval TRUE:set passkey success
   *         FALSE:set passkey  failed
@@ -407,13 +418,12 @@
 
 
 /**
-  * @brief  Set ble adv parm
-  * @param  data: pointer to  adv parmdata.
-  *         DataLen: data length(len must be 2)
+  * @brief  Set ble adv interval
+  * @param  ble_adv_interval: ble adv interval is ble_adv_interval*0.625ms
   * @retval TRUE:set ble adv parm success.
   *         FALSE:set ble adv parm failed
   */
-Boolean BT_SetLEAdvParm(uint8_t*data,int DataLen);
+Boolean BT_SetLEAdvInterval(uint16_t ble_adv_interval);
 
 /**
   * @brief  Set reject just work
@@ -437,7 +447,7 @@
 
 /**
   * @brief  ble disconnect
-  * @param  none 
+  * @param  none
   * @retval TRUE:ble disconnected success.
   *         FALSE:ble disconnected failed
   */
@@ -445,8 +455,8 @@
 
 
 /**
-  * @brief  Set spp(bt3.0) class of device 
-  * @param  bt_cod:cod buf(must be 3 byte) 
+  * @brief  Set spp(bt3.0) class of device
+  * @param  bt_cod:cod buf(must be 3 byte)
   * @retval TRUE:success.
   *         FALSE:failed
   */
@@ -502,7 +512,7 @@
 	*																	bit6		Authentication Signed Write
 	*																	bit7		Extended Properties
 	*														byte1:			characterisitic uuid length(2 or 16)
-	*														byte2-3(17):characterisitic uuid 
+	*														byte2-3(17):characterisitic uuid
 	*														byte4(18):	write/read payload length(1--20;default:1)
 	*														byte5(19)-x:write/read payload(default:00)
 	*					service_Characteristic_payload_len: sizeof(ble_Characteristic_uuid)
@@ -572,7 +582,7 @@
 Boolean BT_DnsReq( uint8_t *dns_data,int len);
 /**
   * @brief  Connect Bnep
-  * @param   *phone_mac_addr: pointer to phone_mac_addr. 
+  * @param   *phone_mac_addr: pointer to phone_mac_addr.
 	           Byte0~Byte5   The MAC address you want to connect to your phone
 						 Byte6~Byte21  Link key
 						 (phone MAC and Link key from NVRAM event,all zero is connect last pair phone)
@@ -647,7 +657,7 @@
 
 /**
   * @brief  Disconnect  Tcp
-  * @param  tcp_handle: the want to disconnect TCP handle(0x00 or 0x01)                
+  * @param  tcp_handle: the want to disconnect TCP handle(0x00 or 0x01)
   * @retval TRUE:success
   *         FALSE:fail
   */
@@ -659,5 +669,5 @@
 
 
 
-#endif 
+#endif
 
Index: sdk/yc_bt.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_bt.c	(revision 788)
+++ /YC3121_SDK/fw/sdk/yc_bt.c	(working copy)
@@ -2,6 +2,12 @@
 #include "yc_systick.h"
 #include "yc_timer.h"
 #include "yc_ipc.h"
+
+#define BT_LOG	0
+#define     BT_ERROR_LOG
+
+
+
 static tick StartTick;
 static uint32_t HCI_CMD_BIT_FLAG[2]={0};
 #define BTTIMEOUT 500
@@ -13,7 +19,7 @@
 static uint8_t CmdRepData[5];
 static int PacketNum=0;
 
-extern IPC_TypeDef *IpcTx; 
+extern IPC_TypeDef *IpcTx;
 extern IPC_TypeDef *IpcRx;
 
 HCI_TypeDef hci_bt;
@@ -58,7 +64,9 @@
 {
 	BluetoothBuf.ReadIndex+=Num;
 	if(BluetoothBuf.ReadIndex>=BluetoothBuf.BufSize)	BluetoothBuf.ReadIndex-=BluetoothBuf.BufSize;
+	NVIC_DisableIRQ(BT_IRQn);
 	BluetoothBuf.count-=Num;
+	NVIC_EnableIRQ(BT_IRQn);
 }
 
 static void SaveData(uint8_t* data,int len)
@@ -66,7 +74,7 @@
 	int i;
 	if(BluetoothBuf.count+len>BluetoothBuf.BufSize)
 	{
-		#ifdef SDK_DEBUG
+		#ifdef BT_ERROR_LOG
 		MyPrintf("BluetoothBuf full\r\n");
 		#endif
 		return;
@@ -145,8 +153,11 @@
 	int i;
 	for(i=0;i<5;i++)	CmdRepData[i]=0;
 	for(i=0;i<BT_BUFSIZE;i++)	rcvbuf[i]=0;
-	hci_bt.p_data =  ipcrecbuf; 
+	hci_bt.p_data =  ipcrecbuf;
 	IpcInit();
+	#ifdef BT_ERROR_LOG
+	MyPrintf("BT_Init end\n");
+	#endif
 	return TRUE;
 }
 
@@ -156,7 +167,9 @@
 	TempData=BluetoothBuf.pBuf[BluetoothBuf.ReadIndex];
 	if(UpdataAnalyzeIndex)
 	{
+		NVIC_DisableIRQ(BT_IRQn);
 		BluetoothBuf.count--;
+		NVIC_EnableIRQ(BT_IRQn);
 		BluetoothBuf.ReadIndex++;
 		if(BluetoothBuf.ReadIndex>=BluetoothBuf.BufSize)	BluetoothBuf.ReadIndex=0;
 	}
@@ -168,13 +181,13 @@
 {
 	if((msg->DataLen+3) > IPC_get_available_size())
 	{
-		#if BT_LOG
+		#ifdef BT_ERROR_LOG
 		MyPrintf("IPC BT Tx FULL\n");
 		#endif
 		return FALSE;
 	}
 	msg->type=HCI_CMD;
-#if BT_LOG	
+#if BT_LOG
 	MyPrintf("Print Send Data Pack:\n");
 	PrintHCIPack(msg, "Send");//打印发送包
 #endif
@@ -216,7 +229,7 @@
 		{
 			return TRUE;
 		}
-	}  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));//ms    
+	}  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));//ms
 	return FALSE;
 }
 
@@ -243,7 +256,7 @@
 		{
 			return TRUE;
 		}
-	}  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));   
+	}  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));
 	return FALSE;
 }
 
@@ -262,7 +275,7 @@
 		{
     		return TRUE;
 		}
-  }  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT)); 
+  }  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));
 	return FALSE;
 }
 
@@ -272,7 +285,7 @@
 	HCI_TypeDef msg;
 	msg.opcode = HCI_CMD_SET_BLE_NAME;
 	msg.DataLen = name_len;
-	msg.p_data  = ble_name;        
+	msg.p_data  = ble_name;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_SET_BLE_NAME);
 	SendCMD(&msg);
 	StartTick=SysTick_GetTick();
@@ -293,7 +306,7 @@
 	HCI_TypeDef msg;
 	msg.opcode = HCI_CMD_SEND_SPP_DATA;
 	msg.DataLen = DataLen;
-	msg.p_data = spp_data;	
+	msg.p_data = spp_data;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_SEND_SPP_DATA);
 	SendCMD(&msg);
 	StartTick=SysTick_GetTick();
@@ -364,7 +377,7 @@
 		{
 			return TRUE;
 		}
-	}  while(!SysTick_IsTimeOut(StartTick, BTTIMEOUT));	
+	}  while(!SysTick_IsTimeOut(StartTick, BTTIMEOUT));
 	return FALSE;
 }
 
@@ -416,7 +429,7 @@
 	msg.DataLen = 0;
 	msg.p_data = NULL;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_GET_VERSION);
-	SendCMD(&msg);	
+	SendCMD(&msg);
 	StartTick=SysTick_GetTick();
 	do
 	{
@@ -480,6 +493,28 @@
 	return TRUE;
 }
 
+extern uint8_t bt_lpm_mode;
+Boolean BT_SetLpmMode(uint8_t mode)
+{
+	HCI_TypeDef msg;
+	uint8_t temp_mode=mode;
+	msg.opcode = HCI_CMD_SET_LPM_MODE;
+	msg.DataLen =1;
+	msg.p_data = &temp_mode;
+	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_SET_LPM_MODE);
+	SendCMD(&msg);
+	StartTick=SysTick_GetTick();
+	do
+	{
+		if(BT_BIT_GET(HCI_CMD_BIT_FLAG,BIT_SET_LPM_MODE))
+		{
+			bt_lpm_mode = mode;
+			return TRUE;
+		}
+	}  while(!SysTick_IsTimeOut(StartTick, BTTIMEOUT));
+	return FALSE;
+}
+
 
 Boolean BT_ConfirmGkey(uint8_t isMatching)
 {
@@ -505,7 +540,7 @@
 {
 	HCI_TypeDef msg;
 	msg.opcode = HCI_CMD_GET_CREADIT_GIVEN;
-	msg.DataLen =0;
+	msg.DataLen =1;
 	uint8_t temp_packetNum=packetNum;
 	msg.p_data = &temp_packetNum;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_GET_CREADIT_GIVEN);
@@ -530,7 +565,7 @@
 		{
 			return TRUE;
 		}
-	}  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));	
+	}  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));
 	return FALSE;
 }
 
@@ -540,7 +575,7 @@
 	msg.opcode = HCI_CMD_LE_SET_PAIRING;
 	msg.DataLen = 1;
 	uint8_t temp_mode=mode;
-	msg.p_data = &temp_mode;		
+	msg.p_data = &temp_mode;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_LE_SET_PARING);
 	SendCMD(&msg);
 	StartTick=SysTick_GetTick();
@@ -550,7 +585,7 @@
 		{
 			return TRUE;
 		}
-	}  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));	
+	}  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));
 	return FALSE;
 }
 
@@ -570,7 +605,7 @@
 			return TRUE;
 		}
 	}  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));
-	return FALSE;     
+	return FALSE;
 }
 
 Boolean BT_SetLEScanData(uint8_t* scan_data, int DataLen)
@@ -589,17 +624,17 @@
 			return TRUE;
 		}
 	}  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));
-	return FALSE;     
+	return FALSE;
 }
 
 Boolean BT_SetLESendConnUpdate(uint8_t *data,int len)
 {
-	if(0x08 != len) 
+	if(0x08 != len)
 		return FALSE;
 	HCI_TypeDef msg;
 	msg.opcode = HCI_CMD_LE_SEND_CONN_UPDATE_REQ;
-	msg.DataLen = len;	
-	msg.p_data = data;	
+	msg.DataLen = len;
+	msg.p_data = data;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_LE_SEND_CONN_UPDATE);
 	SendCMD(&msg);
 	StartTick=SysTick_GetTick();
@@ -613,15 +648,15 @@
 	return FALSE;
 }
 
-Boolean BT_SetLEAdvParm(uint8_t*nvdata,int DataLen)//bt code did not exist
+Boolean BT_SetLEAdvInterval(uint16_t ble_adv_interval)
 {
-	if(0 == DataLen) 
-		return FALSE;
-    
 	HCI_TypeDef msg;
 	msg.opcode = HCI_CMD_LE_SET_ADV_PARM;
-	msg.DataLen = DataLen;	
-	msg.p_data = nvdata;
+	msg.DataLen = 2;
+    uint8_t ble_adv_interval_buf[2];
+    ble_adv_interval_buf[0]=(ble_adv_interval&0xff);
+    ble_adv_interval_buf[1]=((ble_adv_interval>>8)&0xff);
+	msg.p_data = ble_adv_interval_buf;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_LE_SET_ADV_PARM);
 	SendCMD(&msg);
 	StartTick=SysTick_GetTick();
@@ -642,7 +677,7 @@
 	uint8_t td = justwork;
 	HCI_TypeDef msg;
 	msg.opcode = HCI_CMD_REJECT_JUSTWORK;
-	msg.DataLen = 0x01;  
+	msg.DataLen = 0x01;
 	msg.p_data = &td;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_REJECT_JUSTWORK);
 	SendCMD(&msg);
@@ -659,10 +694,10 @@
 
 Boolean BT_SetTxPower(uint8_t power)
 {
-	uint8_t tpower = power;	
+	uint8_t tpower = power;
 	HCI_TypeDef msg;
 	msg.opcode = HCI_CMD_SET_TX_POWER;
-	msg.DataLen = 0x01;	
+	msg.DataLen = 0x01;
 	msg.p_data = &tpower;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_SET_TXPOWER);
 	SendCMD(&msg);
@@ -681,7 +716,7 @@
 {
 	HCI_TypeDef msg;
 	msg.opcode = HCI_CMD_LE_SET_FIXED_PASSKEY;
-	msg.DataLen = 0x05;	
+	msg.DataLen = 0x05;
 	msg.p_data = key;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_LE_SET_FIXED_PASSKEY);
 	SendCMD(&msg);
@@ -703,7 +738,7 @@
 	msg.DataLen = 3;
 	msg.p_data = bt_cod;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_SET_COD);
-	SendCMD(&msg);	
+	SendCMD(&msg);
 	StartTick=SysTick_GetTick();
 	do
 	{
@@ -711,7 +746,7 @@
 		{
 			return TRUE;
 		}
-	}  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));//ms    
+	}  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));//ms
 	return FALSE;
 }
 
@@ -723,12 +758,12 @@
 	msg.DataLen = 0;
 	msg.p_data = NULL;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_DELETE_SERVICE);
-	SendCMD(&msg);	
+	SendCMD(&msg);
 	StartTick=SysTick_GetTick();
 	do
 	{
 		if(BT_BIT_GET(HCI_CMD_BIT_FLAG,BIT_DELETE_SERVICE))
-		{			
+		{
 			return TRUE;
 		}
 	}while(!SysTick_IsTimeOut(StartTick, BTTIMEOUT));
@@ -740,7 +775,7 @@
 	HCI_TypeDef msg;
 	msg.opcode = HCI_CMD_ADD_SERVICE_UUID;
 	msg.DataLen = service_uuid_len;
-	msg.p_data  = ble_service_uuid;        
+	msg.p_data  = ble_service_uuid;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_ADD_UUID);
 	SendCMD(&msg);
 	StartTick=SysTick_GetTick();
@@ -755,14 +790,14 @@
 }
 
 
-	
-	
+
+
 uint16_t BT_AddBleCharacteristic(uint8_t* ble_Characteristic_uuid, uint16_t service_Characteristic_payload_len)
 {
 	HCI_TypeDef msg;
 	msg.opcode = HCI_CMD_ADD_CHARACTERISTIC_UUID;
 	msg.DataLen = service_Characteristic_payload_len;
-	msg.p_data  = ble_Characteristic_uuid;        
+	msg.p_data  = ble_Characteristic_uuid;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_ADD_UUID);
 	SendCMD(&msg);
 	StartTick=SysTick_GetTick();
@@ -884,10 +919,10 @@
 			packetLen=(len-1)>(MAX_BLUETOOTH_DATA_LEN-BIG_DATA_HEAD_LEN)?(MAX_BLUETOOTH_DATA_LEN-BIG_DATA_HEAD_LEN):(len-1);
 			msg.DataLen=packetLen+BIG_DATA_HEAD_LEN;
 			firstPacketData[0]=tcpdata[0];//handle
-			
+
 			firstPacketData[1]=((len-1)&0xff);
 			firstPacketData[2]=(((len-1)>>8)&0xff);//big packet len
-			
+
 			firstPacketData[3]=0;
 			firstPacketData[4]=0;//reserved
 			memcpy((uint8_t*)&firstPacketData[5],(uint8_t*)&tcpdata[1],packetLen);
@@ -960,7 +995,8 @@
 	HCI_TypeDef msg;
 	msg.opcode = HCI_CMD_DISCONNECT_TCP;
 	msg.DataLen = 1;
-	msg.p_data = &tcp_handle;
+    uint8_t temp_tcp_handle=tcp_handle;
+	msg.p_data = &temp_tcp_handle;
 	BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_DISCONNECT_TCP);
   SendCMD(&msg);
   StartTick=SysTick_GetTick();
@@ -993,7 +1029,7 @@
 		#endif
 		if(hci_bt.type==HCI_EVENT)
 		{
-			
+
 			StartTick=SysTick_GetTick();//处理tx被rx阻塞时的timeout
 			switch(hci_bt.opcode)
 			{
@@ -1003,28 +1039,28 @@
 					SaveData(hci_bt.p_data,hci_bt.DataLen);
 					PacketNum++;
 					break;
-					
+
 				case HCI_EVENT_BLE_DATA_RECEIVED:
 //					SaveData((uint8_t *)&hci_bt,hci_bt.DataLen+3);
 					SaveData((uint8_t*)&hci_bt,3);
-					SaveData(hci_bt.p_data,hci_bt.DataLen);												
+					SaveData(hci_bt.p_data,hci_bt.DataLen);
 					PacketNum++;
 					break;
-				
+
 				case HCI_EVENT_BNEP_RECEIVE_TCP_DATA:
 //					SaveData((uint8_t *)&hci_bt,hci_bt.DataLen+3);
 					SaveData((uint8_t*)&hci_bt,3);
-					SaveData(hci_bt.p_data,hci_bt.DataLen);												
+					SaveData(hci_bt.p_data,hci_bt.DataLen);
 					PacketNum++;
 					break;
-				
+
 				case HCI_EVENT_BNEP_RECEIVE_UDP_DATA:
 //					SaveData((uint8_t *)&hci_bt,hci_bt.DataLen+3);
 					SaveData((uint8_t*)&hci_bt,3);
-					SaveData(hci_bt.p_data,hci_bt.DataLen);												
+					SaveData(hci_bt.p_data,hci_bt.DataLen);
 					PacketNum++;
 					break;
-				
+
 				case HCI_EVENT_BT_CONNECTED:
 				case HCI_EVENT_BLE_CONNECTED:
 				case HCI_EVENT_GKEY:
@@ -1046,8 +1082,8 @@
 				case HCI_EVENT_BB_DISCONNECT:
 				case HCI_EVENT_BT_NAME:
 				case HCI_EVENT_UDP_INFO:
-				
-					
+
+
 			//		SaveData((uint8_t *)&hci_bt,hci_bt.DataLen+3);
 					SaveData((uint8_t*)&hci_bt,3);
 					SaveData(hci_bt.p_data,hci_bt.DataLen);
@@ -1119,7 +1155,7 @@
 								BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_SET_PINCODE);
 							}
 							break;
-							
+
 						case HCI_CMD_VERSION_REQUEST:
 							if(!hci_bt.p_data[1])
 							{
@@ -1163,6 +1199,13 @@
 							}
 							break;
 
+						case HCI_CMD_SET_LPM_MODE:
+							if(!hci_bt.p_data[1])
+							{
+								BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_SET_LPM_MODE);
+							}
+							break;
+
 						case HCI_CMD_PASSKEY_ENTRY:
 							if(!hci_bt.p_data[1])
 							{
@@ -1183,7 +1226,7 @@
 								BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_LE_SET_SCAN_DATA);
 							}
 						break;
-						
+
 						case HCI_CMD_LE_SEND_CONN_UPDATE_REQ:
 							if(!hci_bt.p_data[1])
 							{
@@ -1194,94 +1237,97 @@
 						if(!hci_bt.p_data[1])
 						{
 							 BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_LE_SET_ADV_PARM);
-						}							
+						}
 						break;
-						
+
 					case HCI_CMD_SET_TX_POWER:
 						if(!hci_bt.p_data[1])
 						{
 							 BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_SET_TXPOWER);
-						}							
+						}
 						break;
-						
+
 						case HCI_CMD_REJECT_JUSTWORK:
 						if(!hci_bt.p_data[1])
 						{
 							 BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_REJECT_JUSTWORK);
-						}								
+						}
 						break;
-						
+
 						case HCI_CMD_SET_COD:
 						if(!hci_bt.p_data[1])
 						{
 							BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_SET_COD);
 						}
 						break;
-												
+
 						case HCI_CMD_DELETE_CUSTOMIZE_SERVICE:
 						if(!hci_bt.p_data[1])
 						{
 							BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_DELETE_SERVICE);
 						}
-						break;					
-				
+						break;
+
 						case HCI_CMD_LE_SET_FIXED_PASSKEY:
 						if(!hci_bt.p_data[1])
 						{
 							 BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_LE_SET_FIXED_PASSKEY);
 						}
 						break;
-						
+
 						case HCI_CMD_CONNECT_BNEP:
 						if(!hci_bt.p_data[1])
 						{
 							 BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_CONNECT_BNEP);
 						}
 						break;
-						
+
 						case HCI_CMD_CONNECT_TCP:
 						if(!hci_bt.p_data[1])
 						{
 							 BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_CONNECT_TCP);
 						}
 						break;
-						
+
 						case HCI_CMD_DISCONNECT_TCP:
 						if(!hci_bt.p_data[1])
 						{
 							 BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_DISCONNECT_TCP);
 						}
 						break;
-						
+
 						case HCI_CMD_BNEP_SEND_TCP_DATA:
 						if(!hci_bt.p_data[1])
 						{
 							 BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_BNEP_SEND_TCP_DATA);
 						}
 						break;
-						
+
 						case HCI_CMD_SEND_UDP_DATA:
 						if(!hci_bt.p_data[1])
 						{
 							 BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_BNEP_SEND_UDP_DATA);
 						}
 						break;
-						
+
 						case HCI_CMD_SEND_BIG_DATA:
 						if(!hci_bt.p_data[1])
 						{
 							 BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_BNEP_SEND_TCP_BIG_DATA);
 						}
 						break;
-						
+
 						case HCI_CMD_DNS_REQ:
 						if(!hci_bt.p_data[1])
 						{
 							 BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_DNS_REQ);
 						}
 						break;
-						
+
 						default:
+						#ifdef BT_ERROR_LOG
+						MyPrintf("bt 06 cmd err\n");
+						#endif
 							break;
 					}
 					break;
@@ -1294,20 +1340,20 @@
 					BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_STATUS_REQUEST);
 					CmdRepData[0] = hci_bt.p_data[0];
 					break;
-				
+
 				case HCI_EVENT_UUID_HANDLE:
 					BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_ADD_UUID);
 					CmdRepData[0] = hci_bt.p_data[0];
 					CmdRepData[1] = hci_bt.p_data[1];
 					break;
-				
+
 				case HCI_EVENT_BIG_DATA_FINISH:
 					if(hci_bt.p_data[0]==0x00)
 					{
 						BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_BNEP_SEND_TCP_BIG_DATA_FINISH);
 					}
 					break;
-				
+
 				case HCI_EVENT_BIG_DATA_STATUS:
 					if(hci_bt.p_data[0]==0x03||hci_bt.p_data[0]==0x04)
 					{
@@ -1316,6 +1362,9 @@
 					break;
 
 				default:
+				#ifdef BT_ERROR_LOG
+				MyPrintf("bt event err");
+				#endif
 					break;
 			}
 			IPC_HOLD_BT = 0;
@@ -1323,14 +1372,14 @@
 		}
 		else
 		{
-			#if BT_LOG
-			MyPrintf("receive bt data err");
+			#ifdef BT_ERROR_LOG
+			MyPrintf("bt 02 err");
 			#endif
 		}
 	}
 	else
 	{
-		#if BT_LOG
+		#ifdef BT_ERROR_LOG
 		MyPrintf("receive bt data err");
 		#endif
 	}
@@ -1344,7 +1393,7 @@
 	if(TempIndex==BluetoothBuf.BufSize)	TempIndex=0;
 	TempOpcode=BluetoothBuf.pBuf[TempIndex];
 
-	/*这几个事件用户不用取数据，所以跳过数据包，维护读指针， 
+	/*这几个事件用户不用取数据，所以跳过数据包，维护读指针，
 	其他需要用户获取数据的事件则在BT_ReadBTData中维护指针*/
 	if(	TempOpcode==BT_CONNECTED||\
 		TempOpcode==BLE_CONNECTED||\
@@ -1358,7 +1407,9 @@
 	{
 		SkipData(3);
 	}
+	NVIC_DisableIRQ(BT_IRQn);
 	PacketNum--;
+	NVIC_EnableIRQ(BT_IRQn);
 	return TempOpcode;
 }
 
@@ -1373,11 +1424,11 @@
 	SkipData(1);
 	OpCode=GetData(TRUE);
 	len=GetData(TRUE);
-	if(OpCode==BLE_DATA)
-	{
-		len-=2;//ble handle 处理
-		SkipData(2);
-	}
+//	if(OpCode==BLE_DATA)
+//	{
+//		len-=2;//ble handle 处理
+//		SkipData(2);
+//	}
 	for(i=0;i<len;i++)
 	{
 		pbuf[i]=GetData(TRUE);
Index: sdk/yc_ipc.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_ipc.h	(revision 788)
+++ /YC3121_SDK/fw/sdk/yc_ipc.h	(working copy)
@@ -18,6 +18,14 @@
 #define RB_UPDATE_PTR(p,s,e)       ((p) == (e))?((p)=(s)):((p)++)
 #define M0_BASE_ADDR               0xC0000
 
+#define MEM_SPP_FLOWCTRL_FLAG_ADDR    (0xc453d)
+#define MEM_SPP_FLOWCTRL_FLAG_VALUE   (0x01)	//0x00:disable flowctrl  0x01:enable flowctrl
+
+
+#define MEM_RFCOMM_LMP_DIS_FLAG_ADDR	(0xc4acf)
+#define MEM_RFCOMM_LMP_DIS_FLAG_VALUE	(0x00)	//0x00:յ rfcomm disconnected Ͽlmp   0x01:յrfcomm disconnectedϿlmp
+
+
 #pragma pack(1)
 typedef struct
 {
Index: sdk/yc_ipc.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_ipc.c	(revision 788)
+++ /YC3121_SDK/fw/sdk/yc_ipc.c	(working copy)
@@ -6,6 +6,7 @@
 IPC_TypeDef *IpcTx = (IPC_TypeDef *)(IPC_TX_START_ADDR);
 
 uint8_t ipcrecbuf[IPCREVSIZE] = {0};
+uint8_t bt_lpm_mode=0;
 
 Boolean IPC_have_data()
 {
@@ -14,6 +15,13 @@
 
 uint16_t IPC_get_available_size()
 {
+	uint16_t retLen=0;
+    if(bt_lpm_mode==1)
+    {
+        WAKEUP_BT |= (1 << WAKEUP_BT_FLAG);
+        IPC_HOLD_BT  = 1;
+        delay_ms(10);
+    }
     uint16_t readtx = HR_REG_16BIT(&IpcTx->ReadPtr);
     uint16_t wrtptr = HR_REG_16BIT(&IpcTx->WrtiePtr);
     uint16_t ipcendaddr = HR_REG_16BIT(&IpcTx->IpcEndAddr);
@@ -21,12 +29,18 @@
 
     if (readtx > wrtptr)
     {
-        return readtx - wrtptr;
+        retLen = readtx - wrtptr;
     }
     else
     {
-        return ((ipcendaddr - ipcstartaddr + 1) - (readtx - wrtptr));
+        retLen = ((ipcendaddr - ipcstartaddr + 1) - (readtx - wrtptr));
     }
+    if(bt_lpm_mode==1)
+    {
+        IPC_HOLD_BT = 0;
+        WAKEUP_BT &= ~(1 << WAKEUP_BT_FLAG);
+    }
+    return retLen;
 }
 
 void IPC_TxData(HCI_TypeDef *IpcData)
@@ -34,9 +48,12 @@
 	#ifdef IPC_DEBUG
 	PrintHCIPack(IpcData,"tx");
 	#endif
-    WAKEUP_BT |= (1 << WAKEUP_BT_FLAG);
-    IPC_HOLD_BT  = 1;
-    delay_ms(10);
+    if(bt_lpm_mode==1)
+    {
+        WAKEUP_BT |= (1 << WAKEUP_BT_FLAG);
+        IPC_HOLD_BT  = 1;
+        delay_ms(10);
+    }
     uint16_t Wptr  = HR_REG_16BIT(&IpcTx->WrtiePtr);
     uint16_t Len   = IpcData->DataLen + 3;
     uint8_t *Rptr = (uint8_t *)IpcData;
@@ -45,12 +62,15 @@
         HW_IPC_REG_8BIT(Wptr, *Rptr++);
         RB_UPDATE_PTR(Wptr, HR_REG_16BIT(&IpcTx->IpcStartAddr),  HR_REG_16BIT(&IpcTx->IpcEndAddr));
         if (Len == IpcData->DataLen)
-            Rptr = IpcData->p_data;
+        Rptr = IpcData->p_data;
     }
 
     HW_REG_16BIT(&IpcTx->WrtiePtr, (uint32_t)Wptr);
-    IPC_HOLD_BT = 0;
-    WAKEUP_BT &= ~(1 << WAKEUP_BT_FLAG);
+    if(bt_lpm_mode==1)
+    {
+        IPC_HOLD_BT = 0;
+        WAKEUP_BT &= ~(1 << WAKEUP_BT_FLAG);
+    }
 }
 
 Boolean IPC_PutBtData(const void *buf, uint32_t size)
@@ -59,9 +79,12 @@
     {
         return FALSE;
     }
-    WAKEUP_BT |= (1 << WAKEUP_BT_FLAG);
-    IPC_HOLD_BT  = 1;
-    delay_ms(10);
+    if(bt_lpm_mode==1)
+    {
+        WAKEUP_BT |= (1 << WAKEUP_BT_FLAG);
+        IPC_HOLD_BT  = 1;
+        delay_ms(10);
+    }
     uint16_t Wptr  = HR_REG_16BIT(&IpcTx->WrtiePtr);
     uint8_t *Rptr = (uint8_t *)buf;
     while (size--)
@@ -71,8 +94,11 @@
     }
 
     HW_REG_16BIT(&IpcTx->WrtiePtr, (uint32_t)Wptr);
-    IPC_HOLD_BT = 0;
-    WAKEUP_BT &= ~(1 << WAKEUP_BT_FLAG);
+    if(bt_lpm_mode==1)
+    {
+        IPC_HOLD_BT = 0;
+        WAKEUP_BT &= ~(1 << WAKEUP_BT_FLAG);
+    }
     return TRUE;
 }
 
@@ -176,7 +202,23 @@
         btcode += 2;
         addr = GETWORD(btcode) | 0xc0000;
         btcode += 2;
-        _dmacopy((byte *)addr, (byte *)btcode, len);
+        if(addr==MEM_SPP_FLOWCTRL_FLAG_ADDR && len==0x0004)
+        {
+            byte mem_spp_flowctrl_buf[4];
+            mem_spp_flowctrl_buf[0]=MEM_SPP_FLOWCTRL_FLAG_VALUE;
+            memcpy((byte*)&mem_spp_flowctrl_buf[1],btcode+1,3);
+            _dmacopy((byte *)addr, mem_spp_flowctrl_buf, len);
+        }
+        else if(addr==MEM_RFCOMM_LMP_DIS_FLAG_ADDR && len==0x0001)
+        {
+            byte mem_rfcomm_lmp_dis_flag;
+            mem_rfcomm_lmp_dis_flag=MEM_RFCOMM_LMP_DIS_FLAG_VALUE;
+            _dmacopy((byte *)addr, (byte *)&mem_rfcomm_lmp_dis_flag, len);
+        }
+        else
+        {
+          _dmacopy((byte *)addr, (byte *)btcode, len);
+        }
         btcode += len;
     }
 }
@@ -189,7 +231,9 @@
     for (uint32_t i = 0; i < 0x1000; i++)
     {
         *(volatile uint8_t *)(0xc0000 + i) = 0;
+        delay_us(1);
         *(volatile uint8_t *)(0xc4000 + i) = 0;
+        delay_us(1);
     }
 }
 #if (VERSIONS == NO_BT)
@@ -197,7 +241,9 @@
 {
     uint16_t addr = 0;
     addr  = (*(uint8_t *)(0xc800e));
+    delay_us(1100);
     addr += (*(uint8_t *)(0xc800f)) << 8;
+    delay_us(1100);
     return addr;
 }
 
@@ -229,11 +275,15 @@
         disable_intr(INTR_BT);
         ipc_inited = TRUE;
         SYSCTRL_ROM_SWITCH = 0x94;
-        delay(10000);   //wait rom switch ok
+        //delay(10000);   //wait rom switch ok
+        delay_ms(10);
         BT_RESET = 1;
-        delay(10000);   //wait for reset ok
+        //delay(10000);   //wait for reset ok
+        delay_ms(1);
         while (!(BT_CONFIG & (1 << BT_INIT_FLAG)));
         BT_CONFIG &= (~(1 << BT_INIT_FLAG));
+        lpm_bt_write(1, 0x00f20b0a);
+        lpm_bt_write(0, 0x3084cf0f);
         erase_memory();
         _download_btcode(bt_code);
         WAKEUP_BT = 0x9c;
@@ -245,15 +295,22 @@
         disable_intr(INTR_BT);
         ipc_inited = TRUE;
 
+        SYSCTRL_ROM_SWITCH = 0x94;
+        //delay(10000);   //wait rom switch ok
+        delay_ms(10);
+
         lpm_bt_write(1, 0xd00000);
-        delay_us(1000);
+        //delay_us(1000);
+        delay_ms(1);
 
-        SYSCTRL_ROM_SWITCH = 0x94;
-        delay(10000);   //wait rom switch ok
         BT_RESET = 1;
-        delay(10000);   //wait for reset ok
+        //delay(10000);   //wait for reset ok
+        delay_ms(1);
         while (!(BT_CONFIG & (1 << BT_INIT_FLAG)));
         BT_CONFIG &= (~(1 << BT_INIT_FLAG));
+		lpm_bt_write(1, 0x00f20b0a);
+        lpm_bt_write(0, 0x3084cf0f);
+        erase_memory();
         *(volatile uint8_t *)0xC4176 = 0x0f;
         *(volatile uint8_t *)0xC4177 = 0x84;
         *(volatile uint8_t *)0xC4178 = 0x30;
@@ -262,6 +319,26 @@
         *(volatile uint8_t *)0xC40c4 = 0x4f;
         *(volatile uint8_t *)0xC4f00 = 0xff;
         delay_ms(60);
+        *(volatile uint8_t *)0xC8042 = 0x06;
+    }
+#elif (VERSIONS == NO_XTAL)
+    if (ipc_inited == FALSE)
+    {
+        disable_intr(INTR_BT);
+        ipc_inited = TRUE;
+
+        SYSCTRL_ROM_SWITCH = 0x94;
+        delay_ms(10); //wait rom switch ok
+
+        lpm_bt_write(1, 0xd00000);
+        delay_ms(1);
+
+        BT_RESET = 1;
+        delay_ms(1); //wait for reset ok
+        while (!(BT_CONFIG & (1 << BT_INIT_FLAG)));
+        BT_CONFIG &= (~(1 << BT_INIT_FLAG));
+		lpm_bt_write(1, 0x00f20b0a);
+        lpm_bt_write(0, 0x3084cf0f);
     }
 #endif
 }
Index: sdk/yc_sysctrl.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_sysctrl.c	(revision 788)
+++ /YC3121_SDK/fw/sdk/yc_sysctrl.c	(working copy)
@@ -29,6 +29,7 @@
 void SYSCTRL_HCLKConfig(uint32_t HCLK_Div)
 {
     _ASSERT(IS_GET_SYSCTRL_HCLK_DIV(HCLK_Div));
+    __asm("CPSID i");
     if (HCLK_Div == SYSCTRL_HCLK_Div_None)
     {
         uint32_t HCLKConfig_Div_None_addr = (uint32_t)HCLKConfig_Div_None;
@@ -40,7 +41,7 @@
         int temp = (SYSCTRL_HCLK_CON & (~SYSCTRL_HCLK_COFG_REGBIT)) | HCLK_Div;
         SYSCTRL_HCLK_CON =  temp;
     }
-
+    __asm("CPSIE i");
 }
 
 void SYSCTRL_GetClocksFreq(SYSCTRL_ClocksTypeDef *SYSCTRL_Clocks)
