3 * Copyright 2009 Free Software Foundation, Inc.
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.
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.
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/>.
19 #ifndef INCLUDED_BSM12_H
20 #define INCLUDED_BSM12_H
23 #include "memory_map.h"
26 * buffer state machine: 1 input to two outputs
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.
33 typedef struct _bsm12 bsm12_t;
36 * Pointer to function that does packet inspection.
38 * \param sm the state machine
39 * \param buf_this the index of the buffer to inspect and/or pass on
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.
45 typedef int (*bsm12_inspector_t)(bsm12_t *sm, int buf_this);
49 * buffer state machine: 1 input to two outputs
53 uint8_t buf0; // This machine uses buf0, buf0+1 and buf0+2. buf0 % 4 == 0.
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;
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
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);
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);
83 #endif /* INCLUDED_BSM12_H */