[665] | 1 | /*! \file warpmac.h |
---|
| 2 | \brief Header file for the WARPMAC Framework. |
---|
[444] | 3 | |
---|
[1643] | 4 | @version 16.1 |
---|
[941] | 5 | @author Chris Hunter and Patrick Murphy |
---|
[665] | 6 | |
---|
| 7 | This header file contains the macros, function prototypes, and typedefs required for WARPMAC. |
---|
| 8 | */ |
---|
| 9 | |
---|
[677] | 10 | /*! \mainpage WARP APIs |
---|
[1642] | 11 | * @version Used with Reference Design v16.1 |
---|
[665] | 12 | * |
---|
[903] | 13 | * \section change_sec CHANGELOG |
---|
[1169] | 14 | * http://warp.rice.edu/trac/wiki/OFDMReferenceDesign/Changelog |
---|
[903] | 15 | * |
---|
[665] | 16 | * \section intro_sec Introduction |
---|
| 17 | * |
---|
[825] | 18 | * This document is the collective API for WARPMAC (the MAC design framework), |
---|
[1642] | 19 | * WARPPHY (the PHY driver/interface), the radio controller driver and CSMAMAC (the carrier-sensing random access |
---|
| 20 | * reference design). |
---|
[665] | 21 | * |
---|
[678] | 22 | * \section start_sec Getting Started |
---|
[665] | 23 | * |
---|
[981] | 24 | * Obtain the latest reference design: http://warp.rice.edu/trac/wiki/OFDMReferenceDesign . |
---|
[825] | 25 | * In addition to being in the repository, all the source code for WARPMAC is available in |
---|
[677] | 26 | * the reference design project and is configured to compile "as-is." |
---|
[665] | 27 | * |
---|
[677] | 28 | * \section licence_sec License |
---|
| 29 | * http://warp.rice.edu/license/ |
---|
| 30 | * |
---|
[665] | 31 | */ |
---|
| 32 | |
---|
[444] | 33 | #ifndef WARPMAC_H |
---|
| 34 | #define WARPMAC_H |
---|
| 35 | |
---|
[1379] | 36 | #include "warp_fpga_board.h" |
---|
[665] | 37 | #include "xstatus.h" |
---|
[719] | 38 | #include "warpphy.h" |
---|
[444] | 39 | |
---|
[665] | 40 | //Define which radios get used below |
---|
| 41 | //RADIOx_ADDR are defined by the radio controller driver |
---|
[979] | 42 | //Address of the first radio |
---|
[665] | 43 | #define FIRST_RADIO RADIO2_ADDR |
---|
[979] | 44 | //Address of the second radio |
---|
[665] | 45 | #define SECOND_RADIO RADIO3_ADDR |
---|
[444] | 46 | |
---|
[1282] | 47 | //Helper macros for constructing headers |
---|
| 48 | #define htons(A) ((((Xuint16)(A) & 0xff00) >> 8) | (((Xuint16)(A) & 0x00ff) << 8)) |
---|
| 49 | #define NODEID_TO_ADDR(theID) ( theID & 0xFFFF ) |
---|
| 50 | #define ADDR_TO_NODEID(theAddr) ( theAddr & 0xFFFF ) |
---|
| 51 | |
---|
[444] | 52 | #define MY_XEM_MAX_FRAME_SIZE 2000 |
---|
| 53 | |
---|
[1015] | 54 | //Masks for supported modulation schemes; equivalent to number of bits per symbol |
---|
| 55 | #define BPSK 1 |
---|
[1379] | 56 | #define QPSK 2 |
---|
[1015] | 57 | #define QAM_16 4 |
---|
| 58 | #define QAM_64 6 |
---|
[665] | 59 | |
---|
[1015] | 60 | //Constants used for packet headers specifying full-rate modulation per-packet |
---|
| 61 | // This constant fills in an 8-bit field in the header |
---|
| 62 | // Each 4-bit nibble corresponds to an antenna |
---|
[1103] | 63 | #define HDR_FULLRATE_BPSK (BPSK | (BPSK<<4)) |
---|
| 64 | #define HDR_FULLRATE_QPSK (QPSK | (QPSK<<4)) |
---|
| 65 | #define HDR_FULLRATE_QAM_16 (QAM_16 | (QAM_16<<4)) |
---|
| 66 | #define HDR_FULLRATE_QAM_64 (QAM_64 | (QAM_64<<4)) |
---|
[1015] | 67 | |
---|
[1379] | 68 | //2.4 GHz Band |
---|
| 69 | #define GHZ_2 1 |
---|
[979] | 70 | //5 GHz Band |
---|
[665] | 71 | #define GHZ_5 0 |
---|
| 72 | |
---|
[941] | 73 | //Shortcuts for xparameters.h constants |
---|
| 74 | // Device IDs |
---|
| 75 | #define DMA_CTRL_DEVICE_ID XPAR_DMACENTRAL_0_DEVICE_ID |
---|
| 76 | |
---|
[1379] | 77 | //Average RSSI threshold for carrier sensing |
---|
| 78 | #define THRESH_CARRIER_SENSE 5000 |
---|
[944] | 79 | |
---|
[1379] | 80 | //Event ID's for callback registration |
---|
| 81 | #define EVENT_UPBUTTON 1 |
---|
| 82 | #define EVENT_LEFTBUTTON 2 |
---|
| 83 | #define EVENT_RIGHTBUTTON 3 |
---|
| 84 | #define EVENT_MIDDLEBUTTON 4 |
---|
| 85 | #define EVENT_TIMER 5 |
---|
| 86 | #define EVENT_DATAFROMNETWORK 6 |
---|
| 87 | #define EVENT_MGMTPKT 7 |
---|
| 88 | #define EVENT_PHYGOODHEADER 8 |
---|
| 89 | #define EVENT_PHYBADHEADER 9 |
---|
| 90 | #define EVENT_UARTRX 10 |
---|
[941] | 91 | |
---|
[825] | 92 | //The number of bytes in the header must be fixed and known by every node ahead of time |
---|
| 93 | // It also must occupy an integral number of OFDM symbols (i.e. the base-rate symbols) |
---|
| 94 | #define NUM_HEADER_BYTES 24 |
---|
| 95 | |
---|
[1103] | 96 | #define NUM_PAYLOAD_CRC_BYTES 4 |
---|
[1164] | 97 | //#define NUM_PAYLOAD_TAIL_BYTES 1 //Use for coded PHY |
---|
| 98 | #define NUM_PAYLOAD_TAIL_BYTES 0 //Use for uncoded PHY |
---|
[1103] | 99 | |
---|
[1379] | 100 | //Assign IDs for various timers |
---|
[1633] | 101 | #define TIMEOUT_TIMER 0 |
---|
| 102 | #define BACKOFF_TIMER 1 |
---|
| 103 | #define USER_TIMER_A 2 |
---|
| 104 | #define USER_TIMER_B 3 |
---|
| 105 | #define USER_TIMER_C 4 |
---|
| 106 | #define USER_TIMER_D 5 |
---|
| 107 | #define USERIO_TIMER 6 |
---|
| 108 | #define PKTGEN_TIMER 7 |
---|
[1477] | 109 | |
---|
[1633] | 110 | //Enable polling of timers that are actually used (6-7 are always enabled) |
---|
[1379] | 111 | #define POLL_TIMER0 |
---|
| 112 | #define POLL_TIMER1 |
---|
[1633] | 113 | #define POLL_TIMER2 |
---|
[1650] | 114 | #define POLL_TIMER3 |
---|
| 115 | #define POLL_TIMER4 |
---|
| 116 | #define POLL_TIMER5 |
---|
[1379] | 117 | |
---|
| 118 | //Number of clock cycles in 1us (X for XMHz PLB hosting the timer core) |
---|
| 119 | #define TIMERCLK_CYCLES_PER_USEC 80 |
---|
[1650] | 120 | #define TIMERCLK_CYCLES_PER_MSEC 80000 |
---|
[1379] | 121 | |
---|
[1633] | 122 | //Poll the user I/O every 1 msec |
---|
| 123 | #define USERIO_POLLRATE 1000*TIMERCLK_CYCLES_PER_USEC |
---|
[1379] | 124 | |
---|
[982] | 125 | ///Structure contains the header contents of a packet |
---|
[543] | 126 | typedef struct { |
---|
[719] | 127 | ///Physical layer header struct |
---|
| 128 | phyHeader header; |
---|
| 129 | } Macframe __attribute__((__aligned__(8))); |
---|
[444] | 130 | |
---|
[982] | 131 | ///Structure of miscellaneous control bits needed for correct operation of the MAC. |
---|
[444] | 132 | typedef struct { |
---|
[665] | 133 | ///Timeout time of system |
---|
[444] | 134 | volatile unsigned int timeout; |
---|
[665] | 135 | ///Smallest time interval in system |
---|
[444] | 136 | volatile unsigned int slotTime; |
---|
[665] | 137 | ///Maximum number of retransmissions before dropping a packet |
---|
[444] | 138 | volatile unsigned char maxReSend; |
---|
[1176] | 139 | ///Maximum contention window index: [0, 2^(maxCW+4)-1] |
---|
| 140 | volatile unsigned char maxCW; |
---|
| 141 | ///Current contention window index |
---|
| 142 | volatile unsigned char currentCW; |
---|
[665] | 143 | ///Whether the Emac is currently enabled |
---|
[1379] | 144 | volatile unsigned char enableDataFromNetwork; |
---|
[1404] | 145 | volatile unsigned char pktBuf_phyTx; |
---|
[1379] | 146 | volatile unsigned char pktBuf_phyRx; |
---|
| 147 | volatile unsigned char pktBuf_emacRx; |
---|
| 148 | volatile unsigned char dummyPacketMode; |
---|
| 149 | |
---|
| 150 | ///Constellation order of the full rate symbols |
---|
[617] | 151 | volatile unsigned char mod_fullRateA; |
---|
[825] | 152 | //volatile unsigned char mod_fullRateB; |
---|
[444] | 153 | } Maccontrol; |
---|
| 154 | |
---|
[1379] | 155 | //Function prototypes |
---|
[941] | 156 | void nullCallback(void* param); |
---|
[1494] | 157 | int nullCallback_i(void* param); |
---|
[1011] | 158 | void warpmac_init(); |
---|
[1379] | 159 | inline void warpmac_pollPeripherals(); |
---|
[1712] | 160 | void warpmac_pollPhy(); |
---|
[1379] | 161 | inline void warpmac_pollTimer(); |
---|
| 162 | inline void warpmac_pollDataSource(); |
---|
| 163 | inline void phyRx_goodHeader_handler(); |
---|
| 164 | inline void phyRx_badHeader_handler(); |
---|
| 165 | void emacRx_handler(); |
---|
| 166 | inline void warpmac_waitForDMA(); |
---|
| 167 | inline void warpmac_clearTimer(unsigned char theTimer); |
---|
| 168 | inline void warpmac_startTimer(unsigned char theTimer, unsigned char mode); |
---|
[1011] | 169 | void warpmac_setTimer(int type); |
---|
[1379] | 170 | inline unsigned int randNum(unsigned int N); |
---|
| 171 | inline int warpmac_carrierSense(); |
---|
| 172 | inline void warpmac_prepPktToNetwork(void* thePkt, unsigned int length); |
---|
| 173 | inline void warpmac_startPktToNetwork(unsigned int length); |
---|
| 174 | void warpmac_setCallback(int eventID, void(*handler)()); |
---|
[665] | 175 | void warpmac_setBaseRate(unsigned char rate); |
---|
[1379] | 176 | int warpmac_setAntennaMode(unsigned int txMode, unsigned int rxMode); |
---|
| 177 | void warpmac_prepPhyForXmit(Macframe* packet, unsigned char buffer); |
---|
| 178 | inline void warpmac_startPhyXmit(unsigned char buffer); |
---|
[941] | 179 | void warpmac_finishPhyXmit(); |
---|
[1379] | 180 | inline void warpmac_setRxBuffers(Macframe* rxFrame, unsigned char phyRxBuff); |
---|
[1404] | 181 | inline void warpmac_setPHYTxBuffer(unsigned char txBuff); |
---|
| 182 | inline void warpmac_setEMACRxBuffer(unsigned char emacRxBuff); |
---|
[1379] | 183 | int warpmac_decrementRemainingReSend(Macframe* packet); |
---|
[1176] | 184 | void warpmac_resetCurrentCW(); |
---|
[1379] | 185 | inline void warpmac_setMaxResend(unsigned int c); |
---|
| 186 | inline void warpmac_setMaxCW(unsigned int c); |
---|
| 187 | inline void warpmac_setTimeout(unsigned int time); |
---|
| 188 | inline void warpmac_setSlotTime(unsigned int time); |
---|
| 189 | inline int warpmac_inTimeout(); |
---|
| 190 | inline int warpmac_inBackoff(); |
---|
| 191 | inline void warpmac_setCSMA(char mode); |
---|
[1491] | 192 | inline void warpmac_setDebugGPIO(unsigned char val, unsigned char mask); |
---|
[1379] | 193 | inline void warpmac_enableDataFromNetwork(); |
---|
| 194 | inline void warpmac_disableDataFromNetwork(); |
---|
| 195 | inline char warpmac_finishPhyRecv(); |
---|
| 196 | void warpmac_uartRecvHandler(void *CallBackRef); |
---|
| 197 | inline void warpmac_setDummyPacketMode(char mode); |
---|
[1221] | 198 | void warpmac_startPacketGeneration(unsigned int length, unsigned int interval); |
---|
| 199 | void warpmac_stopPacketGeneration(); |
---|
[1379] | 200 | int warpmac_getMyId(); |
---|
[1221] | 201 | |
---|
[1379] | 202 | inline void printBytes(unsigned char* data, int length); |
---|
[543] | 203 | |
---|
[1379] | 204 | //**********START***********// |
---|
| 205 | // FPGA Board Specific Code // |
---|
| 206 | //**************************// |
---|
| 207 | #ifdef WARP_FPGA_BOARD_V1_2 |
---|
| 208 | void userIO_handler(void *InstancePtr); |
---|
| 209 | void warpmac_incrementLEDLow(); |
---|
| 210 | void warpmac_incrementLEDHigh(); |
---|
| 211 | unsigned char sevenSegmentMap(unsigned char x); |
---|
| 212 | void warpmac_leftHex(unsigned char x); |
---|
| 213 | void warpmac_rightHex(unsigned char x); |
---|
[665] | 214 | |
---|
[1379] | 215 | #elif defined WARP_FPGA_BOARD_V2_2 |
---|
| 216 | void userIO_handler(void *InstancePtr); |
---|
| 217 | void warpmac_incrementLEDLow(); |
---|
| 218 | void warpmac_incrementLEDHigh(); |
---|
[1369] | 219 | void warpmac_leftHex(unsigned char x); |
---|
| 220 | void warpmac_rightHex(unsigned char x); |
---|
| 221 | void warpmac_middleHex(unsigned char x); |
---|
[1379] | 222 | #endif//ifdef WARP_FPGA_BOARD_V1_2 |
---|
[1203] | 223 | |
---|
[1379] | 224 | #endif//ifndef WARPMAC_H |
---|
[1105] | 225 | |
---|
| 226 | |
---|
[1221] | 227 | |
---|