IEEE802154A.h

00001 /* -*- mode:c++ -*- ********************************************************
00002  * file:        IEEE802154A.h
00003  *
00004  * author:      Jerome Rousselot <jerome.rousselot@csem.ch>
00005  *
00006  * copyright:   (C) 2008 Centre Suisse d'Electronique et Microtechnique (CSEM) SA
00007  *        Systems Engineering
00008  *              Real-Time Software and Networking
00009  *              Jaquet-Droz 1, CH-2002 Neuchatel, Switzerland.
00010  *
00011  *              This program is free software; you can redistribute it
00012  *              and/or modify it under the terms of the GNU General Public
00013  *              License as published by the Free Software Foundation; either
00014  *              version 2 of the License, or (at your option) any later
00015  *              version.
00016  *              For further information see file COPYING
00017  *              in the top level directory
00018  * description: this class holds constants specified in IEEE 802.15.4A UWB-IR Phy
00019  * acknowledgment: this work was supported (in part) by the National Competence
00020  *          Center in Research on Mobile Information and Communication Systems
00021  *        NCCR-MICS, a center supported by the Swiss National Science
00022  *        Foundation under grant number 5005-67322.
00023  ***************************************************************************/
00024 
00025 #ifndef _IEEE802154A_H
00026 #define _IEEE802154A_H
00027 
00028 #include "Signal_.h"
00029 #include <vector>
00030 #include <utility>
00031 
00032 using namespace std;
00033 
00044 class IEEE802154A {
00045 public:
00047     static const int mandatory_bitrate;
00049     static const_simtime_t mandatory_symbol;
00051     static const_simtime_t mandatory_timeShift;
00053     static const_simtime_t mandatory_pulse;
00055     static const_simtime_t mandatory_burst;
00057     static const int mandatory_pulses_per_burst;
00059     static const double mandatory_centerFreq; // in MHz !
00061     static const_simtime_t mandatory_preambleLength;
00063     static const double maxPulse;
00064 
00065     static const short C31[8][31];
00066 
00067     static const short Ci = 5;
00068 
00069     static const short shortSFD[8];
00070 
00071     static const_simtime_t MaxFrameDuration;
00072 
00073 
00074 
00075     static const int maxS = 20000;
00076     static short s_array[maxS];
00077     static int last_s;
00078 
00079     static double signalStart; // we cannot use a simtime_t here because the scale exponent is not yet known at initialization.
00080 
00082   static const int NSync = 64;  // default sync preamble length
00084   static const short CLength = 31;
00086   static const short spreadingdL = 16;
00088   static const_simtime_t Tpsym;
00089 
00091   static const short RSSymbolLength = 6;
00093   static const short RSMaxSymbolErrors = 4; // =(n-k)/2
00094 
00096   static const int MaxPSDULength = 128;
00097 
00099   static const_simtime_t tFirstSyncPulseMax;
00100 
00101     enum UWBPRF {
00102       PRF_OFF,
00103       NOMINAL_4_M,
00104       NOMINAL_16_M,
00105       NOMINAL_64_M
00106     };
00107 
00108     enum Ranging {
00109           NON_RANGING,
00110           ALL_RANGING,
00111           PHY_HEADER_ONLY
00112     };
00113 
00114     enum UWBPreambleSymbolRepetitions {
00115       PSR_SHORT=16,
00116       PSR_DEFAULT=64,
00117       PSR_MEDIUM=1024,
00118       PSR_LONG=4096
00119     };
00120 
00121     enum DataRate {
00122               DATA_RATE_0,
00123               DATA_RATE_1,
00124               DATA_RATE_2,
00125               DATA_RATE_3,
00126               DATA_RATE_4
00127     };
00128 
00129 public:
00131     struct config {
00132       int channel;
00133       UWBPRF prf;
00134       Ranging ranging;
00135       UWBPreambleSymbolRepetitions NSync;
00136       int CLength;
00137       int spreadingdL;    // spreading deltaL
00138       int Ncpb;
00139       int bitrate;
00140       int nbPulsesPerBurst;
00141 
00142 //      simtime_t sync_symbol_duration;
00143 //      simtime_t data_symbol_duration;
00144 //      simtime_t shift_duration;
00145 //      simtime_t pulse_duration;
00146 //      simtime_t burst_duration;
00147 //      simtime_t preambleLength;
00148       double sync_symbol_duration;
00149       double data_symbol_duration;
00150       double shift_duration;
00151       double pulse_duration;
00152       double burst_duration;
00153       double preambleLength;
00154 
00155       double centerFrequency;
00156     };
00157 
00158 
00159 
00160 
00161     typedef std::pair<Signal *, vector<bool> * > signalAndData;
00162 
00163     /* @brief Sets the configuration of the IEEE802.15.4A standard.
00164      *  Use this (and the struct config) to implement optional modes of the standard. */
00165     static void setConfig(config newCfg);
00166 
00167     static config getConfig() { return cfg; }
00168 
00169     // sets the number of data bytes to encode in the data structure.
00170     static void setPSDULength(int _psduLength);
00171 
00172     /* @brief Generates a frame starting at time signalStart and composed of
00173    * psduLength bytes of data (this value must be set before by using setPSDULength()).
00174      * If allZeros is set to true, all bit values are equal to zero.
00175      * If it is set to false or undefined, bit values are generated randomly.
00176      * The returned structure is a pair. Its first component is the Signal*,
00177      * and the second component is a vector of bool with the the generated bit values.
00178      * */
00179     static signalAndData generateIEEE802154AUWBSignal(simtime_t signalStart, bool allZeros=false);
00180 
00181     static simtime_t getMaxFrameDuration();
00182 
00183 // Constants from standard
00184     /* @brief Always 16 symbols for the PHY header */
00185     static const int Nhdr = 16;
00186 
00187 
00188 protected:
00189   static void generateSyncPreamble(Mapping* mapping, Argument* arg);
00190   static void generateSFD(Mapping* mapping, Argument* arg);
00191   static void generatePhyHeader(Mapping* mapping, Argument* arg);
00192     static void generateBurst(Mapping* mapping, Argument* arg, simtime_t burstStart, short polarity);
00193     static void generatePulse(Mapping* mapping, Argument* arg, short polarity,
00194         double peak=IEEE802154A::maxPulse, simtime_t chip=IEEE802154A::mandatory_pulse);
00195     static void setBitRate(Signal* s);
00196     static int s(int n);
00197 
00198 
00199 public:
00200   static int psduLength;
00201   static config cfg;
00202   static const config cfg_mandatory_16M, cfg_mandatory_4M;
00203 
00204   // Compute derived parameters
00205     static simtime_t getPhyMaxFrameDuration();
00206     static simtime_t getThdr();
00207     static int getHoppingPos(int sym);
00208 
00209 };
00210 
00211 
00212 #endif  /* _IEEE802154A_H */
00213