Index: format/app_dongle.format
===================================================================
--- /branch/usb/usb_public/format/app_dongle.format	(revision 237)
+++ /branch/usb/usb_public/format/app_dongle.format	(working copy)
@@ -33,6 +33,18 @@
 
 1 mem_24g_device1_bind_disable
 1 mem_24g_device2_bind_disable
+
+
+//uart start 
+1 mem_device_uart_tx_gpio
+1 mem_device_uart_rx_gpio
+2 mem_device_uart_rx_buffer
+2 mem_device_uart_rx_buffer_end
+2 mem_device_uart_tx_buffer
+2 mem_device_uart_tx_buffer_end
+2 mem_device_uart_baud_rate
+//uart end
+
 )
 
 
Index: output/eeprom.dat
===================================================================
--- /branch/usb/usb_public/output/eeprom.dat	(revision 237)
+++ /branch/usb/usb_public/output/eeprom.dat	(working copy)
@@ -2,8 +2,8 @@
 02
 aa
 55
-1a
-02
+06
+03
 c2
 84
 00
@@ -11,23 +11,23 @@
 c0
 00
 00
-0d
+0f
 c0
 0a
 80
-33
+35
 c0
 1b
 00
-19
+1b
 c0
 5c
 80
-1d
+1f
 c0
 6a
 80
-2e
+30
 20
 20
 3a
@@ -39,19 +39,27 @@
 c0
 14
 00
-3a
+3c
+c0
+1d
+00
+60
 c0
 1d
 80
-44
+74
+c0
+20
+80
+46
 c0
 22
 00
-7b
+b6
 c0
 40
 00
-12
+14
 20
 20
 3a
@@ -107,7 +115,7 @@
 20
 40
 00
-1b
+1d
 20
 20
 52
@@ -195,7 +203,7 @@
 c2
 80
 80
-31
+33
 20
 20
 3d
@@ -279,23 +287,211 @@
 6f
 e0
 c5
+59
+c1
+00
+00
+00
+6f
+e0
+c5
+6d
+24
+7a
+00
+00
+6f
+e0
+c5
+6b
+24
+7a
+00
+00
+6f
+e0
+c5
+67
+20
+7a
+00
+00
+6f
+e0
+c5
+6e
+2f
+e0
+06
+03
+20
+20
+ca
+dc
+20
+40
+48
+ef
+24
+74
+00
+00
+6f
+e1
+45
+69
+1f
+e0
+fe
+01
+67
+e1
+45
+69
+d8
+40
+07
+d0
+98
+46
+7c
+00
+20
+21
+4a
+dc
+6f
+e0
+c5
+6c
+1f
+e0
+fe
+01
+1f
+e1
+7e
+01
+67
+e0
+c5
+6c
+c0
+00
+4b
+a3
+c0
+00
+c9
+9f
+20
+60
+00
+00
+20
+40
+4a
+54
+20
+40
+47
+ce
+24
+37
+ca
+54
+20
+40
+49
+bf
+20
+40
+00
+6c
+20
+40
+4a
+2e
+20
+40
+53
+c3
+6f
+e0
+c4
+f4
+20
+7a
+00
+00
+6f
+e2
+45
+6f
+20
+7a
+00
+00
+20
+20
+48
+e0
+6f
+e0
+c4
+3d
+67
+e0
+c4
+cf
+20
+40
+48
+be
+20
+40
+4a
+3b
+24
+37
+c8
+37
+20
+40
+48
+8f
+20
+40
+48
+3f
+20
+20
+48
+37
+6f
+e0
+c5
 2d
 c0
 55
 00
-49
+7a
 c0
 2a
 80
-53
+84
 c0
 11
 00
-63
-20
+94
+c0
+7f
+80
+ac
 20
-49
-c8
+60
+00
+00
 6f
 e0
 c5
@@ -303,11 +499,11 @@
 c0
 00
 80
-4d
+7e
 c0
 01
 00
-50
+81
 20
 60
 00
@@ -343,7 +539,7 @@
 20
 3a
 00
-59
+8a
 6f
 e2
 45
@@ -367,11 +563,11 @@
 c0
 00
 80
-5d
+8e
 c0
 01
 00
-60
+91
 20
 60
 00
@@ -407,7 +603,7 @@
 20
 3a
 00
-69
+9a
 6f
 e2
 45
@@ -431,11 +627,11 @@
 c0
 00
 80
-6d
+9e
 c0
 01
 00
-74
+a5
 20
 60
 00
@@ -455,7 +651,7 @@
 c0
 01
 00
-72
+a3
 20
 60
 00
@@ -467,7 +663,7 @@
 20
 20
 4a
-01
+02
 6f
 e0
 c5
@@ -483,7 +679,7 @@
 c0
 80
 00
-79
+aa
 20
 60
 00
@@ -495,7 +691,47 @@
 20
 20
 4a
-0c
+0d
+6f
+e0
+c5
+2e
+c0
+00
+80
+b0
+c0
+01
+00
+b3
+20
+60
+00
+00
+6f
+e0
+c5
+d7
+24
+7a
+00
+00
+20
+20
+4c
+24
+6f
+e0
+c5
+d8
+24
+7a
+00
+00
+20
+20
+4c
+28
 6f
 e0
 c5
@@ -507,7 +743,7 @@
 20
 40
 00
-7f
+ba
 20
 20
 4b
@@ -540,8 +776,8 @@
 20
 4b
 0b
-cb
-d8
+29
+7a
 aa
 55
 40
@@ -587,8 +823,8 @@
 00
 01
 00
-08
-10
+0c
+12
 00
 00
 00
@@ -630,6 +866,20 @@
 55
 01
 00
+de
+01
+5a
+aa
+55
+01
+00
+eb
+43
+01
+aa
+55
+01
+00
 ab
 45
 01
@@ -646,10 +896,10 @@
 00
 37
 44
-36
-26
+67
+44
 13
-36
+ad
 06
 13
 aa
@@ -662,11 +912,34 @@
 00
 aa
 55
-01
+02
 00
-eb
-43
-01
+d9
+45
+0a
+ff
+aa
+55
+02
+00
+e3
+45
+d0
+00
+aa
+55
+08
+00
+db
+45
+00
+1c
+ff
+1f
+00
+4f
+ff
+4f
 aa
 55
 08
@@ -752,19 +1025,11 @@
 40
 1e
 41
-aa
-55
-02
-00
-ec
-43
-85
-86
 55
 aa
 aa
 55
-4d
-2a
-2e
-8d
+36
+35
+fd
+85
Index: output/memmap.format
===================================================================
--- /branch/usb/usb_public/output/memmap.format	(revision 204)
+++ /branch/usb/usb_public/output/memmap.format	(working copy)
@@ -1323,6 +1323,13 @@
 0x45d6 mem_dg_24g_tx_power_default
 0x45d7 mem_24g_device1_bind_disable
 0x45d8 mem_24g_device2_bind_disable
+0x45d9 mem_device_uart_tx_gpio
+0x45da mem_device_uart_rx_gpio
+0x45db mem_device_uart_rx_buffer
+0x45dd mem_device_uart_rx_buffer_end
+0x45df mem_device_uart_tx_buffer
+0x45e1 mem_device_uart_tx_buffer_end
+0x45e3 mem_device_uart_baud_rate
 0x4518 mem_rssi_hex_received
 0x4519 mem_24g_pair_sm
 0x451a mem_24g_pair_no_ack
Index: output/program.lis
===================================================================
--- /branch/usb/usb_public/output/program.lis	(revision 237)
+++ /branch/usb/usb_public/output/program.lis	(working copy)
@@ -1,191 +1,262 @@
               include "bt_format "
               org 0x0000
 0000 c2840007 bbit1 8 ,pf_patch_ext 
-0001 c000000d beq patch00_0 ,p_soft_reset 
-0002 c00a8033 beq patch02_5 ,p_set_freq_tx 
-0003 c01b0019 beq patch06_6 ,p_dongle_usb_dispatch 
-0004 c05c801d beq patch17_1 ,p_usb_init 
-0005 c06a802e beq patch1a_5 ,p_le_enable_phy_by_pdata 
+0001 c000000f beq patch00_0 ,p_soft_reset 
+0002 c00a8035 beq patch02_5 ,p_set_freq_tx 
+0003 c01b001b beq patch06_6 ,p_dongle_usb_dispatch 
+0004 c05c801f beq patch17_1 ,p_usb_init 
+0005 c06a8030 beq patch1a_5 ,p_le_enable_phy_by_pdata 
 0006 20203aba branch assert 
 
 pf_patch_ext:
 0007 c17f8000 rtneq patch3f_7 
-0008 c014003a beq patch25_0 ,p_g24_receive_skip_end 
-0009 c01d8044 beq patch27_3 ,p_g24_bind_data_parse_next 
-000a c022007b beq patch28_4 ,p_g24_search_mode_auto 
-000b c0400012 beq patch30_0 ,p_dongle_default_init 
-000c 20203aba branch assert 
+0008 c014003c beq patch25_0 ,p_g24_receive_skip_end 
+0009 c01d0060 beq patch27_2 ,p_g24_bind_data_process 
+000a c01d8074 beq patch27_3 ,p_g24_bind_data_parse_next 
+000b c0208046 beq patch28_1 ,p_g24_mode_switch_bind_search 
+000c c02200b6 beq patch28_4 ,p_g24_search_mode_auto 
+000d c0400014 beq patch30_0 ,p_dongle_default_init 
+000e 20203aba branch assert 
 
 p_soft_reset:
-000d 20800000 clear_stack 
-000e 6fe240cc fetch 4 ,mem_lpm_ctrl3 
-000f 67f2004c store 4 ,core_lpm_reg 
-0010 20403c49 call lpm_write_ctrl3 
-0011 20203803 branch soft_reset + 2 
+000f 20800000 clear_stack 
+0010 6fe240cc fetch 4 ,mem_lpm_ctrl3 
+0011 67f2004c store 4 ,core_lpm_reg 
+0012 20403c49 call lpm_write_ctrl3 
+0013 20203803 branch soft_reset + 2 
 
 p_dongle_default_init:
-0012 20405255 call dongle_default_init + 1 
-0013 70451000 jam off ,mem_24g_disable_fec1 
-0014 2040492b call g24_enable_1m 
-0015 6fe0c5ab fetch 1 ,mem_dg_sys_config 
-0016 c4000000 rtnbit0 dg_enable_new_revision 
-0017 70451001 jam on ,mem_24g_disable_fec1 
-0018 2020492e branch g24_enable_2m 
+0014 20405255 call dongle_default_init + 1 
+0015 70451000 jam off ,mem_24g_disable_fec1 
+0016 2040492b call g24_enable_1m 
+0017 6fe0c5ab fetch 1 ,mem_dg_sys_config 
+0018 c4000000 rtnbit0 dg_enable_new_revision 
+0019 70451001 jam on ,mem_24g_disable_fec1 
+001a 2020492e branch g24_enable_2m 
 
 p_dongle_usb_dispatch:
-0019 2040001b call p_wdt_kick 
-001a 202052ee branch dongle_usb_dispatch + 1 
+001b 2040001d call p_wdt_kick 
+001c 202052ee branch dongle_usb_dispatch + 1 
 
 p_wdt_kick:
-001b 58000010 setarg 16 
-001c 20206de1 branch wdt_init_config 
+001d 58000010 setarg 16 
+001e 20206de1 branch wdt_init_config 
 
 p_usb_init:
-001d 20406fd3 call enable_authrom 
-001e 204071a1 call usb_init_param 
-001f 70061003 jam 0x03 ,mem_devicedesc + 17 
-0020 708c0000 jam 0x00 ,core_usb_config 
-0021 20002710 nop 10000 
-0022 708c1800 jam 0x00 ,core_usb_trig 
-0023 6ff10050 fetch 2 ,core_clkoff 
-0024 793ffe0a set0 clock_off_usb ,pdata 
-0025 67f10050 store 2 ,core_clkoff 
-0026 708c1100 jam 0x0 ,core_usb_hmode 
-0027 708c003c jam 0x3c ,core_usb_config 
-0028 58000bb3 setarg mem_usb_rxbuf_new 
-0029 67f10c03 store 2 ,core_usb_rx_saddr 
-002a 67f10c07 store 2 ,core_usb_rxptr 
-002b 58000bf7 setarg mem_usb_rxbuf_new_end 
-002c 67f10c05 store 2 ,core_usb_rx_eaddr 
-002d 20207192 branch usb_init + 16 
+001f 20406fd3 call enable_authrom 
+0020 204071a1 call usb_init_param 
+0021 70061003 jam 0x03 ,mem_devicedesc + 17 
+0022 708c0000 jam 0x00 ,core_usb_config 
+0023 20002710 nop 10000 
+0024 708c1800 jam 0x00 ,core_usb_trig 
+0025 6ff10050 fetch 2 ,core_clkoff 
+0026 793ffe0a set0 clock_off_usb ,pdata 
+0027 67f10050 store 2 ,core_clkoff 
+0028 708c1100 jam 0x0 ,core_usb_hmode 
+0029 708c003c jam 0x3c ,core_usb_config 
+002a 58000bb3 setarg mem_usb_rxbuf_new 
+002b 67f10c03 store 2 ,core_usb_rx_saddr 
+002c 67f10c07 store 2 ,core_usb_rxptr 
+002d 58000bf7 setarg mem_usb_rxbuf_new_end 
+002e 67f10c05 store 2 ,core_usb_rx_eaddr 
+002f 20207192 branch usb_init + 16 
 
 p_le_enable_phy_by_pdata:
-002e 18427e00 copy temp ,pdata 
-002f c2808031 bbit1 bit_le_2m_phy ,p_le_enable_2m 
-0030 20203d19 branch le_enable_phy_by_pdata + 3 
+0030 18427e00 copy temp ,pdata 
+0031 c2808033 bbit1 bit_le_2m_phy ,p_le_enable_2m 
+0032 20203d19 branch le_enable_phy_by_pdata + 3 
 
 p_le_enable_2m:
-0031 708a6d89 jam 0x89 ,core_rx_bq_cfg0 
-0032 20203d1f branch le_enable_2m 
+0033 708a6d89 jam 0x89 ,core_rx_bq_cfg0 
+0034 20203d1f branch le_enable_2m 
 
 p_set_freq_tx:
-0033 708a3d12 jam 0x12 ,core_syn_top_ctrl 
-0034 60488008 storet 1 ,mem_last_freq 
-0035 1840a202 add temp ,2 ,rega 
-0036 2040398e call rf_tx_write_freq 
-0037 c51a39cf bmark1 mark_pllon ,txon 
-0038 200003c0 nop 0x3c0 
-0039 202039cf branch txon 
+0035 708a3d12 jam 0x12 ,core_syn_top_ctrl 
+0036 60488008 storet 1 ,mem_last_freq 
+0037 1840a202 add temp ,2 ,rega 
+0038 2040398e call rf_tx_write_freq 
+0039 c51a39cf bmark1 mark_pllon ,txon 
+003a 200003c0 nop 0x3c0 
+003b 202039cf branch txon 
 
 p_g24_receive_skip_end:
-003a 6fe0c5ab fetch 1 ,mem_dg_sys_config 
-003b c300481c bbit0 dg_enable_new_revision ,g24_receive_skip_end 
-003c 2000012c nop 300 
-003d 6fe0c43e fetch 1 ,mem_24g_rxbuf + 1 
-003e 79207e00 set1 bit_ack_24g ,pdata 
-003f 67e0c43e store 1 ,mem_24g_rxbuf + 1 
-0040 79200034 set1 mark_pllon ,mark 
-0041 20404a3b call g24_ackpayload_prep 
-0042 2040488f call g24_transmit_prep 
-0043 2020483f branch g24_transmit 
+003c 6fe0c5ab fetch 1 ,mem_dg_sys_config 
+003d c300481c bbit0 dg_enable_new_revision ,g24_receive_skip_end 
+003e 2000012c nop 300 
+003f 6fe0c43e fetch 1 ,mem_24g_rxbuf + 1 
+0040 79207e00 set1 bit_ack_24g ,pdata 
+0041 67e0c43e store 1 ,mem_24g_rxbuf + 1 
+0042 79200034 set1 mark_pllon ,mark 
+0043 20404a3b call g24_ackpayload_prep 
+0044 2040488f call g24_transmit_prep 
+0045 2020483f branch g24_transmit 
+
+p_g24_mode_switch_bind_search:
+0046 6fe0c559 fetch 1 ,mem_24g_work_mode 
+0047 c1000000 rtneq dongle_work 
+0048 6fe0c56d fetch 1 ,mem_24g_b_s_mode_switch_disable 
+0049 247a0000 nrtn blank 
+004a 6fe0c56b fetch 1 ,mem_24g_mode_b_s_switch_exit 
+004b 247a0000 nrtn blank 
+004c 6fe0c567 fetch 1 ,mem_24g_mode_b_s_switch 
+004d 207a0000 rtn blank 
+004e 6fe0c56e fetch 1 ,mem_24g_bind_device_living 
+004f 2fe00603 compare 3 ,pdata ,3 
+0050 2020cadc branch g24_mode_b_s_switch_exit ,true 
+0051 204048ef call g24_timer_check 
+0052 24740000 nrtn user 
+0053 6fe14569 fetch 2 ,mem_24g_mode_b_s_switch_cnt 
+0054 1fe0fe01 increase 1 ,pdata 
+0055 67e14569 store 2 ,mem_24g_mode_b_s_switch_cnt 
+0056 d84007d0 arg 0x7d0 ,temp 
+0057 98467c00 isub temp ,null 
+0058 20214adc branch g24_mode_b_s_switch_exit ,positive 
+0059 6fe0c56c fetch 1 ,mem_24g_b_s_time_slice 
+005a 1fe0fe01 increase 1 ,pdata 
+005b 1fe17e01 and_into 1 ,pdata 
+005c 67e0c56c store 1 ,mem_24g_b_s_time_slice 
+005d c0004ba3 beq 0 ,g24_search_mode_enable 
+005e c000c99f beq 1 ,g24_bind_mode_enable 
+005f 20600000 rtn 
+
+p_g24_bind_data_process:
+0060 20404a54 call g24_rx_interrupt_clear 
+0061 204047ce call g24_receive_packet 
+0062 2437ca54 nbranch g24_rx_interrupt_clear ,user3 
+0063 204049bf call g24_bind_data_parse 
+0064 2040006c call p_g24_bind_transmit_ack 
+0065 20404a2e call g24_bind_device_status_check 
+0066 204053c3 call dongle_kb_bind_soft_reset 
+0067 6fe0c4f4 fetch 1 ,mem_24g_pair_switch 
+0068 207a0000 rtn blank 
+0069 6fe2456f fetch 4 ,mem_24g_transmitter_addr 
+006a 207a0000 rtn blank 
+006b 202048e0 branch g24_update_addr_and_synccrc8 
+
+p_g24_bind_transmit_ack:
+006c 6fe0c43d fetch 1 ,mem_24g_rxbuf 
+006d 67e0c4cf store 1 ,mem_24g_data_type 
+006e 204048be call g24_read_len_pid_crc 
+006f 20404a3b call g24_ackpayload_prep 
+0070 2437c837 nbranch g24_end_of_packet ,user3 
+0071 2040488f call g24_transmit_prep 
+0072 2040483f call g24_transmit 
+0073 20204837 branch g24_end_of_packet 
 
 p_g24_bind_data_parse_next:
-0044 6fe0c52d fetch 1 ,mem_24g_rxdata_temp + 2 
-0045 c0550049 beq datatype_bind ,p_g24_bind_first_step 
-0046 c02a8053 beq datatype_config ,p_g24_bind_second_step 
-0047 c0110063 beq datatype_ok ,p_g24_bind_third_step 
-0048 202049c8 branch g24_bind_data_parse_next + 4 
+0074 6fe0c52d fetch 1 ,mem_24g_rxdata_temp + 2 
+0075 c055007a beq datatype_bind ,p_g24_bind_first_step 
+0076 c02a8084 beq datatype_config ,p_g24_bind_second_step 
+0077 c0110094 beq datatype_ok ,p_g24_bind_third_step 
+0078 c07f80ac beq datatype_attemp ,p_g24_data_attemp 
+0079 20600000 rtn 
 
 p_g24_bind_first_step:
-0049 6fe0c52e fetch 1 ,mem_24g_rxdata_temp + 3 
-004a c000804d beq datatype_device1 ,p_g24_bind_first_step_device1 
-004b c0010050 beq datatype_device2 ,p_g24_bind_first_step_device2 
-004c 20600000 rtn 
+007a 6fe0c52e fetch 1 ,mem_24g_rxdata_temp + 3 
+007b c000807e beq datatype_device1 ,p_g24_bind_first_step_device1 
+007c c0010081 beq datatype_device2 ,p_g24_bind_first_step_device2 
+007d 20600000 rtn 
 
 p_g24_bind_first_step_device1:
-004d 6fe0c5d7 fetch 1 ,mem_24g_device1_bind_disable 
-004e 247a0000 nrtn blank 
-004f 202049ce branch g24_bind_first_step_device1 
+007e 6fe0c5d7 fetch 1 ,mem_24g_device1_bind_disable 
+007f 247a0000 nrtn blank 
+0080 202049ce branch g24_bind_first_step_device1 
 
 p_g24_bind_first_step_device2:
-0050 6fe0c5d8 fetch 1 ,mem_24g_device2_bind_disable 
-0051 247a0000 nrtn blank 
-0052 202049d4 branch g24_bind_first_step_device2 
+0081 6fe0c5d8 fetch 1 ,mem_24g_device2_bind_disable 
+0082 247a0000 nrtn blank 
+0083 202049d4 branch g24_bind_first_step_device2 
 
 p_g24_bind_second_step:
-0053 6fe0c4f4 fetch 1 ,mem_24g_pair_switch 
-0054 203a0059 branch p_g24_bind_second_step_skip ,blank 
-0055 6fe2452f fetch 4 ,mem_24g_rxdata_temp + 4 
-0056 684a4437 fetcht 4 ,mem_24g_lap 
-0057 98467c00 isub temp ,null 
-0058 24628000 nrtn zero 
+0084 6fe0c4f4 fetch 1 ,mem_24g_pair_switch 
+0085 203a008a branch p_g24_bind_second_step_skip ,blank 
+0086 6fe2452f fetch 4 ,mem_24g_rxdata_temp + 4 
+0087 684a4437 fetcht 4 ,mem_24g_lap 
+0088 98467c00 isub temp ,null 
+0089 24628000 nrtn zero 
 
 p_g24_bind_second_step_skip:
-0059 6fe0c52e fetch 1 ,mem_24g_rxdata_temp + 3 
-005a c000805d beq datatype_device1 ,p_g24_bind_second_step_device1 
-005b c0010060 beq datatype_device2 ,p_g24_bind_second_step_device2 
-005c 20600000 rtn 
+008a 6fe0c52e fetch 1 ,mem_24g_rxdata_temp + 3 
+008b c000808e beq datatype_device1 ,p_g24_bind_second_step_device1 
+008c c0010091 beq datatype_device2 ,p_g24_bind_second_step_device2 
+008d 20600000 rtn 
 
 p_g24_bind_second_step_device1:
-005d 6fe0c5d7 fetch 1 ,mem_24g_device1_bind_disable 
-005e 247a0000 nrtn blank 
-005f 202049e1 branch g24_bind_second_step_device1 
+008e 6fe0c5d7 fetch 1 ,mem_24g_device1_bind_disable 
+008f 247a0000 nrtn blank 
+0090 202049e1 branch g24_bind_second_step_device1 
 
 p_g24_bind_second_step_device2:
-0060 6fe0c5d8 fetch 1 ,mem_24g_device2_bind_disable 
-0061 247a0000 nrtn blank 
-0062 202049ec branch g24_bind_second_step_device2 
+0091 6fe0c5d8 fetch 1 ,mem_24g_device2_bind_disable 
+0092 247a0000 nrtn blank 
+0093 202049ec branch g24_bind_second_step_device2 
 
 p_g24_bind_third_step:
-0063 6fe0c4f4 fetch 1 ,mem_24g_pair_switch 
-0064 203a0069 branch p_g24_bind_third_step_skip ,blank 
-0065 6fe2452f fetch 4 ,mem_24g_rxdata_temp + 4 
-0066 684a456f fetcht 4 ,mem_24g_transmitter_addr 
-0067 98467c00 isub temp ,null 
-0068 24628000 nrtn zero 
+0094 6fe0c4f4 fetch 1 ,mem_24g_pair_switch 
+0095 203a009a branch p_g24_bind_third_step_skip ,blank 
+0096 6fe2452f fetch 4 ,mem_24g_rxdata_temp + 4 
+0097 684a456f fetcht 4 ,mem_24g_transmitter_addr 
+0098 98467c00 isub temp ,null 
+0099 24628000 nrtn zero 
 
 p_g24_bind_third_step_skip:
-0069 6fe0c52e fetch 1 ,mem_24g_rxdata_temp + 3 
-006a c000806d beq datatype_device1 ,p_g24_bind_third_step_device1 
-006b c0010074 beq datatype_device2 ,p_g24_bind_third_step_device2 
-006c 20600000 rtn 
+009a 6fe0c52e fetch 1 ,mem_24g_rxdata_temp + 3 
+009b c000809e beq datatype_device1 ,p_g24_bind_third_step_device1 
+009c c00100a5 beq datatype_device2 ,p_g24_bind_third_step_device2 
+009d 20600000 rtn 
 
 p_g24_bind_third_step_device1:
-006d 6fe0c5d7 fetch 1 ,mem_24g_device1_bind_disable 
-006e 247a0000 nrtn blank 
-006f 6fe0c518 fetch 1 ,mem_24g_device1_bind_step 
-0070 c0010072 beq 2 ,p_g24_bind_dvc1_step_success 
-0071 20600000 rtn 
+009e 6fe0c5d7 fetch 1 ,mem_24g_device1_bind_disable 
+009f 247a0000 nrtn blank 
+00a0 6fe0c518 fetch 1 ,mem_24g_device1_bind_step 
+00a1 c00100a3 beq 2 ,p_g24_bind_dvc1_step_success 
+00a2 20600000 rtn 
 
 p_g24_bind_dvc1_step_success:
-0072 7045d701 jam 1 ,mem_24g_device1_bind_disable 
-0073 20204a01 branch g24_bind_dvc1_step_success 
+00a3 7045d701 jam 1 ,mem_24g_device1_bind_disable 
+00a4 20204a02 branch g24_bind_dvc1_step_success + 1 
 
 p_g24_bind_third_step_device2:
-0074 6fe0c5d8 fetch 1 ,mem_24g_device2_bind_disable 
-0075 247a0000 nrtn blank 
-0076 6fe0c519 fetch 1 ,mem_24g_device2_bind_step 
-0077 c0800079 bne 0 ,p_g24_bind_dvc2_step_success 
-0078 20600000 rtn 
+00a5 6fe0c5d8 fetch 1 ,mem_24g_device2_bind_disable 
+00a6 247a0000 nrtn blank 
+00a7 6fe0c519 fetch 1 ,mem_24g_device2_bind_step 
+00a8 c08000aa bne 0 ,p_g24_bind_dvc2_step_success 
+00a9 20600000 rtn 
 
 p_g24_bind_dvc2_step_success:
-0079 7045d801 jam 1 ,mem_24g_device2_bind_disable 
-007a 20204a0c branch g24_bind_dvc2_step_success 
+00aa 7045d801 jam 1 ,mem_24g_device2_bind_disable 
+00ab 20204a0d branch g24_bind_dvc2_step_success + 1 
+
+p_g24_data_attemp:
+00ac 6fe0c52e fetch 1 ,mem_24g_rxdata_temp + 3 
+00ad c00080b0 beq datatype_device1 ,p_g24_data_attemp_device1 
+00ae c00100b3 beq datatype_device2 ,p_g24_data_attemp_device2 
+00af 20600000 rtn 
+
+p_g24_data_attemp_device1:
+00b0 6fe0c5d7 fetch 1 ,mem_24g_device1_bind_disable 
+00b1 247a0000 nrtn blank 
+00b2 20204c24 branch g24_data_attemp_device1 
+
+p_g24_data_attemp_device2:
+00b3 6fe0c5d8 fetch 1 ,mem_24g_device2_bind_disable 
+00b4 247a0000 nrtn blank 
+00b5 20204c28 branch g24_data_attemp_device2 
 
 p_g24_search_mode_auto:
-007b 6fe0c559 fetch 1 ,mem_24g_work_mode 
-007c c1838000 rtnne dongle_search 
-007d 2040007f call p_g24_search_mode_init 
-007e 20204b1b branch g24_search_mode_auto + 4 
+00b6 6fe0c559 fetch 1 ,mem_24g_work_mode 
+00b7 c1838000 rtnne dongle_search 
+00b8 204000ba call p_g24_search_mode_init 
+00b9 20204b1b branch g24_search_mode_auto + 4 
 
 p_g24_search_mode_init:
-007f 6fe0c558 fetch 1 ,mem_24g_mode_init 
-0080 c3838000 rtnbit1 dongle_search 
-0081 79207e07 set1 dongle_search ,pdata 
-0082 67e0c558 store 1 ,mem_24g_mode_init 
-0083 6fe0c566 fetch 1 ,mem_tx_power_temp 
-0084 67e0c116 store 1 ,mem_tx_power 
-0085 20204b0b branch g24_search_mode_init + 4 
+00ba 6fe0c558 fetch 1 ,mem_24g_mode_init 
+00bb c3838000 rtnbit1 dongle_search 
+00bc 79207e07 set1 dongle_search ,pdata 
+00bd 67e0c558 store 1 ,mem_24g_mode_init 
+00be 6fe0c566 fetch 1 ,mem_tx_power_temp 
+00bf 67e0c116 store 1 ,mem_tx_power 
+00c0 20204b0b branch g24_search_mode_init + 4 
               org 0x3800
 
 start:
Index: program/patch.prog
===================================================================
--- /branch/usb/usb_public/program/patch.prog	(revision 237)
+++ /branch/usb/usb_public/program/patch.prog	(working copy)
@@ -1,4 +1,6 @@
 
+//define UART_LOG
+
 	bbit1 8,pf_patch_ext
 	beq patch00_0,p_soft_reset
 	beq patch02_5,p_set_freq_tx
@@ -10,7 +12,9 @@
 pf_patch_ext:
 	rtneq patch3f_7
 	beq patch25_0,p_g24_receive_skip_end
+	beq patch27_2,p_g24_bind_data_process
 	beq patch27_3,p_g24_bind_data_parse_next
+	beq patch28_1,p_g24_mode_switch_bind_search
 	beq patch28_4,p_g24_search_mode_auto
 	beq patch30_0,p_dongle_default_init
 	branch assert
@@ -25,6 +29,9 @@
 
 
 p_dongle_default_init:
+ifdef UART_LOG
+	call p_device_hardware_init
+endif
 	call dongle_default_init+1
 	jam OFF,mem_24g_disable_fec1
 	call g24_enable_1M
@@ -95,12 +102,76 @@
 	branch g24_transmit
 
 
+
+p_g24_mode_switch_bind_search:
+	fetch 1,mem_24g_work_mode
+	rtneq DONGLE_WORK
+	fetch 1,mem_24g_B_S_mode_switch_disable
+	nrtn blank
+	fetch 1,mem_24g_mode_B_S_switch_exit
+	nrtn blank
+	fetch 1,mem_24g_mode_B_S_switch
+	rtn blank
+	fetch 1,mem_24g_bind_device_living
+	compare 3,pdata,3
+	branch g24_mode_B_S_switch_exit,true
+	call g24_timer_check
+	nrtn user
+	fetch 2,mem_24g_mode_B_S_switch_cnt
+	increase 1,pdata
+	store 2,mem_24g_mode_B_S_switch_cnt
+	arg 0x7d0,temp	//1min
+	isub temp,null
+	branch g24_mode_B_S_switch_exit,positive
+	fetch 1,mem_24g_B_S_time_slice
+	increase 1,pdata
+	and_into 1,pdata
+	store 1,mem_24g_B_S_time_slice
+	beq 0,g24_search_mode_enable
+	beq 1,g24_bind_mode_enable
+	rtn
+
+
+
+p_g24_bind_data_process:
+	call g24_rx_interrupt_clear
+	call g24_receive_packet
+	nbranch g24_rx_interrupt_clear,user3
+ifdef UART_LOG
+	call p_24g_rxpayload_print
+endif
+	call g24_bind_data_parse
+	call p_g24_bind_transmit_ack
+	call g24_bind_device_status_check
+	call dongle_kb_bind_soft_reset
+	fetch 1,mem_24g_pair_switch
+	rtn blank
+	fetch 4,mem_24g_transmitter_addr
+	rtn blank
+	branch g24_update_addr_and_synccrc8
+
+
+p_g24_bind_transmit_ack:
+	fetch 1,mem_24g_rxbuf
+	store 1,mem_24g_data_type
+	call g24_read_len_pid_crc
+	call g24_ackpayload_prep
+	nbranch g24_end_of_packet,user3
+	call g24_transmit_prep
+	call g24_transmit
+ifdef UART_LOG
+	call p_24g_txpayload_print
+endif
+	branch g24_end_of_packet
+
+
 p_g24_bind_data_parse_next:
 	fetch 1,mem_24g_rxdata_temp+2
 	beq DATATYPE_BIND,p_g24_bind_first_step	//bind step 1
 	beq DATATYPE_CONFIG,p_g24_bind_second_step
 	beq DATATYPE_OK,p_g24_bind_third_step
-	branch g24_bind_data_parse_next+4
+	beq DATATYPE_ATTEMP,p_g24_data_attemp
+	rtn
 
 p_g24_bind_first_step:
 	fetch 1,mem_24g_rxdata_temp+3
@@ -158,7 +229,7 @@
 	rtn
 p_g24_bind_dvc1_step_success:
 	jam 1,mem_24g_device1_bind_disable	
-	branch g24_bind_dvc1_step_success
+	branch g24_bind_dvc1_step_success+1
 
 p_g24_bind_third_step_device2:
 	fetch 1,mem_24g_device2_bind_disable
@@ -168,7 +239,23 @@
 	rtn
 p_g24_bind_dvc2_step_success:
 	jam 1,mem_24g_device2_bind_disable
-	branch g24_bind_dvc2_step_success
+	branch g24_bind_dvc2_step_success+1
+
+
+p_g24_data_attemp:
+	fetch 1,mem_24g_rxdata_temp+3
+	beq DATATYPE_DEVICE1,p_g24_data_attemp_device1
+	beq DATATYPE_DEVICE2,p_g24_data_attemp_device2
+	rtn
+p_g24_data_attemp_device1:
+	fetch 1,mem_24g_device1_bind_disable
+	nrtn blank
+	branch g24_data_attemp_device1
+
+p_g24_data_attemp_device2:
+	fetch 1,mem_24g_device2_bind_disable
+	nrtn blank
+	branch g24_data_attemp_device2
 
 
 p_g24_search_mode_auto:
@@ -190,4 +277,145 @@
 
 
 
+ifdef UART_LOG
+p_device_hardware_init:
+	fetch 1,core_uart_ctrl
+	set0 BIT_UART_CONTROL_ENABLE,pdata
+	store 1,core_uart_ctrl
+	fetch 8,mem_device_uart_rx_buffer
+	call uarta_init_dma_mem
+	fetch uart_baud_len,mem_device_uart_baud_rate
+	call uarta_init_baud_rate
+	call uart_clock_select_main_freq_crystal
+	fetch 1,mem_device_uart_tx_gpio
+	arg gpcfg_uart_txd,temp
+	call p_gpio_config_function_int
+	fetch 1,mem_device_uart_rx_gpio
+	arg gpcfg_uart_rxd|gpcfg_pullup,temp
+	call p_gpio_config_function_int
+	arg FUN_UART_CONTROL_ENABLE|FUN_UART_CONTROL_SETTING_RATE_BAUD,temp
+	storet 1,core_uart_ctrl
+	rtn
+
+p_gpio_config_function_int:
+	rtneq GPIO_DISABLE
+	branch gpio_config_function_int
+
+
+
+p_24g_rxpayload_print:
+	arg mem_temp_block0,contw
+	call memset0_16
+	fetch 1,mem_24g_work_mode
+	store 1,mem_temp_block0
+	arg,mem_24g_rxbuf,contr
+	ifetch 8,contr
+	istore 8,contw
+	ifetch 7,contr
+	istore 7,contw
+
+	arg 16,loopcnt
+	arg mem_temp_block0,regc
+	call log_bytes
+	branch log_end
+
+p_24g_txpayload_print:
+	arg mem_temp_block0,contw
+	call memset0_16
+	fetch 1,mem_24g_work_mode
+	store 1,mem_temp_block0
+	fetch 1,mem_24g_txlen
+	istore 1,contw
+	arg,mem_24g_txpayload,contr
+	ifetch 8,contr
+	istore 8,contw
+	ifetch 6,contr
+	istore 6,contw
+
+	arg 16,loopcnt
+	arg mem_temp_block0,regc
+	call log_bytes
+	branch log_end
+
+//input: 1 byte hex @pdata  
+//output: 4 byte  '0','x', ASCII,ASCII, @pdata
+hex2ascii:
+	rshift4 pdata,rega  //high 4bit in rega
+	and_into 0x0f,pdata
+	call hex2ascii_half_byte
+	copy pdata,regb
+	copy rega,pdata
+	call hex2ascii_half_byte
+	lshift8 regb,regb
+	iadd regb,pdata
+//	lshift16 pdata,pdata
+//	arg 0x7830,regb   //0x
+//	iadd regb,pdata
+	rtn
+
+//input: 1 byte hex @pdata  
+//output: 4 byte  '0','x', ASCII,ASCII, @pdata
+hex2ascii_half_byte:
+	arg 0xa,temp
+	isub temp,temp
+	nbranch hex2ascii_half_byte_numberic,positive
+	setarg 0x41  // A
+	iadd temp,pdata
+	rtn
+hex2ascii_half_byte_numberic:
+	arg 0x30,temp
+	iadd temp,pdata
+	rtn
+
+//input: loopcnt--length,regc--data ptr	
+log_bytes:
+	copy loopcnt,pdata
+	branch log_len0,blank
+log_bytes_loop:
+	ifetch 1,regc
+	increase 1,regc
+	call log_byte
+	call log_space
+	loop log_bytes_loop
+uart_wait:
+	fetch 1,core_uart_status
+	bbit1 uart_status_tx_busy,uart_wait
+//	nop 12000
+	rtn	
+
+log_len0:
+	call uarta_prepare_tx
+	setarg 0x656c
+	istore 2,contwu
+	setarg 0x306e
+	istore 2,contwu
+	call uarta_send
+	branch log_end
+
+//input 1byte @pdata
+log_byte:
+	call uarta_prepare_tx
+	call hex2ascii
+//	istore 4,contu	//0x
+	istore 2,contwu
+	branch uarta_send
+
+log_space:
+	call uarta_prepare_tx
+	setarg 0x20
+	istore 1,contwu
+	branch uarta_send
+
+log_end:
+	call uarta_prepare_tx
+	setarg 0x0a0d
+	istore 2,contwu
+	branch uarta_send
+
+log_colon:
+	call uarta_prepare_tx
+	setarg 0x3a
+	istore 1,contwu
+	branch uarta_send
 
+endif
Index: sched/dongle.dat
===================================================================
--- /branch/usb/usb_public/sched/dongle.dat	(revision 237)
+++ /branch/usb/usb_public/sched/dongle.dat	(working copy)
@@ -1,6 +1,9 @@
 
 mem_device_option:04
+
 mem_ui_button_gpio:ff
+mem_load_check_sum:5a #skip data check when loadcode
+mem_wdt_always_work:01
 
 #sys config
 #bit7:enable 16M xtal#0:24M#1:16M
@@ -30,7 +33,7 @@
 
 
 #rf config
-mem_24g_lap:36 26 13 36 06 13#low 4B used for 24g rxaddr
+mem_24g_lap:67 44 13 ad 06 13#low 4B used for 24g rxaddr
 #mem_24g_tx_phy:01#0x01:1M/0x02:2M/0x04:S2/0x84:S8
 #mem_24g_rx_phy:01#0x01:1M/0x02:2M/0x04:S2/0x84:S8
 #mem_24g_no_ack:00#no ack
@@ -58,9 +61,17 @@
 #mem_rssi_noise_device1_buffer_ptr:mem_dg_rssi_noise_ms_buffer
 #mem_rssi_noise_device2_buffer_ptr:mem_dg_rssi_noise_kb_buffer
 
-#mem_load_check_sum:5a
-mem_wdt_always_work:01
 
+#log log log log log log log log log log log
+
+#uart config
+mem_device_uart_tx_gpio:0a	#08
+mem_device_uart_rx_gpio:ff
+mem_device_uart_baud_rate:d0 00	#115200	
+mem_device_uart_rx_buffer:00 1c
+mem_device_uart_rx_buffer_end:ff 1f
+mem_device_uart_tx_buffer:00 4f
+mem_device_uart_tx_buffer_end:ff 4f
 
 
 
