1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
20 /* header include files -- defines (.h) */
21 #include "common_def.h"
22 #include "lrg.h" /* Layer manager interface includes*/
23 #include "crg.h" /* CRG interface includes*/
24 #include "rgu.h" /* RGU interface includes*/
25 #include "tfu.h" /* TFU interface includes */
26 #include "rg_sch_inf.h" /* SCH interface includes */
27 #include "rg_prg.h" /* PRG (MAC-MAC) interface includes*/
28 #include "rg_env.h" /* MAC environmental includes*/
29 #include "rg.h" /* MAC includes*/
30 #include "rg_err.h" /* MAC error includes*/
32 #include "lwr_mac_fsm.h"
34 /* header/extern include files (.x) */
35 #include "rgu.x" /* RGU types */
36 #include "tfu.x" /* RGU types */
37 #include "lrg.x" /* layer management typedefs for MAC */
38 #include "crg.x" /* CRG interface includes */
39 #include "rg_sch_inf.x" /* SCH interface typedefs */
40 #include "rg_prg.x" /* PRG (MAC-MAC) Interface typedefs */
41 #include "du_app_mac_inf.h"
43 #include "rg.x" /* typedefs for MAC */
44 #include "lwr_mac_phy.h"
46 #define MIB_SFN_BITMASK 0xFC
47 #define PDCCH_PDU_TYPE 0
48 #define PDSCH_PDU_TYPE 1
49 #define SSB_PDU_TYPE 3
50 #define PRACH_PDU_TYPE 0
51 #define PUSCH_PDU_TYPE 1
52 #define PUCCH_PDU_TYPE 2
54 #define SET_MSG_LEN(x, size) x += size
56 extern void fapiMacConfigRsp();
57 extern uint8_t UnrestrictedSetNcsTable[MAX_ZERO_CORR_CFG_IDX];
59 /* Global variables */
61 uint16_t sendTxDataReq(SlotIndInfo currTimingInfo, DlSchedInfo *dlInfo);
68 /* Initializing WLS free mem list */
70 for(idx = 0; idx < WLS_MEM_FREE_PRD; idx++)
72 cmLListInit(&wlsBlockToFreeList[idx]);
77 /*******************************************************************
79 * @brief Handles Invalid Request Event
83 * Function : lwr_mac_handleInvalidEvt
86 * - Displays the PHY state when the invalid event occurs
89 * @return ROK - success
92 * ****************************************************************/
93 S16 lwr_mac_handleInvalidEvt(void *msg)
95 printf("\nLWR_MAC: Error Indication Event[%d] received in state [%d]", clGlobalCp.event, clGlobalCp.phyState);
100 /*******************************************************************
102 * @brief Fills FAPI message header
106 * Function : fillMsgHeader
109 * -Fills FAPI message header
111 * @params[in] Pointer to header
117 * ****************************************************************/
118 PUBLIC void fillMsgHeader(fapi_msg_t *hdr, uint16_t msgType, uint16_t msgLen)
120 memset(hdr, 0, sizeof(fapi_msg_t));
121 hdr->msg_id = msgType;
122 hdr->length = msgLen;
125 /*******************************************************************
127 * @brief Fills FAPI Config Request message header
131 * Function : fillTlvs
134 * -Fills FAPI Config Request message header
136 * @params[in] Pointer to TLV
143 * ****************************************************************/
144 PUBLIC void fillTlvs(fapi_uint32_tlv_t *tlv, uint16_t tag, uint16_t length,
145 uint16_t value, uint32_t *msgLen)
148 tlv->tl.length = length;
150 *msgLen = *msgLen + sizeof(tag) + sizeof(length) + length;
152 /*******************************************************************
154 * @brief fills the cyclic prefix by comparing the bitmask
158 * Function : fillCyclicPrefix
161 * -checks the value with the bitmask and
162 * fills the cellPtr's cyclic prefix.
164 * @params[in] Pointer to ClCellParam
165 * Value to be compared
168 ********************************************************************/
169 PUBLIC void fillCyclicPrefix(uint8_t value, ClCellParam **cellPtr)
171 if((value & FAPI_NORMAL_CYCLIC_PREFIX_MASK) == FAPI_NORMAL_CYCLIC_PREFIX_MASK)
173 (*cellPtr)->cyclicPrefix = NORMAL_CYCLIC_PREFIX_MASK;
175 else if((value & FAPI_EXTENDED_CYCLIC_PREFIX_MASK) == FAPI_EXTENDED_CYCLIC_PREFIX_MASK)
177 (*cellPtr)->cyclicPrefix = EXTENDED_CYCLIC_PREFIX_MASK;
181 (*cellPtr)->cyclicPrefix = INVALID_VALUE;
185 /*******************************************************************
187 * @brief fills the subcarrier spacing of Downlink by comparing the bitmask
191 * Function : fillSubcarrierSpaceDl
194 * -checks the value with the bitmask and
195 * fills the cellPtr's subcarrier spacing in DL
197 * @params[in] Pointer to ClCellParam
198 * Value to be compared
201 * ****************************************************************/
203 PUBLIC void fillSubcarrierSpaceDl(uint8_t value, ClCellParam **cellPtr)
205 if((value & FAPI_15KHZ_MASK) == FAPI_15KHZ_MASK)
207 (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_15_KHZ;
209 else if((value & FAPI_30KHZ_MASK) == FAPI_30KHZ_MASK)
211 (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_30_KHZ;
213 else if((value & FAPI_60KHZ_MASK) == FAPI_60KHZ_MASK)
215 (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_60_KHZ;
217 else if((value & FAPI_120KHZ_MASK) == FAPI_120KHZ_MASK)
219 (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_120_KHZ;
223 (*cellPtr)->supportedSubcarrierSpacingDl = INVALID_VALUE;
227 /*******************************************************************
229 * @brief fills the downlink bandwidth by comparing the bitmask
233 * Function : fillBandwidthDl
236 * -checks the value with the bitmask and
237 * -fills the cellPtr's DL Bandwidth
239 * @params[in] Pointer to ClCellParam
240 * Value to be compared
243 * ****************************************************************/
245 PUBLIC void fillBandwidthDl(uint16_t value, ClCellParam **cellPtr)
247 if((value & FAPI_5MHZ_BW_MASK) == FAPI_5MHZ_BW_MASK)
249 (*cellPtr)->supportedBandwidthDl = BW_5MHZ;
251 else if((value & FAPI_10MHZ_BW_MASK) == FAPI_10MHZ_BW_MASK)
253 (*cellPtr)->supportedBandwidthDl = BW_10MHZ;
255 else if((value & FAPI_15MHZ_BW_MASK) == FAPI_15MHZ_BW_MASK)
257 (*cellPtr)->supportedBandwidthDl = BW_15MHZ;
259 else if((value & FAPI_20MHZ_BW_MASK) == FAPI_20MHZ_BW_MASK)
261 (*cellPtr)->supportedBandwidthDl = BW_20MHZ;
263 else if((value & FAPI_40MHZ_BW_MASK) == FAPI_40MHZ_BW_MASK)
265 (*cellPtr)->supportedBandwidthDl = BW_40MHZ;
267 else if((value & FAPI_50MHZ_BW_MASK) == FAPI_50MHZ_BW_MASK)
269 (*cellPtr)->supportedBandwidthDl = BW_50MHZ;
271 else if((value & FAPI_60MHZ_BW_MASK) == FAPI_60MHZ_BW_MASK)
273 (*cellPtr)->supportedBandwidthDl = BW_60MHZ;
275 else if((value & FAPI_70MHZ_BW_MASK) == FAPI_70MHZ_BW_MASK)
277 (*cellPtr)->supportedBandwidthDl = BW_70MHZ;
279 else if((value & FAPI_80MHZ_BW_MASK) == FAPI_80MHZ_BW_MASK)
281 (*cellPtr)->supportedBandwidthDl = BW_80MHZ;
283 else if((value & FAPI_90MHZ_BW_MASK) == FAPI_90MHZ_BW_MASK)
285 (*cellPtr)->supportedBandwidthDl = BW_90MHZ;
287 else if((value & FAPI_100MHZ_BW_MASK) == FAPI_100MHZ_BW_MASK)
289 (*cellPtr)->supportedBandwidthDl = BW_100MHZ;
291 else if((value & FAPI_200MHZ_BW_MASK) == FAPI_200MHZ_BW_MASK)
293 (*cellPtr)->supportedBandwidthDl = BW_200MHZ;
295 else if((value & FAPI_400MHZ_BW_MASK) == FAPI_400MHZ_BW_MASK)
297 (*cellPtr)->supportedBandwidthDl = BW_400MHZ;
301 (*cellPtr)->supportedBandwidthDl = INVALID_VALUE;
305 /*******************************************************************
307 * @brief fills the subcarrier spacing of Uplink by comparing the bitmask
311 * Function : fillSubcarrierSpaceUl
314 * -checks the value with the bitmask and
315 * -fills cellPtr's subcarrier spacing in UL
317 * @params[in] Pointer to ClCellParam
318 * Value to be compared
321 * ****************************************************************/
323 PUBLIC void fillSubcarrierSpaceUl(uint8_t value, ClCellParam **cellPtr)
325 if((value & FAPI_15KHZ_MASK) == FAPI_15KHZ_MASK)
327 (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_15_KHZ;
329 else if((value & FAPI_30KHZ_MASK) == FAPI_30KHZ_MASK)
331 (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_30_KHZ;
333 else if((value & FAPI_60KHZ_MASK) == FAPI_60KHZ_MASK)
335 (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_60_KHZ;
337 else if((value & FAPI_120KHZ_MASK) == FAPI_120KHZ_MASK)
339 (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_120_KHZ;
343 (*cellPtr)->supportedSubcarrierSpacingsUl = INVALID_VALUE;
347 /*******************************************************************
349 * @brief fills the uplink bandwidth by comparing the bitmask
353 * Function : fillBandwidthUl
356 * -checks the value with the bitmask and
357 * fills the cellPtr's UL Bandwidth
361 * @params[in] Pointer to ClCellParam
362 * Value to be compared
366 * ****************************************************************/
368 PUBLIC void fillBandwidthUl(uint16_t value, ClCellParam **cellPtr)
370 if((value & FAPI_5MHZ_BW_MASK) == FAPI_5MHZ_BW_MASK)
372 (*cellPtr)->supportedBandwidthUl = BW_5MHZ;
374 else if((value & FAPI_10MHZ_BW_MASK) == FAPI_10MHZ_BW_MASK)
376 (*cellPtr)->supportedBandwidthUl = BW_10MHZ;
378 else if((value & FAPI_15MHZ_BW_MASK) == FAPI_15MHZ_BW_MASK)
380 (*cellPtr)->supportedBandwidthUl = BW_15MHZ;
382 else if((value & FAPI_20MHZ_BW_MASK) == FAPI_20MHZ_BW_MASK)
384 (*cellPtr)->supportedBandwidthUl = BW_20MHZ;
386 else if((value & FAPI_40MHZ_BW_MASK) == FAPI_40MHZ_BW_MASK)
388 (*cellPtr)->supportedBandwidthUl = BW_40MHZ;
390 else if((value & FAPI_50MHZ_BW_MASK) == FAPI_50MHZ_BW_MASK)
392 (*cellPtr)->supportedBandwidthUl = BW_50MHZ;
394 else if((value & FAPI_60MHZ_BW_MASK) == FAPI_60MHZ_BW_MASK)
396 (*cellPtr)->supportedBandwidthUl = BW_60MHZ;
398 else if((value & FAPI_70MHZ_BW_MASK) == FAPI_70MHZ_BW_MASK)
400 (*cellPtr)->supportedBandwidthUl = BW_70MHZ;
402 else if((value & FAPI_80MHZ_BW_MASK) == FAPI_80MHZ_BW_MASK)
404 (*cellPtr)->supportedBandwidthUl = BW_80MHZ;
406 else if((value & FAPI_90MHZ_BW_MASK) == FAPI_90MHZ_BW_MASK)
408 (*cellPtr)->supportedBandwidthUl = BW_90MHZ;
410 else if((value & FAPI_100MHZ_BW_MASK) == FAPI_100MHZ_BW_MASK)
412 (*cellPtr)->supportedBandwidthUl = BW_100MHZ;
414 else if((value & FAPI_200MHZ_BW_MASK) == FAPI_200MHZ_BW_MASK)
416 (*cellPtr)->supportedBandwidthUl = BW_200MHZ;
418 else if((value & FAPI_400MHZ_BW_MASK) == FAPI_400MHZ_BW_MASK)
420 (*cellPtr)->supportedBandwidthUl = BW_400MHZ;
424 (*cellPtr)->supportedBandwidthUl = INVALID_VALUE;
427 /*******************************************************************
429 * @brief fills the CCE maping by comparing the bitmask
433 * Function : fillCCEmaping
436 * -checks the value with the bitmask and
437 * fills the cellPtr's CCE Mapping Type
440 * @params[in] Pointer to ClCellParam
441 * Value to be compared
444 * ****************************************************************/
446 PUBLIC void fillCCEmaping(uint8_t value, ClCellParam **cellPtr)
448 if ((value & FAPI_CCE_MAPPING_INTERLEAVED_MASK) == FAPI_CCE_MAPPING_INTERLEAVED_MASK)
450 (*cellPtr)->cceMappingType = CCE_MAPPING_INTERLEAVED_MASK;
452 else if((value & FAPI_CCE_MAPPING_INTERLEAVED_MASK) == FAPI_CCE_MAPPING_NONINTERLVD_MASK)
454 (*cellPtr)->cceMappingType = CCE_MAPPING_NONINTERLVD_MASK;
458 (*cellPtr)->cceMappingType = INVALID_VALUE;
462 /*******************************************************************
464 * @brief fills the PUCCH format by comparing the bitmask
468 * Function : fillPucchFormat
471 * -checks the value with the bitmask and
472 * fills the cellPtr's pucch format
475 * @params[in] Pointer to ClCellParam
476 * Value to be compared
479 * ****************************************************************/
481 PUBLIC void fillPucchFormat(uint8_t value, ClCellParam **cellPtr)
483 if((value & FAPI_FORMAT_0_MASK) == FAPI_FORMAT_0_MASK)
485 (*cellPtr)->pucchFormats = FORMAT_0;
487 else if((value & FAPI_FORMAT_1_MASK) == FAPI_FORMAT_1_MASK)
489 (*cellPtr)->pucchFormats = FORMAT_1;
491 else if((value & FAPI_FORMAT_2_MASK) == FAPI_FORMAT_2_MASK)
493 (*cellPtr)->pucchFormats = FORMAT_2;
495 else if((value & FAPI_FORMAT_3_MASK) == FAPI_FORMAT_3_MASK)
497 (*cellPtr)->pucchFormats = FORMAT_3;
499 else if((value & FAPI_FORMAT_4_MASK) == FAPI_FORMAT_4_MASK)
501 (*cellPtr)->pucchFormats = FORMAT_4;
505 (*cellPtr)->pucchFormats = INVALID_VALUE;
509 /*******************************************************************
511 * @brief fills the PDSCH Mapping Type by comparing the bitmask
515 * Function : fillPdschMappingType
518 * -checks the value with the bitmask and
519 * fills the cellPtr's PDSCH MappingType
521 * @params[in] Pointer to ClCellParam
522 * Value to be compared
525 * ****************************************************************/
527 PUBLIC void fillPdschMappingType(uint8_t value, ClCellParam **cellPtr)
529 if((value & FAPI_PDSCH_MAPPING_TYPE_A_MASK) == FAPI_PDSCH_MAPPING_TYPE_A_MASK)
531 (*cellPtr)->pdschMappingType = MAPPING_TYPE_A;
533 else if((value & FAPI_PDSCH_MAPPING_TYPE_B_MASK) == FAPI_PDSCH_MAPPING_TYPE_B_MASK)
535 (*cellPtr)->pdschMappingType = MAPPING_TYPE_B;
539 (*cellPtr)->pdschMappingType = INVALID_VALUE;
543 /*******************************************************************
545 * @brief fills the PDSCH Allocation Type by comparing the bitmask
549 * Function : fillPdschAllocationType
552 * -checks the value with the bitmask and
553 * fills the cellPtr's PDSCH AllocationType
555 * @params[in] Pointer to ClCellParam
556 * Value to be compared
559 * ****************************************************************/
561 PUBLIC void fillPdschAllocationType(uint8_t value, ClCellParam **cellPtr)
563 if((value & FAPI_PDSCH_ALLOC_TYPE_0_MASK) == FAPI_PDSCH_ALLOC_TYPE_0_MASK)
565 (*cellPtr)->pdschAllocationTypes = ALLOCATION_TYPE_0;
567 else if((value & FAPI_PDSCH_ALLOC_TYPE_1_MASK) == FAPI_PDSCH_ALLOC_TYPE_1_MASK)
569 (*cellPtr)->pdschAllocationTypes = ALLOCATION_TYPE_1;
573 (*cellPtr)->pdschAllocationTypes = INVALID_VALUE;
577 /*******************************************************************
579 * @brief fills the PDSCH PRB Mapping Type by comparing the bitmask
583 * Function : fillPrbMappingType
586 * -checks the value with the bitmask and
587 * fills the cellPtr's PRB Mapping Type
589 * @params[in] Pointer to ClCellParam
590 * Value to be compared
593 ******************************************************************/
594 PUBLIC void fillPrbMappingType(uint8_t value, ClCellParam **cellPtr)
596 if((value & FAPI_PDSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK) == FAPI_PDSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK)
598 (*cellPtr)->pdschVrbToPrbMapping = VRB_TO_PRB_MAP_NON_INTLV;
600 else if((value & FAPI_PDSCH_VRB_TO_PRB_MAP_INTLVD_MASK) == FAPI_PDSCH_VRB_TO_PRB_MAP_INTLVD_MASK)
602 (*cellPtr)->pdschVrbToPrbMapping = VRB_TO_PRB_MAP_INTLVD;
606 (*cellPtr)->pdschVrbToPrbMapping = INVALID_VALUE;
610 /*******************************************************************
612 * @brief fills the PDSCH DmrsConfig Type by comparing the bitmask
616 * Function : fillPdschDmrsConfigType
619 * -checks the value with the bitmask and
620 * fills the cellPtr's DmrsConfig Type
622 * @params[in] Pointer to ClCellParam
623 * Value to be compared
626 ******************************************************************/
628 PUBLIC void fillPdschDmrsConfigType(uint8_t value, ClCellParam **cellPtr)
630 if((value & FAPI_PDSCH_DMRS_CONFIG_TYPE_1_MASK) == FAPI_PDSCH_DMRS_CONFIG_TYPE_1_MASK)
632 (*cellPtr)->pdschDmrsConfigTypes = DMRS_CONFIG_TYPE_1;
634 else if((value & FAPI_PDSCH_DMRS_CONFIG_TYPE_2_MASK) == FAPI_PDSCH_DMRS_CONFIG_TYPE_2_MASK)
636 (*cellPtr)->pdschDmrsConfigTypes = DMRS_CONFIG_TYPE_2;
640 (*cellPtr)->pdschDmrsConfigTypes = INVALID_VALUE;
644 /*******************************************************************
646 * @brief fills the PDSCH DmrsLength by comparing the bitmask
650 * Function : fillPdschDmrsLength
653 * -checks the value with the bitmask and
654 * fills the cellPtr's PdschDmrsLength
656 * @params[in] Pointer to ClCellParam
657 * Value to be compared
660 ******************************************************************/
661 PUBLIC void fillPdschDmrsLength(uint8_t value, ClCellParam **cellPtr)
663 if(value == FAPI_PDSCH_DMRS_MAX_LENGTH_1)
665 (*cellPtr)->pdschDmrsMaxLength = DMRS_MAX_LENGTH_1;
667 else if(value == FAPI_PDSCH_DMRS_MAX_LENGTH_2)
669 (*cellPtr)->pdschDmrsMaxLength = DMRS_MAX_LENGTH_2;
673 (*cellPtr)->pdschDmrsMaxLength = INVALID_VALUE;
677 /*******************************************************************
679 * @brief fills the PDSCH Dmrs Additional Pos by comparing the bitmask
683 * Function : fillPdschDmrsAddPos
686 * -checks the value with the bitmask and
687 * fills the cellPtr's Pdsch DmrsAddPos
689 * @params[in] Pointer to ClCellParam
690 * Value to be compared
693 ******************************************************************/
695 PUBLIC void fillPdschDmrsAddPos(uint8_t value, ClCellParam **cellPtr)
697 if((value & FAPI_DMRS_ADDITIONAL_POS_0_MASK) == FAPI_DMRS_ADDITIONAL_POS_0_MASK)
699 (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_0;
701 else if((value & FAPI_DMRS_ADDITIONAL_POS_1_MASK) == FAPI_DMRS_ADDITIONAL_POS_1_MASK)
703 (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_1;
705 else if((value & FAPI_DMRS_ADDITIONAL_POS_2_MASK) == FAPI_DMRS_ADDITIONAL_POS_2_MASK)
707 (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_2;
709 else if((value & FAPI_DMRS_ADDITIONAL_POS_3_MASK) == FAPI_DMRS_ADDITIONAL_POS_3_MASK)
711 (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_3;
715 (*cellPtr)->pdschDmrsAdditionalPos = INVALID_VALUE;
719 /*******************************************************************
721 * @brief fills the Modulation Order in DL by comparing the bitmask
725 * Function : fillModulationOrderDl
728 * -checks the value with the bitmask and
729 * fills the cellPtr's ModulationOrder in DL.
731 * @params[in] Pointer to ClCellParam
732 * Value to be compared
735 ******************************************************************/
736 PUBLIC void fillModulationOrderDl(uint8_t value, ClCellParam **cellPtr)
740 (*cellPtr)->supportedMaxModulationOrderDl = MOD_QPSK;
744 (*cellPtr)->supportedMaxModulationOrderDl = MOD_16QAM;
748 (*cellPtr)->supportedMaxModulationOrderDl = MOD_64QAM;
752 (*cellPtr)->supportedMaxModulationOrderDl = MOD_256QAM;
756 (*cellPtr)->supportedMaxModulationOrderDl = INVALID_VALUE;
760 /*******************************************************************
762 * @brief fills the PUSCH DmrsConfig Type by comparing the bitmask
766 * Function : fillPuschDmrsConfigType
769 * -checks the value with the bitmask and
770 * fills the cellPtr's PUSCH DmrsConfigType
772 * @params[in] Pointer to ClCellParam
773 * Value to be compared
776 ******************************************************************/
778 PUBLIC void fillPuschDmrsConfig(uint8_t value, ClCellParam **cellPtr)
780 if((value & FAPI_PUSCH_DMRS_CONFIG_TYPE_1_MASK) == FAPI_PUSCH_DMRS_CONFIG_TYPE_1_MASK)
782 (*cellPtr)->puschDmrsConfigTypes = DMRS_CONFIG_TYPE_1;
784 else if((value & FAPI_PUSCH_DMRS_CONFIG_TYPE_2_MASK) == FAPI_PUSCH_DMRS_CONFIG_TYPE_2_MASK)
786 (*cellPtr)->puschDmrsConfigTypes = DMRS_CONFIG_TYPE_2;
790 (*cellPtr)->puschDmrsConfigTypes = INVALID_VALUE;
794 /*******************************************************************
796 * @brief fills the PUSCH DmrsLength by comparing the bitmask
800 * Function : fillPuschDmrsLength
803 * -checks the value with the bitmask and
804 * fills the cellPtr's PUSCH DmrsLength
806 * @params[in] Pointer to ClCellParam
807 * Value to be compared
810 ******************************************************************/
812 PUBLIC void fillPuschDmrsLength(uint8_t value, ClCellParam **cellPtr)
814 if(value == FAPI_PUSCH_DMRS_MAX_LENGTH_1)
816 (*cellPtr)->puschDmrsMaxLength = DMRS_MAX_LENGTH_1;
818 else if(value == FAPI_PUSCH_DMRS_MAX_LENGTH_2)
820 (*cellPtr)->puschDmrsMaxLength = DMRS_MAX_LENGTH_2;
824 (*cellPtr)->puschDmrsMaxLength = INVALID_VALUE;
828 /*******************************************************************
830 * @brief fills the PUSCH Dmrs Additional position by comparing the bitmask
834 * Function : fillPuschDmrsAddPos
837 * -checks the value with the bitmask and
838 * fills the cellPtr's PUSCH DmrsAddPos
840 * @params[in] Pointer to ClCellParam
841 * Value to be compared
844 ******************************************************************/
846 PUBLIC void fillPuschDmrsAddPos(uint8_t value, ClCellParam **cellPtr)
848 if((value & FAPI_DMRS_ADDITIONAL_POS_0_MASK) == FAPI_DMRS_ADDITIONAL_POS_0_MASK)
850 (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_0;
852 else if((value & FAPI_DMRS_ADDITIONAL_POS_1_MASK) == FAPI_DMRS_ADDITIONAL_POS_1_MASK)
854 (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_1;
856 else if((value & FAPI_DMRS_ADDITIONAL_POS_2_MASK) == FAPI_DMRS_ADDITIONAL_POS_2_MASK)
858 (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_2;
860 else if((value & FAPI_DMRS_ADDITIONAL_POS_3_MASK) == FAPI_DMRS_ADDITIONAL_POS_3_MASK)
862 (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_3;
866 (*cellPtr)->puschDmrsAdditionalPos = INVALID_VALUE;
870 /*******************************************************************
872 * @brief fills the PUSCH Mapping Type by comparing the bitmask
876 * Function : fillPuschMappingType
879 * -checks the value with the bitmask and
880 * fills the cellPtr's PUSCH MappingType
882 * @params[in] Pointer to ClCellParam
883 * Value to be compared
886 ******************************************************************/
888 PUBLIC void fillPuschMappingType(uint8_t value, ClCellParam **cellPtr)
890 if((value & FAPI_PUSCH_MAPPING_TYPE_A_MASK) == FAPI_PUSCH_MAPPING_TYPE_A_MASK)
892 (*cellPtr)->puschMappingType = MAPPING_TYPE_A;
894 else if((value & FAPI_PUSCH_MAPPING_TYPE_B_MASK) == FAPI_PUSCH_MAPPING_TYPE_B_MASK)
896 (*cellPtr)->puschMappingType = MAPPING_TYPE_B;
900 (*cellPtr)->puschMappingType = INVALID_VALUE;
904 /*******************************************************************
906 * @brief fills the PUSCH Allocation Type by comparing the bitmask
910 * Function : fillPuschAllocationType
913 * -checks the value with the bitmask and
914 * fills the cellPtr's PUSCH AllocationType
916 * @params[in] Pointer to ClCellParam
917 * Value to be compared
920 ******************************************************************/
922 PUBLIC void fillPuschAllocationType(uint8_t value, ClCellParam **cellPtr)
924 if((value & FAPI_PUSCH_ALLOC_TYPE_0_MASK) == FAPI_PUSCH_ALLOC_TYPE_0_MASK)
926 (*cellPtr)->puschAllocationTypes = ALLOCATION_TYPE_0;
928 else if((value & FAPI_PUSCH_ALLOC_TYPE_0_MASK) == FAPI_PUSCH_ALLOC_TYPE_0_MASK)
930 (*cellPtr)->puschAllocationTypes = ALLOCATION_TYPE_1;
934 (*cellPtr)->puschAllocationTypes = INVALID_VALUE;
938 /*******************************************************************
940 * @brief fills the PUSCH PRB Mapping Type by comparing the bitmask
944 * Function : fillPuschPrbMappingType
947 * -checks the value with the bitmask and
948 * fills the cellPtr's PUSCH PRB MApping Type
950 * @params[in] Pointer to ClCellParam
951 * Value to be compared
954 ******************************************************************/
956 PUBLIC void fillPuschPrbMappingType(uint8_t value, ClCellParam **cellPtr)
958 if((value & FAPI_PUSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK) == FAPI_PUSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK)
960 (*cellPtr)->puschVrbToPrbMapping = VRB_TO_PRB_MAP_NON_INTLV;
962 else if((value & FAPI_PUSCH_VRB_TO_PRB_MAP_INTLVD_MASK) == FAPI_PUSCH_VRB_TO_PRB_MAP_INTLVD_MASK)
964 (*cellPtr)->puschVrbToPrbMapping = VRB_TO_PRB_MAP_INTLVD;
968 (*cellPtr)->puschVrbToPrbMapping = INVALID_VALUE;
972 /*******************************************************************
974 * @brief fills the Modulation Order in Ul by comparing the bitmask
978 * Function : fillModulationOrderUl
981 * -checks the value with the bitmask and
982 * fills the cellPtr's Modualtsion Order in UL.
984 * @params[in] Pointer to ClCellParam
985 * Value to be compared
988 ******************************************************************/
990 PUBLIC void fillModulationOrderUl(uint8_t value, ClCellParam **cellPtr)
994 (*cellPtr)->supportedModulationOrderUl = MOD_QPSK;
998 (*cellPtr)->supportedModulationOrderUl = MOD_16QAM;
1002 (*cellPtr)->supportedModulationOrderUl = MOD_64QAM;
1006 (*cellPtr)->supportedModulationOrderUl = MOD_256QAM;
1010 (*cellPtr)->supportedModulationOrderUl = INVALID_VALUE;
1014 /*******************************************************************
1016 * @brief fills the PUSCH Aggregation Factor by comparing the bitmask
1020 * Function : fillPuschAggregationFactor
1023 * -checks the value with the bitmask and
1024 * fills the cellPtr's PUSCH Aggregation Factor
1026 * @params[in] Pointer to ClCellParam
1027 * Value to be compared
1030 ******************************************************************/
1032 PUBLIC void fillPuschAggregationFactor(uint8_t value, ClCellParam **cellPtr)
1034 if((value & FAPI_FORMAT_0_MASK) == FAPI_FORMAT_0_MASK)
1036 (*cellPtr)->puschAggregationFactor = AGG_FACTOR_1;
1038 else if((value & FAPI_FORMAT_1_MASK) == FAPI_FORMAT_1_MASK)
1040 (*cellPtr)->puschAggregationFactor = AGG_FACTOR_2;
1042 else if((value & FAPI_FORMAT_2_MASK) == FAPI_FORMAT_2_MASK)
1044 (*cellPtr)->puschAggregationFactor = AGG_FACTOR_4;
1046 else if((value & FAPI_FORMAT_3_MASK) == FAPI_FORMAT_3_MASK)
1048 (*cellPtr)->puschAggregationFactor = AGG_FACTOR_8;
1052 (*cellPtr)->puschAggregationFactor = INVALID_VALUE;
1056 /*******************************************************************
1058 * @brief fills the PRACH Long Format by comparing the bitmask
1062 * Function : fillPrachLongFormat
1065 * -checks the value with the bitmask and
1066 * fills the cellPtr's PRACH Long Format
1068 * @params[in] Pointer to ClCellParam
1069 * Value to be compared
1072 ******************************************************************/
1074 PUBLIC void fillPrachLongFormat(uint8_t value, ClCellParam **cellPtr)
1076 if((value & FAPI_PRACH_LF_FORMAT_0_MASK) == FAPI_PRACH_LF_FORMAT_0_MASK)
1078 (*cellPtr)->prachLongFormats = FORMAT_0;
1080 else if((value & FAPI_PRACH_LF_FORMAT_1_MASK) == FAPI_PRACH_LF_FORMAT_1_MASK)
1082 (*cellPtr)->prachLongFormats = FORMAT_1;
1084 else if((value & FAPI_PRACH_LF_FORMAT_2_MASK) == FAPI_PRACH_LF_FORMAT_2_MASK)
1086 (*cellPtr)->prachLongFormats = FORMAT_2;
1088 else if((value & FAPI_PRACH_LF_FORMAT_3_MASK) == FAPI_PRACH_LF_FORMAT_3_MASK)
1090 (*cellPtr)->prachLongFormats = FORMAT_3;
1094 (*cellPtr)->prachLongFormats = INVALID_VALUE;
1098 /*******************************************************************
1100 * @brief fills the PRACH Short Format by comparing the bitmask
1104 * Function : fillPrachShortFormat
1107 * -checks the value with the bitmask and
1108 * fills the cellPtr's PRACH ShortFormat
1110 * @params[in] Pointer to ClCellParam
1111 * Value to be compared
1114 ******************************************************************/
1116 PUBLIC void fillPrachShortFormat(uint8_t value, ClCellParam **cellPtr)
1118 if((value & FAPI_PRACH_SF_FORMAT_A1_MASK) == FAPI_PRACH_SF_FORMAT_A1_MASK)
1120 (*cellPtr)->prachShortFormats = SF_FORMAT_A1;
1122 else if((value & FAPI_PRACH_SF_FORMAT_A2_MASK) == FAPI_PRACH_SF_FORMAT_A2_MASK)
1124 (*cellPtr)->prachShortFormats = SF_FORMAT_A2;
1126 else if((value & FAPI_PRACH_SF_FORMAT_A3_MASK) == FAPI_PRACH_SF_FORMAT_A3_MASK)
1128 (*cellPtr)->prachShortFormats = SF_FORMAT_A3;
1130 else if((value & FAPI_PRACH_SF_FORMAT_B1_MASK) == FAPI_PRACH_SF_FORMAT_B1_MASK)
1132 (*cellPtr)->prachShortFormats = SF_FORMAT_B1;
1134 else if((value & FAPI_PRACH_SF_FORMAT_B2_MASK) == FAPI_PRACH_SF_FORMAT_B2_MASK)
1136 (*cellPtr)->prachShortFormats = SF_FORMAT_B2;
1138 else if((value & FAPI_PRACH_SF_FORMAT_B3_MASK) == FAPI_PRACH_SF_FORMAT_B3_MASK)
1140 (*cellPtr)->prachShortFormats = SF_FORMAT_B3;
1142 else if((value & FAPI_PRACH_SF_FORMAT_B4_MASK) == FAPI_PRACH_SF_FORMAT_B4_MASK)
1144 (*cellPtr)->prachShortFormats = SF_FORMAT_B4;
1146 else if((value & FAPI_PRACH_SF_FORMAT_C0_MASK) == FAPI_PRACH_SF_FORMAT_C0_MASK)
1148 (*cellPtr)->prachShortFormats = SF_FORMAT_C0;
1150 else if((value & FAPI_PRACH_SF_FORMAT_C2_MASK) == FAPI_PRACH_SF_FORMAT_C2_MASK)
1152 (*cellPtr)->prachShortFormats = SF_FORMAT_C2;
1156 (*cellPtr)->prachShortFormats = INVALID_VALUE;
1160 /*******************************************************************
1162 * @brief fills the Fd Occasions Type by comparing the bitmask
1166 * Function : fillFdOccasions
1169 * -checks the value with the bitmask and
1170 * fills the cellPtr's Fd Occasions
1172 * @params[in] Pointer to ClCellParam
1173 * Value to be compared
1176 ******************************************************************/
1178 PUBLIC void fillFdOccasions(uint8_t value, ClCellParam **cellPtr)
1182 (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_1;
1186 (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_2;
1190 (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_4;
1194 (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_8;
1198 (*cellPtr)->maxPrachFdOccasionsInASlot = INVALID_VALUE;
1202 /*******************************************************************
1204 * @brief fills the RSSI Measurement by comparing the bitmask
1208 * Function : fillRssiMeas
1211 * -checks the value with the bitmask and
1212 * fills the cellPtr's RSSI Measurement report
1214 * @params[in] Pointer to ClCellParam
1215 * Value to be compared
1218 ******************************************************************/
1220 PUBLIC void fillRssiMeas(uint8_t value, ClCellParam **cellPtr)
1222 if((value & FAPI_RSSI_REPORT_IN_DBM_MASK) == FAPI_RSSI_REPORT_IN_DBM_MASK)
1224 (*cellPtr)->rssiMeasurementSupport = RSSI_REPORT_DBM;
1226 else if((value & FAPI_RSSI_REPORT_IN_DBFS_MASK) == FAPI_RSSI_REPORT_IN_DBFS_MASK)
1228 (*cellPtr)->rssiMeasurementSupport = RSSI_REPORT_DBFS;
1232 (*cellPtr)->rssiMeasurementSupport = INVALID_VALUE;
1236 /*******************************************************************
1238 * @brief Returns the TLVs value
1242 * Function : getParamValue
1245 * -return TLVs value
1248 * @return ROK - temp
1251 * ****************************************************************/
1253 uint32_t getParamValue(fapi_uint16_tlv_t *tlv, uint16_t type)
1255 //uint16_t valueLen;
1257 //valueLen = tlv->tl.length;
1258 posPtr = &tlv->tl.tag;
1259 posPtr += sizeof(tlv->tl.tag);
1260 posPtr += sizeof(tlv->tl.length);
1261 /*TO DO: malloc to SSI memory */
1262 if(type == FAPI_UINT_8)
1264 //temp = (uint8_t *)malloc(valueLen * sizeof(U8));
1265 //memcpy(temp, posPtr, valueLen);
1266 return(*(uint8_t *)posPtr);
1268 else if(type == FAPI_UINT_16)
1270 return(*(uint16_t *)posPtr);
1272 else if(type == FAPI_UINT_32)
1274 return(*(uint32_t *)posPtr);
1278 DU_LOG("\nLWR_MAC: Value Extraction failed" );
1283 /*******************************************************************
1285 * @brief Sends FAPI Param req to PHY
1289 * Function : lwr_mac_handleParamReqEvt
1292 * -Sends FAPI Param req to PHY
1295 * @return ROK - success
1298 * ****************************************************************/
1300 S16 lwr_mac_handleParamReqEvt(void *msg)
1303 /* startGuardTimer(); */
1304 uint32_t msgLen = 0; //Length of message Body
1305 fapi_param_req_t *paramReq = NULL;
1307 LWR_MAC_ALLOC(paramReq, sizeof(fapi_param_req_t));
1308 if(paramReq != NULL)
1310 fillMsgHeader(¶mReq->header, FAPI_PARAM_REQUEST, msgLen);
1312 DU_LOG("\nLWR_MAC: Sending Param Request to Phy");
1313 LwrMacSendToPhy(paramReq->header.msg_id, \
1314 sizeof(fapi_param_req_t), (void *)paramReq);
1318 DU_LOG("\nLWR_MAC: Failed to allocate memory for Param Request");
1325 /*******************************************************************
1327 * @brief Sends FAPI Param Response to MAC via PHY
1331 * Function : lwr_mac_handleParamRspEvt
1334 * -Sends FAPI Param rsp to MAC via PHY
1337 * @return ROK - success
1340 * ****************************************************************/
1342 S16 lwr_mac_handleParamRspEvt(void *msg)
1345 /* stopGuardTimer(); */
1347 uint32_t encodedVal;
1348 fapi_param_resp_t *paramRsp;
1349 ClCellParam *cellParam = NULLP;
1351 paramRsp = (fapi_param_resp_t *)msg;
1352 DU_LOG("\nLWR_MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
1354 if(paramRsp != NULLP)
1356 MAC_ALLOC(cellParam, sizeof(ClCellParam));
1357 if(cellParam != NULLP)
1359 DU_LOG("\n LWR_MAC: Filling TLVS into MAC API");
1360 if(paramRsp->error_code == MSG_OK)
1362 for(index = 0; index < paramRsp->number_of_tlvs; index++)
1364 switch(paramRsp->tlvs[index].tl.tag)
1366 case FAPI_RELEASE_CAPABILITY_TAG:
1367 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_16);
1368 if(encodedVal != RFAILED && (encodedVal & RELEASE_15) == RELEASE_15)
1370 cellParam->releaseCapability = RELEASE_15;
1374 case FAPI_PHY_STATE_TAG:
1375 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1376 if(encodedVal != RFAILED && encodedVal != clGlobalCp.phyState)
1378 printf("\n PhyState mismatch [%d][%d]", clGlobalCp.phyState, clGlobalCp.event);
1383 case FAPI_SKIP_BLANK_DL_CONFIG_TAG:
1384 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1385 if(encodedVal != RFAILED && encodedVal != 0)
1387 cellParam->skipBlankDlConfig = SUPPORTED;
1391 cellParam->skipBlankDlConfig = NOT_SUPPORTED;
1395 case FAPI_SKIP_BLANK_UL_CONFIG_TAG:
1396 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1397 if(encodedVal != RFAILED && encodedVal != 0)
1399 cellParam->skipBlankUlConfig = SUPPORTED;
1403 cellParam->skipBlankUlConfig = NOT_SUPPORTED;
1407 case FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG:
1408 cellParam->numTlvsToReport = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_16);
1411 case FAPI_CYCLIC_PREFIX_TAG:
1412 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1413 if(encodedVal != RFAILED)
1415 fillCyclicPrefix(encodedVal, &cellParam);
1419 case FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG:
1420 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1421 if(encodedVal != RFAILED)
1423 fillSubcarrierSpaceDl(encodedVal, &cellParam);
1427 case FAPI_SUPPORTED_BANDWIDTH_DL_TAG:
1428 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_16);
1429 if(encodedVal != RFAILED)
1431 fillBandwidthDl(encodedVal, &cellParam);
1435 case FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG:
1436 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1437 if(encodedVal != RFAILED)
1439 fillSubcarrierSpaceUl(encodedVal, &cellParam);
1443 case FAPI_SUPPORTED_BANDWIDTH_UL_TAG:
1444 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_16);
1445 if(encodedVal != RFAILED)
1447 fillBandwidthUl(encodedVal, &cellParam);
1451 case FAPI_CCE_MAPPING_TYPE_TAG:
1452 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1453 if(encodedVal != RFAILED)
1455 fillCCEmaping(encodedVal, &cellParam);
1459 case FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG:
1460 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1461 if(encodedVal != RFAILED && encodedVal != 0)
1463 cellParam->coresetOutsideFirst3OfdmSymsOfSlot = SUPPORTED;
1467 cellParam->coresetOutsideFirst3OfdmSymsOfSlot = NOT_SUPPORTED;
1471 case FAPI_PRECODER_GRANULARITY_CORESET_TAG:
1472 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1473 if(encodedVal != RFAILED && encodedVal != 0)
1475 cellParam->precoderGranularityCoreset = SUPPORTED;
1479 cellParam->precoderGranularityCoreset = NOT_SUPPORTED;
1483 case FAPI_PDCCH_MU_MIMO_TAG:
1484 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1485 if(encodedVal != RFAILED && encodedVal != 0)
1487 cellParam->pdcchMuMimo = SUPPORTED;
1491 cellParam->pdcchMuMimo = NOT_SUPPORTED;
1495 case FAPI_PDCCH_PRECODER_CYCLING_TAG:
1496 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1497 if(encodedVal != RFAILED && encodedVal != 0)
1499 cellParam->pdcchPrecoderCycling = SUPPORTED;
1503 cellParam->pdcchPrecoderCycling = NOT_SUPPORTED;
1507 case FAPI_MAX_PDCCHS_PER_SLOT_TAG:
1508 cellParam->maxPdcchsPerSlot = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1511 case FAPI_PUCCH_FORMATS_TAG:
1512 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1513 if(encodedVal != RFAILED)
1515 fillPucchFormat(encodedVal, &cellParam);
1519 case FAPI_MAX_PUCCHS_PER_SLOT_TAG:
1520 cellParam->maxPucchsPerSlot = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1523 case FAPI_PDSCH_MAPPING_TYPE_TAG:
1524 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1525 if(encodedVal != RFAILED)
1527 fillPdschMappingType(encodedVal, &cellParam);
1531 case FAPI_PDSCH_ALLOCATION_TYPES_TAG:
1532 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1533 if(encodedVal != RFAILED)
1535 fillPdschAllocationType(encodedVal, &cellParam);
1539 case FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG:
1540 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1541 if(encodedVal != RFAILED)
1543 fillPrbMappingType(encodedVal, &cellParam);
1547 case FAPI_PDSCH_CBG_TAG:
1548 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1549 if(encodedVal != RFAILED && encodedVal != 0)
1551 cellParam->pdschCbg = SUPPORTED;
1555 cellParam->pdschCbg = NOT_SUPPORTED;
1559 case FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG:
1560 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1561 if(encodedVal != RFAILED)
1563 fillPdschDmrsConfigType(encodedVal, &cellParam);
1567 case FAPI_PDSCH_DMRS_MAX_LENGTH_TAG:
1568 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1569 if(encodedVal != RFAILED)
1571 fillPdschDmrsLength(encodedVal, &cellParam);
1575 case FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG:
1576 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1577 if(encodedVal != RFAILED)
1579 fillPdschDmrsAddPos(encodedVal, &cellParam);
1583 case FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG:
1584 cellParam->maxPdschsTBsPerSlot = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1587 case FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG:
1588 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1589 if(encodedVal != RFAILED && encodedVal < FAPI_MAX_NUMBERMIMO_LAYERS_PDSCH)
1591 cellParam->maxNumberMimoLayersPdsch = encodedVal;
1595 case FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG:
1596 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1597 if(encodedVal != RFAILED)
1599 fillModulationOrderDl(encodedVal, &cellParam);
1603 case FAPI_MAX_MU_MIMO_USERS_DL_TAG:
1604 cellParam->maxMuMimoUsersDl = \
1605 getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1608 case FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG:
1609 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1610 if(encodedVal != RFAILED && encodedVal != 0)
1612 cellParam->pdschDataInDmrsSymbols = SUPPORTED;
1616 cellParam->pdschDataInDmrsSymbols = NOT_SUPPORTED;
1620 case FAPI_PREMPTIONSUPPORT_TAG:
1621 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1622 if(encodedVal != RFAILED && encodedVal != 0)
1624 cellParam->premptionSupport = SUPPORTED;
1628 cellParam->premptionSupport = NOT_SUPPORTED;
1632 case FAPI_PDSCH_NON_SLOT_SUPPORT_TAG:
1633 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1634 if(encodedVal != RFAILED && encodedVal != 0)
1636 cellParam->pdschNonSlotSupport = SUPPORTED;
1640 cellParam->pdschNonSlotSupport = NOT_SUPPORTED;
1644 case FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG:
1645 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1646 if(encodedVal != RFAILED && encodedVal != 0)
1648 cellParam->uciMuxUlschInPusch = SUPPORTED;
1652 cellParam->uciMuxUlschInPusch = NOT_SUPPORTED;
1656 case FAPI_UCI_ONLY_PUSCH_TAG:
1657 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1658 if(encodedVal != RFAILED && encodedVal != 0)
1660 cellParam->uciOnlyPusch = SUPPORTED;
1664 cellParam->uciOnlyPusch = NOT_SUPPORTED;
1668 case FAPI_PUSCH_FREQUENCY_HOPPING_TAG:
1669 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1670 if(encodedVal != RFAILED && encodedVal != 0)
1672 cellParam->puschFrequencyHopping = SUPPORTED;
1676 cellParam->puschFrequencyHopping = NOT_SUPPORTED;
1680 case FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG:
1681 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1682 if(encodedVal != RFAILED)
1684 fillPuschDmrsConfig(encodedVal, &cellParam);
1688 case FAPI_PUSCH_DMRS_MAX_LEN_TAG:
1689 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1690 if(encodedVal != RFAILED)
1692 fillPuschDmrsLength(encodedVal, &cellParam);
1696 case FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG:
1697 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1698 if(encodedVal != RFAILED)
1700 fillPuschDmrsAddPos(encodedVal, &cellParam);
1704 case FAPI_PUSCH_CBG_TAG:
1705 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1706 if(encodedVal != RFAILED && encodedVal != 0)
1708 cellParam->puschCbg = SUPPORTED;
1712 cellParam->puschCbg = NOT_SUPPORTED;
1716 case FAPI_PUSCH_MAPPING_TYPE_TAG:
1717 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1718 if(encodedVal != RFAILED)
1720 fillPuschMappingType(encodedVal, &cellParam);
1724 case FAPI_PUSCH_ALLOCATION_TYPES_TAG:
1725 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1726 if(encodedVal != RFAILED)
1728 fillPuschAllocationType(encodedVal, &cellParam);
1732 case FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG:
1733 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1734 if(encodedVal != RFAILED)
1736 fillPuschPrbMappingType(encodedVal, &cellParam);
1740 case FAPI_PUSCH_MAX_PTRS_PORTS_TAG:
1741 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1742 if(encodedVal != RFAILED && encodedVal < FAPI_PUSCH_MAX_PTRS_PORTS_UB)
1744 cellParam->puschMaxPtrsPorts = encodedVal;
1748 case FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG:
1749 cellParam->maxPduschsTBsPerSlot = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1752 case FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG:
1753 cellParam->maxNumberMimoLayersNonCbPusch = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1756 case FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG:
1757 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1758 if(encodedVal != RFAILED)
1760 fillModulationOrderUl(encodedVal, &cellParam);
1764 case FAPI_MAX_MU_MIMO_USERS_UL_TAG:
1765 cellParam->maxMuMimoUsersUl = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1768 case FAPI_DFTS_OFDM_SUPPORT_TAG:
1769 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1770 if(encodedVal != RFAILED && encodedVal != 0)
1772 cellParam->dftsOfdmSupport = SUPPORTED;
1776 cellParam->dftsOfdmSupport = NOT_SUPPORTED;
1780 case FAPI_PUSCH_AGGREGATION_FACTOR_TAG:
1781 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1782 if(encodedVal != RFAILED)
1784 fillPuschAggregationFactor(encodedVal, &cellParam);
1788 case FAPI_PRACH_LONG_FORMATS_TAG:
1789 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1790 if(encodedVal != RFAILED)
1792 fillPrachLongFormat(encodedVal, &cellParam);
1796 case FAPI_PRACH_SHORT_FORMATS_TAG:
1797 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1798 if(encodedVal != RFAILED)
1800 fillPrachShortFormat(encodedVal, &cellParam);
1804 case FAPI_PRACH_RESTRICTED_SETS_TAG:
1805 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1806 if(encodedVal != RFAILED && encodedVal != 0)
1808 cellParam->prachRestrictedSets = SUPPORTED;
1812 cellParam->prachRestrictedSets = NOT_SUPPORTED;
1816 case FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG:
1817 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1818 if(encodedVal != RFAILED)
1820 fillFdOccasions(encodedVal, &cellParam);
1824 case FAPI_RSSI_MEASUREMENT_SUPPORT_TAG:
1825 encodedVal = getParamValue(¶mRsp->tlvs[index], FAPI_UINT_8);
1826 if(encodedVal != RFAILED)
1828 fillRssiMeas(encodedVal, &cellParam);
1832 //printf("\n Invalid value for TLV[%x] at index[%d]", paramRsp->tlvs[index].tl.tag, index);
1836 MAC_FREE(cellParam, sizeof(ClCellParam));
1837 sendToLowerMac(FAPI_CONFIG_REQUEST, 0, (void *)NULL);
1842 DU_LOG("\n LWR_MAC: Invalid error code %d", paramRsp->error_code);
1848 DU_LOG("\nLWR_MAC: Failed to allocate memory for cell param");
1854 DU_LOG("\nLWR_MAC: Param Response received from PHY is NULL");
1862 /*******************************************************************
1864 * @brief Sends FAPI Config req to PHY
1868 * Function : lwr_mac_handleConfigReqEvt
1871 * -Sends FAPI Config Req to PHY
1874 * @return ROK - success
1877 * ****************************************************************/
1879 S16 lwr_mac_handleConfigReqEvt(void *msg)
1885 uint32_t msgLen = 0;
1886 RgCellCb *cellParams;
1887 MacCellCfg macCfgParams;
1888 fapi_config_req_t *configReq;
1890 DU_LOG("\nLWR_MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, \
1891 clGlobalCp.phyState);
1893 cellParams = rgCb[inst].cell;
1894 macCfgParams = cellParams->macCellCfg;
1896 LWR_MAC_ALLOC(configReq, sizeof(fapi_config_req_t));
1897 if(configReq != NULL)
1899 memset(configReq, 0, sizeof(fapi_config_req_t));
1900 msgLen = sizeof(macCfgParams.numTlv);
1901 configReq->number_of_tlvs = macCfgParams.numTlv;
1903 if(macCfgParams.dlCarrCfg.pres)
1905 fillTlvs(&configReq->tlvs[index++], FAPI_DL_BANDWIDTH_TAG, \
1906 sizeof(uint16_t), macCfgParams.dlCarrCfg.bw, &msgLen);
1907 fillTlvs(&configReq->tlvs[index++], FAPI_DL_FREQUENCY_TAG, \
1908 sizeof(uint32_t), macCfgParams.dlCarrCfg.freq, &msgLen);
1909 fillTlvs(&configReq->tlvs[index++], FAPI_DL_K0_TAG, \
1910 sizeof(uint16_t), macCfgParams.dlCarrCfg.k0[0], &msgLen);
1911 fillTlvs(&configReq->tlvs[index++], FAPI_DL_GRIDSIZE_TAG, \
1912 sizeof(uint16_t), macCfgParams.dlCarrCfg.gridSize[0], &msgLen);
1913 fillTlvs(&configReq->tlvs[index++], FAPI_NUM_TX_ANT_TAG, \
1914 sizeof(uint16_t), macCfgParams.dlCarrCfg.numAnt, &msgLen);
1916 if(macCfgParams.ulCarrCfg.pres)
1918 fillTlvs(&configReq->tlvs[index++], FAPI_UPLINK_BANDWIDTH_TAG, \
1919 sizeof(uint16_t), macCfgParams.ulCarrCfg.bw, &msgLen);
1920 fillTlvs(&configReq->tlvs[index++], FAPI_UPLINK_FREQUENCY_TAG, \
1921 sizeof(uint32_t), macCfgParams.ulCarrCfg.freq, &msgLen);
1922 fillTlvs(&configReq->tlvs[index++], FAPI_UL_K0_TAG, \
1923 sizeof(uint16_t), macCfgParams.ulCarrCfg.k0[0], &msgLen);
1924 fillTlvs(&configReq->tlvs[index++], FAPI_UL_GRID_SIZE_TAG, \
1925 sizeof(uint16_t), macCfgParams.ulCarrCfg.gridSize[0], &msgLen);
1926 fillTlvs(&configReq->tlvs[index++], FAPI_NUM_RX_ANT_TAG, \
1927 sizeof(uint16_t), macCfgParams.ulCarrCfg.numAnt, &msgLen);
1929 fillTlvs(&configReq->tlvs[index++], FAPI_FREQUENCY_SHIFT_7P5_KHZ_TAG, \
1930 sizeof(uint8_t), macCfgParams.freqShft, &msgLen);
1932 /* fill cell config */
1933 fillTlvs(&configReq->tlvs[index++], FAPI_PHY_CELL_ID_TAG, \
1934 sizeof(uint8_t), macCfgParams.phyCellId, &msgLen);
1935 fillTlvs(&configReq->tlvs[index++], FAPI_FRAME_DUPLEX_TYPE_TAG, \
1936 sizeof(uint8_t), macCfgParams.dupType, &msgLen);
1938 /* fill SSB configuration */
1939 fillTlvs(&configReq->tlvs[index++], FAPI_SS_PBCH_POWER_TAG, \
1940 sizeof(uint32_t), macCfgParams.ssbCfg.ssbPbchPwr, &msgLen);
1941 fillTlvs(&configReq->tlvs[index++], FAPI_BCH_PAYLOAD_TAG, \
1942 sizeof(uint8_t), macCfgParams.ssbCfg.bchPayloadFlag, &msgLen);
1943 fillTlvs(&configReq->tlvs[index++], FAPI_SCS_COMMON_TAG, \
1944 sizeof(uint8_t), macCfgParams.ssbCfg.scsCmn, &msgLen);
1946 /* fill PRACH configuration */
1947 fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_SEQUENCE_LENGTH_TAG, \
1948 sizeof(uint8_t), macCfgParams.prachCfg.prachSeqLen, &msgLen);
1949 fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_SUBC_SPACING_TAG, \
1950 sizeof(uint8_t), macCfgParams.prachCfg.prachSubcSpacing, &msgLen);
1951 fillTlvs(&configReq->tlvs[index++], FAPI_RESTRICTED_SET_CONFIG_TAG, \
1952 sizeof(uint8_t), macCfgParams.prachCfg.prachRstSetCfg, &msgLen);
1953 fillTlvs(&configReq->tlvs[index++], FAPI_NUM_PRACH_FD_OCCASIONS_TAG,
1954 sizeof(uint8_t), macCfgParams.prachCfg.msg1Fdm, &msgLen);
1955 fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_ROOT_SEQUENCE_INDEX_TAG, \
1956 sizeof(uint16_t), macCfgParams.prachCfg.fdm[0].rootSeqIdx, &msgLen);
1957 fillTlvs(&configReq->tlvs[index++], FAPI_NUM_ROOT_SEQUENCES_TAG, \
1958 sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].numRootSeq, &msgLen);
1959 fillTlvs(&configReq->tlvs[index++], FAPI_K1_TAG, \
1960 sizeof(uint16_t), macCfgParams.prachCfg.fdm[0].k1, &msgLen);
1961 fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_ZERO_CORR_CONF_TAG , \
1962 sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].zeroCorrZoneCfg, &msgLen);
1963 fillTlvs(&configReq->tlvs[index++], FAPI_NUM_UNUSED_ROOT_SEQUENCES_TAG, \
1964 sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].numUnusedRootSeq, &msgLen);
1965 if(macCfgParams.prachCfg.fdm[0].numUnusedRootSeq)
1967 for(idx = 0; idx < macCfgParams.prachCfg.fdm[0].numUnusedRootSeq; idx++)
1968 fillTlvs(&configReq->tlvs[index++], FAPI_UNUSED_ROOT_SEQUENCES_TAG, \
1969 sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].unsuedRootSeq[idx], \
1974 macCfgParams.prachCfg.fdm[0].unsuedRootSeq = NULL;
1977 fillTlvs(&configReq->tlvs[index++], FAPI_SSB_PER_RACH_TAG, \
1978 sizeof(uint8_t), macCfgParams.prachCfg.ssbPerRach, &msgLen);
1979 fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_MULTIPLE_CARRIERS_IN_A_BAND_TAG, \
1980 sizeof(uint8_t), macCfgParams.prachCfg.prachMultCarrBand, &msgLen);
1982 /* fill SSB table */
1983 fillTlvs(&configReq->tlvs[index++], FAPI_SSB_OFFSET_POINT_A_TAG, \
1984 sizeof(uint16_t), macCfgParams.ssbCfg.ssbOffsetPointA, &msgLen);
1985 fillTlvs(&configReq->tlvs[index++], FAPI_BETA_PSS_TAG, \
1986 sizeof(uint8_t), macCfgParams.ssbCfg.betaPss, &msgLen);
1987 fillTlvs(&configReq->tlvs[index++], FAPI_SSB_PERIOD_TAG, \
1988 sizeof(uint8_t), macCfgParams.ssbCfg.ssbPeriod, &msgLen);
1989 fillTlvs(&configReq->tlvs[index++], FAPI_SSB_SUBCARRIER_OFFSET_TAG, \
1990 sizeof(uint8_t), macCfgParams.ssbCfg.ssbScOffset, &msgLen);
1991 fillTlvs(&configReq->tlvs[index++], FAPI_MIB_TAG , \
1992 sizeof(uint32_t), macCfgParams.ssbCfg.mibPdu[0], &msgLen);
1993 fillTlvs(&configReq->tlvs[index++], FAPI_SSB_MASK_TAG, \
1994 sizeof(uint32_t), macCfgParams.ssbCfg.ssbMask[0], &msgLen);
1995 fillTlvs(&configReq->tlvs[index++], FAPI_BEAM_ID_TAG, \
1996 sizeof(uint8_t), macCfgParams.ssbCfg.beamId[0], &msgLen);
1997 fillTlvs(&configReq->tlvs[index++], FAPI_SS_PBCH_MULTIPLE_CARRIERS_IN_A_BAND_TAG, \
1998 sizeof(uint8_t), macCfgParams.ssbCfg.multCarrBand, &msgLen);
1999 fillTlvs(&configReq->tlvs[index++], FAPI_MULTIPLE_CELLS_SS_PBCH_IN_A_CARRIER_TAG, \
2000 sizeof(uint8_t), macCfgParams.ssbCfg.multCellCarr, &msgLen);
2002 /* fill TDD table */
2003 fillTlvs(&configReq->tlvs[index++], FAPI_TDD_PERIOD_TAG, \
2004 sizeof(uint8_t), macCfgParams.tddCfg.tddPeriod, &msgLen);
2005 fillTlvs(&configReq->tlvs[index++], FAPI_SLOT_CONFIG_TAG, \
2006 sizeof(uint8_t), macCfgParams.tddCfg.slotCfg[0][0], &msgLen);
2008 /* fill measurement config */
2009 fillTlvs(&configReq->tlvs[index++], FAPI_RSSI_MEASUREMENT_TAG, \
2010 sizeof(uint8_t), macCfgParams.rssiUnit, &msgLen);
2012 /* fill DMRS Type A Pos */
2013 fillTlvs(&configReq->tlvs[index++], FAPI_DMRS_TYPE_A_POS_TAG, \
2014 sizeof(uint8_t), macCfgParams.dmrsTypeAPos, &msgLen);
2016 fillMsgHeader(&configReq->header, FAPI_CONFIG_REQUEST, \
2017 (sizeof(fapi_config_req_t) - sizeof(fapi_msg_t)));
2019 DU_LOG("\nLWR_MAC: Sending Config Request to Phy");
2020 LwrMacSendToPhy(configReq->header.msg_id, sizeof(fapi_config_req_t), (void *)configReq);
2024 DU_LOG("\nLWR_MAC: Failed to allocate memory for config Request");
2030 } /* lwr_mac_handleConfigReqEvt */
2032 /*******************************************************************
2034 * @brief Processes config response from phy
2038 * Function : lwr_mac_handleConfigRspEvt
2041 * Processes config response from phy
2043 * @params[in] FAPI message pointer
2044 * @return ROK - success
2047 * ****************************************************************/
2049 S16 lwr_mac_handleConfigRspEvt(void *msg)
2052 fapi_config_resp_t *configRsp;
2053 configRsp = (fapi_config_resp_t *)msg;
2055 DU_LOG("\nLWR_MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, \
2056 clGlobalCp.phyState);
2058 if(configRsp != NULL)
2060 if(configRsp->error_code == MSG_OK)
2062 DU_LOG("\nLWR_MAC: PHY has moved to Configured state \n");
2063 clGlobalCp.phyState = PHY_STATE_CONFIGURED;
2065 * Store config response into an intermediate struture and send to MAC
2066 * Support LC and LWLC for sending config rsp to MAC
2072 DU_LOG("\n LWR_MAC: Invalid error code %d", configRsp->error_code);
2078 DU_LOG("\nLWR_MAC: Config Response received from PHY is NULL");
2084 } /* lwr_mac_handleConfigRspEvt */
2086 /*******************************************************************
2088 * @brief Build and send start request to phy
2092 * Function : lwr_mac_handleStartReqEvt
2095 * Build and send start request to phy
2097 * @params[in] FAPI message pointer
2098 * @return ROK - success
2101 * ****************************************************************/
2102 S16 lwr_mac_handleStartReqEvt(void *msg)
2105 uint32_t msgLen = 0;
2106 fapi_start_req_t *startReq;
2108 LWR_MAC_ALLOC(startReq, sizeof(fapi_start_req_t));
2109 if(startReq != NULL)
2111 memset(startReq, 0, sizeof(fapi_start_req_t));
2112 fillMsgHeader(&startReq->header, FAPI_START_REQUEST, msgLen);
2114 DU_LOG("\nLWR_MAC: Sending Start Request to PHY");
2115 LwrMacSendToPhy(startReq->header.msg_id, sizeof(fapi_start_req_t),\
2120 DU_LOG("\nLWR_MAC: Failed to allocate memory for Start Request");
2125 } /* lwr_mac_handleStartReqEvt */
2127 /*******************************************************************
2129 * @brief Sends FAPI Stop Req to PHY
2133 * Function : lwr_mac_handleStopReqEvt
2136 * -Sends FAPI Stop Req to PHY
2139 * @return ROK - success
2142 ********************************************************************/
2144 S16 lwr_mac_handleStopReqEvt(void *msg)
2147 uint32_t msgLen = 0;
2148 fapi_stop_req_t *stopReq = NULLP;
2149 LWR_MAC_ALLOC(stopReq, sizeof(fapi_stop_req_t));
2150 if(stopReq != NULLP)
2152 memset(stopReq, 0, sizeof(fapi_stop_req_t));
2153 fillMsgHeader(&stopReq->header, FAPI_STOP_REQUEST, msgLen);
2154 DU_LOG("\nLOWER MAC: Sending Stop Request to PHY");
2155 LwrMacSendToPhy(stopReq->header.msg_id, sizeof(fapi_stop_req_t), (void *)stopReq);
2159 DU_LOG("\nLOWER MAC: Failed to allocate memory for Stop Request");
2166 /*******************************************************************
2168 * @brief Modifes the received mibPdu to uint32 bit
2169 * and stores it in MacCellCfg
2173 * Function : setMibPdu
2178 * @params[in] Pointer to mibPdu
2179 * pointer to modified value
2180 ******************************************************************/
2182 PUBLIC void setMibPdu(uint8_t *mibPdu, uint32_t *val, uint16_t sfn)
2184 *mibPdu |= (((uint8_t)(sfn >> 2)) & MIB_SFN_BITMASK);
2185 *val = (mibPdu[0] << 24 | mibPdu[1] << 16 | mibPdu[2] << 8);
2186 DU_LOG("\nLWR_MAC: MIB PDU %x", *val);
2190 /*******************************************************************
2192 * @brief fills SSB PDU required for DL TTI info in MAC
2196 * Function : fillSsbPdu
2199 * -Fills the SSB PDU info
2202 * @params[in] Pointer to FAPI DL TTI Req
2203 * Pointer to RgCellCb
2204 * Pointer to msgLen of DL TTI Info
2207 ******************************************************************/
2209 S16 fillSsbPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, MacCellCfg *macCellCfg,
2210 MacDlSlot *currDlSlot, uint8_t ssbIdxCount, uint16_t sfn)
2212 uint32_t mibPayload = 0;
2213 if(dlTtiReqPdu != NULL)
2215 dlTtiReqPdu->pduType = SSB_PDU_TYPE; /* SSB PDU */
2216 dlTtiReqPdu->pdu.ssb_pdu.physCellId = macCellCfg->phyCellId;
2217 dlTtiReqPdu->pdu.ssb_pdu.betaPss = macCellCfg->ssbCfg.betaPss;
2218 dlTtiReqPdu->pdu.ssb_pdu.ssbBlockIndex = currDlSlot->dlInfo.brdcstAlloc.ssbInfo[ssbIdxCount].ssbIdx;
2219 dlTtiReqPdu->pdu.ssb_pdu.ssbSubCarrierOffset = macCellCfg->ssbCfg.ssbScOffset;
2220 /* ssbOfPdufstA to be filled in ssbCfg */
2221 dlTtiReqPdu->pdu.ssb_pdu.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
2222 dlTtiReqPdu->pdu.ssb_pdu.bchPayloadFlag = macCellCfg->ssbCfg.bchPayloadFlag;
2223 /* Bit manipulation for SFN */
2224 setMibPdu(macCellCfg->ssbCfg.mibPdu, &mibPayload, sfn);
2225 dlTtiReqPdu->pdu.ssb_pdu.bchPayload.bchPayload = mibPayload;
2226 dlTtiReqPdu->pdu.ssb_pdu.preCodingAndBeamforming.numPrgs = 0;
2227 dlTtiReqPdu->pdu.ssb_pdu.preCodingAndBeamforming.prgSize = 0;
2228 dlTtiReqPdu->pdu.ssb_pdu.preCodingAndBeamforming.digBfInterfaces = 0;
2229 dlTtiReqPdu->pdu.ssb_pdu.preCodingAndBeamforming.pmi_bfi[0].pmIdx = 0;
2230 dlTtiReqPdu->pdu.ssb_pdu.preCodingAndBeamforming. \
2231 pmi_bfi[0].beamIdx[0].beamidx = macCellCfg->ssbCfg.beamId[0];
2232 dlTtiReqPdu->pduSize = sizeof(fapi_dl_ssb_pdu_t); /* Size of SSB PDU */
2239 /*******************************************************************
2241 * @brief fills Dl DCI PDU required for DL TTI info in MAC
2245 * Function : fillSib1DlDciPdu
2248 * -Fills the Dl DCI PDU
2250 * @params[in] Pointer to fapi_dl_dci_t
2251 * Pointer to PdcchCfg
2254 ******************************************************************/
2256 void fillSib1DlDciPdu(fapi_dl_dci_t *dlDciPtr, PdcchCfg *sib1PdcchInfo)
2258 if(dlDciPtr != NULLP)
2264 uint16_t coreset0Size;
2267 uint32_t freqDomResAssign;
2268 uint32_t timeDomResAssign;
2270 uint32_t modNCodScheme;
2271 uint8_t redundancyVer;
2272 uint32_t sysInfoInd;
2275 /* Size(in bits) of each field in DCI format 0_1
2276 * as mentioned in spec 38.214 */
2277 uint8_t freqDomResAssignSize;
2278 uint8_t timeDomResAssignSize = 4;
2279 uint8_t VRB2PRBMapSize = 1;
2280 uint8_t modNCodSchemeSize = 5;
2281 uint8_t redundancyVerSize = 2;
2282 uint8_t sysInfoIndSize = 1;
2283 uint8_t reservedSize = 15;
2285 dlDciPtr->rnti = sib1PdcchInfo->dci.rnti;
2286 dlDciPtr->scramblingId = sib1PdcchInfo->dci.scramblingId;
2287 dlDciPtr->scramblingRnti = sib1PdcchInfo->dci.scramblingRnti;
2288 dlDciPtr->cceIndex = sib1PdcchInfo->dci.cceIndex;
2289 dlDciPtr->aggregationLevel = sib1PdcchInfo->dci.aggregLevel;
2290 dlDciPtr->pc_and_bform.numPrgs = sib1PdcchInfo->dci.beamPdcchInfo.numPrgs;
2291 dlDciPtr->pc_and_bform.prgSize = sib1PdcchInfo->dci.beamPdcchInfo.prgSize;
2292 dlDciPtr->pc_and_bform.digBfInterfaces = sib1PdcchInfo->dci.beamPdcchInfo.digBfInterfaces;
2293 dlDciPtr->pc_and_bform.pmi_bfi[0].pmIdx = sib1PdcchInfo->dci.beamPdcchInfo.prg[0].pmIdx;
2294 dlDciPtr->pc_and_bform.pmi_bfi[0].beamIdx[0].beamidx = sib1PdcchInfo->dci.beamPdcchInfo.prg[0].beamIdx[0];
2295 dlDciPtr->beta_pdcch_1_0 = sib1PdcchInfo->dci.txPdcchPower.powerValue;
2296 dlDciPtr->powerControlOfssetSS = sib1PdcchInfo->dci.txPdcchPower.powerControlOffsetSS;
2298 /* Calculating freq domain resource allocation field value and size
2299 * coreset0Size = Size of coreset 0
2300 * RBStart = Starting Virtual Rsource block
2301 * RBLen = length of contiguously allocted RBs
2302 * Spec 38.214 Sec 5.1.2.2.2
2304 coreset0Size= sib1PdcchInfo->coreset0Cfg.coreSet0Size;
2305 rbStart = 0; /* For SIB1 */
2306 //rbStart = sib1PdcchInfo->dci.pdschCfg->pdschFreqAlloc.freqAlloc.startPrb;
2307 rbLen = sib1PdcchInfo->dci.pdschCfg->pdschFreqAlloc.freqAlloc.numPrb;
2309 if((rbLen >=1) && (rbLen <= coreset0Size - rbStart))
2311 if((rbLen - 1) <= floor(coreset0Size / 2))
2312 freqDomResAssign = (coreset0Size * (rbLen-1)) + rbStart;
2314 freqDomResAssign = (coreset0Size * (coreset0Size - rbLen + 1)) \
2315 + (coreset0Size - 1 - rbStart);
2317 freqDomResAssignSize = ceil(log2(coreset0Size * (coreset0Size + 1) / 2));
2320 /* Fetching DCI field values */
2321 timeDomResAssign = sib1PdcchInfo->dci.pdschCfg->pdschTimeAlloc.
2323 VRB2PRBMap = sib1PdcchInfo->dci.pdschCfg->pdschFreqAlloc.\
2325 modNCodScheme = sib1PdcchInfo->dci.pdschCfg->codeword[0].mcsIndex;
2326 redundancyVer = sib1PdcchInfo->dci.pdschCfg->codeword[0].rvIndex;
2327 sysInfoInd = 0; /* 0 for SIB1; 1 for SI messages */
2330 /* Reversing bits in each DCI field */
2331 freqDomResAssign = reverseBits(freqDomResAssign, freqDomResAssignSize);
2332 timeDomResAssign = reverseBits(timeDomResAssign, timeDomResAssignSize);
2333 VRB2PRBMap = reverseBits(VRB2PRBMap, VRB2PRBMapSize);
2334 modNCodScheme = reverseBits(modNCodScheme, modNCodSchemeSize);
2335 redundancyVer = reverseBits(redundancyVer, redundancyVerSize);
2336 sysInfoInd = reverseBits(sysInfoInd, sysInfoIndSize);
2338 /* Calulating total number of bytes in buffer */
2339 dlDciPtr->payloadSizeBits = freqDomResAssignSize + timeDomResAssignSize\
2340 + VRB2PRBMapSize + modNCodSchemeSize + redundancyVerSize\
2341 + sysInfoIndSize + reservedSize;
2343 numBytes = dlDciPtr->payloadSizeBits / 8;
2344 if(dlDciPtr->payloadSizeBits % 8)
2347 if(numBytes > FAPI_DCI_PAYLOAD_BYTE_LEN)
2349 DU_LOG("\nLWR_MAC : Total bytes for DCI is more than expected");
2353 /* Initialize buffer */
2354 for(bytePos = 0; bytePos < numBytes; bytePos++)
2355 dlDciPtr->payload[bytePos] = 0;
2357 bytePos = numBytes - 1;
2360 /* Packing DCI format fields */
2361 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2362 freqDomResAssign, freqDomResAssignSize);
2363 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2364 timeDomResAssign, timeDomResAssignSize);
2365 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2366 VRB2PRBMap, VRB2PRBMapSize);
2367 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2368 modNCodScheme, modNCodSchemeSize);
2369 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2370 redundancyVer, redundancyVerSize);
2371 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2372 sysInfoInd, sysInfoIndSize);
2373 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2374 reserved, reservedSize);
2377 } /* fillSib1DlDciPdu */
2379 /*******************************************************************
2381 * @brief fills Dl DCI PDU required for DL TTI info in MAC
2385 * Function : fillRarDlDciPdu
2388 * -Fills the Dl DCI PDU
2390 * @params[in] Pointer to fapi_dl_dci_t
2391 * Pointer to PdcchCfg
2394 ******************************************************************/
2396 void fillRarDlDciPdu(fapi_dl_dci_t *dlDciPtr, PdcchCfg *rarPdcchInfo)
2398 if(dlDciPtr != NULLP)
2404 uint16_t coreset0Size;
2407 uint32_t freqDomResAssign;
2408 uint8_t timeDomResAssign;
2410 uint8_t modNCodScheme;
2414 /* Size(in bits) of each field in DCI format 1_0 */
2415 uint8_t freqDomResAssignSize;
2416 uint8_t timeDomResAssignSize = 4;
2417 uint8_t VRB2PRBMapSize = 1;
2418 uint8_t modNCodSchemeSize = 5;
2419 uint8_t tbScalingSize = 2;
2420 uint8_t reservedSize = 16;
2422 dlDciPtr->rnti = rarPdcchInfo->dci.rnti;
2423 dlDciPtr->scramblingId = rarPdcchInfo->dci.scramblingId;
2424 dlDciPtr->scramblingRnti = rarPdcchInfo->dci.scramblingRnti;
2425 dlDciPtr->cceIndex = rarPdcchInfo->dci.cceIndex;
2426 dlDciPtr->aggregationLevel = rarPdcchInfo->dci.aggregLevel;
2427 dlDciPtr->pc_and_bform.numPrgs = rarPdcchInfo->dci.beamPdcchInfo.numPrgs;
2428 dlDciPtr->pc_and_bform.prgSize = rarPdcchInfo->dci.beamPdcchInfo.prgSize;
2429 dlDciPtr->pc_and_bform.digBfInterfaces = rarPdcchInfo->dci.beamPdcchInfo.digBfInterfaces;
2430 dlDciPtr->pc_and_bform.pmi_bfi[0].pmIdx = rarPdcchInfo->dci.beamPdcchInfo.prg[0].pmIdx;
2431 dlDciPtr->pc_and_bform.pmi_bfi[0].beamIdx[0].beamidx = rarPdcchInfo->dci.beamPdcchInfo.prg[0].beamIdx[0];
2432 dlDciPtr->beta_pdcch_1_0 = rarPdcchInfo->dci.txPdcchPower.powerValue;
2433 dlDciPtr->powerControlOfssetSS = rarPdcchInfo->dci.txPdcchPower.powerControlOffsetSS;
2435 /* Calculating freq domain resource allocation field value and size
2436 * coreset0Size = Size of coreset 0
2437 * RBStart = Starting Virtual Rsource block
2438 * RBLen = length of contiguously allocted RBs
2439 * Spec 38.214 Sec 5.1.2.2.2
2442 /* TODO: Fill values of coreset0Size, rbStart and rbLen */
2443 coreset0Size= rarPdcchInfo->coreset0Cfg.coreSet0Size;
2444 rbStart = 0; /* For SIB1 */
2445 //rbStart = rarPdcchInfo->dci.pdschCfg->freqAlloc.rbStart;
2446 rbLen = rarPdcchInfo->dci.pdschCfg->pdschFreqAlloc.freqAlloc.numPrb;
2448 if((rbLen >=1) && (rbLen <= coreset0Size - rbStart))
2450 if((rbLen - 1) <= floor(coreset0Size / 2))
2451 freqDomResAssign = (coreset0Size * (rbLen-1)) + rbStart;
2453 freqDomResAssign = (coreset0Size * (coreset0Size - rbLen + 1)) \
2454 + (coreset0Size - 1 - rbStart);
2456 freqDomResAssignSize = ceil(log2(coreset0Size * (coreset0Size + 1) / 2));
2459 /* Fetching DCI field values */
2460 timeDomResAssign = rarPdcchInfo->dci.pdschCfg->pdschTimeAlloc.rowIndex -1;
2461 VRB2PRBMap = rarPdcchInfo->dci.pdschCfg->pdschFreqAlloc.vrbPrbMapping;
2462 modNCodScheme = rarPdcchInfo->dci.pdschCfg->codeword[0].mcsIndex;
2463 tbScaling = 0; /* configured to 0 scaling */
2466 /* Reversing bits in each DCI field */
2467 freqDomResAssign = reverseBits(freqDomResAssign, freqDomResAssignSize);
2468 timeDomResAssign = reverseBits(timeDomResAssign, timeDomResAssignSize);
2469 VRB2PRBMap = reverseBits(VRB2PRBMap, VRB2PRBMapSize);
2470 modNCodScheme = reverseBits(modNCodScheme, modNCodSchemeSize);
2471 tbScaling = reverseBits(tbScaling, tbScalingSize);
2473 /* Calulating total number of bytes in buffer */
2474 dlDciPtr->payloadSizeBits = freqDomResAssignSize + timeDomResAssignSize\
2475 + VRB2PRBMapSize + modNCodSchemeSize + tbScalingSize + reservedSize;
2477 numBytes = dlDciPtr->payloadSizeBits / 8;
2478 if(dlDciPtr->payloadSizeBits % 8)
2481 if(numBytes > FAPI_DCI_PAYLOAD_BYTE_LEN)
2483 DU_LOG("\nLWR_MAC : Total bytes for DCI is more than expected");
2487 /* Initialize buffer */
2488 for(bytePos = 0; bytePos < numBytes; bytePos++)
2489 dlDciPtr->payload[bytePos] = 0;
2491 bytePos = numBytes - 1;
2494 /* Packing DCI format fields */
2495 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2496 freqDomResAssign, freqDomResAssignSize);
2497 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2498 timeDomResAssign, timeDomResAssignSize);
2499 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2500 VRB2PRBMap, VRB2PRBMapSize);
2501 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2502 modNCodScheme, modNCodSchemeSize);
2503 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2504 tbScaling, tbScalingSize);
2505 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2506 reserved, reservedSize);
2508 } /* fillRarDlDciPdu */
2510 /*******************************************************************
2512 * @brief fills msg4 Dl DCI PDU required for DL TTI info in MAC
2516 * Function : fillMsg4DlDciPdu
2519 * -Fills the Msg4 Dl DCI PDU
2521 * @params[in] Pointer to fapi_dl_dci_t
2522 * Pointer to PdcchCfg
2525 ******************************************************************/
2526 void fillMsg4DlDciPdu(fapi_dl_dci_t *dlDciPtr, PdcchCfg *msg4PdcchInfo,\
2529 if(dlDciPtr != NULLP)
2535 uint16_t coreset0Size = 0;
2536 uint16_t rbStart = 0;
2538 uint8_t dciFormatId;
2539 uint32_t freqDomResAssign;
2540 uint8_t timeDomResAssign;
2542 uint8_t modNCodScheme;
2544 uint8_t redundancyVer = 0;
2545 uint8_t harqProcessNum = 0;
2546 uint8_t dlAssignmentIdx = 0;
2547 uint8_t pucchTpc = 0;
2548 uint8_t pucchResoInd = 0;
2549 uint8_t harqFeedbackInd = 0;
2551 /* Size(in bits) of each field in DCI format 1_0 */
2552 uint8_t dciFormatIdSize = 1;
2553 uint8_t freqDomResAssignSize;
2554 uint8_t timeDomResAssignSize = 4;
2555 uint8_t VRB2PRBMapSize = 1;
2556 uint8_t modNCodSchemeSize = 5;
2557 uint8_t ndiSize = 1;
2558 uint8_t redundancyVerSize = 2;
2559 uint8_t harqProcessNumSize = 4;
2560 uint8_t dlAssignmentIdxSize = 2;
2561 uint8_t pucchTpcSize = 2;
2562 uint8_t pucchResoIndSize = 3;
2563 uint8_t harqFeedbackIndSize = 3;
2565 dlDciPtr->rnti = msg4PdcchInfo->dci.rnti;
2566 dlDciPtr->scramblingId = msg4PdcchInfo->dci.scramblingId;
2567 dlDciPtr->scramblingRnti = msg4PdcchInfo->dci.scramblingRnti;
2568 dlDciPtr->cceIndex = msg4PdcchInfo->dci.cceIndex;
2569 dlDciPtr->aggregationLevel = msg4PdcchInfo->dci.aggregLevel;
2570 dlDciPtr->pc_and_bform.numPrgs = msg4PdcchInfo->dci.beamPdcchInfo.numPrgs;
2571 dlDciPtr->pc_and_bform.prgSize = msg4PdcchInfo->dci.beamPdcchInfo.prgSize;
2572 dlDciPtr->pc_and_bform.digBfInterfaces = msg4PdcchInfo->dci.beamPdcchInfo.digBfInterfaces;
2573 dlDciPtr->pc_and_bform.pmi_bfi[0].pmIdx = msg4PdcchInfo->dci.beamPdcchInfo.prg[0].pmIdx;
2574 dlDciPtr->pc_and_bform.pmi_bfi[0].beamIdx[0].beamidx = msg4PdcchInfo->dci.beamPdcchInfo.prg[0].beamIdx[0];
2575 dlDciPtr->beta_pdcch_1_0 = msg4PdcchInfo->dci.txPdcchPower.powerValue;
2576 dlDciPtr->powerControlOfssetSS = msg4PdcchInfo->dci.txPdcchPower.powerControlOffsetSS;
2578 /* Calculating freq domain resource allocation field value and size
2579 * coreset0Size = Size of coreset 0
2580 * RBStart = Starting Virtual Rsource block
2581 * RBLen = length of contiguously allocted RBs
2582 * Spec 38.214 Sec 5.1.2.2.2
2585 /* TODO: Fill values of coreset0Size, rbStart and rbLen */
2586 coreset0Size = msg4PdcchInfo->coreset0Cfg.coreSet0Size;
2587 //rbStart = msg4PdcchInfo->dci.pdschCfg->freqAlloc.rbStart;
2588 rbLen = msg4PdcchInfo->dci.pdschCfg->pdschFreqAlloc.freqAlloc.numPrb;
2590 if((rbLen >=1) && (rbLen <= coreset0Size - rbStart))
2592 if((rbLen - 1) <= floor(coreset0Size / 2))
2593 freqDomResAssign = (coreset0Size * (rbLen-1)) + rbStart;
2595 freqDomResAssign = (coreset0Size * (coreset0Size - rbLen + 1)) \
2596 + (coreset0Size - 1 - rbStart);
2598 freqDomResAssignSize = ceil(log2(coreset0Size * (coreset0Size + 1) / 2));
2601 /* Fetching DCI field values */
2602 dciFormatId = msg4Info->dciFormatId; /* DCI indentifier for DL */
2603 timeDomResAssign = msg4PdcchInfo->dci.pdschCfg->pdschTimeAlloc.rowIndex -1;
2604 VRB2PRBMap = msg4PdcchInfo->dci.pdschCfg->pdschFreqAlloc.vrbPrbMapping;
2605 modNCodScheme = msg4PdcchInfo->dci.pdschCfg->codeword[0].mcsIndex;
2606 ndi = msg4Info->ndi;
2607 redundancyVer = msg4PdcchInfo->dci.pdschCfg->codeword[0].rvIndex;
2608 harqProcessNum = msg4Info->harqProcNum;
2609 dlAssignmentIdx = msg4Info->dlAssignIdx;
2610 pucchTpc = msg4Info->pucchTpc;
2611 pucchResoInd = msg4Info->pucchResInd;
2612 harqFeedbackInd = msg4Info->harqFeedbackInd;
2614 /* Reversing bits in each DCI field */
2615 dciFormatId = reverseBits(dciFormatId, dciFormatIdSize);
2616 freqDomResAssign = reverseBits(freqDomResAssign, freqDomResAssignSize);
2617 timeDomResAssign = reverseBits(timeDomResAssign, timeDomResAssignSize);
2618 VRB2PRBMap = reverseBits(VRB2PRBMap, VRB2PRBMapSize);
2619 modNCodScheme = reverseBits(modNCodScheme, modNCodSchemeSize);
2620 ndi = reverseBits(ndi, ndiSize);
2621 redundancyVer = reverseBits(redundancyVer, redundancyVerSize);
2622 harqProcessNum = reverseBits(harqProcessNum, harqProcessNumSize);
2623 dlAssignmentIdx = reverseBits(dlAssignmentIdx , dlAssignmentIdxSize);
2624 pucchTpc = reverseBits(pucchTpc, pucchTpcSize);
2625 pucchResoInd = reverseBits(pucchResoInd, pucchResoIndSize);
2626 harqFeedbackInd = reverseBits(harqFeedbackInd, harqFeedbackIndSize);
2629 /* Calulating total number of bytes in buffer */
2630 dlDciPtr->payloadSizeBits = (dciFormatIdSize + freqDomResAssignSize\
2631 + timeDomResAssignSize + VRB2PRBMapSize + modNCodSchemeSize\
2632 + ndiSize + redundancyVerSize + harqProcessNumSize + dlAssignmentIdxSize\
2633 + pucchTpcSize + pucchResoIndSize + harqFeedbackIndSize);
2635 numBytes = dlDciPtr->payloadSizeBits / 8;
2636 if(dlDciPtr->payloadSizeBits % 8)
2639 if(numBytes > FAPI_DCI_PAYLOAD_BYTE_LEN)
2641 DU_LOG("\nLWR_MAC : Total bytes for DCI is more than expected");
2645 /* Initialize buffer */
2646 for(bytePos = 0; bytePos < numBytes; bytePos++)
2647 dlDciPtr->payload[bytePos] = 0;
2649 bytePos = numBytes - 1;
2652 /* Packing DCI format fields */
2653 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2654 dciFormatId, dciFormatIdSize);
2655 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2656 freqDomResAssign, freqDomResAssignSize);
2657 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2658 timeDomResAssign, timeDomResAssignSize);
2659 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2660 VRB2PRBMap, VRB2PRBMapSize);
2661 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2662 modNCodScheme, modNCodSchemeSize);
2663 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2665 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2666 redundancyVer, redundancyVerSize);
2667 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2668 redundancyVer, redundancyVerSize);
2669 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2670 harqProcessNum, harqProcessNumSize);
2671 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2672 dlAssignmentIdx, dlAssignmentIdxSize);
2673 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2674 pucchTpc, pucchTpcSize);
2675 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2676 pucchResoInd, pucchResoIndSize);
2677 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2678 harqFeedbackInd, harqFeedbackIndSize);
2680 } /* fillMsg4DlDciPdu */
2682 /*******************************************************************
2684 * @brief fills PDCCH PDU required for DL TTI info in MAC
2688 * Function : fillPdcchPdu
2691 * -Fills the Pdcch PDU info
2694 * @params[in] Pointer to FAPI DL TTI Req
2695 * Pointer to PdcchCfg
2698 ******************************************************************/
2699 uint8_t fillPdcchPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, DlSchedInfo *dlInfo, \
2700 RntiType rntiType, uint8_t coreSetType)
2702 if(dlTtiReqPdu != NULLP)
2704 PdcchCfg *pdcchInfo = NULLP;
2705 BwpCfg *bwp = NULLP;
2707 memset(&dlTtiReqPdu->pdu.pdcch_pdu, 0, sizeof(fapi_dl_pdcch_pdu_t));
2708 if(rntiType == SI_RNTI_TYPE)
2710 pdcchInfo = &dlInfo->brdcstAlloc.sib1Alloc.sib1PdcchCfg;
2711 bwp = &dlInfo->brdcstAlloc.sib1Alloc.bwp;
2712 fillSib1DlDciPdu(dlTtiReqPdu->pdu.pdcch_pdu.dlDci, pdcchInfo);
2714 else if(rntiType == RA_RNTI_TYPE)
2716 pdcchInfo = &dlInfo->rarAlloc->rarPdcchCfg;
2717 bwp = &dlInfo->rarAlloc->bwp;
2718 fillRarDlDciPdu(dlTtiReqPdu->pdu.pdcch_pdu.dlDci, pdcchInfo);
2720 else if(rntiType == TC_RNTI_TYPE)
2722 pdcchInfo = &dlInfo->msg4Alloc->msg4PdcchCfg;
2723 bwp = &dlInfo->msg4Alloc->bwp;
2724 fillMsg4DlDciPdu(dlTtiReqPdu->pdu.pdcch_pdu.dlDci, pdcchInfo,\
2725 &dlInfo->msg4Alloc->msg4Info);
2729 DU_LOG("\nLWR_MAC: Failed filling PDCCH Pdu");
2732 dlTtiReqPdu->pduType = PDCCH_PDU_TYPE;
2733 dlTtiReqPdu->pdu.pdcch_pdu.bwpSize = bwp->freqAlloc.numPrb;
2734 dlTtiReqPdu->pdu.pdcch_pdu.bwpStart = bwp->freqAlloc.startPrb;
2735 dlTtiReqPdu->pdu.pdcch_pdu.subCarrierSpacing = bwp->subcarrierSpacing;
2736 dlTtiReqPdu->pdu.pdcch_pdu.cyclicPrefix = bwp->cyclicPrefix;
2737 dlTtiReqPdu->pdu.pdcch_pdu.startSymbolIndex = pdcchInfo->coreset0Cfg.startSymbolIndex;
2738 dlTtiReqPdu->pdu.pdcch_pdu.durationSymbols = pdcchInfo->coreset0Cfg.durationSymbols;
2739 memcpy(dlTtiReqPdu->pdu.pdcch_pdu.freqDomainResource, pdcchInfo->coreset0Cfg.freqDomainResource, 6);
2740 dlTtiReqPdu->pdu.pdcch_pdu.cceRegMappingType = pdcchInfo->coreset0Cfg.cceRegMappingType;
2741 dlTtiReqPdu->pdu.pdcch_pdu.regBundleSize = pdcchInfo->coreset0Cfg.regBundleSize;
2742 dlTtiReqPdu->pdu.pdcch_pdu.interleaverSize = pdcchInfo->coreset0Cfg.interleaverSize;
2743 dlTtiReqPdu->pdu.pdcch_pdu.coreSetSize = pdcchInfo->coreset0Cfg.coreSetType;
2744 dlTtiReqPdu->pdu.pdcch_pdu.shiftIndex = pdcchInfo->coreset0Cfg.shiftIndex;
2745 dlTtiReqPdu->pdu.pdcch_pdu.precoderGranularity = pdcchInfo->coreset0Cfg.precoderGranularity;
2746 dlTtiReqPdu->pdu.pdcch_pdu.numDlDci = pdcchInfo->numDlDci;
2747 dlTtiReqPdu->pdu.pdcch_pdu.coreSetType = coreSetType;
2749 /* Calculating PDU length. Considering only one dl dci pdu for now */
2750 dlTtiReqPdu->pduSize = sizeof(fapi_dl_pdcch_pdu_t);
2756 /*******************************************************************
2758 * @brief fills PDSCH PDU required for DL TTI info in MAC
2762 * Function : fillPdschPdu
2765 * -Fills the Pdsch PDU info
2768 * @params[in] Pointer to FAPI DL TTI Req
2769 * Pointer to PdschCfg
2770 * Pointer to msgLen of DL TTI Info
2773 ******************************************************************/
2775 void fillPdschPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, PdschCfg *pdschInfo,
2776 BwpCfg bwp, uint16_t pduIndex)
2780 if(dlTtiReqPdu != NULLP)
2782 dlTtiReqPdu->pduType = PDSCH_PDU_TYPE;
2783 memset(&dlTtiReqPdu->pdu.pdsch_pdu, 0, sizeof(fapi_dl_pdsch_pdu_t));
2784 dlTtiReqPdu->pdu.pdsch_pdu.pduBitMap = pdschInfo->pduBitmap;
2785 dlTtiReqPdu->pdu.pdsch_pdu.rnti = pdschInfo->rnti;
2786 dlTtiReqPdu->pdu.pdsch_pdu.pdu_index = pduIndex;
2787 dlTtiReqPdu->pdu.pdsch_pdu.bwpSize = bwp.freqAlloc.numPrb;
2788 dlTtiReqPdu->pdu.pdsch_pdu.bwpStart = bwp.freqAlloc.startPrb;
2789 dlTtiReqPdu->pdu.pdsch_pdu.subCarrierSpacing = bwp.subcarrierSpacing;
2790 dlTtiReqPdu->pdu.pdsch_pdu.cyclicPrefix = bwp.cyclicPrefix;
2791 dlTtiReqPdu->pdu.pdsch_pdu.nrOfCodeWords = pdschInfo->numCodewords;
2792 for(idx = 0; idx < MAX_CODEWORDS ; idx++)
2794 dlTtiReqPdu->pdu.pdsch_pdu.cwInfo[idx].targetCodeRate = pdschInfo->codeword[idx].targetCodeRate;
2795 dlTtiReqPdu->pdu.pdsch_pdu.cwInfo[idx].qamModOrder = pdschInfo->codeword[idx].qamModOrder;
2796 dlTtiReqPdu->pdu.pdsch_pdu.cwInfo[idx].mcsIndex = pdschInfo->codeword[idx].mcsIndex;
2797 dlTtiReqPdu->pdu.pdsch_pdu.cwInfo[idx].mcsTable = pdschInfo->codeword[idx].mcsTable;
2798 dlTtiReqPdu->pdu.pdsch_pdu.cwInfo[idx].rvIndex = pdschInfo->codeword[idx].rvIndex;
2799 dlTtiReqPdu->pdu.pdsch_pdu.cwInfo[idx].tbSize = pdschInfo->codeword[idx].tbSize;
2801 dlTtiReqPdu->pdu.pdsch_pdu.dataScramblingId = pdschInfo->dataScramblingId;
2802 dlTtiReqPdu->pdu.pdsch_pdu.nrOfLayers = pdschInfo->numLayers;
2803 dlTtiReqPdu->pdu.pdsch_pdu.transmissionScheme = pdschInfo->transmissionScheme;
2804 dlTtiReqPdu->pdu.pdsch_pdu.refPoint = pdschInfo->refPoint;
2805 dlTtiReqPdu->pdu.pdsch_pdu.dlDmrsSymbPos = pdschInfo->dmrs.dlDmrsSymbPos;
2806 dlTtiReqPdu->pdu.pdsch_pdu.dmrsConfigType = pdschInfo->dmrs.dmrsConfigType;
2807 dlTtiReqPdu->pdu.pdsch_pdu.dlDmrsScramblingId = pdschInfo->dmrs.dlDmrsScramblingId;
2808 dlTtiReqPdu->pdu.pdsch_pdu.scid = pdschInfo->dmrs.scid;
2809 dlTtiReqPdu->pdu.pdsch_pdu.numDmrsCdmGrpsNoData = pdschInfo->dmrs.numDmrsCdmGrpsNoData;
2810 dlTtiReqPdu->pdu.pdsch_pdu.dmrsPorts = pdschInfo->dmrs.dmrsPorts;
2811 dlTtiReqPdu->pdu.pdsch_pdu.resourceAlloc = pdschInfo->pdschFreqAlloc.resourceAllocType;
2812 /* since we are using type-1, hence rbBitmap excluded */
2813 dlTtiReqPdu->pdu.pdsch_pdu.rbStart = pdschInfo->pdschFreqAlloc.freqAlloc.startPrb;
2814 dlTtiReqPdu->pdu.pdsch_pdu.rbSize = pdschInfo->pdschFreqAlloc.freqAlloc.numPrb;
2815 dlTtiReqPdu->pdu.pdsch_pdu.vrbToPrbMapping = pdschInfo->pdschFreqAlloc.vrbPrbMapping;
2816 dlTtiReqPdu->pdu.pdsch_pdu.startSymbIndex = pdschInfo->pdschTimeAlloc.timeAlloc.startSymb;
2817 dlTtiReqPdu->pdu.pdsch_pdu.nrOfSymbols = pdschInfo->pdschTimeAlloc.timeAlloc.numSymb;
2818 dlTtiReqPdu->pdu.pdsch_pdu.preCodingAndBeamforming.numPrgs = pdschInfo->beamPdschInfo.numPrgs;
2819 dlTtiReqPdu->pdu.pdsch_pdu.preCodingAndBeamforming.prgSize = pdschInfo->beamPdschInfo.prgSize;
2820 dlTtiReqPdu->pdu.pdsch_pdu.preCodingAndBeamforming.digBfInterfaces = pdschInfo->beamPdschInfo.digBfInterfaces;
2821 dlTtiReqPdu->pdu.pdsch_pdu.preCodingAndBeamforming.pmi_bfi[0]. \
2822 pmIdx = pdschInfo->beamPdschInfo.prg[0].pmIdx;
2823 dlTtiReqPdu->pdu.pdsch_pdu.preCodingAndBeamforming.pmi_bfi[0]. \
2824 beamIdx[0].beamidx = pdschInfo->beamPdschInfo.prg[0].beamIdx[0];
2825 dlTtiReqPdu->pdu.pdsch_pdu.powerControlOffset = pdschInfo->txPdschPower.powerControlOffset;
2826 dlTtiReqPdu->pdu.pdsch_pdu.powerControlOffsetSS = pdschInfo->txPdschPower.powerControlOffsetSS;
2827 dlTtiReqPdu->pdu.pdsch_pdu.mappingType = pdschInfo->dmrs.mappingType;
2828 dlTtiReqPdu->pdu.pdsch_pdu.nrOfDmrsSymbols = pdschInfo->dmrs.nrOfDmrsSymbols;
2829 dlTtiReqPdu->pdu.pdsch_pdu.dmrsAddPos = pdschInfo->dmrs.dmrsAddPos;
2831 dlTtiReqPdu->pduSize = sizeof(fapi_dl_pdsch_pdu_t);
2835 /***********************************************************************
2837 * @brief calculates the total size to be allocated for DL TTI Req
2841 * Function : calcDlTtiReqPduCount
2844 * -calculates the total pdu count to be allocated for DL TTI Req
2846 * @params[in] DlBrdcstAlloc *cellBroadcastInfo
2849 * ********************************************************************/
2850 uint8_t calcDlTtiReqPduCount(DlSchedInfo *dlInfo)
2855 if(dlInfo->isBroadcastPres)
2857 if(dlInfo->brdcstAlloc.ssbTrans)
2859 for(idx = 0; idx < dlInfo->brdcstAlloc.ssbIdxSupported; idx++)
2861 /* SSB PDU is filled */
2865 if(dlInfo->brdcstAlloc.sib1Trans)
2867 /* PDCCH and PDSCH PDU is filled */
2871 if(dlInfo->rarAlloc != NULLP)
2873 /* PDCCH and PDSCH PDU is filled */
2876 if(dlInfo->msg4Alloc != NULLP)
2878 /* PDCCH and PDSCH PDU is filled */
2885 /***********************************************************************
2887 * @brief calculates the total size to be allocated for DL TTI Req
2891 * Function : calcTxDataReqPduCount
2894 * -calculates the total pdu count to be allocated for DL TTI Req
2896 * @params[in] DlBrdcstAlloc *cellBroadcastInfo
2899 * ********************************************************************/
2900 uint8_t calcTxDataReqPduCount(DlSchedInfo *dlInfo)
2904 if(dlInfo->isBroadcastPres && dlInfo->brdcstAlloc.sib1Trans)
2908 if(dlInfo->rarAlloc != NULLP)
2912 if(dlInfo->msg4Alloc != NULLP)
2919 /***********************************************************************
2921 * @brief fills the SIB1 TX-DATA request message
2925 * Function : fillSib1TxDataReq
2928 * - fills the SIB1 TX-DATA request message
2930 * @params[in] fapi_tx_pdu_desc_t *pduDesc
2931 * @params[in] macCellCfg consist of SIB1 pdu
2932 * @params[in] uint32_t *msgLen
2933 * @params[in] uint16_t pduIndex
2936 * ********************************************************************/
2937 uint8_t fillSib1TxDataReq(fapi_tx_pdu_desc_t *pduDesc,MacCellCfg *macCellCfg,
2940 uint32_t pduLen = 0;
2941 uint8_t *sib1TxdataValue = NULLP;
2943 pduDesc[pduIndex].pdu_index = pduIndex;
2944 pduDesc[pduIndex].num_tlvs = 1;
2947 /* as of now, memory is allocated from SSI, later WLS memory needs to be taken */
2948 pduDesc[pduIndex].tlvs[0].tl.tag = 1; /* pointer to be sent */
2949 pduDesc[pduIndex].tlvs[0].tl.length = macCellCfg->sib1Cfg.sib1PduLen;
2950 LWR_MAC_ALLOC(sib1TxdataValue,macCellCfg->sib1Cfg.sib1PduLen);
2951 if(sib1TxdataValue == NULLP)
2955 memcpy(sib1TxdataValue,macCellCfg->sib1Cfg.sib1Pdu,
2956 macCellCfg->sib1Cfg.sib1PduLen);
2957 pduDesc[pduIndex].tlvs[0].value = sib1TxdataValue;
2959 /* The total length of the PDU description and PDU data */
2960 pduLen += 8; /* size of PDU length 2 bytes, PDU index 2 bytes, numTLV 4 bytes */
2961 pduLen += sizeof(fapi_uint8_ptr_tlv_t); /* only 1 TLV is present */
2962 pduDesc[pduIndex].pdu_length = pduLen;
2965 MAC_FREE(sib1TxdataValue,macCellCfg->sib1Cfg.sib1PduLen);
2971 /***********************************************************************
2973 * @brief fills the RAR TX-DATA request message
2977 * Function : fillRarTxDataReq
2980 * - fills the RAR TX-DATA request message
2982 * @params[in] fapi_tx_pdu_desc_t *pduDesc
2983 * @params[in] RarInfo *rarInfo
2984 * @params[in] uint32_t *msgLen
2985 * @params[in] uint16_t pduIndex
2988 * ********************************************************************/
2989 uint8_t fillRarTxDataReq(fapi_tx_pdu_desc_t *pduDesc, RarInfo *rarInfo,
2992 uint32_t pduLen = 0;
2993 uint8_t *rarTxdataValue = NULLP;
2995 pduDesc[pduIndex].pdu_index = pduIndex;
2996 pduDesc[pduIndex].num_tlvs = 1;
2999 /* as of now, memory is allocated from SSI, later WLS memory needs to be taken */
3000 pduDesc[pduIndex].tlvs[0].tl.tag = 1; /* pointer to be sent */
3001 pduDesc[pduIndex].tlvs[0].tl.length = rarInfo->rarPduLen;
3002 LWR_MAC_ALLOC(rarTxdataValue,rarInfo->rarPduLen);
3003 if(rarTxdataValue == NULLP)
3007 memcpy(rarTxdataValue,rarInfo->rarPdu,rarInfo->rarPduLen);
3008 pduDesc[pduIndex].tlvs[0].value = rarTxdataValue;
3010 /* The total length of the PDU description and PDU data */
3011 pduLen += 8; /* size of PDU length 2 bytes, PDU index 2 bytes, numTLV 4 bytes */
3012 pduLen += sizeof(fapi_uint8_ptr_tlv_t); /* only 1 TLV is present */
3013 pduDesc[pduIndex].pdu_length = pduLen;
3015 /* TODO: The pointer value which was stored, needs to be free-ed at PHY *
3016 * But since we did not implement WLS, this has to be done here
3019 MAC_FREE(rarTxdataValue,rarInfo->rarPduLen);
3025 /***********************************************************************
3027 * @brief fills the Msg4 TX-DATA request message
3031 * Function : fillMsg4TxDataReq
3034 * - fills the Msg4 TX-DATA request message
3036 * @params[in] fapi_tx_pdu_desc_t *pduDesc
3037 * @params[in] Msg4Info *msg4Info
3038 * @params[in] uint32_t *msgLen
3039 * @params[in] uint16_t pduIndex
3042 * ********************************************************************/
3043 uint8_t fillMsg4TxDataReq(fapi_tx_pdu_desc_t *pduDesc, Msg4Info *msg4Info,
3046 uint32_t pduLen = 0;
3047 uint8_t *msg4TxDataValue = NULLP;
3049 pduDesc[pduIndex].pdu_index = pduIndex;
3050 pduDesc[pduIndex].num_tlvs = 1;
3053 /* as of now, memory is allocated from SSI, later WLS memory needs to be taken */
3054 pduDesc[pduIndex].tlvs[0].tl.tag = 1; /* pointer to be sent */
3055 pduDesc[pduIndex].tlvs[0].tl.length = msg4Info->msg4PduLen;
3056 LWR_MAC_ALLOC(msg4TxDataValue, msg4Info->msg4PduLen);
3057 if(msg4TxDataValue == NULLP)
3061 memcpy(msg4TxDataValue, msg4Info->msg4Pdu, msg4Info->msg4PduLen);
3062 pduDesc[pduIndex].tlvs[0].value = msg4TxDataValue;
3064 /* The total length of the PDU description and PDU data */
3065 pduLen += 8; /* size of PDU length 2 bytes, PDU index 2 bytes, numTLV 4 bytes */
3066 pduLen += sizeof(fapi_uint8_ptr_tlv_t); /* only 1 TLV is present */
3067 pduDesc[pduIndex].pdu_length = pduLen;
3069 /* TODO: The pointer value which was stored, needs to be free-ed at PHY *
3070 * But since we did not implement WLS, this has to be done here
3073 MAC_FREE(msg4TxDataValue, msg4Info->msg4PduLen);
3080 /*******************************************************************
3082 * @brief Sends DL TTI Request to PHY
3086 * Function : handleDlTtiReq
3089 * -Sends FAPI DL TTI req to PHY
3091 * @params[in] timing info
3092 * @return ROK - success
3095 * ****************************************************************/
3096 uint16_t handleDlTtiReq(SlotIndInfo currTimingInfo)
3101 uint8_t numPduEncoded = 0;
3102 uint16_t pduIndex = 0;
3103 uint32_t msgLen = 0;
3105 fapi_dl_tti_req_t *dlTtiReq = NULLP;
3106 SlotIndInfo dlTtiReqTimingInfo;
3108 RgCellCb *cellCbParams = NULLP;
3109 MacDlSlot *currDlSlot = NULLP;
3110 MacCellCfg macCellCfg;
3111 memset(&macCellCfg, 0, sizeof(MacCellCfg));
3115 if(clGlobalCp.phyState == PHY_STATE_RUNNING)
3117 /* consider phy delay */
3118 ADD_DELTA_TO_TIME(currTimingInfo,dlTtiReqTimingInfo,PHY_DELTA);
3120 cellCbParams = rgCb[inst].cell;
3121 macCellCfg = cellCbParams->macCellCfg;
3123 currDlSlot = &macCb.macCell->dlSlot[dlTtiReqTimingInfo.slot];
3124 nPdu = calcDlTtiReqPduCount(&currDlSlot->dlInfo);
3125 LWR_MAC_ALLOC(dlTtiReq, sizeof(fapi_dl_tti_req_t));
3126 if(dlTtiReq != NULLP)
3128 memset(dlTtiReq, 0, sizeof(fapi_dl_tti_req_t));
3129 dlTtiReq->sfn = dlTtiReqTimingInfo.sfn;
3130 dlTtiReq->slot = dlTtiReqTimingInfo.slot;
3131 dlTtiReq->nPdus = calcDlTtiReqPduCount(&currDlSlot->dlInfo); /* get total Pdus */
3132 nPdu = dlTtiReq->nPdus;
3133 dlTtiReq->nGroup = 0;
3135 if(dlTtiReq->nPdus > 0)
3137 if(currDlSlot->dlInfo.isBroadcastPres)
3139 if(currDlSlot->dlInfo.brdcstAlloc.ssbTrans)
3141 if(dlTtiReq->pdus != NULLP)
3143 for(idx = 0; idx < currDlSlot->dlInfo.brdcstAlloc.ssbIdxSupported; idx++)
3145 fillSsbPdu(&dlTtiReq->pdus[numPduEncoded], &macCellCfg,\
3146 currDlSlot, idx, dlTtiReq->sfn);
3150 printf("\033[1;31m");
3151 DU_LOG("\nLWR_MAC: MIB sent..");
3154 if(currDlSlot->dlInfo.brdcstAlloc.sib1Trans)
3156 /* Filling SIB1 param */
3157 if(numPduEncoded != nPdu)
3159 rntiType = SI_RNTI_TYPE;
3160 fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded],&currDlSlot->dlInfo,\
3161 rntiType, CORESET_TYPE0);
3163 fillPdschPdu(&dlTtiReq->pdus[numPduEncoded],
3164 &currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.sib1PdschCfg,
3165 currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.bwp,
3170 printf("\033[1;34m");
3171 DU_LOG("\nLWR_MAC: SIB1 sent...");
3175 if(currDlSlot->dlInfo.rarAlloc != NULLP)
3177 /* Filling RAR param */
3178 rntiType = RA_RNTI_TYPE;
3179 fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded], \
3180 &currDlSlot->dlInfo, rntiType, CORESET_TYPE0);
3182 fillPdschPdu(&dlTtiReq->pdus[numPduEncoded],
3183 &currDlSlot->dlInfo.rarAlloc->rarPdschCfg,
3184 currDlSlot->dlInfo.rarAlloc->bwp,
3189 printf("\033[1;32m");
3190 DU_LOG("\nLWR_MAC: RAR sent...");
3193 if(currDlSlot->dlInfo.msg4Alloc != NULLP)
3195 /* Filling Msg4 param */
3196 rntiType = TC_RNTI_TYPE;
3197 fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded], \
3198 &currDlSlot->dlInfo, rntiType, CORESET_TYPE0);
3200 fillPdschPdu(&dlTtiReq->pdus[numPduEncoded],
3201 &currDlSlot->dlInfo.msg4Alloc->msg4PdschCfg,
3202 currDlSlot->dlInfo.msg4Alloc->bwp,
3207 printf("\033[1;32m");
3208 DU_LOG("\nLWR_MAC: MSG4 sent...");
3211 msgLen = sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
3212 fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
3213 LwrMacSendToPhy(dlTtiReq->header.msg_id, sizeof(fapi_dl_tti_req_t), \
3216 /* send Tx-DATA req message */
3217 sendTxDataReq(currTimingInfo, &currDlSlot->dlInfo);
3221 msgLen = sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
3222 fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
3223 LwrMacSendToPhy(dlTtiReq->header.msg_id, sizeof(fapi_dl_tti_req_t), (void *)dlTtiReq);
3225 memset(currDlSlot, 0, sizeof(MacDlSlot));
3230 DU_LOG("\nLWR_MAC: Failed to allocate memory for DL TTI Request");
3231 memset(currDlSlot, 0, sizeof(MacDlSlot));
3237 lwr_mac_handleInvalidEvt(&currTimingInfo);
3244 /*******************************************************************
3246 * @brief Sends TX data Request to PHY
3250 * Function : sendTxDataReq
3253 * -Sends FAPI TX data req to PHY
3255 * @params[in] timing info
3256 * @return ROK - success
3259 * ****************************************************************/
3260 uint16_t sendTxDataReq(SlotIndInfo currTimingInfo, DlSchedInfo *dlInfo)
3264 uint32_t msgLen = 0;
3265 uint16_t pduIndex = 0;
3266 uint32_t txDataReqMsgSize = 0;
3267 fapi_tx_data_req_t *txDataReq = NULLP;
3270 /* send TX_Data request message */
3271 nPdu = calcTxDataReqPduCount(dlInfo);
3274 txDataReqMsgSize = sizeof(fapi_tx_data_req_t);
3275 if(dlInfo->brdcstAlloc.sib1Trans)
3277 txDataReqMsgSize += rgCb[inst].cell->macCellCfg.sib1Cfg.sib1PduLen;
3279 if(dlInfo->rarAlloc != NULLP)
3281 txDataReqMsgSize += dlInfo->rarAlloc->rarInfo.rarPduLen;
3283 if(dlInfo->msg4Alloc != NULLP)
3285 txDataReqMsgSize += dlInfo->msg4Alloc->msg4Info.msg4PduLen;
3288 LWR_MAC_ALLOC(txDataReq, txDataReqMsgSize);
3289 if(txDataReq == NULLP)
3291 DU_LOG("\nLWR_MAC: Failed to allocate memory for TX data Request");
3295 memset(txDataReq, 0, txDataReqMsgSize);
3296 txDataReq->sfn = currTimingInfo.sfn;
3297 txDataReq->slot = currTimingInfo.slot;
3298 if(dlInfo->brdcstAlloc.sib1Trans)
3300 fillSib1TxDataReq(txDataReq->pdu_desc,
3301 &rgCb[inst].cell->macCellCfg, pduIndex);
3303 txDataReq->num_pdus++;
3305 if(dlInfo->rarAlloc != NULLP)
3307 fillRarTxDataReq(txDataReq->pdu_desc, &dlInfo->rarAlloc->rarInfo, pduIndex);
3309 txDataReq->num_pdus++;
3311 MAC_FREE(dlInfo->rarAlloc,sizeof(RarAlloc));
3312 dlInfo->rarAlloc = NULLP;
3314 if(dlInfo->msg4Alloc != NULLP && dlInfo->msg4Alloc->msg4Info.msg4Pdu != NULLP)
3316 fillMsg4TxDataReq(txDataReq->pdu_desc, &dlInfo->msg4Alloc->\
3317 msg4Info, pduIndex);
3319 txDataReq->num_pdus++;
3321 MAC_FREE(dlInfo->msg4Alloc->msg4Info.msg4Pdu,\
3322 dlInfo->msg4Alloc->msg4Info.msg4PduLen);
3323 dlInfo->msg4Alloc->msg4Info.msg4Pdu = NULLP;
3324 MAC_FREE(dlInfo->msg4Alloc,sizeof(Msg4Alloc));
3325 dlInfo->msg4Alloc = NULLP;
3327 msgLen = txDataReqMsgSize - sizeof(fapi_msg_t);
3328 fillMsgHeader(&txDataReq->header, FAPI_TX_DATA_REQUEST, msgLen);
3329 LwrMacSendToPhy(txDataReq->header.msg_id, txDataReqMsgSize, \
3336 /***********************************************************************
3338 * @brief calculates the total size to be allocated for UL TTI Req
3342 * Function : getnPdus
3345 * -calculates the total pdu count to be allocated for UL TTI Req
3347 * @params[in] Pointer to fapi Ul TTI Req
3348 * Pointer to CurrUlSlot
3350 * ********************************************************************/
3352 uint8_t getnPdus(fapi_ul_tti_req_t *ulTtiReq, MacUlSlot *currUlSlot)
3354 uint8_t pduCount = 0;
3356 if(ulTtiReq && currUlSlot)
3358 if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PRACH)
3361 ulTtiReq->rachPresent++;
3363 if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PUSCH)
3368 if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PUSCH_UCI)
3373 if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_UCI)
3378 if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_SRS)
3387 /***********************************************************************
3389 * @brief Set the value of zero correlation config in PRACH PDU
3393 * Function : setNumCs
3396 * -Set the value of zero correlation config in PRACH PDU
3398 * @params[in] Pointer to zero correlation config
3399 * Pointer to MacCellCfg
3400 * ********************************************************************/
3402 void setNumCs(uint16_t *numCs, MacCellCfg *macCellCfg)
3406 if(macCellCfg != NULLP)
3408 idx = macCellCfg->prachCfg.fdm[0].zeroCorrZoneCfg;
3409 *numCs = UnrestrictedSetNcsTable[idx];
3414 /***********************************************************************
3416 * @brief Fills the PRACH PDU in UL TTI Request
3420 * Function : fillPrachPdu
3423 * -Fills the PRACH PDU in UL TTI Request
3425 * @params[in] Pointer to Prach Pdu
3426 * Pointer to CurrUlSlot
3427 * Pointer to macCellCfg
3429 * ********************************************************************/
3432 void fillPrachPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg, MacUlSlot *currUlSlot)
3434 if(ulTtiReqPdu != NULLP)
3436 ulTtiReqPdu->pduType = PRACH_PDU_TYPE;
3437 ulTtiReqPdu->pdu.prach_pdu.physCellId = macCellCfg->phyCellId;
3438 ulTtiReqPdu->pdu.prach_pdu.numPrachOcas = currUlSlot->ulInfo.prachSchInfo.numPrachOcas;
3439 ulTtiReqPdu->pdu.prach_pdu.prachFormat = \
3440 currUlSlot->ulInfo.prachSchInfo.prachFormat;
3441 ulTtiReqPdu->pdu.prach_pdu.numRa = currUlSlot->ulInfo.prachSchInfo.numRa;
3442 ulTtiReqPdu->pdu.prach_pdu.prachStartSymbol = \
3443 currUlSlot->ulInfo.prachSchInfo.prachStartSymb;
3444 setNumCs(&ulTtiReqPdu->pdu.prach_pdu.numCs, macCellCfg);
3445 ulTtiReqPdu->pdu.prach_pdu.beamforming.numPrgs = 0;
3446 ulTtiReqPdu->pdu.prach_pdu.beamforming.prgSize = 0;
3447 ulTtiReqPdu->pdu.prach_pdu.beamforming.digBfInterface = 0;
3448 ulTtiReqPdu->pdu.prach_pdu.beamforming.rx_bfi[0].beamIdx[0].beamidx = 0;
3449 ulTtiReqPdu->pduSize = sizeof(fapi_ul_prach_pdu_t);
3453 void fillPuschPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg, MacUlSlot *currUlSlot)
3455 if(ulTtiReqPdu != NULLP)
3457 ulTtiReqPdu->pduType = PUSCH_PDU_TYPE;
3458 memset(&ulTtiReqPdu->pdu.pusch_pdu, 0, sizeof(fapi_ul_pusch_pdu_t));
3459 ulTtiReqPdu->pdu.pusch_pdu.pduBitMap = 1;
3460 ulTtiReqPdu->pdu.pusch_pdu.rnti = currUlSlot->ulInfo.crnti;
3461 /* TODO : Fill handle in raCb when scheduling pusch and access here */
3462 ulTtiReqPdu->pdu.pusch_pdu.handle = 100;
3463 ulTtiReqPdu->pdu.pusch_pdu.bwpSize = macCellCfg->initialUlBwp.bwp.numPrb;
3464 ulTtiReqPdu->pdu.pusch_pdu.bwpStart = macCellCfg->initialUlBwp.bwp.firstPrb;
3465 ulTtiReqPdu->pdu.pusch_pdu.subCarrierSpacing = \
3466 macCellCfg->initialUlBwp.bwp.scs;
3467 ulTtiReqPdu->pdu.pusch_pdu.cyclicPrefix = \
3468 macCellCfg->initialUlBwp.bwp.cyclicPrefix;
3469 ulTtiReqPdu->pdu.pusch_pdu.targetCodeRate = 308;
3470 ulTtiReqPdu->pdu.pusch_pdu.qamModOrder = 2;
3471 ulTtiReqPdu->pdu.pusch_pdu.mcsIndex = \
3472 currUlSlot->ulInfo.schPuschInfo.tbInfo.mcs;
3473 ulTtiReqPdu->pdu.pusch_pdu.mcsTable = 0;
3474 ulTtiReqPdu->pdu.pusch_pdu.transformPrecoding = 1;
3475 ulTtiReqPdu->pdu.pusch_pdu.dataScramblingId = currUlSlot->ulInfo.cellId;
3476 ulTtiReqPdu->pdu.pusch_pdu.nrOfLayers = 1;
3477 ulTtiReqPdu->pdu.pusch_pdu.ulDmrsSymbPos = 4;
3478 ulTtiReqPdu->pdu.pusch_pdu.dmrsConfigType = 0;
3479 ulTtiReqPdu->pdu.pusch_pdu.ulDmrsScramblingId = currUlSlot->ulInfo.cellId;
3480 ulTtiReqPdu->pdu.pusch_pdu.scid = 0;
3481 ulTtiReqPdu->pdu.pusch_pdu.numDmrsCdmGrpsNoData = 1;
3482 ulTtiReqPdu->pdu.pusch_pdu.dmrsPorts = 0;
3483 ulTtiReqPdu->pdu.pusch_pdu.resourceAlloc = \
3484 currUlSlot->ulInfo.schPuschInfo.resAllocType;
3485 ulTtiReqPdu->pdu.pusch_pdu.rbStart = \
3486 currUlSlot->ulInfo.schPuschInfo.fdAlloc.startPrb;
3487 ulTtiReqPdu->pdu.pusch_pdu.rbSize = \
3488 currUlSlot->ulInfo.schPuschInfo.fdAlloc.numPrb;
3489 ulTtiReqPdu->pdu.pusch_pdu.vrbToPrbMapping = 0;
3490 ulTtiReqPdu->pdu.pusch_pdu.frequencyHopping = 0;
3491 ulTtiReqPdu->pdu.pusch_pdu.txDirectCurrentLocation = 0;
3492 ulTtiReqPdu->pdu.pusch_pdu.uplinkFrequencyShift7p5khz = 0;
3493 ulTtiReqPdu->pdu.pusch_pdu.startSymbIndex = \
3494 currUlSlot->ulInfo.schPuschInfo.tdAlloc.startSymb;
3495 ulTtiReqPdu->pdu.pusch_pdu.nrOfSymbols = \
3496 currUlSlot->ulInfo.schPuschInfo.tdAlloc.numSymb;
3497 ulTtiReqPdu->pdu.pusch_pdu.mappingType = \
3498 currUlSlot->ulInfo.schPuschInfo.dmrsMappingType;
3499 ulTtiReqPdu->pdu.pusch_pdu.nrOfDmrsSymbols = \
3500 currUlSlot->ulInfo.schPuschInfo.nrOfDmrsSymbols;
3501 ulTtiReqPdu->pdu.pusch_pdu.dmrsAddPos = \
3502 currUlSlot->ulInfo.schPuschInfo.dmrsAddPos;
3503 ulTtiReqPdu->pdu.pusch_pdu.puschData.rvIndex = \
3504 currUlSlot->ulInfo.schPuschInfo.tbInfo.rv;
3505 ulTtiReqPdu->pdu.pusch_pdu.puschData.harqProcessId = \
3506 currUlSlot->ulInfo.schPuschInfo.harqProcId;
3507 ulTtiReqPdu->pdu.pusch_pdu.puschData.newDataIndicator = \
3508 currUlSlot->ulInfo.schPuschInfo.tbInfo.ndi;
3509 ulTtiReqPdu->pdu.pusch_pdu.puschData.tbSize = \
3510 currUlSlot->ulInfo.schPuschInfo.tbInfo.tbSize;
3511 /* numCb is 0 for new transmission */
3512 ulTtiReqPdu->pdu.pusch_pdu.puschData.numCb = 0;
3514 ulTtiReqPdu->pduSize = sizeof(fapi_ul_pusch_pdu_t);
3518 void fillPucchPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg,\
3519 MacUlSlot *currUlSlot)
3521 if(ulTtiReqPdu != NULLP)
3523 ulTtiReqPdu->pduType = PUCCH_PDU_TYPE;
3524 memset(&ulTtiReqPdu->pdu.pucch_pdu, 0, sizeof(fapi_ul_pucch_pdu_t));
3525 ulTtiReqPdu->pdu.pucch_pdu.rnti = currUlSlot->ulInfo.schPucchInfo.rnti;
3526 /* TODO : Fill handle in raCb when scheduling pucch and access here */
3527 ulTtiReqPdu->pdu.pucch_pdu.handle = 100;
3528 ulTtiReqPdu->pdu.pucch_pdu.bwpSize = macCellCfg->initialUlBwp.bwp.numPrb;
3529 ulTtiReqPdu->pdu.pucch_pdu.bwpStart = macCellCfg->initialUlBwp.bwp.firstPrb;
3530 ulTtiReqPdu->pdu.pucch_pdu.subCarrierSpacing = macCellCfg->initialUlBwp.bwp.scs;
3531 ulTtiReqPdu->pdu.pucch_pdu.cyclicPrefix = macCellCfg->initialUlBwp.bwp.cyclicPrefix;
3532 ulTtiReqPdu->pdu.pucch_pdu.formatType = currUlSlot->ulInfo.schPucchInfo.pucchFormat; /* Supporting PUCCH Format 0 */
3533 ulTtiReqPdu->pdu.pucch_pdu.multiSlotTxIndicator = 0; /* No Multi Slot transmission */
3534 ulTtiReqPdu->pdu.pucch_pdu.pi2Bpsk = 0; /* Disabled */
3535 ulTtiReqPdu->pdu.pucch_pdu.prbStart = currUlSlot->ulInfo.schPucchInfo.fdAlloc.startPrb;
3536 ulTtiReqPdu->pdu.pucch_pdu.prbSize = currUlSlot->ulInfo.schPucchInfo.fdAlloc.numPrb;
3537 ulTtiReqPdu->pdu.pucch_pdu.startSymbolIndex = currUlSlot->ulInfo.schPucchInfo.tdAlloc.startSymb;
3538 ulTtiReqPdu->pdu.pucch_pdu.nrOfSymbols = currUlSlot->ulInfo.schPucchInfo.tdAlloc.numSymb;
3539 ulTtiReqPdu->pdu.pucch_pdu.freqHopFlag = 0; /* Disabled */
3540 ulTtiReqPdu->pdu.pucch_pdu.secondHopPrb = 0;
3541 ulTtiReqPdu->pdu.pucch_pdu.groupHopFlag = 0;
3542 ulTtiReqPdu->pdu.pucch_pdu.sequenceHopFlag = 0;
3543 ulTtiReqPdu->pdu.pucch_pdu.hoppingId = 0;
3544 ulTtiReqPdu->pdu.pucch_pdu.initialCyclicShift = 0;
3545 ulTtiReqPdu->pdu.pucch_pdu.dataScramblingId = 0; /* Valid for Format 2, 3, 4 */
3546 ulTtiReqPdu->pdu.pucch_pdu.timeDomainOccIdx = 0; /* Valid for Format 1 */
3547 ulTtiReqPdu->pdu.pucch_pdu.preDftOccIdx = 0; /* Valid for Format 4 */
3548 ulTtiReqPdu->pdu.pucch_pdu.preDftOccLen = 0; /* Valid for Format 4 */
3549 ulTtiReqPdu->pdu.pucch_pdu.addDmrsFlag = 0; /* Valid for Format 3, 4 */
3550 ulTtiReqPdu->pdu.pucch_pdu.dmrsScramblingId = 0; /* Valid for Format 2 */
3551 ulTtiReqPdu->pdu.pucch_pdu.dmrsCyclicShift = 0; /* Valid for Format 4 */
3552 ulTtiReqPdu->pdu.pucch_pdu.srFlag = currUlSlot->ulInfo.schPucchInfo.srFlag;
3553 ulTtiReqPdu->pdu.pucch_pdu.bitLenHarq = currUlSlot->ulInfo.schPucchInfo.numHarqBits;
3554 ulTtiReqPdu->pdu.pucch_pdu.bitLenCsiPart1 = 0; /* Valid for Format 2, 3, 4 */
3555 ulTtiReqPdu->pdu.pucch_pdu.bitLenCsiPart2 = 0; /* Valid for Format 2, 3, 4 */
3556 ulTtiReqPdu->pdu.pucch_pdu.beamforming.numPrgs = 0; /* Not Supported */
3557 ulTtiReqPdu->pdu.pucch_pdu.beamforming.prgSize = 0;
3558 ulTtiReqPdu->pdu.pucch_pdu.beamforming.digBfInterface = 0;
3559 ulTtiReqPdu->pdu.pucch_pdu.beamforming.rx_bfi[0].beamIdx[0].beamidx = 0;
3561 ulTtiReqPdu->pduSize = sizeof(fapi_ul_pucch_pdu_t);
3567 /*******************************************************************
3569 * @brief Sends UL TTI Request to PHY
3573 * Function : handleUlTtiReq
3576 * -Sends FAPI Param req to PHY
3578 * @params[in] Pointer to CmLteTimingInfo
3579 * @return ROK - success
3582 ******************************************************************/
3583 uint16_t handleUlTtiReq(SlotIndInfo currTimingInfo)
3586 uint8_t pduIdx = -1;
3587 uint32_t msgLen = 0;
3588 uint32_t msgSize = 0;
3590 fapi_ul_tti_req_t *ulTtiReq = NULLP;
3591 SlotIndInfo ulTtiReqTimingInfo;
3593 RgCellCb *cellCbParams = NULLP;
3594 MacUlSlot *currUlSlot = NULLP;
3595 MacCellCfg macCellCfg;
3598 if(clGlobalCp.phyState == PHY_STATE_RUNNING)
3600 cellCbParams = rgCb[inst].cell;
3601 macCellCfg = cellCbParams->macCellCfg;
3604 ADD_DELTA_TO_TIME(currTimingInfo,ulTtiReqTimingInfo,PHY_DELTA);
3606 currUlSlot = &macCb.macCell->ulSlot[ulTtiReqTimingInfo.slot % MAX_SLOT_SUPPORTED];
3607 msgSize = sizeof(fapi_ul_tti_req_t);
3608 LWR_MAC_ALLOC(ulTtiReq, msgSize);
3610 if(ulTtiReq != NULLP)
3612 memset(ulTtiReq, 0, msgSize);
3613 ulTtiReq->sfn = ulTtiReqTimingInfo.sfn;
3614 ulTtiReq->slot = ulTtiReqTimingInfo.slot;
3615 ulTtiReq->nPdus = getnPdus(ulTtiReq, currUlSlot);
3616 ulTtiReq->nGroup = 0;
3617 if(ulTtiReq->nPdus > 0)
3619 /* Fill Prach Pdu */
3620 if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PRACH)
3623 fillPrachPdu(&ulTtiReq->pdus[pduIdx], &macCellCfg, currUlSlot);
3626 /* Fill PUSCH PDU */
3627 if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PUSCH)
3630 fillPuschPdu(&ulTtiReq->pdus[pduIdx], &macCellCfg, currUlSlot);
3632 /* Fill PUCCH PDU */
3633 if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_UCI)
3636 fillPucchPdu(&ulTtiReq->pdus[pduIdx], &macCellCfg, currUlSlot);
3639 msgLen = sizeof(fapi_ul_tti_req_t) - sizeof(fapi_msg_t);
3640 fillMsgHeader(&ulTtiReq->header, FAPI_UL_TTI_REQUEST, msgLen);
3642 DU_LOG("\nLWR_MAC: Sending UL TTI Request");
3643 LwrMacSendToPhy(ulTtiReq->header.msg_id, msgSize, (void *)ulTtiReq);
3645 memset(currUlSlot, 0, sizeof(MacUlSlot));
3650 DU_LOG("\nLWR_MAC: Failed to allocate memory for UL TTI Request");
3651 memset(currUlSlot, 0, sizeof(MacUlSlot));
3657 lwr_mac_handleInvalidEvt(&currTimingInfo);
3663 lwrMacFsmHdlr fapiEvtHdlr[MAX_STATE][MAX_EVENT] =
3666 /* PHY_STATE_IDLE */
3667 lwr_mac_handleParamReqEvt,
3668 lwr_mac_handleParamRspEvt,
3669 lwr_mac_handleConfigReqEvt,
3670 lwr_mac_handleConfigRspEvt,
3671 lwr_mac_handleInvalidEvt,
3672 lwr_mac_handleInvalidEvt,
3675 /* PHY_STATE_CONFIGURED */
3676 lwr_mac_handleParamReqEvt,
3677 lwr_mac_handleParamRspEvt,
3678 lwr_mac_handleConfigReqEvt,
3679 lwr_mac_handleConfigRspEvt,
3680 lwr_mac_handleStartReqEvt,
3681 lwr_mac_handleInvalidEvt,
3684 /* PHY_STATE_RUNNING */
3685 lwr_mac_handleInvalidEvt,
3686 lwr_mac_handleInvalidEvt,
3687 lwr_mac_handleConfigReqEvt,
3688 lwr_mac_handleConfigRspEvt,
3689 lwr_mac_handleInvalidEvt,
3690 lwr_mac_handleStopReqEvt,
3694 /*******************************************************************
3696 * @brief Sends message to LWR_MAC Fsm Event Handler
3700 * Function : sendToLowerMac
3703 * -Sends message to LowerMac
3705 * @params[in] Message Type
3711 ******************************************************************/
3712 void sendToLowerMac(uint16_t msgType, uint32_t msgLen, void *msg)
3714 clGlobalCp.event = msgType;
3715 fapiEvtHdlr[clGlobalCp.phyState][clGlobalCp.event](msg);
3717 /**********************************************************************
3719 **********************************************************************/