1 | /*! \file warpmac.h |
---|
2 | \brief Header file for the WARPMAC Framework. |
---|
3 | |
---|
4 | @version 16.1 |
---|
5 | @author Chris Hunter and Patrick Murphy |
---|
6 | |
---|
7 | This header file contains the macros, function prototypes, and typedefs required for WARPMAC. |
---|
8 | */ |
---|
9 | |
---|
10 | /*! \mainpage WARP APIs |
---|
11 | * @version Used with Reference Design v16.1 |
---|
12 | * |
---|
13 | * \section change_sec CHANGELOG |
---|
14 | * http://warp.rice.edu/trac/wiki/OFDMReferenceDesign/Changelog |
---|
15 | * |
---|
16 | * \section intro_sec Introduction |
---|
17 | * |
---|
18 | * This document is the collective API for WARPMAC (the MAC design framework), |
---|
19 | * WARPPHY (the PHY driver/interface), the radio controller driver and CSMAMAC (the carrier-sensing random access |
---|
20 | * reference design). |
---|
21 | * |
---|
22 | * \section start_sec Getting Started |
---|
23 | * |
---|
24 | * Obtain the latest reference design: http://warp.rice.edu/trac/wiki/OFDMReferenceDesign . |
---|
25 | * In addition to being in the repository, all the source code for WARPMAC is available in |
---|
26 | * the reference design project and is configured to compile "as-is." |
---|
27 | * |
---|
28 | * \section licence_sec License |
---|
29 | * http://warp.rice.edu/license/ |
---|
30 | * |
---|
31 | */ |
---|
32 | |
---|
33 | #ifndef WARPMAC_H |
---|
34 | #define WARPMAC_H |
---|
35 | |
---|
36 | #include "warp_fpga_board.h" |
---|
37 | #include "xstatus.h" |
---|
38 | #include "warpphy.h" |
---|
39 | |
---|
40 | //Define which radios get used below |
---|
41 | //RADIOx_ADDR are defined by the radio controller driver |
---|
42 | //Address of the first radio |
---|
43 | #define FIRST_RADIO RADIO2_ADDR |
---|
44 | //Address of the second radio |
---|
45 | #define SECOND_RADIO RADIO3_ADDR |
---|
46 | |
---|
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 | |
---|
52 | #define MY_XEM_MAX_FRAME_SIZE 2000 |
---|
53 | |
---|
54 | //Masks for supported modulation schemes; equivalent to number of bits per symbol |
---|
55 | #define BPSK 1 |
---|
56 | #define QPSK 2 |
---|
57 | #define QAM_16 4 |
---|
58 | #define QAM_64 6 |
---|
59 | |
---|
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 |
---|
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)) |
---|
67 | |
---|
68 | //2.4 GHz Band |
---|
69 | #define GHZ_2 1 |
---|
70 | //5 GHz Band |
---|
71 | #define GHZ_5 0 |
---|
72 | |
---|
73 | //Shortcuts for xparameters.h constants |
---|
74 | // Device IDs |
---|
75 | #define DMA_CTRL_DEVICE_ID XPAR_DMACENTRAL_0_DEVICE_ID |
---|
76 | |
---|
77 | //Average RSSI threshold for carrier sensing |
---|
78 | #define THRESH_CARRIER_SENSE 5000 |
---|
79 | |
---|
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 |
---|
91 | |
---|
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 | |
---|
96 | #define NUM_PAYLOAD_CRC_BYTES 4 |
---|
97 | //#define NUM_PAYLOAD_TAIL_BYTES 1 //Use for coded PHY |
---|
98 | #define NUM_PAYLOAD_TAIL_BYTES 0 //Use for uncoded PHY |
---|
99 | |
---|
100 | //Assign IDs for various timers |
---|
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 |
---|
109 | |
---|
110 | //Enable polling of timers that are actually used (6-7 are always enabled) |
---|
111 | #define POLL_TIMER0 |
---|
112 | #define POLL_TIMER1 |
---|
113 | #define POLL_TIMER2 |
---|
114 | #define POLL_TIMER3 |
---|
115 | #define POLL_TIMER4 |
---|
116 | #define POLL_TIMER5 |
---|
117 | |
---|
118 | //Number of clock cycles in 1us (X for XMHz PLB hosting the timer core) |
---|
119 | #define TIMERCLK_CYCLES_PER_USEC 80 |
---|
120 | #define TIMERCLK_CYCLES_PER_MSEC 80000 |
---|
121 | |
---|
122 | //Poll the user I/O every 1 msec |
---|
123 | #define USERIO_POLLRATE 1000*TIMERCLK_CYCLES_PER_USEC |
---|
124 | |
---|
125 | ///Structure contains the header contents of a packet |
---|
126 | typedef struct { |
---|
127 | ///Physical layer header struct |
---|
128 | phyHeader header; |
---|
129 | } Macframe __attribute__((__aligned__(8))); |
---|
130 | |
---|
131 | ///Structure of miscellaneous control bits needed for correct operation of the MAC. |
---|
132 | typedef struct { |
---|
133 | ///Timeout time of system |
---|
134 | volatile unsigned int timeout; |
---|
135 | ///Smallest time interval in system |
---|
136 | volatile unsigned int slotTime; |
---|
137 | ///Maximum number of retransmissions before dropping a packet |
---|
138 | volatile unsigned char maxReSend; |
---|
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; |
---|
143 | ///Whether the Emac is currently enabled |
---|
144 | volatile unsigned char enableDataFromNetwork; |
---|
145 | volatile unsigned char pktBuf_phyTx; |
---|
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 |
---|
151 | volatile unsigned char mod_fullRateA; |
---|
152 | //volatile unsigned char mod_fullRateB; |
---|
153 | } Maccontrol; |
---|
154 | |
---|
155 | //Function prototypes |
---|
156 | void nullCallback(void* param); |
---|
157 | int nullCallback_i(void* param); |
---|
158 | void warpmac_init(); |
---|
159 | inline void warpmac_pollPeripherals(); |
---|
160 | void warpmac_pollPhy(); |
---|
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); |
---|
169 | void warpmac_setTimer(int type); |
---|
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)()); |
---|
175 | void warpmac_setBaseRate(unsigned char rate); |
---|
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); |
---|
179 | void warpmac_finishPhyXmit(); |
---|
180 | inline void warpmac_setRxBuffers(Macframe* rxFrame, unsigned char phyRxBuff); |
---|
181 | inline void warpmac_setPHYTxBuffer(unsigned char txBuff); |
---|
182 | inline void warpmac_setEMACRxBuffer(unsigned char emacRxBuff); |
---|
183 | int warpmac_decrementRemainingReSend(Macframe* packet); |
---|
184 | void warpmac_resetCurrentCW(); |
---|
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); |
---|
192 | inline void warpmac_setDebugGPIO(unsigned char val, unsigned char mask); |
---|
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); |
---|
198 | void warpmac_startPacketGeneration(unsigned int length, unsigned int interval); |
---|
199 | void warpmac_stopPacketGeneration(); |
---|
200 | int warpmac_getMyId(); |
---|
201 | |
---|
202 | inline void printBytes(unsigned char* data, int length); |
---|
203 | |
---|
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); |
---|
214 | |
---|
215 | #elif defined WARP_FPGA_BOARD_V2_2 |
---|
216 | void userIO_handler(void *InstancePtr); |
---|
217 | void warpmac_incrementLEDLow(); |
---|
218 | void warpmac_incrementLEDHigh(); |
---|
219 | void warpmac_leftHex(unsigned char x); |
---|
220 | void warpmac_rightHex(unsigned char x); |
---|
221 | void warpmac_middleHex(unsigned char x); |
---|
222 | #endif//ifdef WARP_FPGA_BOARD_V1_2 |
---|
223 | |
---|
224 | #endif//ifndef WARPMAC_H |
---|
225 | |
---|
226 | |
---|
227 | |
---|