srsLTE/srsue/hdr/stack/mac/mac.h

197 lines
6.1 KiB
C
Raw Normal View History

2019-04-26 12:27:38 -07:00
/*
* Copyright 2013-2019 Software Radio Systems Limited
2017-05-30 06:38:04 -07:00
*
2019-04-26 12:27:38 -07:00
* This file is part of srsLTE.
2017-05-30 06:38:04 -07:00
*
2019-04-26 12:27:38 -07:00
* srsLTE is free software: you can redistribute it and/or modify
2017-05-30 06:38:04 -07:00
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
2019-04-26 12:27:38 -07:00
* srsLTE is distributed in the hope that it will be useful,
2017-05-30 06:38:04 -07:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
2018-03-31 10:04:04 -07:00
#ifndef SRSUE_MAC_H
#define SRSUE_MAC_H
2017-05-30 06:38:04 -07:00
2019-01-17 03:42:01 -08:00
#include "demux.h"
#include "dl_harq.h"
#include "mac_metrics.h"
2019-01-17 03:42:01 -08:00
#include "mux.h"
#include "proc_bsr.h"
#include "proc_phr.h"
2019-01-17 03:42:01 -08:00
#include "proc_ra.h"
#include "proc_sr.h"
#include "srslte/common/log.h"
#include "srslte/common/mac_pcap.h"
#include "srslte/common/threads.h"
2019-01-17 03:42:01 -08:00
#include "srslte/common/timers.h"
#include "srslte/common/tti_sync_cv.h"
#include "srslte/interfaces/ue_interfaces.h"
#include "ul_harq.h"
#include <condition_variable>
#include <mutex>
2017-05-30 06:38:04 -07:00
namespace srsue {
2019-04-23 01:53:11 -07:00
class mac : public mac_interface_phy_lte,
2019-04-23 01:53:11 -07:00
public mac_interface_rrc,
public srslte::timer_callback,
public srslte::mac_interface_timers,
public mac_interface_demux
2017-05-30 06:38:04 -07:00
{
public:
mac(srslte::log* log_);
~mac();
bool init(phy_interface_mac_lte* phy, rlc_interface_mac* rlc, rrc_interface_mac* rrc);
2017-05-30 06:38:04 -07:00
void stop();
2019-04-23 01:53:11 -07:00
void get_metrics(mac_metrics_t m[SRSLTE_MAX_CARRIERS]);
2017-05-30 06:38:04 -07:00
2019-04-23 01:53:11 -07:00
/******** Interface from PHY (PHY -> MAC) ****************/
2017-05-30 06:38:04 -07:00
/* see mac_interface.h for comments */
2019-04-23 01:53:11 -07:00
void new_grant_ul(uint32_t cc_idx, mac_grant_ul_t grant, tb_action_ul_t* action);
void new_grant_dl(uint32_t cc_idx, mac_grant_dl_t grant, tb_action_dl_t* action);
void new_mch_dl(srslte_pdsch_grant_t phy_grant, tb_action_dl_t* action);
void tb_decoded(uint32_t cc_idx, mac_grant_dl_t grant, bool ack[SRSLTE_MAX_CODEWORDS]);
2017-05-30 06:38:04 -07:00
void bch_decoded_ok(uint8_t *payload, uint32_t len);
2019-04-23 01:53:11 -07:00
uint16_t get_dl_sched_rnti(uint32_t tti);
uint16_t get_ul_sched_rnti(uint32_t tti);
2017-05-30 06:38:04 -07:00
2019-04-23 01:53:11 -07:00
void mch_decoded(uint32_t len, bool crc);
void process_mch_pdu(uint32_t len);
void set_mbsfn_config(uint32_t nof_mbsfn_services);
2019-04-23 01:53:11 -07:00
void run_tti(const uint32_t tti);
/******** Interface from RRC (RRC -> MAC) ****************/
2017-05-30 06:38:04 -07:00
void bcch_start_rx(int si_window_start, int si_window_length);
2019-04-23 01:53:11 -07:00
void bcch_stop_rx();
void pcch_start_rx();
2017-05-30 06:38:04 -07:00
void setup_lcid(uint32_t lcid, uint32_t lcg, uint32_t priority, int PBR_x_tti, uint32_t BSD);
void setup_lcid(const logical_channel_config_t& config);
void mch_start_rx(uint32_t lcid);
void reconfiguration(const uint32_t& cc_idx, const bool& enable);
2017-11-23 10:46:34 -08:00
void reset();
void wait_uplink();
2017-05-30 06:38:04 -07:00
2019-04-23 01:53:11 -07:00
/******** set/get MAC configuration ****************/
void set_config(mac_cfg_t& mac_cfg);
2017-05-30 06:38:04 -07:00
void set_contention_id(uint64_t uecri);
2017-11-23 10:46:34 -08:00
2019-04-23 01:53:11 -07:00
/******* interface from demux object ****************/
void reset_harq(uint32_t cc_idx);
bool contention_resolution_id_rcv(uint64_t id);
2017-11-23 10:46:34 -08:00
void start_noncont_ho(uint32_t preamble_index, uint32_t prach_mask);
void start_cont_ho();
2017-05-30 06:38:04 -07:00
void get_rntis(ue_rnti_t *rntis);
2017-11-23 10:46:34 -08:00
void set_ho_rnti(uint16_t crnti, uint16_t target_pci);
2017-05-30 06:38:04 -07:00
void start_pcap(srslte::mac_pcap* pcap);
2017-09-19 06:15:25 -07:00
// Timer callback interface
void timer_expired(uint32_t timer_id);
2017-09-19 06:15:25 -07:00
2017-05-30 06:38:04 -07:00
uint32_t get_current_tti();
// Interface for upper-layer timers
srslte::timers::timer* timer_get(uint32_t timer_id);
void timer_release_id(uint32_t timer_id);
uint32_t timer_get_unique_id();
2019-04-23 01:53:11 -07:00
private:
void clear_rntis();
bool is_in_window(uint32_t tti, int* start, int* len);
2017-09-19 06:15:25 -07:00
static const int MAC_MAIN_THREAD_PRIO = -1; // Use default high-priority below UHD
2019-04-23 01:53:11 -07:00
static const int MAC_PDU_THREAD_PRIO = 5;
2017-05-30 06:38:04 -07:00
// Interaction with PHY
phy_interface_mac_lte *phy_h;
2017-05-30 06:38:04 -07:00
rlc_interface_mac *rlc_h;
rrc_interface_mac *rrc_h;
srslte::log *log_h;
mac_interface_phy_lte::mac_phy_cfg_mbsfn_t phy_mbsfn_cfg;
2017-05-30 06:38:04 -07:00
2019-04-23 01:53:11 -07:00
// RNTI search window scheduling
int si_window_length, si_window_start;
int ra_window_length, ra_window_start;
int p_window_start;
// UE-specific RNTIs
ue_rnti_t uernti;
2017-05-30 06:38:04 -07:00
/* Multiplexing/Demultiplexing Units */
2019-04-23 01:53:11 -07:00
mux mux_unit;
demux demux_unit;
2017-06-23 04:19:18 -07:00
/* DL/UL HARQ */
dl_harq_entity_vector dl_harq;
ul_harq_entity_vector ul_harq;
ul_harq_cfg_t ul_harq_cfg;
2019-04-23 01:53:11 -07:00
2017-05-30 06:38:04 -07:00
/* MAC Uplink-related Procedures */
ra_proc ra_procedure;
sr_proc sr_procedure;
bsr_proc bsr_procedure;
phr_proc phr_procedure;
/* Buffers for PCH reception (not included in DL HARQ) */
const static uint32_t pch_payload_buffer_sz = 8*1024;
srslte_softbuffer_rx_t pch_softbuffer;
uint8_t pch_payload_buffer[pch_payload_buffer_sz];
/* Buffers for MCH reception (not included in DL HARQ) */
const static uint32_t mch_payload_buffer_sz = SRSLTE_MAX_BUFFER_SIZE_BYTES;
srslte_softbuffer_rx_t mch_softbuffer;
uint8_t mch_payload_buffer[mch_payload_buffer_sz];
srslte::mch_pdu mch_msg;
2017-05-30 06:38:04 -07:00
/* Functions for MAC Timers */
uint32_t timer_alignment;
2019-04-23 01:53:11 -07:00
void setup_timers(int time_alignment_timer);
void timer_alignment_expire();
srslte::timers timers;
2017-05-30 06:38:04 -07:00
// pointer to MAC PCAP object
srslte::mac_pcap* pcap = nullptr;
bool is_first_ul_grant = false;
2017-05-30 06:38:04 -07:00
mac_metrics_t metrics[SRSLTE_MAX_CARRIERS] = {};
2018-02-24 12:29:57 -08:00
bool initialized = false;
2017-05-30 06:38:04 -07:00
/* Class to process MAC PDUs from DEMUX unit */
class pdu_process : public thread {
public:
explicit pdu_process(demux* demux_unit);
~pdu_process();
2017-05-30 06:38:04 -07:00
void notify();
void stop();
private:
void run_thread() final;
bool running = false;
bool have_data = false;
std::mutex mutex;
std::condition_variable cvar;
demux* demux_unit = nullptr;
2017-05-30 06:38:04 -07:00
};
pdu_process pdu_process_thread;
};
} // namespace srsue
2018-03-31 10:04:04 -07:00
#endif // SRSUE_MAC_H