From 285e01943d224b6909f6b2f9a84e52c8a536e214 Mon Sep 17 00:00:00 2001 From: Raymond Knopp Date: Sat, 26 May 2018 06:26:33 +0200 Subject: [PATCH] fixing conflicts --- targets/RT/USER/lte-ru.c | 258 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 257 insertions(+), 1 deletion(-) diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c index aaf842a266..07d2a46efa 100644 --- a/targets/RT/USER/lte-ru.c +++ b/targets/RT/USER/lte-ru.c @@ -138,7 +138,7 @@ void reset_proc(RU_t *ru); int connect_rau(RU_t *ru); extern uint16_t sf_ahead; - +static void* ru_thread_control( void* param ); /*************************************************************/ /* Functions to attach and configure RRU */ @@ -2992,3 +2992,259 @@ void RCconfig_RU(void) { return; } + + +static void* ru_thread_control( void* param ) { + + + RU_t *ru = (RU_t*)param; + RU_proc_t *proc = &ru->proc; + RRU_CONFIG_msg_t rru_config_msg; + ssize_t msg_len; + int len, ret; + + + // Start IF device if any + if (ru->start_if) { + LOG_I(PHY,"Starting IF interface for RU %d\n",ru->idx); + AssertFatal( + ru->start_if(ru,NULL) == 0, "Could not start the IF device\n"); + + if (ru->if_south != LOCAL_RF) wait_eNBs(); + } + + + ru->state = (ru->function==eNodeB_3GPP)? RU_RUN : RU_IDLE; + LOG_I(PHY,"Control channel ON for RU %d\n", ru->idx); + + while (!oai_exit) // Change the cond + { + msg_len = sizeof(RRU_CONFIG_msg_t); // TODO : check what should be the msg len + + if (ru->state == RU_IDLE && ru->if_south != LOCAL_RF) + send_tick(ru); + + + if ((len = ru->ifdevice.trx_ctlrecv_func(&ru->ifdevice, + &rru_config_msg, + msg_len))<0) { + LOG_D(PHY,"Waiting msg for RU %d\n", ru->idx); + } + else + { + switch(rru_config_msg.type) + { + case RAU_tick: // RRU + if (ru->if_south != LOCAL_RF){ + LOG_I(PHY,"Received Tick msg...Ignoring\n"); + }else{ + LOG_I(PHY,"Tick received from RAU\n"); + + if (send_capab(ru) == 0) ru->state = RU_CONFIG; + } + break; + + case RRU_capabilities: // RAU + if (ru->if_south == LOCAL_RF) LOG_E(PHY,"Received RRU_capab msg...Ignoring\n"); + + else{ + msg_len = sizeof(RRU_CONFIG_msg_t)-MAX_RRU_CONFIG_SIZE+sizeof(RRU_capabilities_t); + + AssertFatal(rru_config_msg.len==msg_len,"Received capabilities with incorrect length (%d!=%d)\n",(int)rru_config_msg.len,(int)msg_len); + LOG_I(PHY,"Received capabilities from RRU %d (len %d/%d, num_bands %d,max_pdschReferenceSignalPower %d, max_rxgain %d, nb_tx %d, nb_rx %d)\n",ru->idx, + (int)rru_config_msg.len,(int)msg_len, + ((RRU_capabilities_t*)&rru_config_msg.msg[0])->num_bands, + ((RRU_capabilities_t*)&rru_config_msg.msg[0])->max_pdschReferenceSignalPower[0], + ((RRU_capabilities_t*)&rru_config_msg.msg[0])->max_rxgain[0], + ((RRU_capabilities_t*)&rru_config_msg.msg[0])->nb_tx[0], + ((RRU_capabilities_t*)&rru_config_msg.msg[0])->nb_rx[0]); + + configure_ru(ru->idx,(RRU_capabilities_t *)&rru_config_msg.msg[0]); + + // send config + if (send_config(ru,rru_config_msg) == 0) ru->state = RU_CONFIG; + } + + break; + + case RRU_config: // RRU + if (ru->if_south == LOCAL_RF){ + LOG_I(PHY,"Configuration received from RAU (num_bands %d,band0 %d,txfreq %u,rxfreq %u,att_tx %d,att_rx %d,N_RB_DL %d,N_RB_UL %d,3/4FS %d, prach_FO %d, prach_CI %d)\n", + ((RRU_config_t *)&rru_config_msg.msg[0])->num_bands, + ((RRU_config_t *)&rru_config_msg.msg[0])->band_list[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->tx_freq[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->rx_freq[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->att_tx[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->att_rx[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->N_RB_DL[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->N_RB_UL[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->threequarter_fs[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->prach_FreqOffset[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->prach_ConfigIndex[0]); + + configure_rru(ru->idx, (void*)&rru_config_msg.msg[0]); + + + fill_rf_config(ru,ru->rf_config_file); + init_frame_parms(&ru->frame_parms,1); + ru->frame_parms.nb_antennas_rx = ru->nb_rx; + phy_init_RU(ru); + + //if (ru->is_slave == 1) lte_sync_time_init(&ru->frame_parms); + + if (ru->rfdevice.is_init != 1){ + ret = openair0_device_load(&ru->rfdevice,&ru->openair0_cfg); + } + + + if (ru->rfdevice.trx_config_func) AssertFatal((ru->rfdevice.trx_config_func(&ru->rfdevice,&ru->openair0_cfg)==0), + "Failed to configure RF device for RU %d\n",ru->idx); + + + + + if (setup_RU_buffers(ru)!=0) { + printf("Exiting, cannot initialize RU Buffers\n"); + exit(-1); + } + + // send CONFIG_OK + + rru_config_msg.type = RRU_config_ok; + rru_config_msg.len = sizeof(RRU_CONFIG_msg_t); + LOG_I(PHY,"Sending CONFIG_OK to RAU %d\n", ru->idx); + + AssertFatal((ru->ifdevice.trx_ctlsend_func(&ru->ifdevice,&rru_config_msg,rru_config_msg.len)!=-1), + "RU %d failed send CONFIG_OK to RAU\n",ru->idx); + reset_proc(ru); + ru->state = RU_READY; + } else LOG_E(PHY,"Received RRU_config msg...Ignoring\n"); + + break; + + case RRU_config_ok: // RAU + if (ru->if_south == LOCAL_RF) LOG_E(PHY,"Received RRU_config_ok msg...Ignoring\n"); + else{ + + if (setup_RU_buffers(ru)!=0) { + printf("Exiting, cannot initialize RU Buffers\n"); + exit(-1); + } + + // Set state to RUN for Master RU, Others on SYNC + ru->state = (ru->is_slave == 1) ? RU_SYNC : RU_RUN ; + ru->in_synch = 0; + + + LOG_I(PHY, "Signaling main thread that RU %d (is_slave %d) is ready in state %s\n",ru->idx,ru->is_slave,ru_states[ru->state]); + pthread_mutex_lock(&RC.ru_mutex); + RC.ru_mask &= ~(1<idx); + pthread_cond_signal(&RC.ru_cond); + pthread_mutex_unlock(&RC.ru_mutex); + + wait_sync("ru_thread_control"); + + // send start + rru_config_msg.type = RRU_start; + rru_config_msg.len = sizeof(RRU_CONFIG_msg_t); // TODO: set to correct msg len + + + LOG_I(PHY,"Sending Start to RRU %d\n", ru->idx); + AssertFatal((ru->ifdevice.trx_ctlsend_func(&ru->ifdevice,&rru_config_msg,rru_config_msg.len)!=-1),"Failed to send msg to RU %d\n",ru->idx); + + + pthread_mutex_lock(&proc->mutex_ru); + proc->instance_cnt_ru = 1; + pthread_mutex_unlock(&proc->mutex_ru); + if (pthread_cond_signal(&proc->cond_ru_thread) != 0) { + LOG_E( PHY, "ERROR pthread_cond_signal for RU %d\n",ru->idx); + exit_fun( "ERROR pthread_cond_signal" ); + break; + } + } + break; + + case RRU_start: // RRU + if (ru->if_south == LOCAL_RF){ + LOG_I(PHY,"Start received from RAU\n"); + + if (ru->state == RU_READY){ + + LOG_I(PHY, "Signaling main thread that RU %d is ready\n",ru->idx); + pthread_mutex_lock(&RC.ru_mutex); + RC.ru_mask &= ~(1<idx); + pthread_cond_signal(&RC.ru_cond); + pthread_mutex_unlock(&RC.ru_mutex); + + wait_sync("ru_thread_control"); + + ru->state = (ru->is_slave == 1) ? RU_SYNC : RU_RUN ; + ru->cmd = EMPTY; + pthread_mutex_lock(&proc->mutex_ru); + proc->instance_cnt_ru = 1; + pthread_mutex_unlock(&proc->mutex_ru); + if (pthread_cond_signal(&proc->cond_ru_thread) != 0) { + LOG_E( PHY, "ERROR pthread_cond_signal for RU %d\n",ru->idx); + exit_fun( "ERROR pthread_cond_signal" ); + break; + } + } + else LOG_E(PHY,"RRU not ready, cannot start\n"); + + } else LOG_E(PHY,"Received RRU_start msg...Ignoring\n"); + + + break; + + case RRU_sync_ok: //RAU + if (ru->if_south == LOCAL_RF) LOG_E(PHY,"Received RRU_config_ok msg...Ignoring\n"); + else{ + if (ru->is_slave == 1){ + LOG_I(PHY,"Received RRU_sync_ok from RRU %d\n",ru->idx); + // Just change the state of the RRU to unblock ru_thread() + ru->state = RU_RUN; + }else LOG_E(PHY,"Received RRU_sync_ok from a master RRU...Ignoring\n"); + } + break; + case RRU_frame_resynch: //RRU + if (ru->if_south != LOCAL_RF) LOG_E(PHY,"Received RRU frame resynch message, should not happen in RAU\n"); + else { + LOG_I(PHY,"Received RRU_frame_resynch command\n"); + ru->cmd = RU_FRAME_RESYNCH; + ru->cmdval = ((uint16_t*)&rru_config_msg.msg[0])[0]; + LOG_I(PHY,"Received Frame Resynch messaage with value %d\n",ru->cmdval); + } + break; + + case RRU_stop: // RRU + if (ru->if_south == LOCAL_RF){ + LOG_I(PHY,"Stop received from RAU\n"); + + if (ru->state == RU_RUN || ru->state == RU_ERROR){ + + LOG_I(PHY,"Stopping RRU\n"); + ru->state = RU_READY; + // TODO: stop ru_thread + }else{ + LOG_I(PHY,"RRU not running, can't stop\n"); + } + }else LOG_E(PHY,"Received RRU_stop msg...Ignoring\n"); + + break; + + default: + if (ru->if_south != LOCAL_RF){ + if (ru->state == RU_IDLE){ + // Keep sending TICK + send_tick(ru); + } + } + + break; + } // switch + } //else + + + }//while + return(NULL); +}