aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/zpu/lib/pkt_ctrl.c
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-12-22 19:19:14 -0800
committerJosh Blum <josh@joshknows.com>2010-12-22 19:19:14 -0800
commit22ed61f97815856bf74cec25ae6bca88bfbe5f44 (patch)
tree7d87d49b46f9507ff10486097e6d79e4bee4cb81 /firmware/zpu/lib/pkt_ctrl.c
parent71fc99d006f2347a356c5339905593f64ff902ec (diff)
downloaduhd-22ed61f97815856bf74cec25ae6bca88bfbe5f44.tar.gz
uhd-22ed61f97815856bf74cec25ae6bca88bfbe5f44.tar.bz2
uhd-22ed61f97815856bf74cec25ae6bca88bfbe5f44.zip
zpu: renamed the directory for the usrp2 fw to zpu to reflect the cpu type
Diffstat (limited to 'firmware/zpu/lib/pkt_ctrl.c')
-rw-r--r--firmware/zpu/lib/pkt_ctrl.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/firmware/zpu/lib/pkt_ctrl.c b/firmware/zpu/lib/pkt_ctrl.c
new file mode 100644
index 000000000..a5659eb33
--- /dev/null
+++ b/firmware/zpu/lib/pkt_ctrl.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2010 Ettus Research LLC
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "pkt_ctrl.h"
+#include "memory_map.h"
+#include <nonstdio.h>
+
+void pkt_ctrl_program_inspector(
+ const struct ip_addr *ip_addr, uint16_t ctrl_port, uint16_t data_port
+){
+ buffer_pool_ctrl->ip_addr = ip_addr->addr;
+ buffer_pool_ctrl->ctrl_ports = ctrl_port;
+ buffer_pool_ctrl->data_ports = data_port;
+}
+
+void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){
+ switch(mode){
+ case PKT_CTRL_ROUTING_MODE_SLAVE:
+ buffer_pool_ctrl->misc_ctrl = 0;
+ break;
+ case PKT_CTRL_ROUTING_MODE_MASTER:
+ buffer_pool_ctrl->misc_ctrl = 1;
+ break;
+ }
+}
+
+static inline bool is_status_bit_set(int bit){
+ return buffer_pool_status->status & (1 << bit);
+}
+
+#define CPU_OUT_HS_BIT 0 //from packet router to CPU
+#define CPU_INP_HS_BIT 1 //from CPU to packet router
+
+void *pkt_ctrl_claim_incoming_buffer(size_t *num_lines){
+ buffer_pool_ctrl->cpu_out_ctrl = 0;
+ if (!is_status_bit_set(CPU_OUT_HS_BIT)) return NULL;
+ *num_lines = (buffer_pool_status->status >> 16) & 0xffff;
+ return buffer_ram(0);
+}
+
+void pkt_ctrl_release_incoming_buffer(void){
+ buffer_pool_ctrl->cpu_out_ctrl = 1;
+ while (is_status_bit_set(CPU_OUT_HS_BIT)){}
+ buffer_pool_ctrl->cpu_out_ctrl = 0;
+}
+
+void *pkt_ctrl_claim_outgoing_buffer(void){
+ buffer_pool_ctrl->cpu_inp_ctrl = 0;
+ while (!is_status_bit_set(CPU_INP_HS_BIT)){}
+ return buffer_ram(1);
+}
+
+void pkt_ctrl_commit_outgoing_buffer(size_t num_lines){
+ buffer_pool_ctrl->cpu_inp_ctrl = ((num_lines & 0xffff) << 16) | 1;
+ while (is_status_bit_set(CPU_INP_HS_BIT)){}
+ buffer_pool_ctrl->cpu_inp_ctrl = 0;
+}