source: PlatformSupport/WARPMAC/warpmac.h

Last change on this file was 1712, checked in by murphpo, 12 years ago

Updating code for OFDM ref design v17 in ISE 13.4 tools

File size: 7.4 KB
Line 
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
7This 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
126typedef 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.
132typedef 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
156void nullCallback(void* param);
157int nullCallback_i(void* param);
158void warpmac_init();
159inline void warpmac_pollPeripherals();
160void warpmac_pollPhy();
161inline void warpmac_pollTimer();
162inline void warpmac_pollDataSource();
163inline void phyRx_goodHeader_handler();
164inline void phyRx_badHeader_handler();
165void emacRx_handler();
166inline void warpmac_waitForDMA();
167inline void warpmac_clearTimer(unsigned char theTimer);
168inline void warpmac_startTimer(unsigned char theTimer, unsigned char mode);
169void warpmac_setTimer(int type);
170inline unsigned int randNum(unsigned int N);
171inline int warpmac_carrierSense();
172inline void warpmac_prepPktToNetwork(void* thePkt, unsigned int length);
173inline void warpmac_startPktToNetwork(unsigned int length);
174void warpmac_setCallback(int eventID, void(*handler)());
175void warpmac_setBaseRate(unsigned char rate);
176int warpmac_setAntennaMode(unsigned int txMode, unsigned int rxMode);
177void warpmac_prepPhyForXmit(Macframe* packet, unsigned char buffer);
178inline void warpmac_startPhyXmit(unsigned char buffer);
179void warpmac_finishPhyXmit();
180inline void warpmac_setRxBuffers(Macframe* rxFrame, unsigned char phyRxBuff);
181inline void warpmac_setPHYTxBuffer(unsigned char txBuff);
182inline void warpmac_setEMACRxBuffer(unsigned char emacRxBuff);
183int warpmac_decrementRemainingReSend(Macframe* packet);
184void warpmac_resetCurrentCW();
185inline void warpmac_setMaxResend(unsigned int c);
186inline void warpmac_setMaxCW(unsigned int c);
187inline void warpmac_setTimeout(unsigned int time);
188inline void warpmac_setSlotTime(unsigned int time);
189inline int warpmac_inTimeout();
190inline int warpmac_inBackoff();
191inline void warpmac_setCSMA(char mode);
192inline void warpmac_setDebugGPIO(unsigned char val, unsigned char mask);
193inline void warpmac_enableDataFromNetwork();
194inline void warpmac_disableDataFromNetwork();
195inline char warpmac_finishPhyRecv();
196void warpmac_uartRecvHandler(void *CallBackRef);
197inline void warpmac_setDummyPacketMode(char mode);
198void warpmac_startPacketGeneration(unsigned int length, unsigned int interval);
199void warpmac_stopPacketGeneration();
200int warpmac_getMyId();
201
202inline void printBytes(unsigned char* data, int length);
203
204//**********START***********//
205// FPGA Board Specific Code //
206//**************************//
207#ifdef WARP_FPGA_BOARD_V1_2
208void userIO_handler(void *InstancePtr);
209void warpmac_incrementLEDLow();
210void warpmac_incrementLEDHigh();
211unsigned char sevenSegmentMap(unsigned char x);
212void warpmac_leftHex(unsigned char x);
213void warpmac_rightHex(unsigned char x);
214
215#elif defined WARP_FPGA_BOARD_V2_2
216void userIO_handler(void *InstancePtr);
217void warpmac_incrementLEDLow();
218void warpmac_incrementLEDHigh();
219void warpmac_leftHex(unsigned char x);
220void warpmac_rightHex(unsigned char x);
221void warpmac_middleHex(unsigned char x);
222#endif//ifdef WARP_FPGA_BOARD_V1_2
223
224#endif//ifndef WARPMAC_H
225
226
227
Note: See TracBrowser for help on using the repository browser.