From 51cbfdfd7e7c071914442005139894496ddf6039 Mon Sep 17 00:00:00 2001 From: Paul David Date: Wed, 22 Mar 2017 14:51:53 -0400 Subject: Firmware: fix failures due to fw_comm_protocol.h path --- firmware/usrp3/lib/CMakeLists.txt | 1 - firmware/usrp3/lib/fw_comm_protocol.c | 105 ---------------------------- firmware/usrp3/n230/CMakeLists.txt | 7 +- firmware/usrp3/n230/n230_eth_handlers.c | 2 +- firmware/usrp3/n230/n230_fw_comm_protocol.c | 105 ++++++++++++++++++++++++++++ host/lib/usrp/n230/fw_comm_protocol.h | 102 --------------------------- host/lib/usrp/n230/n230_fw_comm_protocol.h | 102 +++++++++++++++++++++++++++ host/lib/usrp/n230/n230_fw_ctrl_iface.cpp | 2 +- 8 files changed, 215 insertions(+), 211 deletions(-) delete mode 100644 firmware/usrp3/lib/fw_comm_protocol.c create mode 100644 firmware/usrp3/n230/n230_fw_comm_protocol.c delete mode 100644 host/lib/usrp/n230/fw_comm_protocol.h create mode 100644 host/lib/usrp/n230/n230_fw_comm_protocol.h diff --git a/firmware/usrp3/lib/CMakeLists.txt b/firmware/usrp3/lib/CMakeLists.txt index 9d9ee3c6c..cd1a82c3f 100644 --- a/firmware/usrp3/lib/CMakeLists.txt +++ b/firmware/usrp3/lib/CMakeLists.txt @@ -30,7 +30,6 @@ add_library(usrp3fw STATIC print_addrs.c link_state_route_proto.c cron.c - fw_comm_protocol.c flash/spi_flash.c flash/spif_spsn_s25flxx.c ) diff --git a/firmware/usrp3/lib/fw_comm_protocol.c b/firmware/usrp3/lib/fw_comm_protocol.c deleted file mode 100644 index 0cc931a76..000000000 --- a/firmware/usrp3/lib/fw_comm_protocol.c +++ /dev/null @@ -1,105 +0,0 @@ -// -// Copyright 2014 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 "../../../host/lib/usrp/common/fw_comm_protocol.h" - -#include -#include //memcmp - -bool process_fw_comm_protocol_pkt( - const fw_comm_pkt_t* request, - fw_comm_pkt_t* response, - uint8_t product_id, - uint32_t iface_id, - poke32_func poke_callback, - peek32_func peek_callback) -{ - bool send_response = false; - - uint16_t signature = request->id; - uint8_t version = FW_COMM_GET_PROTOCOL_VER(request->id); - uint8_t product = FW_COMM_GET_PRODUCT_ID(request->id); - if (signature == FW_COMM_PROTOCOL_SIGNATURE && //Verify protocol - version <= FW_COMM_PROTOCOL_VERSION && //Verify protocol version (older versions supported) - product == product_id) //Verify device - { - //Request is valid. Copy it into the reply. - memcpy(response, request, sizeof(fw_comm_pkt_t)); - - //Start assuming no error - response->flags &= ~FW_COMM_FLAGS_ERROR_MASK; - - //Otherwise, run the command set by the flags - switch (request->flags & FW_COMM_FLAGS_CMD_MASK) { - case FW_COMM_CMD_ECHO: { - UHD_FW_TRACE(DEBUG, "fw_comm_protocol::echo()"); - response->data_words = 1; - response->data[0] = iface_id; - } break; - - case FW_COMM_CMD_POKE32: { - UHD_FW_TRACE_FSTR(DEBUG, "fw_comm_protocol::poke32(0x%x)=0x%x", - request->addr,*(request->data)); - poke_callback(request->addr, *(request->data)); - } break; - - case FW_COMM_CMD_PEEK32: { - *(response->data) = peek_callback(request->addr); - UHD_FW_TRACE_FSTR(DEBUG, "fw_comm_protocol::peek32(0x%x)=0x%x", - request->addr,*(response->data)); - } break; - - case FW_COMM_CMD_BLOCK_POKE32: { - if (request->data_words > FW_COMM_MAX_DATA_WORDS) { - response->flags |= FW_COMM_ERR_SIZE_ERROR; - response->data_words = FW_COMM_MAX_DATA_WORDS; - } else { - response->data_words = request->data_words; - } - UHD_FW_TRACE_FSTR(DEBUG, "fw_comm_protocol::block_poke32(0x%x,%d)",request->addr,response->data_words); - for (uint32_t i = 0; i < response->data_words; i++) { - poke_callback(request->addr + (i * sizeof(uint32_t)), request->data[i]); - } - } break; - - case FW_COMM_CMD_BLOCK_PEEK32: { - if (request->data_words > FW_COMM_MAX_DATA_WORDS) { - response->flags |= FW_COMM_ERR_SIZE_ERROR; - response->data_words = FW_COMM_MAX_DATA_WORDS; - } else { - response->data_words = request->data_words; - } - for (uint32_t i = 0; i < response->data_words; i++) { - response->data[i] = peek_callback(request->addr + (i * sizeof(uint32_t))); - } - UHD_FW_TRACE_FSTR(DEBUG, "fw_comm_protocol::block_peek32(0x%x,%d)",request->addr,response->data_words); - } break; - - default: { - UHD_FW_TRACE(ERROR, "fw_comm_protocol got an invalid command."); - response->flags |= FW_COMM_ERR_CMD_ERROR; - } - } - - //Send a reply if ack requested - send_response = (request->flags & FW_COMM_FLAGS_ACK); - } else { //Size, protocol, product check failed - UHD_FW_TRACE(WARN, "fw_comm_protocol ignored an unknown request."); - send_response = false; - } - return send_response; -} diff --git a/firmware/usrp3/n230/CMakeLists.txt b/firmware/usrp3/n230/CMakeLists.txt index 6247477f0..5787fbb7d 100644 --- a/firmware/usrp3/n230/CMakeLists.txt +++ b/firmware/usrp3/n230/CMakeLists.txt @@ -19,7 +19,12 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_SOURCE_DIR}/../../host/lib/usrp/n230) -list(APPEND n230_sources n230_eeprom.c n230_eth_handlers.c n230_init.c n230_main.c) +list(APPEND n230_sources + n230_eeprom.c + n230_fw_comm_protocol.c + n230_eth_handlers.c + n230_init.c + n230_main.c) ######################################################################## set(GEN_OUTPUTS_BIN_SIZE 0x7fff) diff --git a/firmware/usrp3/n230/n230_eth_handlers.c b/firmware/usrp3/n230/n230_eth_handlers.c index b291bb39f..f5c319681 100644 --- a/firmware/usrp3/n230/n230_eth_handlers.c +++ b/firmware/usrp3/n230/n230_eth_handlers.c @@ -22,7 +22,7 @@ #include #include #include -#include "../../../host/lib/usrp/common/fw_comm_protocol.h" +#include "../../../host/lib/usrp/n230/n230_fw_comm_protocol.h" #include "../../../host/lib/usrp/n230/n230_fw_defs.h" #include "../n230/n230_fw_host_iface.h" #include "../../../host/lib/usrp/n230/n230_eeprom.h" diff --git a/firmware/usrp3/n230/n230_fw_comm_protocol.c b/firmware/usrp3/n230/n230_fw_comm_protocol.c new file mode 100644 index 000000000..d6f6dff5a --- /dev/null +++ b/firmware/usrp3/n230/n230_fw_comm_protocol.c @@ -0,0 +1,105 @@ +// +// Copyright 2014 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 "../../../host/lib/usrp/n230/n230_fw_comm_protocol.h" + +#include +#include //memcmp + +bool process_fw_comm_protocol_pkt( + const fw_comm_pkt_t* request, + fw_comm_pkt_t* response, + uint8_t product_id, + uint32_t iface_id, + poke32_func poke_callback, + peek32_func peek_callback) +{ + bool send_response = false; + + uint16_t signature = request->id; + uint8_t version = FW_COMM_GET_PROTOCOL_VER(request->id); + uint8_t product = FW_COMM_GET_PRODUCT_ID(request->id); + if (signature == FW_COMM_PROTOCOL_SIGNATURE && //Verify protocol + version <= FW_COMM_PROTOCOL_VERSION && //Verify protocol version (older versions supported) + product == product_id) //Verify device + { + //Request is valid. Copy it into the reply. + memcpy(response, request, sizeof(fw_comm_pkt_t)); + + //Start assuming no error + response->flags &= ~FW_COMM_FLAGS_ERROR_MASK; + + //Otherwise, run the command set by the flags + switch (request->flags & FW_COMM_FLAGS_CMD_MASK) { + case FW_COMM_CMD_ECHO: { + UHD_FW_TRACE(DEBUG, "fw_comm_protocol::echo()"); + response->data_words = 1; + response->data[0] = iface_id; + } break; + + case FW_COMM_CMD_POKE32: { + UHD_FW_TRACE_FSTR(DEBUG, "fw_comm_protocol::poke32(0x%x)=0x%x", + request->addr,*(request->data)); + poke_callback(request->addr, *(request->data)); + } break; + + case FW_COMM_CMD_PEEK32: { + *(response->data) = peek_callback(request->addr); + UHD_FW_TRACE_FSTR(DEBUG, "fw_comm_protocol::peek32(0x%x)=0x%x", + request->addr,*(response->data)); + } break; + + case FW_COMM_CMD_BLOCK_POKE32: { + if (request->data_words > FW_COMM_MAX_DATA_WORDS) { + response->flags |= FW_COMM_ERR_SIZE_ERROR; + response->data_words = FW_COMM_MAX_DATA_WORDS; + } else { + response->data_words = request->data_words; + } + UHD_FW_TRACE_FSTR(DEBUG, "fw_comm_protocol::block_poke32(0x%x,%d)",request->addr,response->data_words); + for (uint32_t i = 0; i < response->data_words; i++) { + poke_callback(request->addr + (i * sizeof(uint32_t)), request->data[i]); + } + } break; + + case FW_COMM_CMD_BLOCK_PEEK32: { + if (request->data_words > FW_COMM_MAX_DATA_WORDS) { + response->flags |= FW_COMM_ERR_SIZE_ERROR; + response->data_words = FW_COMM_MAX_DATA_WORDS; + } else { + response->data_words = request->data_words; + } + for (uint32_t i = 0; i < response->data_words; i++) { + response->data[i] = peek_callback(request->addr + (i * sizeof(uint32_t))); + } + UHD_FW_TRACE_FSTR(DEBUG, "fw_comm_protocol::block_peek32(0x%x,%d)",request->addr,response->data_words); + } break; + + default: { + UHD_FW_TRACE(ERROR, "fw_comm_protocol got an invalid command."); + response->flags |= FW_COMM_ERR_CMD_ERROR; + } + } + + //Send a reply if ack requested + send_response = (request->flags & FW_COMM_FLAGS_ACK); + } else { //Size, protocol, product check failed + UHD_FW_TRACE(WARN, "fw_comm_protocol ignored an unknown request."); + send_response = false; + } + return send_response; +} diff --git a/host/lib/usrp/n230/fw_comm_protocol.h b/host/lib/usrp/n230/fw_comm_protocol.h deleted file mode 100644 index 14adb33a9..000000000 --- a/host/lib/usrp/n230/fw_comm_protocol.h +++ /dev/null @@ -1,102 +0,0 @@ -// -// Copyright 2014 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 . -// - -#ifndef INCLUDED_FW_COMM_PROTOCOL -#define INCLUDED_FW_COMM_PROTOCOL - -#include -#ifndef __cplusplus -#include -#endif - -/*! - * Structs and constants for communication between firmware and host. - * This header is shared by the firmware and host code. - * Therefore, this header may only contain valid C code. - */ -#ifdef __cplusplus -extern "C" { -#endif - -#define FW_COMM_PROTOCOL_SIGNATURE 0xACE3 -#define FW_COMM_PROTOCOL_VERSION 0 -#define FW_COMM_MAX_DATA_WORDS 16 -#define FW_COMM_PROTOCOL_MTU 256 - -#define FW_COMM_FLAGS_ACK 0x00000001 -#define FW_COMM_FLAGS_CMD_MASK 0x00000FF0 -#define FW_COMM_FLAGS_ERROR_MASK 0xFF000000 - -#define FW_COMM_CMD_ECHO 0x00000000 -#define FW_COMM_CMD_POKE32 0x00000010 -#define FW_COMM_CMD_PEEK32 0x00000020 -#define FW_COMM_CMD_BLOCK_POKE32 0x00000030 -#define FW_COMM_CMD_BLOCK_PEEK32 0x00000040 - -#define FW_COMM_ERR_PKT_ERROR 0x80000000 -#define FW_COMM_ERR_CMD_ERROR 0x40000000 -#define FW_COMM_ERR_SIZE_ERROR 0x20000000 - -#define FW_COMM_GENERATE_ID(prod) ((((uint32_t) FW_COMM_PROTOCOL_SIGNATURE) << 0) | \ - (((uint32_t) prod) << 16) | \ - (((uint32_t) FW_COMM_PROTOCOL_VERSION) << 24)) - -#define FW_COMM_GET_PROTOCOL_SIG(id) ((uint16_t)(id & 0xFFFF)) -#define FW_COMM_GET_PRODUCT_ID(id) ((uint8_t)(id >> 16)) -#define FW_COMM_GET_PROTOCOL_VER(id) ((uint8_t)(id >> 24)) - -typedef struct -{ - uint32_t id; //Protocol and device identifier - uint32_t flags; //Holds commands and ack messages - uint32_t sequence; //Sequence number (specific to FW communication transactions) - uint32_t data_words; //Number of data words in payload - uint32_t addr; //Address field for the command in flags - uint32_t data[FW_COMM_MAX_DATA_WORDS]; //Data field for the command in flags -} fw_comm_pkt_t; - -#ifdef __cplusplus -} //extern "C" -#endif - -// The following definitions are only useful in firmware. Exclude in host code. -#ifndef __cplusplus - -typedef void (*poke32_func)(const uint32_t addr, const uint32_t data); -typedef uint32_t (*peek32_func)(const uint32_t addr); - -/*! - * Process a firmware communication packet and compute a response. - * Args: - * - (in) request: Pointer to the request struct - * - (out) response: Pointer to the response struct - * - (in) product_id: The 8-bit usrp3 specific product ID (for request filtering) - * - (func) poke_callback, peek_callback: Callback functions for a single peek/poke - * - return value: Send a response packet - */ -bool process_fw_comm_protocol_pkt( - const fw_comm_pkt_t* request, - fw_comm_pkt_t* response, - uint8_t product_id, - uint32_t iface_id, - poke32_func poke_callback, - peek32_func peek_callback -); - -#endif //ifdef __cplusplus - -#endif /* INCLUDED_FW_COMM_PROTOCOL */ diff --git a/host/lib/usrp/n230/n230_fw_comm_protocol.h b/host/lib/usrp/n230/n230_fw_comm_protocol.h new file mode 100644 index 000000000..b7c85f2ba --- /dev/null +++ b/host/lib/usrp/n230/n230_fw_comm_protocol.h @@ -0,0 +1,102 @@ +// +// Copyright 2014 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 . +// + +#ifndef INCLUDED_N230_FW_COMM_PROTOCOL +#define INCLUDED_N230_FW_COMM_PROTOCOL + +#include +#ifndef __cplusplus +#include +#endif + +/*! + * Structs and constants for communication between firmware and host. + * This header is shared by the firmware and host code. + * Therefore, this header may only contain valid C code. + */ +#ifdef __cplusplus +extern "C" { +#endif + +#define FW_COMM_PROTOCOL_SIGNATURE 0xACE3 +#define FW_COMM_PROTOCOL_VERSION 0 +#define FW_COMM_MAX_DATA_WORDS 16 +#define FW_COMM_PROTOCOL_MTU 256 + +#define FW_COMM_FLAGS_ACK 0x00000001 +#define FW_COMM_FLAGS_CMD_MASK 0x00000FF0 +#define FW_COMM_FLAGS_ERROR_MASK 0xFF000000 + +#define FW_COMM_CMD_ECHO 0x00000000 +#define FW_COMM_CMD_POKE32 0x00000010 +#define FW_COMM_CMD_PEEK32 0x00000020 +#define FW_COMM_CMD_BLOCK_POKE32 0x00000030 +#define FW_COMM_CMD_BLOCK_PEEK32 0x00000040 + +#define FW_COMM_ERR_PKT_ERROR 0x80000000 +#define FW_COMM_ERR_CMD_ERROR 0x40000000 +#define FW_COMM_ERR_SIZE_ERROR 0x20000000 + +#define FW_COMM_GENERATE_ID(prod) ((((uint32_t) FW_COMM_PROTOCOL_SIGNATURE) << 0) | \ + (((uint32_t) prod) << 16) | \ + (((uint32_t) FW_COMM_PROTOCOL_VERSION) << 24)) + +#define FW_COMM_GET_PROTOCOL_SIG(id) ((uint16_t)(id & 0xFFFF)) +#define FW_COMM_GET_PRODUCT_ID(id) ((uint8_t)(id >> 16)) +#define FW_COMM_GET_PROTOCOL_VER(id) ((uint8_t)(id >> 24)) + +typedef struct +{ + uint32_t id; //Protocol and device identifier + uint32_t flags; //Holds commands and ack messages + uint32_t sequence; //Sequence number (specific to FW communication transactions) + uint32_t data_words; //Number of data words in payload + uint32_t addr; //Address field for the command in flags + uint32_t data[FW_COMM_MAX_DATA_WORDS]; //Data field for the command in flags +} fw_comm_pkt_t; + +#ifdef __cplusplus +} //extern "C" +#endif + +// The following definitions are only useful in firmware. Exclude in host code. +#ifndef __cplusplus + +typedef void (*poke32_func)(const uint32_t addr, const uint32_t data); +typedef uint32_t (*peek32_func)(const uint32_t addr); + +/*! + * Process a firmware communication packet and compute a response. + * Args: + * - (in) request: Pointer to the request struct + * - (out) response: Pointer to the response struct + * - (in) product_id: The 8-bit usrp3 specific product ID (for request filtering) + * - (func) poke_callback, peek_callback: Callback functions for a single peek/poke + * - return value: Send a response packet + */ +bool process_fw_comm_protocol_pkt( + const fw_comm_pkt_t* request, + fw_comm_pkt_t* response, + uint8_t product_id, + uint32_t iface_id, + poke32_func poke_callback, + peek32_func peek_callback +); + +#endif //ifdef __cplusplus + +#endif /* INCLUDED_N230_FW_COMM_PROTOCOL */ diff --git a/host/lib/usrp/n230/n230_fw_ctrl_iface.cpp b/host/lib/usrp/n230/n230_fw_ctrl_iface.cpp index 07f9bb7d6..18c2c4cf8 100644 --- a/host/lib/usrp/n230/n230_fw_ctrl_iface.cpp +++ b/host/lib/usrp/n230/n230_fw_ctrl_iface.cpp @@ -22,7 +22,7 @@ #include #include #include //used for htonl and ntohl -#include "fw_comm_protocol.h" +#include "n230_fw_comm_protocol.h" namespace uhd { namespace usrp { namespace n230 { -- cgit v1.2.3