Imported Upstream version 3.2.2
[debian/gnuradio] / usrp2 / firmware / lib / bsm12.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2009 Free Software Foundation, Inc.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef INCLUDED_BSM12_H
20 #define INCLUDED_BSM12_H
21
22 #include "dbsm.h"
23 #include "memory_map.h"
24
25 /*!
26  * buffer state machine: 1 input to two outputs
27  *
28  * Typically used to read packets from the ethernet and then after inspecting,
29  * handle the packet in firmware or pass it on to 1 of the 2 buffer destinations.
30  */
31
32 struct _bsm12;
33 typedef struct _bsm12 bsm12_t;
34
35 /*!
36  * Pointer to function that does packet inspection.
37  *
38  * \param sm            the state machine
39  * \param buf_this      the index of the buffer to inspect and/or pass on
40  *
41  * Returns -1, 0 or 1.  If it returns -1, it means that the s/w
42  * handled that packet, and that it should NOT be passed on to one of
43  * the buffer endpoints.  0 indicates the first endpoint, 1 the second endpoint.
44  */
45 typedef int (*bsm12_inspector_t)(bsm12_t *sm, int buf_this);
46
47
48 /*!
49  * buffer state machine: 1 input to two outputs
50  */
51 struct _bsm12
52 {
53   uint8_t         buf0;  // This machine uses buf0, buf0+1 and buf0+2.  buf0 % 4 == 0.
54   uint8_t         running;
55   int8_t          rx_state;     // -1, 0, 1, 2  which buffer we're receiving into
56   int8_t          tx_state[2];  // -1, 0, 1, 2  which buffer we're sending from
57   buf_cmd_args_t  recv_args;
58   buf_cmd_args_t  send_args[2];
59   bsm12_inspector_t inspect;
60   int             last_line_adj;
61   uint32_t        bps_error;
62   uint32_t        bps_done;
63   uint32_t        bps_error_or_done;
64   uint8_t         next_buf[NBUFFERS];
65   uint32_t        precomputed_receive_to_buf_ctrl_word[3];
66   uint32_t        precomputed_send_from_buf_ctrl_word[4][2];  // really only 3, not 4 
67                                                               //   (easier addr comp)
68 };
69
70 void bsm12_init(bsm12_t *sm, int buf0,
71                 const buf_cmd_args_t *recv,
72                 const buf_cmd_args_t *send0,
73                 const buf_cmd_args_t *send1,
74                 bsm12_inspector_t inspect);
75
76 void bsm12_start(bsm12_t *sm);
77 void bsm12_stop(bsm12_t *sm);
78 void bsm12_process_status(bsm12_t *sm, uint32_t status);
79 void bsm12_handle_tx_underrun(bsm12_t *sm);
80 void bsm12_handle_rx_overrun(bsm12_t *sm);
81
82
83 #endif /* INCLUDED_BSM12_H */