diff options
author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2024-11-03 15:56:55 +0000 |
---|---|---|
committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2024-11-03 15:56:55 +0000 |
commit | cf4444e7390365df43ecbd3d130015c1e06ef88f (patch) | |
tree | 8a6eb114135a04d5efd5af213577b4fac47532ae /Radio/HW/BladeRF/firmware_common | |
parent | ca50c0f64f1b2fce46b4cb83ed111854bac13852 (diff) | |
download | PrySDR-cf4444e7390365df43ecbd3d130015c1e06ef88f.tar.gz PrySDR-cf4444e7390365df43ecbd3d130015c1e06ef88f.zip |
BladeRF library compiles
Diffstat (limited to 'Radio/HW/BladeRF/firmware_common')
-rw-r--r-- | Radio/HW/BladeRF/firmware_common/bladeRF.h | 133 | ||||
-rw-r--r-- | Radio/HW/BladeRF/firmware_common/logger_entry.h | 74 | ||||
-rw-r--r-- | Radio/HW/BladeRF/firmware_common/misc.h | 45 |
3 files changed, 252 insertions, 0 deletions
diff --git a/Radio/HW/BladeRF/firmware_common/bladeRF.h b/Radio/HW/BladeRF/firmware_common/bladeRF.h new file mode 100644 index 0000000..bfc8c0f --- /dev/null +++ b/Radio/HW/BladeRF/firmware_common/bladeRF.h @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2013 Nuand LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef _BLADERF_FIRMWARE_COMMON_H_ +#define _BLADERF_FIRMWARE_COMMON_H_ + +#define BLADE_USB_CMD_QUERY_VERSION 0 +#define BLADE_USB_CMD_QUERY_FPGA_STATUS 1 +#define BLADE_USB_CMD_BEGIN_PROG 2 +#define BLADE_USB_CMD_END_PROG 3 +#define BLADE_USB_CMD_RF_RX 4 +#define BLADE_USB_CMD_RF_TX 5 +#define BLADE_USB_CMD_QUERY_DEVICE_READY 6 +#define BLADE_USB_CMD_QUERY_FLASH_ID 7 +#define BLADE_USB_CMD_QUERY_FPGA_SOURCE 8 +#define BLADE_USB_CMD_FLASH_READ 100 +#define BLADE_USB_CMD_FLASH_WRITE 101 +#define BLADE_USB_CMD_FLASH_ERASE 102 +#define BLADE_USB_CMD_READ_OTP 103 +#define BLADE_USB_CMD_WRITE_OTP 104 +#define BLADE_USB_CMD_RESET 105 +#define BLADE_USB_CMD_JUMP_TO_BOOTLOADER 106 +#define BLADE_USB_CMD_READ_PAGE_BUFFER 107 +#define BLADE_USB_CMD_WRITE_PAGE_BUFFER 108 +#define BLADE_USB_CMD_LOCK_OTP 109 +#define BLADE_USB_CMD_READ_CAL_CACHE 110 +#define BLADE_USB_CMD_INVALIDATE_CAL_CACHE 111 +#define BLADE_USB_CMD_REFRESH_CAL_CACHE 112 +#define BLADE_USB_CMD_SET_LOOPBACK 113 +#define BLADE_USB_CMD_GET_LOOPBACK 114 +#define BLADE_USB_CMD_READ_LOG_ENTRY 115 + +/* String descriptor indices */ +#define BLADE_USB_STR_INDEX_MFR 1 /* Manufacturer */ +#define BLADE_USB_STR_INDEX_PRODUCT 2 /* Product */ +#define BLADE_USB_STR_INDEX_SERIAL 3 /* Serial number */ +#define BLADE_USB_STR_INDEX_FW_VER 4 /* Firmware version */ + +#define CAL_BUFFER_SIZE 256 +#define CAL_PAGE 768 + +#define AUTOLOAD_BUFFER_SIZE 256 +#define AUTOLOAD_PAGE 1024 + +#ifdef _MSC_VER +# define PACK(decl_to_pack_) \ + __pragma(pack(push,1)) \ + decl_to_pack_ \ + __pragma(pack(pop)) +#elif defined(__GNUC__) +# define PACK(decl_to_pack_) \ + decl_to_pack_ __attribute__((__packed__)) +#else +#error "Unexpected compiler/environment" +#endif + +PACK( +struct bladerf_fx3_version { + unsigned short major; + unsigned short minor; +}); + +struct bladeRF_firmware { + unsigned int len; + unsigned char *ptr; +}; + +struct bladeRF_sector { + unsigned int idx; + unsigned int len; + unsigned char *ptr; +}; + +/** + * FPGA configuration source + * + * Note: the numbering of this enum must match bladerf_fpga_source in + * libbladeRF.h + */ +typedef enum { + NUAND_FPGA_CONFIG_SOURCE_INVALID = 0, /**< Uninitialized/invalid */ + NUAND_FPGA_CONFIG_SOURCE_FLASH = 1, /**< Last FPGA load was from flash */ + NUAND_FPGA_CONFIG_SOURCE_HOST = 2 /**< Last FPGA load was from host */ +} NuandFpgaConfigSource; + +#define USB_CYPRESS_VENDOR_ID 0x04b4 +#define USB_FX3_PRODUCT_ID 0x00f3 + +#define BLADE_USB_TYPE_OUT 0x40 +#define BLADE_USB_TYPE_IN 0xC0 +#define BLADE_USB_TIMEOUT_MS 1000 + +#define USB_NUAND_VENDOR_ID 0x2cf0 +#define USB_NUAND_BLADERF_PRODUCT_ID 0x5246 +#define USB_NUAND_BLADERF_BOOT_PRODUCT_ID 0x5247 +#define USB_NUAND_BLADERF2_PRODUCT_ID 0x5250 + +#define USB_NUAND_LEGACY_VENDOR_ID 0x1d50 +#define USB_NUAND_BLADERF_LEGACY_PRODUCT_ID 0x6066 +#define USB_NUAND_BLADERF_LEGACY_BOOT_PRODUCT_ID 0x6080 + +#define USB_NUAND_BLADERF_MINOR_BASE 193 +#define NUM_CONCURRENT 8 +#define NUM_DATA_URB (1024) +#define DATA_BUF_SZ (1024*4) + + +/* Interface numbers */ +#define USB_IF_LEGACY_CONFIG 0 +#define USB_IF_NULL 0 +#define USB_IF_RF_LINK 1 +#define USB_IF_SPI_FLASH 2 +#define USB_IF_CONFIG 3 + +#endif /* _BLADERF_FIRMWARE_COMMON_H_ */ diff --git a/Radio/HW/BladeRF/firmware_common/logger_entry.h b/Radio/HW/BladeRF/firmware_common/logger_entry.h new file mode 100644 index 0000000..03eec3f --- /dev/null +++ b/Radio/HW/BladeRF/firmware_common/logger_entry.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2015 Nuand LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef LOGGER_ENTRY +#define LOGGER_ENTRY + +#include <stdint.h> + +/* A log entry word is laid out as follows. All values are little endian. + * + * +--------+--------+-------------------------------------------------------+ + * | Bit | Length | Description | + * +========+========+=======================================================+ + * | 0 | 16 | Data to include with the logged event | + * +--------+--------+-------------------------------------------------------+ + * | 16 | 11 | Source line number where the event was logged | + * +--------+--------+-------------------------------------------------------+ + * | 27 | 5 | Source file ID where the event was logged | + * +--------+--------+-------------------------------------------------------+ + * + */ +typedef uint32_t logger_entry; + +#define LOG_DATA_SHIFT 0 +#define LOG_DATA_MASK 0xffff + +#define LOG_LINE_SHIFT 16 +#define LOG_LINE_MASK 0x7ff + +#define LOG_FILE_SHIFT 27 +#define LOG_FILE_MASK 0x1f + +#define LOG_EOF 0x00000000 +#define LOG_ERR 0xffffffff + +static inline logger_entry logger_entry_pack(uint8_t file, uint16_t line, + uint16_t data) +{ + logger_entry e; + + e = (data & LOG_DATA_MASK) << LOG_DATA_SHIFT; + e |= (line & LOG_LINE_MASK) << LOG_LINE_SHIFT; + e |= (file & LOG_FILE_MASK) << LOG_FILE_SHIFT; + + return e; +} + +static inline void logger_entry_unpack(logger_entry e, uint8_t *file, + uint16_t *line, uint16_t *data) +{ + *data = (e >> LOG_DATA_SHIFT) & LOG_DATA_MASK; + *line = (e >> LOG_LINE_SHIFT) & LOG_LINE_MASK; + *file = (e >> LOG_FILE_SHIFT) & LOG_FILE_MASK; +} + +#endif diff --git a/Radio/HW/BladeRF/firmware_common/misc.h b/Radio/HW/BladeRF/firmware_common/misc.h new file mode 100644 index 0000000..b3b434e --- /dev/null +++ b/Radio/HW/BladeRF/firmware_common/misc.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Nuand LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef MISC_LIB +#define MISC_LIB + +#include <stdint.h> + +uint16_t zcrc(uint8_t *data, size_t len){ + uint16_t ret = 0; + int b, msb; + unsigned i; + + for (i = 0; i < len; i++) { + ret ^= data[i] << 8; + for (b = 0; b < 8; b++) { + msb = ret & 0x8000; + ret <<= 1; + if (msb) { + ret ^= 0x1021; + } + } + } + return ret; +} + +#endif |