📄 radiomanagement.c
字号:
release_current_message();
}
break;
}
#ifdef PROCESS_TO_ENBLE
_validate_processs_timeout(MSG_TX_ACTION_COMPLETE_FAIL);
#endif
return gSuccess_c;
}
/************************************************************************************
* process_rx_msg
*
* This function process any RX pending msg.
*
************************************************************************************/
static FuncReturn_t process_rx_msg (void){
static bool_t is_there_any_time_out;
msg_rx_state_t state;
state = (msg_rx_state_t)((maMessage_Queu[current_msg])->u8Status.msg_state);
switch(state)
{
case MSG_RX_RQST:
{
// is_there_any_time_out = FALSE;
is_there_any_time_out = TRUE;
clear_all_radio_events();
mRetries_timmer = MAX_RX_RETRIES;
#ifdef PROCESS_TO_ENBLE
// mProcess_timeout = PROCESS_TIMEOUT;
mProcess_timeout = 0x0130;
#endif
_set_cplclk_offset(maMessageTO[current_msg]);
command_xcvr_rx();
(maMessage_Queu[current_msg])->u8Status.msg_state = MSG_RX_PASSED_TO_DEVICE;
}
break;
case MSG_RX_PASSED_TO_DEVICE:
{
#ifdef PROCESS_TO_ENBLE
_t_dec(mProcess_timeout);
#endif
if(is_action_started_evnt()){
clear_action_started_evnt();
(maMessage_Queu[current_msg])->u8Status.msg_state = MSG_RX_ACTION_STARTED;
}
else{
/* Do nothing */
}
}
break;
case MSG_RX_ACTION_STARTED:
{
if(is_rx_action_completed_evnt()){
clear_rx_action_completed_evnt();
if(is_rx_ac_success_evnt()) {
clear_rx_ac_success_evnt();
(maMessage_Queu[current_msg])->u8BufSize = get_rx_packet_sz();
(maMessage_Queu[current_msg])->u8Status.msg_state = \
MSG_RX_ACTION_COMPLETE_SUCCESS;
release_current_message();
}
else {
if(is_timeout_evnt()){
clear_timeout_evnt();
(maMessage_Queu[current_msg])->u8Status.msg_state = MSG_RX_TIMEOUT_FAIL;
release_current_message();
}
else {
if(gNull_c != mRetries_timmer){
_t_dec(mRetries_timmer);
clear_all_radio_events();
(maMessage_Queu[current_msg])->u8BufSize = (0x00);
command_xcvr_rx();
(maMessage_Queu[current_msg])->u8Status.msg_state = \
MSG_RX_PASSED_TO_DEVICE;
}
// else {
if(gNull_c == mRetries_timmer){
(maMessage_Queu[current_msg])->u8Status.msg_state = \
MSG_RX_ACTION_COMPLETE_FAIL;
release_current_message();
}
}
}
}
else {
#ifdef PROCESS_TO_ENBLE
_t_dec(mProcess_timeout);
#endif
}
}
break;
case MSG_RX_SYNC_FOUND:
{
/* Not used at this time */
}
break;
case MSG_RX_RQST_ABORT:
{
(maMessage_Queu[current_msg])->u8Status.msg_state = MSG_RX_ABORTED;
release_current_message();
}
break;
case MSG_RX_ABORTED:
case MSG_RX_TIMEOUT_FAIL:
case MSG_RX_ACTION_COMPLETE_SUCCESS:
case MSG_RX_ACTION_COMPLETE_FAIL:
default:
{
release_current_message();
}
break;
}
#ifdef PROCESS_TO_ENBLE
if(TRUE == is_there_any_time_out){
_validate_processs_timeout(MSG_RX_ACTION_COMPLETE_FAIL);
}
#endif
return gSuccess_c;
}
/************************************************************************************
* process_ed_msg
*
* This function process any Energy Detect pending msg.
*
************************************************************************************/
static FuncReturn_t process_ed_msg (void){
static uint32_t prev_chann;
msg_ed_state_t state;
state = (msg_ed_state_t)((maMessage_Queu[current_msg])->u8Status.msg_state);
switch(state)
{
case MSG_ED_RQST:
{
clear_all_radio_events();
mRetries_timmer = MAX_ED_RETRIES;
#ifdef PROCESS_TO_ENBLE
mProcess_timeout = PROCESS_TIMEOUT;
#endif
/* Use u8BufSize to store the desired channel */
if((uintn8_t)MAX_SMAC_CHANNELS > ((maMessage_Queu[current_msg])->u8BufSize)){
prev_chann = command_xcvr_ed((maMessage_Queu[current_msg])->u8BufSize);
(maMessage_Queu[current_msg])->u8Status.msg_state = MSG_ED_PASSED_TO_DEVICE;
}
else{
(maMessage_Queu[current_msg])->u8Status.msg_state = \
MSG_ED_ACTION_COMPLETE_FAIL;
release_current_message();
}
}
break;
case MSG_ED_PASSED_TO_DEVICE:
{
if(is_action_completed_evnt()){
clear_action_completed_evnt();
if(is_ac_success_evnt()) {
clear_ac_success_evnt();
(maMessage_Queu[current_msg])->u8Status.msg_state = \
MSG_ED_ACTION_COMPLETE_SUCCESS;
*((maMessage_Queu[current_msg])->pu8Buffer->u8Data) = calculate_ed_value(_get_ed_value());
_set_channel(prev_chann);
release_current_message();
}
else {
if(gNull_c != mRetries_timmer){
_t_dec(mRetries_timmer);
clear_all_radio_events();
(void)command_xcvr_ed((maMessage_Queu[current_msg])->u8BufSize);
}
else {
(maMessage_Queu[current_msg])->u8Status.msg_state = \
MSG_ED_ACTION_COMPLETE_FAIL;
_set_channel(prev_chann);
release_current_message();
}
}
}
else {
#ifdef PROCESS_TO_ENBLE
_t_dec(mProcess_timeout);
#endif
}
}
break;
case MSG_ED_RQST_ABORT:
{
(maMessage_Queu[current_msg])->u8Status.msg_state = MSG_ED_ABORTED;
release_current_message();
}
break;
case MSG_ED_ABORTED:
case MSG_ED_ACTION_COMPLETE_SUCCESS:
case MSG_ED_ACTION_COMPLETE_FAIL:
default:
{
release_current_message();
}
break;
}
#ifdef PROCESS_TO_ENBLE
_validate_processs_timeout(MSG_ED_ACTION_COMPLETE_FAIL);
#endif
return gSuccess_c;
}
/************************************************************************************
* process_to_msg
*
* This function process any Timeout pending msg.
*
************************************************************************************/
static FuncReturn_t process_to_msg (void){
msg_to_state_t state;
state = (msg_to_state_t)((maMessage_Queu[current_msg])->u8Status.msg_state);
switch(state)
{
case MSG_TO_RQST:
{
clear_all_radio_events();
mRetries_timmer = MAX_TO_RETRIES;
#ifdef PROCESS_TO_ENBLE
mProcess_timeout = PROCESS_TIMEOUT;
#endif
command_xcvr_to();
(maMessage_Queu[current_msg])->u8Status.msg_state = MSG_TO_PASSED_TO_DEVICE;
}
break;
case MSG_TO_PASSED_TO_DEVICE:
{
if(is_action_completed_evnt()){
clear_action_completed_evnt();
if(( is_ac_success_evnt()) ||
( is_ac_timeout_evnt()) ||
( is_timeout_evnt())) {
clear_ac_success_evnt();
clear_ac_timeout_evnt();
clear_timeout_evnt();
(maMessage_Queu[current_msg])->u8Status.msg_state = \
MSG_TO_ACTION_COMPLETE_SUCCESS;
release_current_message();
}
else {
if(gNull_c != mRetries_timmer){
_t_dec(mRetries_timmer);
clear_all_radio_events();
command_xcvr_to();
}
else {
(maMessage_Queu[current_msg])->u8Status.msg_state = \
MSG_TO_ACTION_COMPLETE_FAIL;
release_current_message();
}
}
}
else {
#ifdef PROCESS_TO_ENBLE
_t_dec(mProcess_timeout);
#endif
}
}
break;
case MSG_TO_RQST_ABORT:
{
(maMessage_Queu[current_msg])->u8Status.msg_state = MSG_TO_ABORTED;
release_current_message();
}
break;
case MSG_TO_ABORTED:
case MSG_TO_ACTION_COMPLETE_SUCCESS:
case MSG_TO_ACTION_COMPLETE_FAIL:
default:
{
release_current_message();
}
break;
}
#ifdef PROCESS_TO_ENBLE
_validate_processs_timeout(MSG_TO_ACTION_COMPLETE_FAIL);
#endif
return gSuccess_c;
}
/************************************************************************************
* calculate_ed_value function
*
* This function is called to calculate the Energy Dectect value.
*
************************************************************************************/
uint8_t calculate_ed_value(uint32_t x_agc_cca_ed_out)
{
uint32_t u32EdVal;
u32EdVal = x_agc_cca_ed_out & 0x000000FF;
if(u32EdVal<0x0F)
{
u32EdVal = 0x00;
}
else if(u32EdVal>0x64)
{
u32EdVal = 0xFF;
}
else
{
u32EdVal = ((u32EdVal<<1)+u32EdVal)-0x2D;
}
return (uint8_t)(u32EdVal);
}
/************************************************************************************
* process_scan_req function
*
* This function is called to procees Channels Scan Requests.
*
************************************************************************************/
void process_scan_req(void)
{
channel_num_t prevChann;
static uint8_t u8BestVal = 0;
static channel_num_t bestChann = CHANNEL26;
static channel_num_t EdCh2Evaluate = CHANNEL11;
static bool_t isSecondPass = FALSE;
if(MSG_ED_ACTION_COMPLETE_SUCCESS == Scan_msg.u8Status.msg_state)
{
u8ScanValPerChann[EdCh2Evaluate] = Scan_msg.pu8Buffer->u8Data[0];
if(u8ScanValPerChann[EdCh2Evaluate] > u8BestVal)
{
u8BestVal = u8ScanValPerChann[EdCh2Evaluate];
bestChann = EdCh2Evaluate;
}
if( (0 != (u8ScanValPerChann[EdCh2Evaluate])) ||
(TRUE == isSecondPass))
{
prevChann = EdCh2Evaluate;
EdCh2Evaluate = get_next_chann_to_scan(EdCh2Evaluate);
isSecondPass = FALSE;
if(prevChann > EdCh2Evaluate)
{
bScanReqFlag = FALSE;
vScanReqCallBack((uint8_t)(bestChann));
u8BestVal = 0;
bestChann = CHANNEL26;
}
}
else
{
isSecondPass = TRUE;
}
if(FALSE == is_a_handled_message(&Scan_msg))
{
MLMEEnergyDetect(&Scan_msg, EdCh2Evaluate);
}
}
else if( (MSG_ED_ABORTED == Scan_msg.u8Status.msg_state) ||
(MSG_ED_ACTION_COMPLETE_FAIL == Scan_msg.u8Status.msg_state) )
{
MLMEEnergyDetect(&Scan_msg, EdCh2Evaluate);
}
}
/************************************************************************************
* get_next_chann_to_scan function
*
* This function answer which is the next m.
*
************************************************************************************/
channel_num_t get_next_chann_to_scan(channel_num_t currentCh)
{
channel_num_t nextChann;
uint8_t timeOut;
nextChann = currentCh;
timeOut = 0;
while(TOTAL_CHANN > timeOut)
{
if(CHANNEL26 > nextChann)
{
nextChann++;
}
else
{
nextChann = CHANNEL11;
}
if(u16ChannToScan & (0x01<<nextChann))
break;
timeOut++;
}
return nextChann;
}
/************************************************************************************
*************************************************************************************
* Private Debug stuff
*************************************************************************************
************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -