]> git.gag.com Git - debian/gnuradio/blob - usrp/host/apps-inband/gmac.h
a6d0bcb128d9524300fc9258d2fe44cb8317bedf
[debian/gnuradio] / usrp / host / apps-inband / gmac.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef INCLUDED_GMAC_H
23 #define INCLUDED_GMAC_H
24
25 #include <mb_mblock.h>
26
27 class gmac;
28
29 class gmac : public mb_mblock
30 {
31
32   // The state is used to determine how to handle incoming messages and of
33   // course, the state of the MAC protocol.
34   enum state_t {
35     INIT,
36     OPENING_USRP,
37     ALLOCATING_CHANNELS,
38     INIT_GMAC,
39     IDLE,
40     CLOSING_CHANNELS,
41     CLOSING_USRP,
42   };
43   state_t       d_state;
44
45   // Ports used for applications to connect to this block
46   mb_port_sptr            d_tx, d_rx, d_cs;
47
48   // Ports to connect to usrp_server (us)
49   mb_port_sptr      d_us_tx, d_us_rx, d_us_cs;
50
51   // The channel numbers assigned for use
52   pmt_t d_us_rx_chan, d_us_tx_chan;
53
54   pmt_t d_which_usrp;
55
56   bool d_carrier_sense;
57   long d_cs_thresh;
58   long d_cs_deadline;
59
60   enum FPGA_REGISTERS {
61     REG_CS_THRESH = 1,
62     REG_CS_DEADLINE = 2
63   };
64   
65  public:
66   gmac(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg);
67   ~gmac();
68   void handle_message(mb_message_sptr msg);
69
70  private:
71   void define_ports();
72   void initialize_usrp();
73   void initialize_gmac();
74   void set_carrier_sense(bool toggle, long threshold, long deadline, pmt_t invocation);
75   void allocate_channels();
76   void enter_receiving();
77   void enter_idle();
78   void close_channels();
79   void open_usrp();
80   void close_usrp();
81   void handle_cmd_tx_pkt(pmt_t data);
82   void handle_response_xmit_raw_frame(pmt_t data);
83   bool carrier_sense_pkt(pmt_t pkt_properties);
84   void handle_cmd_carrier_sense_enable(pmt_t data);
85   void handle_cmd_carrier_sense_threshold(pmt_t data);
86   void handle_cmd_carrier_sense_disable(pmt_t data);
87   void handle_cmd_carrier_sense_deadline(pmt_t data);
88  
89 };
90
91 #endif // INCLUDED_GMAC_H