* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef __INIT_DEFS__H__
#define __INIT_DEFS__H__
#include "PHY/defs.h"
#include "SystemInformationBlockType2.h"
//#include "RadioResourceConfigCommonSIB.h"
#include "RadioResourceConfigDedicated.h"
#include "TDD-Config.h"
#include "MBSFN-SubframeConfigList.h"
#include "MobilityControlInfo.h"
#if defined(Rel10) || defined(Rel14)
#include "SCellToAddMod-r10.h"
#endif
/** @addtogroup _PHY_STRUCTURES_
* @{
*/
/*!
\fn int phy_init_top(LTE_DL_FRAME_PARMS *frame_parms)
\brief Allocate and Initialize the PHY variables after receiving static configuration
@param frame_parms Pointer to LTE_DL_FRAME_PARMS (common configuration)
@returns 0 on success
*/
intphy_init_top(LTE_DL_FRAME_PARMS*frame_parms);
/*!
\brief Allocate and Initialize the PHY variables relevant to the LTE implementation.
\details Only a subset of phy_vars_ue is initialized.
@param[out] phy_vars_ue Pointer to UE Variables
@param nb_connected_eNB Number of eNB that UE can process in one PDSCH demodulation subframe
@param abstraction_flag 1 indicates memory should be allocated for abstracted MODEM
@returns 0 on success
@returns -1 if any memory allocation failed
@note The current implementation will never return -1, but segfault.
*/
intphy_init_lte_ue(PHY_VARS_UE*phy_vars_ue,
intnb_connected_eNB,
uint8_tabstraction_flag);
/*!
\brief Allocate and initialize the PHY variables relevant to the LTE implementation (eNB).
\details Only a subset of phy_vars_eNb is initialized.
@param[out] phy_vars_eNb Pointer to eNB Variables
@param is_secondary_eNb Flag to indicate this eNB gets synch from another
@param abstraction_flag 1 indicates memory should be allocated for abstracted MODEM
@returns 0 on success
@returns -1 if any memory allocation failed
@note The current implementation will never return -1, but segfault.
*/
intphy_init_lte_eNB(PHY_VARS_eNB*phy_vars_eNb,
unsignedcharis_secondary_eNb,
unsignedcharabstraction_flag);
/** \brief Configure LTE_DL_FRAME_PARMS with components derived after initial synchronization (MIB decoding + primary/secondary synch).
\details The basically allows configuration of \f$N_{\mathrm{RB}}^{\mathrm{DL}}\f$, the cell id \f$N_{\mathrm{ID}}^{\mathrm{cell}}\f$, the normal/extended prefix mode, the frame type (FDD/TDD), \f$N_{\mathrm{cp}}\f$, the number of TX antennas at eNB (\f$p\f$) and the number of PHICH groups, \f$N_{\mathrm{group}}^{\mathrm{PHICH}}\f$
@param lte_frame_parms pointer to LTE parameter structure
@param N_RB_DL Number of DL resource blocks
@param Nid_cell Cell ID
@param Ncp Normal/Extended Prefix flag
@param frame_type FDD/TDD framing
@param p_eNB Number of eNB TX antennas
@param phich_config Pointer to PHICH_CONFIG_COMMON
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "defs.h"
#include "SCHED/defs.h"
#include "PHY/extern.h"
#include "SIMULATION/TOOLS/defs.h"
#include "RadioResourceConfigCommonSIB.h"
#include "RadioResourceConfigDedicated.h"
#include "TDD-Config.h"
#include "LAYER2/MAC/extern.h"
#include "MBSFN-SubframeConfigList.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
#define DEBUG_PHY
#include "assertions.h"
#include <math.h>
#include "defs-nb.h"
#include "RadioResourceConfigCommonSIB-NB-r13.h"
#include "PHY/impl_defs_lte-nb.h"
externuint16_tprach_root_sequence_map0_3[838];
externuint16_tprach_root_sequence_map4[138];
uint8_tdmrs1_tab[8]={0,2,3,4,6,8,9,10};
voidNB_phy_config_mib_eNB(intMod_id,
intCC_id,
inteutra_band,
intNid_cell,
intNcp,
intp_eNB,
uint32_tdl_CarrierFreq,
uint32_tul_CarrierFreq){
/*Not sure if phy parameters should be initial here or not*/
/*the phy_config_mib_eNB as the entry point to allocate the context for L1. The RC contains the context for L1,L2. If RC.eNB is NULL, it hasn't been allocated earlier so we allocate it there.*/
///see TS 36.213 (16.2). \vr{[-60..50]}\n Provides the downlink reference-signal EPRE. The actual value in dBm.
int8_tnrs_Power;
}NPDSCH_CONFIG_COMMON;
typedefstruct{
/// The base sequence of DMRS sequence in a cell for 3 tones transmission; see TS 36.211 [21, 10.1.4.1.2]. If absent, it is given by NB-IoT CellID mod 12. Value 12 is not used.
uint8_tthreeTone_BaseSequence;
/// Define 3 cyclic shifts for the 3-tone case, see TS 36.211 [21, 10.1.4.1.2].
uint8_tthreeTone_CyclicShift;
/// The base sequence of DMRS sequence in a cell for 6 tones transmission; see TS 36.211 [21, 10.1.4.1.2]. If absent, it is given by NB-IoT CellID mod 14. Value 14 is not used.
uint8_tsixTone_BaseSequence;
/// Define 4 cyclic shifts for the 6-tone case, see TS 36.211 [21, 10.1.4.1.2].
uint8_tsixTone_CyclicShift;
/// The base sequence of DMRS sequence in a cell for 12 tones transmission; see TS 36.211 [21, 10.1.4.1.2]. If absent, it is given by NB-IoT CellID mod 30. Value 30 is not used.
uint8_ttwelveTone_BaseSequence;
}DMRS_CONFIG_t;
/// UL-ReferenceSignalsNPUSCH from 36.331 RRC spec
typedefstruct{
/// Parameter: Group-hopping-enabled, see TS 36.211 (5.5.1.3). \vr{[0..1]}
uint8_tgroupHoppingEnabled;
/// , see TS 36.211 (5.5.1.3). \vr{[0..29]}
uint8_tgroupAssignmentNPUSCH;
}UL_REFERENCE_SIGNALS_NPUSCH_t;
/// PUSCH-ConfigCommon from 36.331 RRC spec.
typedefstruct{
/// Number of repetitions for ACK/NACK HARQ response to NPDSCH containing Msg4 per NPRACH resource, see TS 36.213 [23, 16.4.2].
uint8_tack_NACK_NumRepetitions_Msg4[3];
/// SRS SubframeConfiguration. See TS 36.211 [21, table 5.5.3.3-1]. Value sc0 corresponds to value 0, sc1 to value 1 and so on.
uint8_tsrs_SubframeConfig;
/// Parameter: \f$N^{HO}_{RB}\f$, see TS 36.211 (5.3.4). \vr{[0..98]}
/// See TS 36.213 [23, 16.2.1.1] where al0 corresponds to 0, al04 corresponds to value 0.4, al05 to 0.5, al06 to 0.6, al07 to 0.7, al08 to 0.8, al09 to 0.9 and al1 corresponds to 1.
uint8_talpha;
/// See TS 36.213 [23, 16.2.1.1]. Actual value = IE value * 2 [dB].
uint8_tdeltaPreambleMsg3;
}UplinkPowerControlCommon_NB;
/* DL-GapConfig-NB-r13 */
typedefstruct{
uint8_tdl_GapThreshold;
uint8_tdl_GapPeriodicity;
uint8_tdl_GapDurationCoeff;
}DL_GapConfig_NB;
typedefstruct{
/// Cell ID
uint16_tNid_cell;
/// Cyclic Prefix for DL (0=Normal CP, 1=Extended CP)
lte_prefix_type_tNcp;
/// Cyclic Prefix for UL (0=Normal CP, 1=Extended CP)
lte_prefix_type_tNcp_UL;
/// shift of pilot position in one RB
uint8_tnushift;
/// indicates if node is a UE (NODE=2) or eNB (PRIMARY_CH=0).
uint8_tnode_id;
/// Frequency index of CBMIMO1 card
uint8_tfreq_idx;
/// RX Frequency for ExpressMIMO/LIME
uint32_tcarrier_freq[4];
/// TX Frequency for ExpressMIMO/LIME
uint32_tcarrier_freqtx[4];
/// RX gain for ExpressMIMO/LIME
uint32_trxgain[4];
/// TX gain for ExpressMIMO/LIME
uint32_ttxgain[4];
/// RF mode for ExpressMIMO/LIME
uint32_trfmode[4];
/// RF RX DC Calibration for ExpressMIMO/LIME
uint32_trxdc[4];
/// RF TX DC Calibration for ExpressMIMO/LIME
uint32_trflocal[4];
/// RF VCO calibration for ExpressMIMO/LIME
uint32_trfvcolocal[4];
/// Turns on second TX of CBMIMO1 card
uint8_tdual_tx;
/// flag to indicate SISO transmission
uint8_tmode1_flag;
/// Indicator that 20 MHz channel uses 3/4 sampling frequency
//uint8_t threequarter_fs;
/// Size of FFT
uint16_tofdm_symbol_size;
/// Number of prefix samples in all but first symbol of slot
uint16_tnb_prefix_samples;
/// Number of prefix samples in first symbol of slot
uint16_tnb_prefix_samples0;
/// Carrier offset in FFT buffer for first RE in PRB0
uint16_tfirst_carrier_offset;
/// Number of samples in a subframe
uint32_tsamples_per_tti;
/// Number of OFDM/SC-FDMA symbols in one subframe (to be modified to account for potential different in UL/DL)
uint16_tsymbols_per_tti;
/// Number of Physical transmit antennas in node
uint8_tnb_antennas_tx;
/// Number of Receive antennas in node
uint8_tnb_antennas_rx;
/// Number of common transmit antenna ports in eNodeB (1 or 2)
//LG commented cause compilation error for RT eNB extern inline unsigned int taus(void);
/** \fn void schedule_RA(module_id_t module_idP,frame_t frameP,sub_frame_t subframe,uint8_t Msg3_subframe,unsigned int *nprb);
\brief First stage of Random-Access Scheduling. Loops over the RA_templates and checks if RAR, Msg3 or its retransmission are to be scheduled in the subframe. It returns the total number of PRB used for RA SDUs. For Msg3 it retrieves the L3msg from RRC and fills the appropriate buffers. For the others it just computes the number of PRBs. Each DCI uses 3 PRBs (format 1A)
/** \brief First stage of SI Scheduling. Gets a SI SDU from RRC if available and computes the MCS required to transport it as a function of the SDU length. It assumes a length less than or equal to 64 bytes (MCS 6, 3 PRBs).
@param Mod_id Instance ID of eNB
@param frame Frame index
@param subframe Subframe number on which to act
@param Msg3_subframe Subframe where Msg3 will be transmitted
/** \brief MBMS scheduling: Checking the position for MBSFN subframes. Create MSI, transfer MCCH from RRC to MAC, transfer MTCHs from RLC to MAC. Multiplexing MSI,MCCH&MTCHs. Return 1 if there are MBSFN data being allocated, otherwise return 0;
/** \brief Second stage of DLSCH scheduling, after schedule_SI, schedule_RA and schedule_dlsch have been called. This routine first allocates random frequency assignments for SI and RA SDUs using distributed VRB allocations and adds the corresponding DCI SDU to the DCI buffer for PHY. It then loops over the UE specific DCIs previously allocated and fills in the remaining DCI fields related to frequency allocation. It assumes localized allocation of type 0 (DCI.rah=0). The allocation is done for tranmission modes 1,2,4.
@param Mod_id Instance of eNB
@param frame Frame index
@param subframe Index of subframe
@param mbsfn_flag Indicates that this subframe is for MCH/MCCH
/** \brief UE specific DLSCH scheduling. Retrieves next ue to be schduled from round-robin scheduler and gets the appropriate harq_pid for the subframe from PHY. If the process is active and requires a retransmission, it schedules the retransmission with the same PRB count and MCS as the first transmission. Otherwise it consults RLC for DCCH/DTCH SDUs (status with maximum number of available PRBS), builds the MAC header (timing advance sent by default) and copies
@param Mod_id Instance ID of eNB
@param frame Frame index
@param subframe Subframe on which to act
@param mbsfn_flag Indicates that MCH/MCCH is in this subframe
/* \brief Function to trigger the eNB scheduling procedure. It is called by PHY at the beginning of each subframe, \f$n$\f
and generates all DLSCH allocations for subframe \f$n\f$ and ULSCH allocations for subframe \f$n+k$\f. The resultant DCI_PDU is
ready after returning from this call.
@param Mod_id Instance ID of eNB
@param cooperation_flag Flag to indicated that this cell has cooperating nodes (i.e. that there are collaborative transport channels that
can be scheduled.
@param subframe Index of current subframe
@param calibration_flag Flag to indicate that eNB scheduler should schedule TDD auto-calibration PUSCH.
*/
voideNB_dlsch_ulsch_scheduler(module_id_tmodule_idP,uint8_tcooperation_flag,frame_tframeP,sub_frame_tsubframeP);//, int calibration_flag);
/* \brief Function to retrieve result of scheduling (DCI) in current subframe. Can be called an arbitrary numeber of times after eNB_dlsch_ulsch_scheduler
/* \brief Allocates a set of PRBS for a particular UE. This is a simple function for the moment, later it should process frequency-domain CQI information and/or PMI information. Currently it just returns the first PRBS that are available in the subframe based on the number requested.
@param UE_id Index of UE on which to act
@param nb_rb Number of PRBs allocated to UE by scheduler
@param rballoc Pointer to bit-map of current PRB allocation given to previous users/control channels. This is updated for subsequent calls to the routine.
@returns an rballoc bitmap for resource type 0 allocation (DCI).
/* \brief Called by PHY to get sdu for PUSCH transmission. It performs the following operations: Checks BSR for DCCH, DCCH1 and DTCH corresponding to previous values computed either in SR or BSR procedures. It gets rlc status indications on DCCH,DCCH1 and DTCH and forms BSR elements and PHR in MAC header. CRNTI element is not supported yet. It computes transport block for up to 3 SDUs and generates header and forms the complete MAC SDU.
/* \brief Function called by PHY to retrieve information to be transmitted using the RA procedure. If the UE is not in PUSCH mode for a particular eNB index, this is assumed to be an Msg3 and MAC attempts to retrieves the CCCH message from RRC. If the UE is in PUSCH mode for a particular eNB index and PUCCH format 0 (Scheduling Request) is not activated, the MAC may use this resource for random-access to transmit a BSR along with the C-RNTI control element (see 5.1.4 from 36.321)
@param Mod_id Index of UE instance
@param Mod_id Component Carrier Index
@param New_Msg3 Flag to indicate this call is for a new Msg3
@param subframe Index of subframe for PRACH transmission (0 ... 9)
/* \brief Function called by PHY to process the received RAR. It checks that the preamble matches what was sent by the eNB and provides the timing advance and t-CRNTI.
@param Mod_id Index of UE instance
@param CC_id Index to a component carrier
@param frame Frame index
@param ra_rnti RA_RNTI value
@param dlsch_buffer Pointer to dlsch_buffer containing RAR PDU
@param t_crnti Pointer to PHY variable containing the T_CRNTI
@param preamble_index Preamble Index used by PHY to transmit the PRACH. This should match the received RAR to trigger the rest of
random-access procedure
@param selected_rar_buffer the output buffer for storing the selected RAR header and RAR payload
@returns timing advance or 0xffff if preamble doesn't match
*/
uint16_t
ue_process_rar(
constmodule_id_tmodule_idP,
constintCC_id,
constframe_tframeP,
constrnti_tra_rnti,
uint8_t*constdlsch_buffer,
rnti_t*constt_crnti,
constuint8_tpreamble_index,
uint8_t*selected_rar_buffer
);
/* \brief Generate header for UL-SCH. This function parses the desired control elements and sdus and generates the header as described
in 36-321 MAC layer specifications. It returns the number of bytes used for the header to be used as an offset for the payload
in the ULSCH buffer.
@param mac_header Pointer to the first byte of the MAC header (UL-SCH buffer)
@param num_sdus Number of SDUs in the payload
@param short_padding Number of bytes for short padding (0,1,2)
@param sdu_lengths Pointer to array of SDU lengths
@param sdu_lcids Pointer to array of LCIDs (the order must be the same as the SDU length array)
@param power_headroom Pointer to power headroom command (NULL means not present in payload)
@param crnti Pointer to CRNTI command (NULL means not present in payload)
@param truncated_bsr Pointer to Truncated BSR command (NULL means not present in payload)
@param short_bsr Pointer to Short BSR command (NULL means not present in payload)
@param long_bsr Pointer to Long BSR command (NULL means not present in payload)
@param post_padding Number of bytes for padding at the end of MAC PDU
\brief UE scheduler where all the ue background tasks are done. This function performs the following: 1) Trigger PDCP every 5ms 2) Call RRC for link status return to PHY3) Perform SR/BSR procedures for scheduling feedback 4) Perform PHR procedures.
\param[in] module_idP instance of the UE
\param[in] rxFrame the RX frame number
\param[in] rxSubframe the RX subframe number
\param[in] txFrame the TX frame number
\param[in] txSubframe the TX subframe number
\param[in] direction subframe direction
\param[in] eNB_index instance of eNB
@returns L2 state (CONNETION_OK or CONNECTION_LOST or PHY_RESYNCH)
*/
UE_L2_STATE_tue_scheduler(
constmodule_id_tmodule_idP,
constframe_trxFrameP,
constsub_frame_trxSubframe,
constframe_ttxFrameP,
constsub_frame_ttxSubframe,
constlte_subframe_tdirection,
constuint8_teNB_index,
constintCC_id);
/*! \fn int cba_access(module_id_t module_idP,frame_t frameP,sub_frame_t subframe, uint8_t eNB_index,uint16_t buflen);
\brief determine whether to use cba resource to transmit or not
/*! \fn locate_BsrIndexByBufferSize (int *table, int size, int value)
\brief locate the BSR level in the table as defined in 36.321. This function requires that he values in table to be monotonic, either increasing or decreasing. The returned value is not less than 0, nor greater than n-1, where n is the size of table.
/** \brief RRC Configuration primitive for PHY/MAC. Allows configuration of PHY/MAC resources based on System Information (SI), RRCConnectionSetup and RRCConnectionReconfiguration messages.
@param Mod_id Instance ID of eNB
@param CC_id Component Carrier of the eNB
@param eNB_flag Indicates if this is a eNB or UE configuration
@param rntiP id of UE if this is an eNB configuration
@param eNB_id Index of eNB if this is a UE configuration
@param radioResourceConfigCommon Structure from SIB2 for common radio parameters (if NULL keep existing configuration)
@param physcialConfigDedicated Structure from RRCConnectionSetup or RRCConnectionReconfiguration for dedicated PHY parameters (if NULL keep existing configuration)
@param measObj Structure from RRCConnectionReconfiguration for UE measurement procedures
@param mac_MainConfig Structure from RRCConnectionSetup or RRCConnectionReconfiguration for dedicated MAC parameters (if NULL keep existing configuration)
@param logicalChannelIdentity Logical channel identity index of corresponding logical channel config
@param logicalChannelConfig Pointer to logical channel configuration
@param measGapConfig Measurement Gap configuration for MAC (if NULL keep existing configuration)
/* \brief Function to retrieve result of scheduling (DCI) in current subframe. Can be called an arbitrary numeber of times after eNB_dlsch_ulsch_scheduler