Index: Librarier/bt_rom/format/headset.format
===================================================================
--- /YC1121E/SoftCode/1121EB/branch/HciDongle/Librarier/bt_rom/format/headset.format	(revision 4391)
+++ /YC1121E/SoftCode/1121EB/branch/HciDongle/Librarier/bt_rom/format/headset.format	(working copy)
@@ -286,6 +286,11 @@
 	2 mem_encryp_inital_value
 	2 mem_encryp_param
 	1 mem_encryp_count
+
+	1 mem_qspi_lock_flag_cm0
+	1 mem_qspi_lock_flag_respin
+	1 mem_qspi_lock_victim
+
 0 mem_headset_end
 )
 (
Index: Librarier/bt_rom/format/ipc.format
===================================================================
--- /YC1121E/SoftCode/1121EB/branch/HciDongle/Librarier/bt_rom/format/ipc.format	(revision 4391)
+++ /YC1121E/SoftCode/1121EB/branch/HciDongle/Librarier/bt_rom/format/ipc.format	(working copy)
@@ -88,6 +88,10 @@
 0x0d IPC_TYPE_HCI
 )
 
+(
+0x35 QSPI_LOCK_VICTIM_CM0   //
+0x53 QSPI_LOCK_VICTIM_RESPIN   //
+)
 
 (
 0x2000 MSBC_PCM_IN_BUFFER_ADDR
Index: Librarier/drivers/qspi/yc11xx_qspi.c
===================================================================
--- /YC1121E/SoftCode/1121EB/branch/HciDongle/Librarier/drivers/qspi/yc11xx_qspi.c	(revision 4391)
+++ /YC1121E/SoftCode/1121EB/branch/HciDongle/Librarier/drivers/qspi/yc11xx_qspi.c	(working copy)
@@ -3,13 +3,29 @@
 #define QSPI_BUSYTIMEOUT (0x1000000)
 #define DMA_WAIT_TIMEOUT (0x10000)
 
+void qspi_get_lock(void)
+{
+    HWRITE_INLINE(mem_qspi_lock_flag_cm0, 1);// I'm interested
+    HWRITE_INLINE(mem_qspi_lock_victim, QSPI_LOCK_VICTIM_CM0);// you go first
+    
+    while(((HREAD_INLINE(mem_qspi_lock_flag_respin)) != 0) 
+        && ((HREAD_INLINE(mem_qspi_lock_victim)) == QSPI_LOCK_VICTIM_CM0));// wait
+}
+void qspi_free_lock(void)
+{
+    HWRITE_INLINE(mem_qspi_lock_flag_cm0, 0);
+}
+
+
 void __attribute__((noinline))   SetLockQSPI( )
 {
+		qspi_get_lock();
 		HWRITE_INLINE(mem_m0_lock_qspi, 1);
 }
 
 void __attribute__((noinline))   SetReleaseQSPI( )
 {
+		qspi_free_lock();
 		HWRITE_INLINE(mem_m0_lock_qspi, 0);	
 }
 
Index: ModuleDemo/25_OTA/bt_demo/BT/patch/patch.prog
===================================================================
--- /YC1121E/SoftCode/1121EB/branch/HciDongle/ModuleDemo/25_OTA/bt_demo/BT/patch/patch.prog	(revision 4391)
+++ /YC1121E/SoftCode/1121EB/branch/HciDongle/ModuleDemo/25_OTA/bt_demo/BT/patch/patch.prog	(working copy)
@@ -3420,6 +3420,7 @@
 	store 2,mem_flash_trans_length
 	setarg mem_zcode_buff_user
 	store 2,mem_flash_data_address
+	call qspi_get_lock
 	call check_m0_qspi_lock_and_pause
 	fetch 1,core_qspi_ctrl
 	store 1,mem_pdatatemp
@@ -3427,6 +3428,9 @@
 	fetch 1,mem_pdatatemp
 	store 1,core_qspi_ctrl
 
+	jam 0,mem_qspi_lock_flag_respin
+	//call qspi_free_lock
+
 	setarg mem_zcode_buff_user
 	branch zcode_entrance0
 
@@ -3543,4 +3547,22 @@
 	isub temp,null
 	nrtn zero
 	branch lpm_dispatch+12
+
+//get qspi lock
+qspi_get_lock:
+	jam 1,mem_qspi_lock_flag_respin // I'm interested
+
+	jam QSPI_LOCK_VICTIM_RESPIN,mem_qspi_lock_victim// you go first
+qspi_get_lock_wait:
+	fetch 1,mem_qspi_lock_flag_cm0
+	rtn blank
+	
+	fetch 1,mem_qspi_lock_victim
+	rtnne DEBUG_LOG_LOCK_VICTIM_RESPIN
+	branch qspi_get_lock_wait
+
+//free qspi lock
+//qspi_free_lock:
+//	jam 0,mem_qspi_lock_flag_respin
+//	rtn
 	
Index: ModuleDemo/25_OTA/bt_demo/CM0/User/btreg.h
===================================================================
--- /YC1121E/SoftCode/1121EB/branch/HciDongle/ModuleDemo/25_OTA/bt_demo/CM0/User/btreg.h	(revision 4391)
+++ /YC1121E/SoftCode/1121EB/branch/HciDongle/ModuleDemo/25_OTA/bt_demo/CM0/User/btreg.h	(working copy)
@@ -1689,7 +1689,10 @@
 #define	mem_encryp_inital_value                 	0x4f5d
 #define	mem_encryp_param                        	0x4f5f
 #define	mem_encryp_count                        	0x4f61
-#define	mem_headset_end                         	0x4f62
+#define	mem_qspi_lock_flag_cm0                  	0x4f62
+#define	mem_qspi_lock_flag_respin               	0x4f63
+#define	mem_qspi_lock_victim                    	0x4f64
+#define	mem_headset_end                         	0x4f65
 #define	mem_usb_mouse_data                      	0x4ace
 #define	mem_usb_kb_data                         	0x4ade
 #define	mem_usb_kb_multikey                     	0x4aee
@@ -1757,6 +1760,8 @@
 #define	IPC_TYPE_HFP                            	0x0b
 #define	IPC_TYPE_TWS                            	0x0c
 #define	IPC_TYPE_HCI                            	0x0d
+#define	QSPI_LOCK_VICTIM_CM0                    	0x35
+#define	QSPI_LOCK_VICTIM_RESPIN                 	0x53
 #define	MSBC_PCM_IN_BUFFER_ADDR                 	0x2000
 #define	MSBC_OUT_BUFFER_ADDR                    	0x2800
 #define	MSBC_IN_BUFFER_ADDR                     	0x3000
Index: ModuleDemo/25_OTA/bt_demo/CM0/respin/memmap.format
===================================================================
--- /YC1121E/SoftCode/1121EB/branch/HciDongle/ModuleDemo/25_OTA/bt_demo/CM0/respin/memmap.format	(revision 4391)
+++ /YC1121E/SoftCode/1121EB/branch/HciDongle/ModuleDemo/25_OTA/bt_demo/CM0/respin/memmap.format	(working copy)
@@ -1687,7 +1687,10 @@
 0x4f5d mem_encryp_inital_value
 0x4f5f mem_encryp_param
 0x4f61 mem_encryp_count
-0x4f62 mem_headset_end
+0x4f62 mem_qspi_lock_flag_cm0
+0x4f63 mem_qspi_lock_flag_respin
+0x4f64 mem_qspi_lock_victim
+0x4f65 mem_headset_end
 0x4ace mem_usb_mouse_data
 0x4ade mem_usb_kb_data
 0x4aee mem_usb_kb_multikey
Index: ModuleDemo/25_OTA/bt_demo/CM0/respin/ramcode.rom
===================================================================
--- /YC1121E/SoftCode/1121EB/branch/HciDongle/ModuleDemo/25_OTA/bt_demo/CM0/respin/ramcode.rom	(revision 4391)
+++ /YC1121E/SoftCode/1121EB/branch/HciDongle/ModuleDemo/25_OTA/bt_demo/CM0/respin/ramcode.rom	(working copy)
@@ -85,8 +85,8 @@
 c04300a2
 c04f00a6
 c0500161
-c0520795
-c0540774
+c0520797
+c0540776
 c05c812d
 c05d0626
 c0700158
@@ -107,7 +107,7 @@
 c01f04e1
 c01f844e
 c0208536
-c021076b
+c021076d
 c025853a
 c027851a
 c0290645
@@ -118,7 +118,7 @@
 c032065f
 c0370743
 c03802b1
-c03887a2
+c03887ab
 c03902c1
 c03a0163
 c0440110
@@ -157,7 +157,7 @@
 18423600
 202023b7
 204045b4
-204007a4
+204007ad
 20404909
 202045b8
 6fe24013
@@ -306,7 +306,7 @@
 67e24bce
 6fe24bef
 67e206ab
-245587a6
+245587af
 20407988
 5800062b
 67e4431d
@@ -314,9 +314,9 @@
 67e4431f
 5800012c
 67e4431b
-5800077c
+5800077e
 67e44315
-5800077f
+58000781
 67e44313
 20558153
 24358146
@@ -326,7 +326,7 @@
 20203f28
 58001171
 67e44f5d
-204007a8
+204007b1
 204057bf
 6fec4140
 67ec4340
@@ -361,10 +361,10 @@
 68420048
 20407a08
 6fe20048
-c28387aa
+c28387b3
 c0188188
 c0060197
-c0038761
+c0038763
 c0058171
 20204f6c
 6fe20b9c
@@ -429,7 +429,7 @@
 20600000
 c6908000
 793f8021
-204007ac
+204007b5
 202002f4
 6fe20183
 203a2378
@@ -501,14 +501,14 @@
 704c9b00
 704ca100
 704c9f00
-202007ae
+202007b7
 6fe24c9a
-203a07b0
+203a07b9
 6fe24c99
 203a0221
 1fe0ffff
 67e24c99
-202007b0
+202007b9
 6fe20018
 1ff18400
 184f840a
@@ -600,7 +600,7 @@
 98467c00
 20628000
 2020037f
-202007b2
+202007bb
 20402337
 202c0263
 204024ca
@@ -736,7 +736,7 @@
 202002fc
 6fe20739
 67e206a4
-20400766
+20400768
 20204d51
 20404f51
 7006ae01
@@ -753,7 +753,7 @@
 67e2004b
 204021e1
 c6108000
-202007ac
+202007b5
 704c8803
 704c8706
 204003e5
@@ -874,7 +874,7 @@
 18007e06
 67e243e2
 20203f1a
-204007b4
+204007bd
 6a464dd8
 20200359
 6a464dd8
@@ -928,10 +928,10 @@
 c4020000
 6fe20639
 67e24e18
-202007b6
+202007bf
 6fe20046
 67e24e18
-202007b6
+202007bf
 6fe20624
 d8400000
 c1018000
@@ -1119,7 +1119,7 @@
 7042a700
 70065b00
 204047d2
-202007b8
+202007c1
 6fe204dd
 c001049c
 c0040490
@@ -1154,7 +1154,7 @@
 6844495b
 20400476
 60444957
-202007ba
+202007c3
 2040047a
 da200009
 d8200003
@@ -1177,7 +1177,7 @@
 20600000
 eff00006
 67f04c0a
-202007bc
+202007c5
 efe20006
 67e206a4
 20204890
@@ -1237,7 +1237,7 @@
 98467c00
 24628000
 2040493a
-202007b8
+202007c1
 20404536
 70100001
 70100100
@@ -1256,7 +1256,7 @@
 202005a6
 7834fc00
 204048fd
-20210771
+20210773
 204045fc
 204003ff
 7856fc00
@@ -1296,7 +1296,7 @@
 c28184f5
 6fe24e17
 1fe67c06
-24210771
+24210773
 1fe0fe01
 67e24e17
 202004f5
@@ -1331,7 +1331,7 @@
 67e40124
 24610000
 2040473e
-202007be
+202007c7
 20404972
 2040475a
 2040052d
@@ -1451,7 +1451,7 @@
 d9601388
 2020053f
 2040010e
-202007c0
+202007c9
 1a208409
 efe20002
 203a2baf
@@ -1582,7 +1582,7 @@
 20203168
 704c8c00
 704c1700
-204007c2
+204007cb
 2040039e
 202031c3
 6842063a
@@ -1600,7 +1600,7 @@
 6fe245b5
 c0014794
 6fe21002
-c0010771
+c0010773
 c002c790
 20600000
 20404906
@@ -1628,7 +1628,7 @@
 79400402
 6042063a
 20600000
-202007c4
+202007cd
 2040066f
 18227e00
 c1018000
@@ -1773,7 +1773,7 @@
 242106f0
 60424170
 20404d51
-202007c6
+202007cf
 70007c04
 20600000
 20404edd
@@ -1879,12 +1879,14 @@
 67e40241
 58004e34
 67e4023f
+204007a4
 204057e8
 6fe280a0
 67e20124
 20405589
 6fe20124
 67e280a0
+704f6300
 58004e34
 20205866
 18007e02
@@ -1903,42 +1905,42 @@
 2040682b
 700f0d15
 20206b2e
-2040076c
+2040076e
 7854fc00
 20600000
 6fe24040
 c3800000
 c3818000
 6fe247cd
-203a077b
+203a077d
 6fe24724
 207a0000
 20202d53
 6fe206ab
 67e24bef
-20200781
+20200783
 7043dd01
 20403f41
 2040554f
-20400792
+20400794
 df200020
 d8c08080
 18c20a00
 efe20006
-c001878e
-c002078e
-c002878e
-c003878e
-c016078e
-c016878e
-c0800790
+c0018790
+c0020790
+c0028790
+c0038790
+c0160790
+c0168790
+c0800792
 58000080
 e7e20005
-c2000785
+c2000787
 20600000
 df200008
 d8c0812a
-20200785
+20200787
 6fe24131
 207a0000
 2040072b
@@ -1952,6 +1954,13 @@
 98467c00
 24628000
 20202d15
+704f6301
+704f6453
+6fe24f62
+207a0000
+6fe24f64
+c1a98000
+202007a6
 580001e0
 20200745
 58000240
Index: ModuleDemo/25_OTA/bt_demo/CM0/respin/zcode.rom
===================================================================
--- /YC1121E/SoftCode/1121EB/branch/HciDongle/ModuleDemo/25_OTA/bt_demo/CM0/respin/zcode.rom	(revision 4391)
+++ /YC1121E/SoftCode/1121EB/branch/HciDongle/ModuleDemo/25_OTA/bt_demo/CM0/respin/zcode.rom	(working copy)
@@ -323,7 +323,7 @@
 2040033e
 2040033b
 c0008007
-c00107e6
+c00107ef
 20202baf
 2040032c
 67e44c94
@@ -335,7 +335,7 @@
 67e24c1a
 2040033b
 67e24c1b
-202007e8
+202007f1
 00000000
 00000000
 00000000
@@ -1353,11 +1353,11 @@
 c004000e
 c01f8012
 2020037d
-202007dc
-202007de
-202007e0
-202007e2
-202007e4
+202007e5
+202007e7
+202007e9
+202007eb
+202007ed
 2020037d
 2020037d
 6fe24c18
@@ -1472,7 +1472,7 @@
 00000000
 20200040
 6fe24f34
-243a07da
+243a07e3
 704f3401
 20400023
 6f224cd2
@@ -1548,7 +1548,7 @@
 c0078015
 c008001a
 c008801e
-202007d8
+202007e1
 2040033b
 67e244de
 20200381
@@ -1605,7 +1605,7 @@
 c0058012
 c0060025
 c0068029
-202007d6
+202007df
 2040033b
 67e244df
 1fe27200
@@ -1798,7 +1798,7 @@
 c0070020
 c0088028
 c009802c
-202007d4
+202007dd
 20400332
 67ec42a9
 d8a04297
@@ -1859,7 +1859,7 @@
 c0030006
 c0040018
 c005002b
-202007d2
+202007db
 2040032c
 67e242a8
 2040033b
@@ -1932,7 +1932,7 @@
 c0230033
 c0238034
 c0288036
-202007d0
+202007d9
 2040032c
 67e44153
 2040032c
@@ -2053,7 +2053,7 @@
 c0058022
 c006002d
 c0068035
-202007ce
+202007d7
 6fe44deb
 c3010393
 6fe44de9
@@ -2117,7 +2117,7 @@
 c0018010
 c0028015
 c003001a
-202007cc
+202007d5
 20400338
 67f04c6c
 20200381
@@ -2249,7 +2249,7 @@
 c00c802b
 c00d0030
 c00d8033
-202007ca
+202007d3
 20400338
 67f04c1c
 20200381
@@ -2308,7 +2308,7 @@
 c0010017
 c0028019
 c0048025
-202007c8
+202007d1
 7920001c
 2040032f
 67e64147
