From 22ed61f97815856bf74cec25ae6bca88bfbe5f44 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 22 Dec 2010 19:19:14 -0800 Subject: zpu: renamed the directory for the usrp2 fw to zpu to reflect the cpu type --- firmware/zpu/lib/pkt_ctrl.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 firmware/zpu/lib/pkt_ctrl.c (limited to 'firmware/zpu/lib/pkt_ctrl.c') 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 . + */ + +#include "pkt_ctrl.h" +#include "memory_map.h" +#include + +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; +} -- cgit v1.2.3 From 57681c7659992eb6b7d78db91f888487d4e2a260 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 27 Dec 2010 16:53:59 -0800 Subject: packet_router: code tweaks, renamed instances of buffer pool, removed unused ctrl reg --- firmware/zpu/apps/txrx_uhd.c | 2 +- firmware/zpu/lib/pkt_ctrl.c | 33 +++++++++++----------------- firmware/zpu/lib/pkt_ctrl.h | 2 +- firmware/zpu/usrp2/memory_map.h | 47 +++++++++++++++++++--------------------- firmware/zpu/usrp2p/memory_map.h | 45 ++++++++++++++++++-------------------- 5 files changed, 58 insertions(+), 71 deletions(-) (limited to 'firmware/zpu/lib/pkt_ctrl.c') diff --git a/firmware/zpu/apps/txrx_uhd.c b/firmware/zpu/apps/txrx_uhd.c index ea74f032e..b16d177d7 100644 --- a/firmware/zpu/apps/txrx_uhd.c +++ b/firmware/zpu/apps/txrx_uhd.c @@ -360,7 +360,7 @@ main(void) //1) register the addresses into the network stack register_addrs(ethernet_mac_addr(), get_ip_addr()); - pkt_ctrl_program_inspector(get_ip_addr(), USRP2_UDP_CTRL_PORT, USRP2_UDP_DATA_PORT); + pkt_ctrl_program_inspector(get_ip_addr(), USRP2_UDP_DATA_PORT); //2) register callbacks for udp ports we service init_udp_listeners(); diff --git a/firmware/zpu/lib/pkt_ctrl.c b/firmware/zpu/lib/pkt_ctrl.c index a5659eb33..ebda35049 100644 --- a/firmware/zpu/lib/pkt_ctrl.c +++ b/firmware/zpu/lib/pkt_ctrl.c @@ -20,52 +20,45 @@ #include void pkt_ctrl_program_inspector( - const struct ip_addr *ip_addr, uint16_t ctrl_port, uint16_t data_port + const struct ip_addr *ip_addr, 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; + router_ctrl->ip_addr = ip_addr->addr; + router_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; + case PKT_CTRL_ROUTING_MODE_SLAVE: router_ctrl->mode_ctrl = 0; break; + case PKT_CTRL_ROUTING_MODE_MASTER: router_ctrl->mode_ctrl = 1; break; } } static inline bool is_status_bit_set(int bit){ - return buffer_pool_status->status & (1 << bit); + return router_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); + *num_lines = (router_status->status >> 16) & 0xffff; + return router_ram(0); } void pkt_ctrl_release_incoming_buffer(void){ - buffer_pool_ctrl->cpu_out_ctrl = 1; + router_ctrl->cpu_out_ctrl = 1; while (is_status_bit_set(CPU_OUT_HS_BIT)){} - buffer_pool_ctrl->cpu_out_ctrl = 0; + router_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); + return router_ram(1); } void pkt_ctrl_commit_outgoing_buffer(size_t num_lines){ - buffer_pool_ctrl->cpu_inp_ctrl = ((num_lines & 0xffff) << 16) | 1; + router_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; + router_ctrl->cpu_inp_ctrl = 0; } diff --git a/firmware/zpu/lib/pkt_ctrl.h b/firmware/zpu/lib/pkt_ctrl.h index 346e22094..410ffdaa4 100644 --- a/firmware/zpu/lib/pkt_ctrl.h +++ b/firmware/zpu/lib/pkt_ctrl.h @@ -30,7 +30,7 @@ typedef enum { //! Program the decision values into the packet inspector void pkt_ctrl_program_inspector( - const struct ip_addr *ip_addr, uint16_t ctrl_port, uint16_t data_port + const struct ip_addr *ip_addr, uint16_t data_port ); //! Set the routing mode for this device diff --git a/firmware/zpu/usrp2/memory_map.h b/firmware/zpu/usrp2/memory_map.h index a2de29cdb..ca7453c24 100644 --- a/firmware/zpu/usrp2/memory_map.h +++ b/firmware/zpu/usrp2/memory_map.h @@ -18,7 +18,7 @@ /* Overall Memory Map * 0000-7FFF 32K RAM space (16K on 1500, 24K on 2000, 32K on DSP) - * 8000-BFFF 16K Buffer Pool + * 8000-BFFF 16K Packet Router * C000-FFFF 16K Peripherals */ @@ -45,20 +45,18 @@ #define RAM_BASE 0x0000 //////////////////////////////////////////////////////////////// -// Buffer Pool RAM, Slave 1 +// Packet Router RAM, Slave 1 // -// The buffers themselves are located in Slave 1, Buffer Pool RAM. -// The status registers are in Slave 5, Buffer Pool Status. +// The buffers themselves are located in Slave 1, Packet Router RAM. +// The status registers are in Slave 5, Packet Router Status. // The control register is in Slave 7, Settings Bus. -#define BUFFER_POOL_RAM_BASE 0x8000 +#define ROUTER_RAM_BASE 0x8000 -#define BP_NLINES 0x0200 // number of 32-bit lines in a buffer +#define RAM_NLINES 0x0200 // number of 32-bit lines in a buffer -#define buffer_pool_ram \ - ((uint32_t *) BUFFER_POOL_RAM_BASE) - -#define buffer_ram(n) (&buffer_pool_ram[(n) * BP_NLINES]) +#define _router_ram ((uint32_t *) ROUTER_RAM_BASE) +#define router_ram(n) (&_router_ram[(n) * RAM_NLINES]) ///////////////////////////////////////////////////// @@ -162,13 +160,13 @@ typedef struct { #define gpio_base ((gpio_regs_t *) GPIO_BASE) /////////////////////////////////////////////////// -// Buffer Pool Status, Slave 5 +// Packet Router Status, Slave 5 // -// The buffers themselves are located in Slave 1, Buffer Pool RAM. -// The status registers are in Slave 5, Buffer Pool Status. +// The buffers themselves are located in Slave 1, Packet Router RAM. +// The status registers are in Slave 5, Packet Router Status. // The control register is in Slave 7, Settings Bus. -#define BUFFER_POOL_STATUS_BASE 0xCC00 +#define ROUTER_STATUS_BASE 0xCC00 typedef struct { volatile uint32_t _padding[8]; @@ -178,9 +176,9 @@ typedef struct { volatile uint32_t irqs; volatile uint32_t pri_enc_bp_status; volatile uint32_t cycle_count; -} buffer_pool_status_t; +} router_status_t; -#define buffer_pool_status ((buffer_pool_status_t *) BUFFER_POOL_STATUS_BASE) +#define router_status ((router_status_t *) ROUTER_STATUS_BASE) // The hw_config register @@ -193,7 +191,7 @@ typedef struct { inline static int hwconfig_simulation_p(void) { - return buffer_pool_status->hw_config & HWC_SIMULATION; + return router_status->hw_config & HWC_SIMULATION; } /*! @@ -203,7 +201,7 @@ hwconfig_simulation_p(void) inline static int hwconfig_wishbone_divisor(void) { - return buffer_pool_status->hw_config & HWC_WB_CLK_DIV_MASK; + return router_status->hw_config & HWC_WB_CLK_DIV_MASK; } /////////////////////////////////////////////////// @@ -225,13 +223,13 @@ hwconfig_wishbone_divisor(void) #define MISC_OUTPUT_BASE 0xD400 #define TX_PROTOCOL_ENGINE_BASE 0xD480 #define RX_PROTOCOL_ENGINE_BASE 0xD4C0 -#define BUFFER_POOL_CTRL_BASE 0xD500 +#define ROUTER_CTRL_BASE 0xD500 #define LAST_SETTING_REG 0xD7FC // last valid setting register #define SR_MISC 0 #define SR_TX_PROT_ENG 32 #define SR_RX_PROT_ENG 48 -#define SR_BUFFER_POOL_CTRL 64 +#define SR_ROUTER_CTRL 64 #define SR_UDP_SM 96 #define SR_TX_DSP 208 #define SR_TX_CTRL 224 @@ -243,18 +241,17 @@ hwconfig_wishbone_divisor(void) #define _SR_ADDR(sr) (MISC_OUTPUT_BASE + (sr) * sizeof(uint32_t)) -// --- buffer pool control regs --- +// --- packet router control regs --- typedef struct { - volatile uint32_t misc_ctrl; + volatile uint32_t mode_ctrl; volatile uint32_t ip_addr; - volatile uint32_t ctrl_ports; //ctrl (low 16) other (high 16) volatile uint32_t data_ports; //dsp0 (low 16) dsp1 (high 16) volatile uint32_t cpu_out_ctrl; volatile uint32_t cpu_inp_ctrl; -} buffer_pool_ctrl_t; +} router_ctrl_t; -#define buffer_pool_ctrl ((buffer_pool_ctrl_t *) BUFFER_POOL_CTRL_BASE) +#define router_ctrl ((router_ctrl_t *) ROUTER_CTRL_BASE) // --- misc outputs --- diff --git a/firmware/zpu/usrp2p/memory_map.h b/firmware/zpu/usrp2p/memory_map.h index 6f5c577e6..151c71237 100644 --- a/firmware/zpu/usrp2p/memory_map.h +++ b/firmware/zpu/usrp2p/memory_map.h @@ -38,20 +38,18 @@ //////////////////////////////////////////////////////////////// -// Buffer Pool RAM, Slave 1 +// Packet Router RAM, Slave 1 // -// The buffers themselves are located in Slave 1, Buffer Pool RAM. -// The status registers are in Slave 5, Buffer Pool Status. +// The buffers themselves are located in Slave 1, Packet Router RAM. +// The status registers are in Slave 5, Packet Router Status. // The control register is in Slave 7, Settings Bus. -#define BUFFER_POOL_RAM_BASE 0x4000 +#define ROUTER_RAM_BASE 0x4000 -#define BP_NLINES 0x0200 // number of 32-bit lines in a buffer +#define RAM_NLINES 0x0200 // number of 32-bit lines in a buffer -#define buffer_pool_ram \ - ((uint32_t *) BUFFER_POOL_RAM_BASE) - -#define buffer_ram(n) (&buffer_pool_ram[(n) * BP_NLINES]) +#define _router_ram ((uint32_t *) ROUTER_RAM_BASE) +#define router_ram(n) (&_router_ram[(n) * RAM_NLINES]) ///////////////////////////////////////////////////// @@ -155,13 +153,13 @@ typedef struct { #define gpio_base ((gpio_regs_t *) GPIO_BASE) /////////////////////////////////////////////////// -// Buffer Pool Status, Slave 5 +// Packet Router Status, Slave 5 // -// The buffers themselves are located in Slave 1, Buffer Pool RAM. -// The status registers are in Slave 5, Buffer Pool Status. +// The buffers themselves are located in Slave 1, Packet Router RAM. +// The status registers are in Slave 5, Packet Router Status. // The control register is in Slave 7, Settings Bus. -#define BUFFER_POOL_STATUS_BASE 0x6300 +#define ROUTER_STATUS_BASE 0x6300 typedef struct { volatile uint32_t _padding[8]; @@ -171,11 +169,11 @@ typedef struct { volatile uint32_t irqs; volatile uint32_t pri_enc_bp_status; volatile uint32_t cycle_count; -} buffer_pool_status_t; +} router_status_t; -#define buffer_pool_status ((buffer_pool_status_t *) BUFFER_POOL_STATUS_BASE) +#define router_status ((router_status_t *) ROUTER_STATUS_BASE) -#define BUTTON_PUSHED ((buffer_pool_status->irqs & PIC_BUTTON) ? 0 : 1) +#define BUTTON_PUSHED ((router_status->irqs & PIC_BUTTON) ? 0 : 1) // The hw_config register @@ -188,7 +186,7 @@ typedef struct { inline static int hwconfig_simulation_p(void) { - return buffer_pool_status->hw_config & HWC_SIMULATION; + return router_status->hw_config & HWC_SIMULATION; } /*! @@ -198,7 +196,7 @@ hwconfig_simulation_p(void) inline static int hwconfig_wishbone_divisor(void) { - return buffer_pool_status->hw_config & HWC_WB_CLK_DIV_MASK; + return router_status->hw_config & HWC_WB_CLK_DIV_MASK; } /////////////////////////////////////////////////// @@ -222,7 +220,7 @@ hwconfig_wishbone_divisor(void) #define SR_MISC 0 #define SR_TX_PROT_ENG 32 #define SR_RX_PROT_ENG 48 -#define SR_BUFFER_POOL_CTRL 64 +#define SR_ROUTER_CTRL 64 #define SR_UDP_SM 96 #define SR_TX_DSP 208 #define SR_TX_CTRL 224 @@ -236,18 +234,17 @@ hwconfig_wishbone_divisor(void) #define SR_ADDR_BLDRDONE _SR_ADDR(5) -// --- buffer pool control regs --- +// --- packet router control regs --- typedef struct { - volatile uint32_t misc_ctrl; + volatile uint32_t mode_ctrl; volatile uint32_t ip_addr; - volatile uint32_t ctrl_ports; //ctrl (low 16) other (high 16) volatile uint32_t data_ports; //dsp0 (low 16) dsp1 (high 16) volatile uint32_t cpu_out_ctrl; volatile uint32_t cpu_inp_ctrl; -} buffer_pool_ctrl_t; +} router_ctrl_t; -#define buffer_pool_ctrl ((buffer_pool_ctrl_t *) _SR_ADDR(SR_BUFFER_POOL_CTRL)) +#define router_ctrl ((router_ctrl_t *) _SR_ADDR(SR_ROUTER_CTRL)) // --- misc outputs --- -- cgit v1.2.3 From f56097198fad8423bba41a9c083abdc3b41f016a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 28 Dec 2010 19:04:36 -0800 Subject: packet_router: change router control for buffer_int2 --- firmware/zpu/apps/txrx_uhd.c | 1 + firmware/zpu/lib/pkt_ctrl.c | 75 ++++++++++++++++++++++++++++++++-------- firmware/zpu/lib/pkt_ctrl.h | 3 ++ firmware/zpu/usrp2/memory_map.h | 3 +- firmware/zpu/usrp2p/memory_map.h | 3 +- 5 files changed, 66 insertions(+), 19 deletions(-) (limited to 'firmware/zpu/lib/pkt_ctrl.c') diff --git a/firmware/zpu/apps/txrx_uhd.c b/firmware/zpu/apps/txrx_uhd.c index b16d177d7..61c2521b9 100644 --- a/firmware/zpu/apps/txrx_uhd.c +++ b/firmware/zpu/apps/txrx_uhd.c @@ -340,6 +340,7 @@ int main(void) { u2_init(); + pkt_ctrl_init(); //we do this to see if we should set a default ip addr or not #ifdef USRP2P diff --git a/firmware/zpu/lib/pkt_ctrl.c b/firmware/zpu/lib/pkt_ctrl.c index ebda35049..96cf76356 100644 --- a/firmware/zpu/lib/pkt_ctrl.c +++ b/firmware/zpu/lib/pkt_ctrl.c @@ -33,32 +33,77 @@ void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ } } -static inline bool is_status_bit_set(int bit){ - return router_status->status & (1 << bit); +//status signals from WB into PR +#define CPU_STAT_RD_DONE (1 << 0) +#define CPU_STAT_RD_EROR (1 << 1) +#define CPU_STAT_RD_IDLE (1 << 2) + +//status signals from PR into WB +#define CPU_STAT_WR_DONE (1 << 4) +#define CPU_STAT_WR_EROR (1 << 5) +#define CPU_STAT_WR_IDLE (1 << 6) + +//control signals from WB into PR +#define CPU_CTRL_RD_CLEAR (1 << 0) +#define CPU_CTRL_RD_START (1 << 1) + +//control signals from PR into WB +#define CPU_CTRL_WR_CLEAR (1 << 2) +#define CPU_CTRL_WR_START (1 << 3) + +static bool i_am_writing; + +static inline void cpu_stat_wait_for(int bm){ + while((router_status->status & bm) == 0){ + /* NOP */ + } } -#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_init(void){ + router_ctrl->iface_ctrl = CPU_CTRL_WR_CLEAR | CPU_CTRL_RD_START; + i_am_writing = false; +} void *pkt_ctrl_claim_incoming_buffer(size_t *num_lines){ - if (!is_status_bit_set(CPU_OUT_HS_BIT)) return NULL; - *num_lines = (router_status->status >> 16) & 0xffff; - return router_ram(0); + uint32_t status = router_status->status; + + //if done: clear the read and return the buffer + if (status & CPU_STAT_RD_DONE){ + *num_lines = (router_status->status >> 16) & 0xffff; + return router_ram(0); + } + + //if error: drop the packet and start a new read + else if (status & CPU_STAT_RD_EROR){ + putstr("E"); + pkt_ctrl_release_incoming_buffer(); + } + + //otherwise null for nothing ready + return NULL; } void pkt_ctrl_release_incoming_buffer(void){ - router_ctrl->cpu_out_ctrl = 1; - while (is_status_bit_set(CPU_OUT_HS_BIT)){} - router_ctrl->cpu_out_ctrl = 0; + //clear, wait for idle, and start a new read + router_ctrl->iface_ctrl = CPU_CTRL_RD_CLEAR; + cpu_stat_wait_for(CPU_STAT_RD_IDLE); + router_ctrl->iface_ctrl = CPU_CTRL_RD_START; } void *pkt_ctrl_claim_outgoing_buffer(void){ - while (!is_status_bit_set(CPU_INP_HS_BIT)){} - return router_ram(1); + if (i_am_writing){ + //wait for the write to become done + cpu_stat_wait_for(CPU_STAT_WR_DONE); + router_ctrl->iface_ctrl = CPU_CTRL_WR_CLEAR; + i_am_writing = false; + } + //wait for idle and return the buffer + cpu_stat_wait_for(CPU_STAT_WR_IDLE); + return router_ram(0); } void pkt_ctrl_commit_outgoing_buffer(size_t num_lines){ - router_ctrl->cpu_inp_ctrl = ((num_lines & 0xffff) << 16) | 1; - while (is_status_bit_set(CPU_INP_HS_BIT)){} - router_ctrl->cpu_inp_ctrl = 0; + //start a new write with the given length + router_ctrl->iface_ctrl = ((num_lines & 0xffff) << 16) | CPU_CTRL_WR_START; + i_am_writing = true; } diff --git a/firmware/zpu/lib/pkt_ctrl.h b/firmware/zpu/lib/pkt_ctrl.h index 410ffdaa4..06b81538d 100644 --- a/firmware/zpu/lib/pkt_ctrl.h +++ b/firmware/zpu/lib/pkt_ctrl.h @@ -23,6 +23,9 @@ #include #include +//! Initialize the packet router into a good state +void pkt_ctrl_init(void); + typedef enum { PKT_CTRL_ROUTING_MODE_SLAVE, PKT_CTRL_ROUTING_MODE_MASTER, diff --git a/firmware/zpu/usrp2/memory_map.h b/firmware/zpu/usrp2/memory_map.h index ca7453c24..40c5e6540 100644 --- a/firmware/zpu/usrp2/memory_map.h +++ b/firmware/zpu/usrp2/memory_map.h @@ -247,8 +247,7 @@ typedef struct { volatile uint32_t mode_ctrl; volatile uint32_t ip_addr; volatile uint32_t data_ports; //dsp0 (low 16) dsp1 (high 16) - volatile uint32_t cpu_out_ctrl; - volatile uint32_t cpu_inp_ctrl; + volatile uint32_t iface_ctrl; } router_ctrl_t; #define router_ctrl ((router_ctrl_t *) ROUTER_CTRL_BASE) diff --git a/firmware/zpu/usrp2p/memory_map.h b/firmware/zpu/usrp2p/memory_map.h index 151c71237..a9db642ed 100644 --- a/firmware/zpu/usrp2p/memory_map.h +++ b/firmware/zpu/usrp2p/memory_map.h @@ -240,8 +240,7 @@ typedef struct { volatile uint32_t mode_ctrl; volatile uint32_t ip_addr; volatile uint32_t data_ports; //dsp0 (low 16) dsp1 (high 16) - volatile uint32_t cpu_out_ctrl; - volatile uint32_t cpu_inp_ctrl; + volatile uint32_t iface_ctrl; } router_ctrl_t; #define router_ctrl ((router_ctrl_t *) _SR_ADDR(SR_ROUTER_CTRL)) -- cgit v1.2.3 From ca0f4f0be8c19533007e4284d1ccc47df0f1c6e3 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 29 Dec 2010 11:15:24 -0800 Subject: usrp2: remove ram macros from memory map, conditionally load fw update --- firmware/zpu/apps/txrx_uhd.c | 2 ++ firmware/zpu/lib/pkt_ctrl.c | 4 ++-- firmware/zpu/usrp2/CMakeLists.txt | 1 - firmware/zpu/usrp2/memory_map.h | 6 ------ firmware/zpu/usrp2/udp_fw_update.c | 34 ---------------------------------- firmware/zpu/usrp2p/memory_map.h | 6 ------ 6 files changed, 4 insertions(+), 49 deletions(-) delete mode 100644 firmware/zpu/usrp2/udp_fw_update.c (limited to 'firmware/zpu/lib/pkt_ctrl.c') diff --git a/firmware/zpu/apps/txrx_uhd.c b/firmware/zpu/apps/txrx_uhd.c index 61c2521b9..2030b1ce9 100644 --- a/firmware/zpu/apps/txrx_uhd.c +++ b/firmware/zpu/apps/txrx_uhd.c @@ -368,7 +368,9 @@ main(void) register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet); register_udp_listener(USRP2_UDP_DATA_PORT, handle_udp_data_packet); register_udp_listener(USRP2_UDP_ERR0_PORT, handle_udp_err0_packet); +#ifdef USRP2P register_udp_listener(USRP2_UDP_UPDATE_PORT, handle_udp_fw_update_packet); +#endif //3) set the routing mode to slave and send a garp pkt_ctrl_set_routing_mode(PKT_CTRL_ROUTING_MODE_SLAVE); diff --git a/firmware/zpu/lib/pkt_ctrl.c b/firmware/zpu/lib/pkt_ctrl.c index 96cf76356..df5851c35 100644 --- a/firmware/zpu/lib/pkt_ctrl.c +++ b/firmware/zpu/lib/pkt_ctrl.c @@ -70,7 +70,7 @@ void *pkt_ctrl_claim_incoming_buffer(size_t *num_lines){ //if done: clear the read and return the buffer if (status & CPU_STAT_RD_DONE){ *num_lines = (router_status->status >> 16) & 0xffff; - return router_ram(0); + return ((uint32_t *) ROUTER_RAM_BASE); } //if error: drop the packet and start a new read @@ -99,7 +99,7 @@ void *pkt_ctrl_claim_outgoing_buffer(void){ } //wait for idle and return the buffer cpu_stat_wait_for(CPU_STAT_WR_IDLE); - return router_ram(0); + return ((uint32_t *) ROUTER_RAM_BASE); } void pkt_ctrl_commit_outgoing_buffer(size_t num_lines){ diff --git a/firmware/zpu/usrp2/CMakeLists.txt b/firmware/zpu/usrp2/CMakeLists.txt index 8ed31b8d4..ca5c6d92a 100644 --- a/firmware/zpu/usrp2/CMakeLists.txt +++ b/firmware/zpu/usrp2/CMakeLists.txt @@ -23,7 +23,6 @@ ADD_LIBRARY(libusrp2fw STATIC ${COMMON_SRCS} sd.c ethernet.c - udp_fw_update.c ) ######################################################################## diff --git a/firmware/zpu/usrp2/memory_map.h b/firmware/zpu/usrp2/memory_map.h index 40c5e6540..b1ca4aa6d 100644 --- a/firmware/zpu/usrp2/memory_map.h +++ b/firmware/zpu/usrp2/memory_map.h @@ -53,12 +53,6 @@ #define ROUTER_RAM_BASE 0x8000 -#define RAM_NLINES 0x0200 // number of 32-bit lines in a buffer - -#define _router_ram ((uint32_t *) ROUTER_RAM_BASE) -#define router_ram(n) (&_router_ram[(n) * RAM_NLINES]) - - ///////////////////////////////////////////////////// // SPI Core, Slave 2. See core docs for more info #define SPI_BASE 0xC000 // Base address (16-bit) diff --git a/firmware/zpu/usrp2/udp_fw_update.c b/firmware/zpu/usrp2/udp_fw_update.c deleted file mode 100644 index 14eb0b1ee..000000000 --- a/firmware/zpu/usrp2/udp_fw_update.c +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- c++ -*- */ -/* - * 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 . - */ - -//Routines to handle updating the SPI Flash firmware via UDP - -#include "net_common.h" -#include "usrp2/fw_common.h" -#include -#include "udp_fw_update.h" - -//Firmware update packet handler -void handle_udp_fw_update_packet(struct socket_address src, struct socket_address dst, - unsigned char *payload, int payload_len) { - - usrp2_fw_update_data_t update_data_out; - update_data_out.id = USRP2_FW_UPDATE_ID_WAT; - - send_udp_pkt(USRP2_UDP_UPDATE_PORT, src, &update_data_out, sizeof(update_data_out)); -} diff --git a/firmware/zpu/usrp2p/memory_map.h b/firmware/zpu/usrp2p/memory_map.h index a9db642ed..85c64466d 100644 --- a/firmware/zpu/usrp2p/memory_map.h +++ b/firmware/zpu/usrp2p/memory_map.h @@ -46,12 +46,6 @@ #define ROUTER_RAM_BASE 0x4000 -#define RAM_NLINES 0x0200 // number of 32-bit lines in a buffer - -#define _router_ram ((uint32_t *) ROUTER_RAM_BASE) -#define router_ram(n) (&_router_ram[(n) * RAM_NLINES]) - - ///////////////////////////////////////////////////// // SPI Core, Slave 2. See core docs for more info #define SPI_BASE 0x6000 // Base address (16-bit) is base peripheral addr -- cgit v1.2.3 From e0005a2a00b49b1c6802fd7e78e8f92ff22a6bce Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 7 Jan 2011 11:51:31 -0800 Subject: usrp2: tweaking firmware added delay to the link up/down code to space out calls removed the pkt_ctrl init and just do it when the mode changes tweaked the addr printing --- firmware/zpu/apps/txrx_uhd.c | 19 +++++++--------- firmware/zpu/lib/nonstdio.h | 9 +++----- firmware/zpu/lib/pkt_ctrl.c | 49 ++++++++++++++++++------------------------ firmware/zpu/lib/pkt_ctrl.h | 3 --- firmware/zpu/lib/print_addrs.c | 9 ++++---- 5 files changed, 37 insertions(+), 52 deletions(-) (limited to 'firmware/zpu/lib/pkt_ctrl.c') diff --git a/firmware/zpu/apps/txrx_uhd.c b/firmware/zpu/apps/txrx_uhd.c index cd66c18f1..3fcda8a4e 100644 --- a/firmware/zpu/apps/txrx_uhd.c +++ b/firmware/zpu/apps/txrx_uhd.c @@ -77,14 +77,14 @@ static void handle_udp_data_packet( sr_udp_sm->dsp0_port = (((uint32_t)dst.port) << 16) | src.port; printf("Storing for fast path:\n"); printf(" source mac addr: "); - print_mac_addr(fp_mac_addr_src.addr); newline(); + print_mac_addr(&fp_mac_addr_src); newline(); printf(" source ip addr: "); - print_ip_addr(&fp_socket_src.addr); newline(); + print_ip_addr(&fp_socket_src); newline(); printf(" source udp port: %d\n", fp_socket_src.port); printf(" destination mac addr: "); - print_mac_addr(fp_mac_addr_dst.addr); newline(); + print_mac_addr(&fp_mac_addr_dst); newline(); printf(" destination ip addr: "); - print_ip_addr(&fp_socket_dst.addr); newline(); + print_ip_addr(&fp_socket_dst); newline(); printf(" destination udp port: %d\n", fp_socket_dst.port); newline(); @@ -332,7 +332,6 @@ int main(void) { u2_init(); - pkt_ctrl_init(); //we do this to see if we should set a default ip addr or not #ifdef USRP2P @@ -344,9 +343,8 @@ main(void) } #endif - putstr("\nTxRx-NEWETH\n"); - print_mac_addr(ethernet_mac_addr()->addr); - newline(); + putstr("\nTxRx-UHD-ZPU\n"); + print_mac_addr(ethernet_mac_addr()); newline(); print_ip_addr(get_ip_addr()); newline(); printf("FPGA compatibility number: %d\n", USRP2_FPGA_COMPAT_NUM); printf("Firmware compatibility number: %d\n", USRP2_FW_COMPAT_NUM); @@ -364,9 +362,8 @@ main(void) register_udp_listener(USRP2_UDP_UPDATE_PORT, handle_udp_fw_update_packet); #endif - //3) set the routing mode to slave and send a garp + //3) set the routing mode to slave to set defaults pkt_ctrl_set_routing_mode(PKT_CTRL_ROUTING_MODE_SLAVE); - send_gratuitous_arp(); //4) setup ethernet hardware to bring the link up ethernet_register_link_changed_callback(link_changed_callback); @@ -390,7 +387,7 @@ main(void) } if (pending & PIC_OVERRUN_INT){ - pic_regs->pending = PIC_OVERRUN_INT; // clear pending interrupt + pic_regs->pending = PIC_OVERRUN_INT; // clear interrupt putchar('O'); } } diff --git a/firmware/zpu/lib/nonstdio.h b/firmware/zpu/lib/nonstdio.h index 6aca7ed9a..2c4aeb961 100644 --- a/firmware/zpu/lib/nonstdio.h +++ b/firmware/zpu/lib/nonstdio.h @@ -38,13 +38,10 @@ void puthex32_nl(unsigned long x); #define puthex_nl puthex32_nl void newline(); // putchar('\n') -void print_mac_addr(const unsigned char addr[6]); -void print_uint64(uint64_t v); +void print_mac_addr(const void *addr); -void print_buffer(uint32_t *buf, size_t n); -//char *itoa(signed long value, char *result, int base); -//void reverse(char s[]); +void print_ip_addr(const void *addr); -void print_ip_addr(const void *t); +void print_buffer(uint32_t *buf, size_t n); #endif /* INCLUDED_NONSTDIO_H */ diff --git a/firmware/zpu/lib/pkt_ctrl.c b/firmware/zpu/lib/pkt_ctrl.c index df5851c35..341ad44e1 100644 --- a/firmware/zpu/lib/pkt_ctrl.c +++ b/firmware/zpu/lib/pkt_ctrl.c @@ -18,20 +18,7 @@ #include "pkt_ctrl.h" #include "memory_map.h" #include - -void pkt_ctrl_program_inspector( - const struct ip_addr *ip_addr, uint16_t data_port -){ - router_ctrl->ip_addr = ip_addr->addr; - router_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: router_ctrl->mode_ctrl = 0; break; - case PKT_CTRL_ROUTING_MODE_MASTER: router_ctrl->mode_ctrl = 1; break; - } -} +#include //status signals from WB into PR #define CPU_STAT_RD_DONE (1 << 0) @@ -51,7 +38,22 @@ void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ #define CPU_CTRL_WR_CLEAR (1 << 2) #define CPU_CTRL_WR_START (1 << 3) -static bool i_am_writing; +void pkt_ctrl_program_inspector( + const struct ip_addr *ip_addr, uint16_t data_port +){ + router_ctrl->ip_addr = ip_addr->addr; + router_ctrl->data_ports = data_port; +} + +void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ + mdelay(100); //give a little delay to space out subsequent calls + switch(mode){ + case PKT_CTRL_ROUTING_MODE_SLAVE: router_ctrl->mode_ctrl = 0; break; + case PKT_CTRL_ROUTING_MODE_MASTER: router_ctrl->mode_ctrl = 1; break; + } + router_ctrl->iface_ctrl = CPU_CTRL_WR_CLEAR; //reset the write state machine + pkt_ctrl_release_incoming_buffer(); //reset the read state machine, and read +} static inline void cpu_stat_wait_for(int bm){ while((router_status->status & bm) == 0){ @@ -59,11 +61,6 @@ static inline void cpu_stat_wait_for(int bm){ } } -void pkt_ctrl_init(void){ - router_ctrl->iface_ctrl = CPU_CTRL_WR_CLEAR | CPU_CTRL_RD_START; - i_am_writing = false; -} - void *pkt_ctrl_claim_incoming_buffer(size_t *num_lines){ uint32_t status = router_status->status; @@ -74,7 +71,7 @@ void *pkt_ctrl_claim_incoming_buffer(size_t *num_lines){ } //if error: drop the packet and start a new read - else if (status & CPU_STAT_RD_EROR){ + if (status & CPU_STAT_RD_EROR){ putstr("E"); pkt_ctrl_release_incoming_buffer(); } @@ -91,12 +88,6 @@ void pkt_ctrl_release_incoming_buffer(void){ } void *pkt_ctrl_claim_outgoing_buffer(void){ - if (i_am_writing){ - //wait for the write to become done - cpu_stat_wait_for(CPU_STAT_WR_DONE); - router_ctrl->iface_ctrl = CPU_CTRL_WR_CLEAR; - i_am_writing = false; - } //wait for idle and return the buffer cpu_stat_wait_for(CPU_STAT_WR_IDLE); return ((uint32_t *) ROUTER_RAM_BASE); @@ -105,5 +96,7 @@ void *pkt_ctrl_claim_outgoing_buffer(void){ void pkt_ctrl_commit_outgoing_buffer(size_t num_lines){ //start a new write with the given length router_ctrl->iface_ctrl = ((num_lines & 0xffff) << 16) | CPU_CTRL_WR_START; - i_am_writing = true; + //wait for the write to become done + cpu_stat_wait_for(CPU_STAT_WR_DONE); + router_ctrl->iface_ctrl = CPU_CTRL_WR_CLEAR; } diff --git a/firmware/zpu/lib/pkt_ctrl.h b/firmware/zpu/lib/pkt_ctrl.h index 06b81538d..410ffdaa4 100644 --- a/firmware/zpu/lib/pkt_ctrl.h +++ b/firmware/zpu/lib/pkt_ctrl.h @@ -23,9 +23,6 @@ #include #include -//! Initialize the packet router into a good state -void pkt_ctrl_init(void); - typedef enum { PKT_CTRL_ROUTING_MODE_SLAVE, PKT_CTRL_ROUTING_MODE_MASTER, diff --git a/firmware/zpu/lib/print_addrs.c b/firmware/zpu/lib/print_addrs.c index 29601c47c..fa2a49fc3 100644 --- a/firmware/zpu/lib/print_addrs.c +++ b/firmware/zpu/lib/print_addrs.c @@ -18,15 +18,16 @@ #include "nonstdio.h" void -print_mac_addr(const unsigned char addr[6]) +print_mac_addr(const void *addr) { + uint8_t *p = (uint8_t *)addr; for(size_t i = 0; i < 6; i++){ if(i) putchar(':'); - puthex8(addr[i]); + puthex8(p[i]); } } -void print_ip_addr(const void *t){ - uint8_t *p = (uint8_t *)t; +void print_ip_addr(const void *addr){ + uint8_t *p = (uint8_t *)addr; printf("%d.%d.%d.%d", p[0], p[1], p[2], p[3]); } -- cgit v1.2.3 From 599771914d0848875a0056cd60850eec39b06654 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 11 Jan 2011 12:19:22 -0800 Subject: usrp2: restart read before mode switch, added comments use cmake compiler force macro (to simplify things), added copyright updates dates to some files --- firmware/zpu/CMakeLists.txt | 7 +++---- firmware/zpu/apps/txrx_uhd.c | 2 +- firmware/zpu/lib/pkt_ctrl.c | 16 +++++++--------- firmware/zpu/lib/pkt_ctrl.h | 6 +++--- firmware/zpu/usrp2/CMakeLists.txt | 2 +- firmware/zpu/usrp2p/CMakeLists.txt | 2 +- firmware/zpu/usrp2p/bootloader/CMakeLists.txt | 2 +- host/lib/convert/convert_with_neon.cpp | 1 - 8 files changed, 17 insertions(+), 21 deletions(-) (limited to 'firmware/zpu/lib/pkt_ctrl.c') diff --git a/firmware/zpu/CMakeLists.txt b/firmware/zpu/CMakeLists.txt index 2df0a6140..d7cedbfb9 100644 --- a/firmware/zpu/CMakeLists.txt +++ b/firmware/zpu/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 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 @@ -19,10 +19,9 @@ # setup project and compiler ######################################################################## CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(CMAKE_C_COMPILER zpu-elf-gcc) #force the compiler because the check wont use the special flag below -SET(CMAKE_C_COMPILER_WORKS TRUE) -SET(CMAKE_C_COMPILER_FORCED TRUE) +INCLUDE(CMakeForceCompiler) +CMAKE_FORCE_C_COMPILER(zpu-elf-gcc GNU) PROJECT(USRP_NXXX_FW C) ######################################################################## diff --git a/firmware/zpu/apps/txrx_uhd.c b/firmware/zpu/apps/txrx_uhd.c index ab960dac8..61a2c1f76 100644 --- a/firmware/zpu/apps/txrx_uhd.c +++ b/firmware/zpu/apps/txrx_uhd.c @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // /* * Copyright 2007,2008 Free Software Foundation, Inc. diff --git a/firmware/zpu/lib/pkt_ctrl.c b/firmware/zpu/lib/pkt_ctrl.c index 341ad44e1..2bbe2f843 100644 --- a/firmware/zpu/lib/pkt_ctrl.c +++ b/firmware/zpu/lib/pkt_ctrl.c @@ -1,5 +1,5 @@ /* - * Copyright 2010 Ettus Research LLC + * Copyright 2010-2011 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 @@ -18,7 +18,6 @@ #include "pkt_ctrl.h" #include "memory_map.h" #include -#include //status signals from WB into PR #define CPU_STAT_RD_DONE (1 << 0) @@ -46,13 +45,12 @@ void pkt_ctrl_program_inspector( } void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ - mdelay(100); //give a little delay to space out subsequent calls - switch(mode){ - case PKT_CTRL_ROUTING_MODE_SLAVE: router_ctrl->mode_ctrl = 0; break; - case PKT_CTRL_ROUTING_MODE_MASTER: router_ctrl->mode_ctrl = 1; break; - } - router_ctrl->iface_ctrl = CPU_CTRL_WR_CLEAR; //reset the write state machine - pkt_ctrl_release_incoming_buffer(); //reset the read state machine, and read + //About to change the mode; ensure that we are accepting packets. + //The plumbing will not switch if it cannot pass an end of packet. + pkt_ctrl_release_incoming_buffer(); + + //Change the mode; this switches the valves and crossbars. + router_ctrl->mode_ctrl = mode; } static inline void cpu_stat_wait_for(int bm){ diff --git a/firmware/zpu/lib/pkt_ctrl.h b/firmware/zpu/lib/pkt_ctrl.h index 410ffdaa4..15e4b0c4d 100644 --- a/firmware/zpu/lib/pkt_ctrl.h +++ b/firmware/zpu/lib/pkt_ctrl.h @@ -1,5 +1,5 @@ /* - * Copyright 2010 Ettus Research LLC + * Copyright 2010-2011 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 @@ -24,8 +24,8 @@ #include typedef enum { - PKT_CTRL_ROUTING_MODE_SLAVE, - PKT_CTRL_ROUTING_MODE_MASTER, + PKT_CTRL_ROUTING_MODE_SLAVE = 0, + PKT_CTRL_ROUTING_MODE_MASTER = 1 } pkt_ctrl_routing_mode_t; //! Program the decision values into the packet inspector diff --git a/firmware/zpu/usrp2/CMakeLists.txt b/firmware/zpu/usrp2/CMakeLists.txt index d126c921c..e54499084 100644 --- a/firmware/zpu/usrp2/CMakeLists.txt +++ b/firmware/zpu/usrp2/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 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 diff --git a/firmware/zpu/usrp2p/CMakeLists.txt b/firmware/zpu/usrp2p/CMakeLists.txt index 93ccf82c3..c7ab9abdb 100644 --- a/firmware/zpu/usrp2p/CMakeLists.txt +++ b/firmware/zpu/usrp2p/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 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 diff --git a/firmware/zpu/usrp2p/bootloader/CMakeLists.txt b/firmware/zpu/usrp2p/bootloader/CMakeLists.txt index 155915011..2c7efb43a 100644 --- a/firmware/zpu/usrp2p/bootloader/CMakeLists.txt +++ b/firmware/zpu/usrp2p/bootloader/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 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 diff --git a/host/lib/convert/convert_with_neon.cpp b/host/lib/convert/convert_with_neon.cpp index f379f4d29..3d677db5b 100644 --- a/host/lib/convert/convert_with_neon.cpp +++ b/host/lib/convert/convert_with_neon.cpp @@ -16,7 +16,6 @@ // #include "convert_common.hpp" -#include #include using namespace uhd::convert; -- cgit v1.2.3