Skip to content

Commit

Permalink
PHICH Decoder for TDD
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanyi7362 committed Jan 26, 2024
1 parent 62f619e commit e7f8145
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 45 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"dci_log.h": "c",
"cmath": "c"
}
}
1 change: 1 addition & 0 deletions lib/include/srsran/phy/ue/ngscope_st.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef struct{
typedef struct{
uint32_t n_dmrs;
uint32_t n_prb_tilde;
uint32_t freq_hopping;
}ngscope_dci_phich_t;


Expand Down
6 changes: 3 additions & 3 deletions lib/src/phy/phch/ra_ul.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ int srsran_ra_ul_dci_to_grant(srsran_cell_t* cell,
/* Compute RE assuming shortened is false*/
srsran_ra_ul_compute_nof_re(grant, cell->cp, 0);

// TODO: Need to compute hopping here before determining if there is collision with SRS, but only MAC knows if it's
// a
// new tx or a retx. Need to split MAC interface in 2 calls. For now, assume hopping is the same
// TODO: Need to compute hopping here before determining if there is collision with SRS,
// but only MAC knows if it's a new tx or a retx. Need to split MAC interface in 2 calls.
// For now, assume hopping is the same
for (uint32_t i = 0; i < 2; i++) {
grant->n_prb_tilde[i] = grant->n_prb[i];
}
Expand Down
29 changes: 22 additions & 7 deletions lib/src/phy/ue/ngscope.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void unpack_dci_message_vec(srsran_ue_dl_t* q,
//Upack the uplink dci to uplink grant
if(srsran_ngscope_unpack_ul_dci_2grant(q, sf, cfg, pdsch_cfg, &dci_msg[j],
&dci_ul, &dci_ul_grant) == SRSRAN_SUCCESS){
// dci_ul_grant to tree->dci_array
srsran_ngscope_dci_into_array_ul(tree->dci_array, 0, loc_idx, tree->dci_location[loc_idx],
dci_msg[j].decode_prob, dci_msg[j].corr, &dci_ul, &dci_ul_grant);
}
Expand All @@ -62,6 +63,7 @@ void copy_dci_to_output(ngscope_tree_t* tree,
int format_idx, int loc_idx)
{
// copy the matched dci message to the results
// printf("before1:: frequency hopping: %d, format: %d\n", tree->dci_array[format_idx][loc_idx].phich.freq_hopping, format_idx);
srsran_ngscope_tree_copy_dci_fromArray2PerSub(tree, dci_per_sub, format_idx, loc_idx);
//printf("nof_dl_msg:%d nof_ul_msg:%d \n", dci_per_sub->nof_dl_dci, dci_per_sub->nof_dl_dci);

Expand Down Expand Up @@ -98,7 +100,7 @@ int child_parent_match(ngscope_tree_t* tree,
// Prune the nodes since it is possible that two RNTIs are matched for one node
pruned_nof_dci = srsran_ngscope_tree_prune_node(tree, nof_matched, matched_root, targetRNTI, matched_format_vec, &format_idx);
}
if(pruned_nof_dci == 1){
if(pruned_nof_dci == 1){
bool space_match = true;
if( (format_idx != 0) && (format_idx != 4)){
//TODO Do we need to use space match for other formats?
Expand Down Expand Up @@ -155,20 +157,33 @@ int srsran_ngscope_search_all_space_array_yx(srsran_ue_dl_t* q,
}else{
search_space.nof_formats = MAX_NOF_FORMAT;
}

/* For TDD, when searching for SIB1, the ul/dl configuration is unknown and need to do blind search over
* the possible mi values
*/
uint32_t mi_set_len;
if (q->cell.frame_type == SRSRAN_TDD && !sf->tdd_config.configured) {
mi_set_len = 3;
} else {
mi_set_len = 1;
}

// Currently we assume FDD only
// Remeber that sf->cfi is set only after calling this function
srsran_ue_dl_set_mi_auto(q);
if ((ret = srsran_ue_dl_decode_fft_estimate(q, sf, cfg)) < 0) {
ERROR("ERROR decode FFT\n");
return 0;
// Blind search PHICH mi value
// Remeber that sf->cfi is set only after calling srsran_ue_dl_decode_fft_estimate
ret = 0;
for (uint32_t i = 0; i < mi_set_len && !ret; i++) {
if (mi_set_len == 1) {
srsran_ue_dl_set_mi_auto(q);
} else {
srsran_ue_dl_set_mi_manual(q, i);
}

if ((ret = srsran_ue_dl_decode_fft_estimate(q, sf, cfg)) < 0) {
ERROR("ERROR decode FFT\n");
return 0;
}
}


//ngscope_tree_t tree;
ngscope_tree_init(tree);
Expand Down
6 changes: 4 additions & 2 deletions lib/src/phy/ue/ngscope_dci.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ int srsran_ngscope_unpack_ul_dci_2grant(srsran_ue_dl_t* q,
// set the hopping config
srsran_pusch_hopping_cfg_t ul_hopping = {.n_sb = 1, .hopping_offset = 0, .hop_mode = 1};


// from dci_msg to dci_ul
if (srsran_dci_msg_unpack_pusch(&q->cell, sf, &cfg->cfg.dci, dci_msg, dci_ul)) {
//ERROR("Unpacking UL DCI");
return SRSRAN_ERROR;
}

// from dci_ul to dci_ul_grant
if (srsran_ra_ul_dci_to_grant(&q->cell, &ul_sf, &ul_hopping, dci_ul, dci_ul_grant)) {
//ERROR("Translate UL DCI to uplink grant");
return SRSRAN_ERROR;
Expand Down Expand Up @@ -149,7 +150,8 @@ void srsran_ngscope_dci_into_array_ul(ngscope_dci_msg_t dci_array[][MAX_CANDIDAT
dci_array[i][j].loc = loc;

dci_array[i][j].phich.n_dmrs = dci_ul->n_dmrs;
dci_array[i][j].phich.n_prb_tilde = dci_ul_grant->n_prb_tilde[0];
dci_array[i][j].phich.n_prb_tilde = dci_ul_grant->n_prb_tilde[0];
dci_array[i][j].phich.freq_hopping = dci_ul_grant->freq_hopping+10;

dci_array[i][j].decode_prob = decode_prob;
dci_array[i][j].corr = corr;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/phy/ue/ngscope_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int ngscope_enqueue_ul_reTx_dci_msg(ngscope_dci_per_sub_t* q, uint16_t targetRNT
msg.format = 0;
msg.tb[0].mcs = 0;
msg.tb[0].tbs = 0;
msg.tb[0].rv = 1;
msg.tb[0].rv = 4;
msg.tb[0].ndi = 0;

ngscope_push_dci_to_per_sub(q, &msg);
Expand Down
3 changes: 3 additions & 0 deletions lib/src/phy/ue/ngscope_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ void srsran_ngscope_tree_copy_dci_fromArray2PerSub(ngscope_tree_t* q,
if((format == 0) ){
if(dci_per_sub->nof_ul_dci < MAX_DCI_PER_SUB){
// Format 0 uplink (we only record maximum of 10 message per subframe )

// printf("before2:: frequency hopping: %d\n", q->dci_array[format][idx].phich.freq_hopping);

dci_per_sub->ul_msg[dci_per_sub->nof_ul_dci] = q->dci_array[format][idx];
dci_per_sub->ul_msg[dci_per_sub->nof_ul_dci].format = SRSRAN_DCI_FORMAT0;
dci_per_sub->nof_ul_dci++;
Expand Down
3 changes: 3 additions & 0 deletions ngscope/hdr/dciLib/dci_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ typedef struct{

FILE* fd_dl[MAX_NOF_RF_DEV];
FILE* fd_ul[MAX_NOF_RF_DEV];
FILE* fd_phich[MAX_NOF_RF_DEV];
bool log_dl[MAX_NOF_RF_DEV];
bool log_ul[MAX_NOF_RF_DEV];
bool log_phich[MAX_NOF_RF_DEV];

// recording the current header of the dci ring buffer
int curr_header[MAX_NOF_RF_DEV];
Expand All @@ -51,6 +53,7 @@ typedef struct{

void fill_file_descriptor(FILE* fd_dl[MAX_NOF_RF_DEV],
FILE* fd_ul[MAX_NOF_RF_DEV],
FILE* fd_phich[MAX_NOF_RF_DEV],
ngscope_config_t* config);
//
// bool log_dl,
Expand Down
1 change: 1 addition & 0 deletions ngscope/hdr/dciLib/load_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ typedef struct{
int disable_plot;
int log_dl;
int log_ul;
int log_phich;
}rf_dev_config_t;

typedef struct{
Expand Down
5 changes: 4 additions & 1 deletion ngscope/hdr/dciLib/phich_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#define UL_PIDOF(tti) (tti%(2*HARQ_DELAY_MS))

#define TTIMOD_SZ (((2*HARQ_DELAY_MS) < 10)?10:20)
#define TTIMOD_SZ 100
#define TTIMOD(tti) (tti%TTIMOD_SZ)

typedef struct {
Expand All @@ -38,6 +38,8 @@ typedef struct {
pending_ack_element pending_ack[TTIMOD_SZ];
} pend_ack_list;

bool subframe_is_ulgrant_tdd(uint32_t tti, uint32_t sf_config);
uint32_t get_phich_tti_tdd(uint32_t tti, uint32_t sf_config);
void init_pending_ack(pend_ack_list* ack_list);
void phich_reset_pending_ack(pend_ack_list* ack_list, uint32_t tti);
void phich_set_pending_ack(pend_ack_list* ack_list, uint32_t tti, uint32_t I_lowest, uint32_t n_dmrs);
Expand All @@ -49,6 +51,7 @@ bool phich_is_any_pending_ack(pend_ack_list* ack_list);
bool decode_phich(srsran_ue_dl_t* ue_dl,
srsran_dl_sf_cfg_t* sf_cfg_dl,
srsran_ue_dl_cfg_t* ue_dl_cfg,
srsran_cell_t* cell,
pend_ack_list* ack_list,
srsran_phich_res_t* phich_res);

Expand Down
64 changes: 39 additions & 25 deletions ngscope/src/dciLib/dci_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,7 @@ int dci_decoder_decode(ngscope_dci_decoder_t* dci_decoder,
dci_decoder->dl_sf.tdd_config.ss_config = config.tdd_special_sf;
dci_decoder->dl_sf.tdd_config.configured = true;
}
}

// Dump SIB (Jon's library)
if(decode_SIB){
} else if(decode_SIB){
if(push_asn_payload(dci_decoder->decoder, payload, len, SIB_4G, tti))
printf("Error pushing 4G SIB message to decoder\n");
}
Expand Down Expand Up @@ -386,7 +383,7 @@ int get_target_dci(ngscope_dci_msg_t* msg, int nof_msg, uint16_t targetRNTI){
}


bool dci_decoder_phich_decode(ngscope_dci_decoder_t* dci_decoder,
bool dci_decoder_phich_decode(ngscope_dci_decoder_t* dci_decoder,
uint32_t tti,
ngscope_dci_per_sub_t* dci_per_sub,
srsran_phich_res_t* phich_res)
Expand All @@ -395,19 +392,30 @@ bool dci_decoder_phich_decode(ngscope_dci_decoder_t* dci_decoder,
bool ack_available = false;
if(targetRNTI > 0){
if(dci_per_sub->nof_ul_dci > 0){
//printf("dci_ul_msg: tti:%d, rnti:%d, mcs:%d, rv:%d\n", tti, dci_per_sub->ul_msg[0].rnti, dci_per_sub->ul_msg[0].tb[0].mcs, dci_per_sub->ul_msg[0].tb[0].rv);
int idx = get_target_dci(dci_per_sub->ul_msg, dci_per_sub->nof_ul_dci, targetRNTI);
if(idx >= 0){
uint32_t n_dmrs = dci_per_sub->ul_msg[idx].phich.n_dmrs;
uint32_t n_prb_tilde = dci_per_sub->ul_msg[idx].phich.n_prb_tilde;
uint32_t tti_phich = 0;

if(dci_decoder->cell.frame_type == SRSRAN_FDD){
tti_phich = TTI_RX_ACK(tti);
} else if(dci_decoder->cell.frame_type == SRSRAN_TDD){
tti_phich = get_phich_tti_tdd(tti, dci_decoder->dl_sf.tdd_config.sf_config);
}

// printf("tti:%d, tti_phich:%d, tti_dl_sf:%d\n", tti, tti_phich, dci_decoder->dl_sf.tti);

pthread_mutex_lock(&ack_mutex);
phich_set_pending_ack(&ack_list, TTI_RX_ACK(tti), n_prb_tilde, n_dmrs);
phich_set_pending_ack(&ack_list, tti_phich, n_prb_tilde, n_dmrs);
pthread_mutex_unlock(&ack_mutex);

// If there is dci0 for the targetRNTI at current tti, reset PHICH for current tti.
phich_reset_pending_ack(&ack_list, tti);
}
}
ack_available = decode_phich(&dci_decoder->ue_dl, &dci_decoder->dl_sf, &dci_decoder->ue_dl_cfg, &ack_list, phich_res);
if(ack_available){
//printf("TTI:%d ACK:%d distance:%f\n", tti, phich_res->ack_value, phich_res->distance);
}
ack_available = decode_phich(&dci_decoder->ue_dl, &dci_decoder->dl_sf, &dci_decoder->ue_dl_cfg, &dci_decoder->cell, &ack_list, phich_res);
}
return ack_available;
}
Expand Down Expand Up @@ -450,7 +458,7 @@ void* dci_decoder_thread(void* p){

int decoder_idx = dci_decoder->decoder_idx;
int rf_idx = dci_decoder->prog_args.rf_index;
//uint16_t targetRNTI = dci_decoder->prog_args.rnti;
uint16_t targetRNTI = dci_decoder->prog_args.rnti;


printf("decoder idx :%d \n", decoder_idx);
Expand Down Expand Up @@ -565,22 +573,28 @@ void* dci_decoder_thread(void* p){
}
#endif
}
//t4 = timestamp_us();

//printf("End of decoding decoder_idx:%d sfn:%d sf_idx:%d tti:%d\n",
// dci_decoder->decoder_idx, sfn, sf_idx, sfn * 10 + sf_idx);
// srsran_phich_res_t phich_res;
// if(dci_decoder_phich_decode(dci_decoder, tti, &dci_per_sub, &phich_res) && (phich_res.ack_value == 0) ){
// if(ngscope_rnti_inside_dci_per_sub_ul(&dci_per_sub,targetRNTI) >= 0){
// printf("Conflict we have both ul dci and ul ack!\n");
// }else{
// printf("TTI:%d We insert one ul reTx dci msg: before: %d", tti, dci_per_sub.nof_ul_dci);
// ngscope_enqueue_ul_reTx_dci_msg(&dci_per_sub, targetRNTI);
// printf("after: %d | \n", dci_per_sub.nof_ul_dci);
// }
// //ngscope_push_dci_to_per_sub(dci_per_sub, &tree->dci_array[i][loc_idx]);

// if(dci_per_sub.nof_ul_dci>0){
// printf("after:: frequency hopping: %d\n", dci_per_sub.ul_msg[0].phich.freq_hopping);
// }

uint32_t sf_config = dci_decoder->dl_sf.tdd_config.sf_config;
bool tdd_configured = dci_decoder->dl_sf.tdd_config.configured;
if(dci_decoder->cell.frame_type == SRSRAN_FDD || (subframe_is_ulgrant_tdd(tti, sf_config) && tdd_configured)){
srsran_phich_res_t phich_res;
bool ack_available = dci_decoder_phich_decode(dci_decoder, tti, &dci_per_sub, &phich_res);
if(ack_available && phich_res.ack_value==0){
if(ngscope_rnti_inside_dci_per_sub_ul(&dci_per_sub,targetRNTI) >= 0){
printf("Conflict we have both ul dci and ul ack!\n");
}else{
printf("TTI:%d We insert one ul reTx dci msg: before: %d, ", tti, dci_per_sub.nof_ul_dci);
ngscope_enqueue_ul_reTx_dci_msg(&dci_per_sub, targetRNTI);
printf("after: %d | \n", dci_per_sub.nof_ul_dci);
}
//ngscope_push_dci_to_per_sub(dci_per_sub, &tree->dci_array[i][loc_idx]);
}
}

dci_ret.dci_per_sub = dci_per_sub;
dci_ret.tti = sfn *10 + sf_idx;
dci_ret.cell_idx = rf_idx;
Expand Down
Loading

0 comments on commit e7f8145

Please sign in to comment.