fun_ofdm  1.0
802.11a Physical Layer for USRP
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
fun::receiver_chain Class Reference

The Receiver Chain class. More...

#include <receiver_chain.h>

Public Member Functions

 receiver_chain ()
 Constructor for receiver_chain. More...
 
std::vector< std::vector
< unsigned char > > 
process_samples (std::vector< std::complex< double > > samples)
 Processes the raw time domain samples. More...
 

Private Member Functions

void add_block (fun::block_base *block)
 Adds block to the receiver call chain. More...
 
void run_block (int index, fun::block_base *block)
 Runs the block by calling its work function. More...
 

Private Attributes

frame_detectorm_frame_detector
 Detects start of frame using STS. More...
 
timing_syncm_timing_sync
 Aligns frame in time using LTS & some freq correction. More...
 
fft_symbolsm_fft_symbols
 Forward FFT of symbols. More...
 
channel_estm_channel_est
 Channel estimation and equalization in freq domain. More...
 
phase_trackerm_phase_tracker
 Phase rotation tracking. More...
 
frame_decoderm_frame_decoder
 Frame decoding. More...
 
std::vector< std::thread > m_threads
 Vector of threads - one for each block. More...
 
std::vector< sem_t > m_wake_sems
 Vector of semaphores used to "wake up" each block. More...
 
std::vector< sem_t > m_done_sems
 Vector of semaphores used to determine when the blocks are done. More...
 

Detailed Description

The Receiver Chain class.

Inputs raw complex doubles representing the base-band digitized time domain signal.

Outputs vector of correctly received payloads (MPDUs) which are themselves vectors of unsigned chars.

The Receiver Chain class is the main controller for the blocks that are used to receive and decode PHY layer frames. It holds the instances of each block and shifts the data through the receive chain as it is processed eventually returning the correctly received payloads (MPDUs) which can then be passed to the upper layers.

Definition at line 40 of file receiver_chain.h.

Constructor & Destructor Documentation

fun::receiver_chain::receiver_chain ( )

Constructor for receiver_chain.

-Initializes each receiver chain block:

Adds each block to the receiver chain.

Definition at line 29 of file receiver_chain.cpp.

References add_block(), m_channel_est, m_done_sems, m_fft_symbols, m_frame_decoder, m_frame_detector, m_phase_tracker, m_timing_sync, and m_wake_sems.

30  {
31  m_frame_detector = new frame_detector();
32  m_timing_sync = new timing_sync();
33  m_fft_symbols = new fft_symbols();
34  m_channel_est = new channel_est();
35  m_phase_tracker = new phase_tracker();
36  m_frame_decoder = new frame_decoder();
37 
38  // We use semaphore references, so we don't
39  // want them to move to a different memory location
40  // if the vectors get resized
41  m_wake_sems.reserve(100);
42  m_done_sems.reserve(100);
43 
44  // Add the blocks to the receiver chain
51  }

Member Function Documentation

void fun::receiver_chain::add_block ( fun::block_base block)
private

Adds block to the receiver call chain.

Parameters
blockA pointer to the block so that its work function can be called

The add_block function creates a wake & done semaphore for each block. It then creates a new thread for the block to run in and adds that thread to the thread vector for reference.

Definition at line 58 of file receiver_chain.cpp.

References m_done_sems, m_threads, m_wake_sems, and run_block().

Referenced by receiver_chain().

59  {
60  m_wake_sems.push_back(sem_t());
61  m_done_sems.push_back(sem_t());
62  int index = m_wake_sems.size() - 1;
63  sem_init(&m_wake_sems[index], 0, 0);
64  sem_init(&m_done_sems[index], 0, 0);
65  m_threads.push_back(std::thread(&receiver_chain::run_block, this, index, block));
66  }
std::vector< std::vector< unsigned char > > fun::receiver_chain::process_samples ( std::vector< std::complex< double > >  samples)

Processes the raw time domain samples.

Parameters
samplesA vector of received time-domain samples from the usrp block to pass to the receive chain for signal processing.
Returns
A vector of correctly received payloads where each payload is its own vector of unsigned chars.

This function is the main scheduler for the receive chain. It takes in raw complex samples from the usrp block and passes them first into the Frame Detector block's input buffer. It then unlocks each of the threads by posting to each block's "wake" semaphore. It then waits for each thread to post that it is done with that call to its work() function. Once all the threads are done it shifts the contents of each blocks output buffer to the input buffer of the next block in the chain and returns the contents of the Frame Decoder's output buffer.

Definition at line 106 of file receiver_chain.cpp.

References fun::block< I, O >::input_buffer, m_channel_est, m_done_sems, m_fft_symbols, m_frame_decoder, m_frame_detector, m_phase_tracker, m_timing_sync, m_wake_sems, and fun::block< I, O >::output_buffer.

Referenced by fun::receiver::receiver_chain_loop(), and test_sim().

107  {
108  // samples -> sync short in
109  m_frame_detector->input_buffer.swap(samples);
110 
111  // Unlock the threads
112  for(int x = 0; x < m_wake_sems.size(); x++) sem_post(&m_wake_sems[x]);
113 
114  // Wait for the threads to finish
115  for(int x = 0; x < m_done_sems.size(); x++) sem_wait(&m_done_sems[x]);
116 
117  // Update the buffers
123 
124  // Return any completed packets
126  }
void fun::receiver_chain::run_block ( int  index,
fun::block_base block 
)
private

Runs the block by calling its work function.

Parameters
indexthe block's index for referencing the correct semaphores for that block.
blockA pointer to the block used as a handle to access its work() function.

The run_block function is the main thread for controlling the calls to each block's work function. This function is a forever loops that first waits for the wake_sempahore to post indicating its time for the block to "wake up" and process the data that has just been placed in its input_buffer by running its work() function. Then once, the work() function returns run_block posts to the done sempahore that the block has finished processing everything in the input_buffer. At this point it loops back around and waits for the block to be "woken up" again when the next set of input data is ready.

Definition at line 78 of file receiver_chain.cpp.

References m_done_sems, m_wake_sems, and fun::block_base::work().

Referenced by add_block().

79  {
80  while(1)
81  {
82  sem_wait(&m_wake_sems[index]);
83 
84  boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time();
85  block->work();
86  boost::posix_time::time_duration elapsed = boost::posix_time::microsec_clock::local_time() - start;
87 
88  if(elapsed.total_microseconds() > (2000 / 5e6 * 1e6))
89  {
90  //std::cout << "! - " << block->name << std::endl;
91  }
92 
93  sem_post(&m_done_sems[index]);
94  }
95  }

Member Data Documentation

channel_est* fun::receiver_chain::m_channel_est
private

Channel estimation and equalization in freq domain.

Definition at line 67 of file receiver_chain.h.

Referenced by process_samples(), and receiver_chain().

std::vector<sem_t> fun::receiver_chain::m_done_sems
private

Vector of semaphores used to determine when the blocks are done.

Definition at line 95 of file receiver_chain.h.

Referenced by add_block(), process_samples(), receiver_chain(), and run_block().

fft_symbols* fun::receiver_chain::m_fft_symbols
private

Forward FFT of symbols.

Definition at line 66 of file receiver_chain.h.

Referenced by process_samples(), and receiver_chain().

frame_decoder* fun::receiver_chain::m_frame_decoder
private

Frame decoding.

Definition at line 69 of file receiver_chain.h.

Referenced by process_samples(), and receiver_chain().

frame_detector* fun::receiver_chain::m_frame_detector
private

Detects start of frame using STS.

Definition at line 64 of file receiver_chain.h.

Referenced by process_samples(), and receiver_chain().

phase_tracker* fun::receiver_chain::m_phase_tracker
private

Phase rotation tracking.

Definition at line 68 of file receiver_chain.h.

Referenced by process_samples(), and receiver_chain().

std::vector<std::thread> fun::receiver_chain::m_threads
private

Vector of threads - one for each block.

Definition at line 89 of file receiver_chain.h.

Referenced by add_block().

timing_sync* fun::receiver_chain::m_timing_sync
private

Aligns frame in time using LTS & some freq correction.

Definition at line 65 of file receiver_chain.h.

Referenced by process_samples(), and receiver_chain().

std::vector<sem_t> fun::receiver_chain::m_wake_sems
private

Vector of semaphores used to "wake up" each block.

Definition at line 92 of file receiver_chain.h.

Referenced by add_block(), process_samples(), receiver_chain(), and run_block().


The documentation for this class was generated from the following files: