Index: ModuleDemo/LPM_SLEEP/lpm_demo/prj/MDK/YC3121_Keil.uvprojx
===================================================================
--- /YC3121_demo/ModuleDemo/LPM_SLEEP/lpm_demo/prj/MDK/YC3121_Keil.uvprojx	(revision 950)
+++ /YC3121_demo/ModuleDemo/LPM_SLEEP/lpm_demo/prj/MDK/YC3121_Keil.uvprojx	(working copy)
@@ -338,7 +338,7 @@
               <MiscControls></MiscControls>
               <Define>__USEKEILCOMPILE__</Define>
               <Undefine></Undefine>
-              <IncludePath>..\..\..\..\..\Librarier\sdk;..\..\..\..\..\Librarier\core;..\..\user</IncludePath>
+              <IncludePath>..\..\..\..\..\Librarier\sdk;..\..\..\..\..\Librarier\core;..\..\user;..\..\user</IncludePath>
             </VariousControls>
           </Cads>
           <Aads>
Index: ModuleDemo/LPM_SLEEP/lpm_demo/user/main.c
===================================================================
--- /YC3121_demo/ModuleDemo/LPM_SLEEP/lpm_demo/user/main.c	(revision 950)
+++ /YC3121_demo/ModuleDemo/LPM_SLEEP/lpm_demo/user/main.c	(working copy)
@@ -36,7 +36,6 @@
 #include "misc.h"
 #include "yc_rtc.h"
 
-
 /* Private typedef -----------------------------------------------------------*/
 /* Private define ------------------------------------------------------------*/
 #define IPC_UART UART0
@@ -56,30 +55,10 @@
 
 //uint8_t connect_data[8] = {0x28, 0x00, 0x28, 0x00, 0x00, 0x00, 0xf4, 0x01};
 uint8_t connect_data[8] = {0x08, 0x89, 0x01, 0x90, 0x00, 0x00, 0x2c, 0x01};
-// byte0： uuid length
-//byte1-16: uuid
-// 49535343-FE78-4AE5-8FA9-9FAFD205E455
-uint8_t ble_service_uuid_lsps[] = {0x10,0x55,0xe4,0x05,0xd2,0xaf,0x9f,0xa9,0x8f,0xe5,0x4a,0x7d,0xfe,0x43,0x53,0x53,0x49};
-
-/*
-byte0: characterisitic
-byte1:characterisitic uuid length
-byte2-17:characterisitic uuid
-byte18:write/read payload length
-byte19-20:write/read payload
-*/
-//49535343-1E4D-4BD9-BA61-23C647249616
-uint8_t ble_Characteristic_uuid_lsps_tx[] = {0x10,0x10,0x16,0x96,0x24,0x47,0xc6,0x23,0x61,0xba,0xd9,0x4b,0x4d,0x1e,0x43,0x53,0x53,0x49,0x01,0x00};
-//49535343-8841-43F4-A8D4-ECBE34729BB3
-uint8_t ble_Characteristic_uuid_lsps_rx[] = {0x0c,0x10,0xb3,0x9b,0x72,0x34,0xbe,0xec,0xd4,0xa8,0xf4,0x43,0x41,0x88,0x43,0x53,0x53,0x49,0x01,0x00};
-//49535343-aca3-481c-91ec-d85e28a60318
-uint8_t ble_Characteristic_uuid_flow_ctrl[] = {0x18,0x10,0x18,0x03,0xa6,0x28,0x5e,0xd8,0xec,0x91,0x1c,0x48,0xa3,0xac,0x43,0x53,0x53,0x49,0x01,0x00};
-
 
 #define IFLASH_NVRAM_ADDR 0x1000000+((512-4)*1024)
 #define NVRAM_LEN 170//Nvram 长度170bytes,每组Nvram长度为34bytes,最多可存储5组配对信息
 
-uint16_t ble_send_handle=0x2a;
 uint8_t bt_cod[3] = {0x24,0x04,0x04};
 uint8_t NvramData[NVRAM_LEN]= {0};
 uint8_t BT_WAKEUP_FLAG = 0;
@@ -165,8 +144,6 @@
     }
 }
 
-
-
 /**
   * @brief  Main program
   * @retval None
@@ -215,19 +192,19 @@
                 GPIO_Config(GPIOA, GPIO_Pin_14, PULL_DOWN);
                 GPIO_Config(GPIOA, GPIO_Pin_15, PULL_DOWN);
 
-                CM0_Sleep(20, GPIO_Pin_5, 0, 0, 1);                       //定时 2s 唤醒(单位100ms)，IO5 输入高唤醒
+                CM0_Sleep(50, GPIO_Pin_5, 0, 0, 1);                       //定时 2s 唤醒(单位100ms)，IO5 输入高唤醒
                 break;
 
             case '3':
                 MyPrintf(" M0 Deep Sleep and BT Runing....\n");           //*******************************************************
-                Disable_Trng();                                           //case功能：M0 深睡，BT 正常运行
+                Disable_Trng();                                           //case功能：M0 深睡，BT 正常运行        
                 GPIO_Unused_Pd();                                         //唤醒方式：GPIO 唤醒，可配置高电平唤醒或者低电平唤醒
                 GPIO_Config(GPIOA, GPIO_Pin_1, PULL_DOWN);                //          RTC 定时唤醒，单位为 100ms，此时由 BT 定时唤醒
-                GPIO_Config(GPIOA, GPIO_Pin_0, PULL_DOWN);
+                GPIO_Config(GPIOA, GPIO_Pin_0, PULL_DOWN);                //          bt 事件会把 m0唤醒
                 GPIO_Config(GPIOA, GPIO_Pin_14, PULL_DOWN);
                 GPIO_Config(GPIOA, GPIO_Pin_15, PULL_DOWN);
 
-                CM0_Sleep(20, GPIO_Pin_5, 0, 0, 0);                        //定时 2s 唤醒(单位100ms),IO5输入高唤醒
+                CM0_Sleep(50, GPIO_Pin_5, 0, 0, 0);                        //定时 2s 唤醒(单位100ms),IO5输入高唤醒
                 break;
 
             case '4':
@@ -249,11 +226,13 @@
                                         SYSCTRL_AHBPeriph_7811 | SYSCTRL_AHBPeriph_ADC7811 | \
                                         SYSCTRL_AHBPeriph_CP, DISABLE);
 
+                BT_SetWakeupGpio(0, 1 << M0_WAKEUP_HOLD_BT_GPIO, 0);      //在 m0 降频 bt 深睡前，必须设置 hold_bt_io，此 io 单独使用，不能用作其他功能
+                GPIO_CONFIG(M0_WAKEUP_HOLD_BT_GPIO) = GPCFG_PD;           //设置初始电平
                 BT_Hibernate();
                 rtccnt_back = RTC_GetRefRegister();
-                MyPrintf("trc = %d\r\n", rtccnt_back);
                 while(1)
                 {
+                    BT_Progress();
                     if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_5) || ((RTC_GetRefRegister() - rtccnt_back) >= 5))    //配置 IO5 输入高恢复，RTC定时 5S 恢复
                     {
                         SYSCTRL_AHBPeriphClockCmd(SYSCTRL_AHBPeriph_INTR | \
@@ -271,11 +250,11 @@
             case '5':
                 MyPrintf(" M0 Light Sleep and BT Light Sleep....\n"); //**********************************************
                 if(BT_SetWakeupRtc(50) == TRUE)                       //case功能：M0 降频，BT 浅睡，BT此时可以维持连接
-                    MyPrintf("BT_SetWakeupRtc success\n");            //唤醒方式：GPIO 唤醒，RTC 唤醒
-                else
+                    MyPrintf("BT_SetWakeupRtc success\n");            //唤醒方式：RTC 唤醒
+                else                                                  //          蓝牙产生事件唤醒
                     MyPrintf("BT_SetWakeupRtc fail\n");
 
-                if( BT_SetWakeupGpio(0, GPIO_Pin_5, 0) == TRUE)
+                if(BT_SetWakeupGpio(0, GPIO_Pin_5, 0) == TRUE)        
                 {
                     MyPrintf("BT_SetWakeupGpio success\n");
                 }
@@ -300,12 +279,15 @@
                                         SYSCTRL_AHBPeriph_7816 | SYSCTRL_AHBPeriph_SM4 | \
                                         SYSCTRL_AHBPeriph_7811 | SYSCTRL_AHBPeriph_ADC7811 | \
                                         SYSCTRL_AHBPeriph_CP, DISABLE);
-            BT_WAKEUP_FLAG = 0;
+                BT_SetWakeupGpio(0, 1 << M0_WAKEUP_HOLD_BT_GPIO, 0);  //在 m0 降频 bt LPM前，必须设置 hold_bt_io，此 io 单独使用，不能用作其他功能
+                GPIO_CONFIG(M0_WAKEUP_HOLD_BT_GPIO) = GPCFG_PD;       //设置初始电平
                 BT_SetLpmMode(0x01);
                 IPC_dishold_bt();
+                BT_WAKEUP_FLAG = 0;
                 while(1)
                 {
-                    if(BT_WAKEUP_FLAG)                               //蓝牙产生事件唤醒
+                    BT_Progress();
+                    if(BT_WAKEUP_FLAG)                               
                     {
                         BT_WAKEUP_FLAG = 0;
                         SYSCTRL_AHBPeriphClockCmd(SYSCTRL_AHBPeriph_INTR | \
@@ -485,35 +467,6 @@
         else
             MyPrintf("set COD failed\n");
 
-        if(BT_DeleteService() == TRUE) //  删除用户自定义服务
-            MyPrintf("delete service sucess\n");
-        else
-            MyPrintf("delete service failed\n");
-
-        temp_handle=BT_AddBleService(ble_service_uuid_lsps,sizeof(ble_service_uuid_lsps));
-        if( temp_handle!= 0)  //增加服务 返回handle无需保存
-            MyPrintf("add service sucess,handle=%04x\n",temp_handle);
-        else
-            MyPrintf("add service failed,return=%04x\n",temp_handle);
-
-        ble_send_handle=BT_AddBleCharacteristic(ble_Characteristic_uuid_lsps_tx,sizeof(ble_Characteristic_uuid_lsps_tx));
-        if( ble_send_handle!= 0)  //增加服务特征  write返回的handle需要保存，发数据使用
-            MyPrintf("add Characteristic tx sucess,handle=%04x\n",ble_send_handle);
-        else
-            MyPrintf("add Characteristic tx failed,return=%04x\n",ble_send_handle);
-
-        temp_handle=BT_AddBleCharacteristic(ble_Characteristic_uuid_lsps_rx,sizeof(ble_Characteristic_uuid_lsps_rx));
-        if( temp_handle!= 0)
-            MyPrintf("add Characteristic rx sucess;handle=%04x\n",temp_handle);
-        else
-            MyPrintf("add Characteristic rx failed,return=%04x\n",temp_handle);
-
-        temp_handle=BT_AddBleCharacteristic(ble_Characteristic_uuid_flow_ctrl,sizeof(ble_Characteristic_uuid_flow_ctrl));
-        if( temp_handle!= 0)
-            MyPrintf("add Characteristic flow_ctrl sucess;handle=%04x\n",temp_handle);
-        else
-            MyPrintf("add Characteristic flow_ctrl failed,return=%04x\n",temp_handle);
-
         genBleAdvData(bt_name,sizeof(bt_name)-1,bt_addr,ble_adv_data);
         if(BT_SetLEAdvData(ble_adv_data,sizeof(ble_adv_data)) == TRUE)
             MyPrintf("BT_SetLEAdvData sucess\n");
@@ -596,14 +549,6 @@
             MyPrintf("received %d bytes ble data[handle:%02x %02x]:\n",BleDataLen-2,bleData[0],bleData[1]);
             for(int i=0; i<(BleDataLen-2); i++)	MyPrintf("%02x ",bleData[2+i]);
             MyPrintf("\n");
-
-            //add handle
-            bleData[0]=(ble_send_handle&0xff);
-            bleData[1]=((ble_send_handle>>8)&0xff);
-            BT_SendBleData(bleData,BleDataLen);
-            MyPrintf("send %d bytes ble data[%02x %02x]:\n",BleDataLen-2,bleData[0],bleData[1]);
-            for(int i=0; i<(BleDataLen-2); i++)	MyPrintf("%02x ",bleData[2+i]);
-            MyPrintf("\n");
         }
         else	MyPrintf("read ble data error\r\n");
     }
