@@ -185,6 +185,7 @@ typedef struct
185185 int32_t rssi_cnt ;
186186 int8_t rssi_ave ;
187187 uint8_t no_signal_state ; // 1: ble rx start; 2: bt rx start 0:stop
188+ uint8_t is_loc_run ;
188189 rt_event_t evt ;
189190 uint16_t saved_open_flag ;
190191 uint8_t * pbuf2mb ;
@@ -588,6 +589,23 @@ static rt_err_t uart_tx_complete(struct uart_env_tag *env, rt_device_t dev, void
588589
589590}
590591
592+ RT_WEAK void blebredr_rf_power_set (uint8_t type , int8_t txpwr )
593+ {
594+ return ;
595+ }
596+ RT_WEAK uint8_t bt_hop_infinite_tx (uint32_t phy , uint32_t data_len , uint32_t type , int8_t pwr )
597+ {
598+ return 0xFF ;
599+ }
600+ RT_WEAK void bt_hop_infinite_set_stop (uint8_t state )
601+ {
602+ return ;
603+ }
604+ RT_WEAK uint8_t bt_pkt_mapping (uint8_t pkt_type , uint8_t * phy )
605+ {
606+ return 0xFF ;
607+ }
608+ RT_WEAK uint8_t tx_chan ;
591609
592610#ifdef USING_IPC_QUEUE
593611#include "mem_map.h"
@@ -1078,6 +1096,21 @@ HAL_RAM_RET_CODE_SECT(crystal_cali_reset, uint8_t crystal_cali_reset(void))
10781096
10791097 return 1 ;
10801098}
1099+ typedef struct
1100+ {
1101+ uint8_t (* func )(uint32_t phy , uint32_t arg1 , uint32_t arg2 , int8_t pwr );
1102+ uint16_t len ;
1103+ uint8_t phy ;
1104+ uint8_t pkt_type ;
1105+ int8_t pwr ;
1106+ } afh_test_cmd_para_t ;
1107+ void wvt_local_hdl_entry (void * param )
1108+ {
1109+ afh_test_cmd_para_t * afh_t = (afh_test_cmd_para_t * )param ;
1110+ afh_t -> func (afh_t -> phy , afh_t -> len , afh_t -> pkt_type , afh_t -> pwr );
1111+ free (param );
1112+ }
1113+ extern uint8_t bt_pkt_mapping (uint8_t pkt_type , uint8_t * phy );
10811114extern void cw_config (uint8_t is_start , uint8_t pa , uint8_t channel );
10821115extern void cw_config_bt (uint8_t is_start , uint8_t pa , uint8_t channel );
10831116static uint8_t loc_cmd_hdl (uint8_t * cmd , uint16_t len )
@@ -1092,68 +1125,135 @@ static uint8_t loc_cmd_hdl(uint8_t *cmd, uint16_t len)
10921125 uint8_t res = 1 ; // Not support
10931126 do
10941127 {
1095- if (cmd [3 ] == 0x02 )
1128+ #if defined(SOC_SF32LB52X ) || defined(SOC_SF32LB56X ) || defined(SOC_SF32LB58X )
1129+ #if defined(SOC_SF32LB52X )
1130+ if ((cmd [3 ] == 0x0 && len == 8 ) || (cmd [3 ] == 0x0 && len == 9 ))
1131+ #else
1132+ if (cmd [3 ] == 0x0 && len == 7 )
1133+ #endif
10961134 {
1097- int8_t tx_pwr = cmd [4 ];
1098- extern void blebredr_rf_power_set (uint8_t type , int8_t txpwr );
1099- blebredr_rf_power_set (0 , tx_pwr );
1100- res = 0 ;
1135+ // AFH test start
1136+ rt_thread_t tid ;
1137+ afh_test_cmd_para_t * para = malloc (sizeof (afh_test_cmd_para_t ));
1138+ if (para == NULL )
1139+ {
1140+ LOG_E ("memory is not enough!!!!" );
1141+ res = 2 ;
1142+ break ;
1143+ }
1144+
1145+ if (env -> is_loc_run )
1146+ {
1147+ LOG_W ("Duplicate command!!!" );
1148+ res = 2 ;
1149+ free (para );
1150+ break ;
1151+ }
1152+
1153+ extern uint8_t bt_hop_infinite_tx (uint32_t phy , uint32_t data_len , uint32_t type , int8_t pwr );
1154+ {
1155+ para -> func = bt_hop_infinite_tx ;
1156+ para -> len = (uint16_t )cmd [4 ] | (uint16_t )cmd [5 ] << 8 ;
1157+ para -> pkt_type = bt_pkt_mapping (cmd [6 ], & para -> phy );
1158+ #ifdef SOC_SF32LB52X
1159+ para -> pwr = cmd [7 ];
1160+ extern uint8_t tx_chan ;
1161+ if (len == 8 )
1162+ {
1163+ tx_chan = 0xFF ;
1164+ }
1165+ else
1166+ {
1167+ tx_chan = cmd [8 ];
1168+ }
1169+ #endif
1170+
1171+ if (para -> pkt_type == 0xFF )
1172+ {
1173+ LOG_E ("Wrongly packet_type!!" );
1174+ res = 2 ;
1175+ free (para );
1176+ break ;
1177+ }
1178+
1179+ tid = rt_thread_create ("loc_hdl" , wvt_local_hdl_entry , para , 4096 , 21 , 10 );
1180+ rt_thread_startup (tid );
1181+
1182+ res = 0 ;
1183+ env -> is_loc_run = 1 ;
1184+ }
11011185 }
1102- else if (cmd [3 ] == 0x82 )
1186+ else if (cmd [3 ] == 0x01 )
11031187 {
1104- int8_t tx_pwr = cmd [ 4 ] ;
1105- extern void blebredr_rf_power_set ( uint8_t type , int8_t txpwr );
1106- blebredr_rf_power_set ( 1 , tx_pwr ) ;
1188+ extern void bt_hop_infinite_set_stop ( uint8_t state ) ;
1189+ bt_hop_infinite_set_stop ( 1 );
1190+ env -> is_loc_run = 0 ;
11071191 res = 0 ;
11081192 }
1193+ else
1194+ #endif
1195+ if (cmd [3 ] == 0x02 )
1196+ {
1197+ int8_t tx_pwr = cmd [4 ];
1198+ extern void blebredr_rf_power_set (uint8_t type , int8_t txpwr );
1199+ blebredr_rf_power_set (0 , tx_pwr );
1200+ res = 0 ;
1201+ }
1202+ else if (cmd [3 ] == 0x82 )
1203+ {
1204+ int8_t tx_pwr = cmd [4 ];
1205+ extern void blebredr_rf_power_set (uint8_t type , int8_t txpwr );
1206+ blebredr_rf_power_set (1 , tx_pwr );
1207+ res = 0 ;
1208+ }
11091209#ifndef SOC_SF32LB55X
1110- else if (cmd [3 ] == 0x03 )
1111- {
1112- uint8_t pa = cmd [4 ];
1113- uint8_t channel = cmd [5 ];
1114- cw_config (1 , pa , channel );
1115- res = 0 ;
1116- }
1117- else if (cmd [3 ] == 0x04 )
1118- {
1119- cw_config (0 , 0 , 0 );
1120- res = 0 ;
1121- }
1122- else if (cmd [3 ] == 0x09 )
1123- {
1124- uint8_t pa = cmd [4 ];
1125- uint8_t channel = cmd [5 ];
1126- cw_config_bt (1 , pa , channel );
1127- res = 0 ;
1128- }
1129- else if (cmd [3 ] == 0x0A )
1130- {
1131- cw_config_bt (0 , 0 , 0 );
1132- res = 0 ;
1133- }
1210+ else if (cmd [3 ] == 0x03 )
1211+ {
1212+ uint8_t pa = cmd [4 ];
1213+ uint8_t channel = cmd [5 ];
1214+ cw_config (1 , pa , channel );
1215+ res = 0 ;
1216+ }
1217+ else if (cmd [3 ] == 0x04 )
1218+ {
1219+ cw_config (0 , 0 , 0 );
1220+ res = 0 ;
1221+ }
1222+ else if (cmd [3 ] == 0x09 )
1223+ {
1224+ uint8_t pa = cmd [4 ];
1225+ uint8_t channel = cmd [5 ];
1226+ cw_config_bt (1 , pa , channel );
1227+ res = 0 ;
1228+ }
1229+ else if (cmd [3 ] == 0x0A )
1230+ {
1231+ cw_config_bt (0 , 0 , 0 );
1232+ res = 0 ;
1233+ }
11341234#endif
1135- else if (cmd [3 ] == 0x05 )
1136- {
1137- ret_len = 8 ;
1138- res = 0 ;
1139- }
1140- else if (cmd [3 ] == 0x06 )
1141- {
1142- int32_t freq_off = ((int32_t )cmd [4 ] | ((int32_t )cmd [5 ] << 8 ) \
1143- | ((int32_t )cmd [6 ] << 16 ) | ((int32_t )cmd [7 ] << 24 ));
1235+ else if (cmd [3 ] == 0x05 )
1236+ {
1237+ ret_len = 8 ;
1238+ res = 0 ;
1239+ }
1240+ else if (cmd [3 ] == 0x06 )
1241+ {
1242+ int32_t freq_off = ((int32_t )cmd [4 ] | ((int32_t )cmd [5 ] << 8 ) \
1243+ | ((int32_t )cmd [6 ] << 16 ) | ((int32_t )cmd [7 ] << 24 ));
11441244
1145- res = crystal_cali_set (freq_off );
1146- }
1147- else if (cmd [3 ] == 0x07 )
1148- {
1149- res = crystal_cali_reset ();
1150- }
1245+ res = crystal_cali_set (freq_off );
1246+ }
1247+ else if (cmd [3 ] == 0x07 )
1248+ {
1249+ res = crystal_cali_reset ();
1250+ }
11511251 }
11521252 while (0 );
11531253
11541254
11551255 {
1156- uint8_t * ptr = malloc (ret_len );
1256+ uint8_t * ptr = bt_mem_alloc (ret_len );
11571257 ptr [0 ] = 0x09 ;
11581258 ptr [1 ] = 0xFF ;
11591259 ptr [2 ] = 0xEE ;
@@ -1263,7 +1363,7 @@ static uint8_t loc_cmd2_hdl(uint8_t *cmd, uint16_t len)
12631363 while (0 );
12641364
12651365 {
1266- uint8_t * ptr = malloc (retlen );
1366+ uint8_t * ptr = bt_mem_alloc (retlen );
12671367 ptr [0 ] = 0x07 ;
12681368 ptr [1 ] = 0xEE ;
12691369 ptr [2 ] = 0xFF ;
0 commit comments