


























AD9361 SPI no-os 文件移植 SoftConsole MPFS250T 初学(一) 驱动代码移植 - 所长 - 博客园
AD9361 SPI no-os 文件移植 SoftConsole MPFS250T 初学(二) AD9361 初始化流程 熟悉 - 所长 - 博客园
AD9361 SPI no-os 文件移植 SoftConsole MPFS250T 初学(三) 接口适配到自己的板子 - 所长 - 博客园
AD9361 SPI no-os 文件移植 SoftConsole MPFS250T 初学(四) ad9361_init 编译报错 和 读取 AD9361 ID - 所长 - 博客园
AD9361 SPI no-os 文件移植 SoftConsole MPFS250T 初学(五) ad9361_check_cal_done 卡死 - 所长 - 博客园
AD9361 SPI no-os 文件移植 SoftConsole MPFS250T 初学(六) 开启 日志打印 Calibration TIMEOUT (0x247, 0x2) - 所长 - 博客园
AD9361 SPI no-os 文件移植 SoftConsole MPFS250T 初学(七) 初始化日志记录 - 所长 - 博客园
上面一章 讲了 初始化 ad9361 基本流程,官方给出的接口是 xilinx , 没有 MPFS250T ,因此 , spi 接口 , gpio 控制接口(复位和使能和同步)需要自己实现
要实现的接口函数 GPIO 和 SPI 接口 ,: 官方 对这两个接口 实现的比较复杂 ,主要参考 xilinx 接口实现
#define GPIO_OPS &xil_gpio_ops
#define SPI_OPS &xil_spi_ops
/** * @brief Xilinx platform specific GPIO platform ops structure */ const struct no_os_gpio_platform_ops xil_gpio_ops = { .gpio_ops_get = &xil_gpio_get, .gpio_ops_get_optional = &xil_gpio_get_optional, .gpio_ops_remove = &xil_gpio_remove, .gpio_ops_direction_input = &xil_gpio_direction_input, .gpio_ops_direction_output = &xil_gpio_direction_output, .gpio_ops_get_direction = &xil_gpio_get_direction, .gpio_ops_set_value = &xil_gpio_set_value, .gpio_ops_get_value = &xil_gpio_get_value, };
/** * @brief Xilinx platform specific SPI platform ops structure */ const struct no_os_spi_platform_ops xil_spi_ops = { .init = &xil_spi_init, .write_and_read = &xil_spi_write_and_read, .remove = &xil_spi_remove };

ad9361_init →
ad9361_reset(phy) →
no_os_gpio_set_value(phy->gpio_desc_resetb, 0); → // 控制引脚 拉低
desc->platform_ops->gpio_ops_set_value(desc, value); → // 调用接口 设置引脚电平
no_os_mdelay(1) → // 延迟 1ms
no_os_gpio_set_value(phy->gpio_desc_resetb, 1); → // 控制引脚 拉高
// SPI 接口 和 GPIO MPFS250T 接口实现
// SPI 收发数据 注意, AD9361 的 库 不会 给出 发送字节数和接收字节数, 需要 修改 AD9361的库
/** * @brief Set the value of the specified GPIO. * @param desc - The GPIO descriptor. * @param value - The value. * Example: NO_OS_GPIO_HIGH * NO_OS_GPIO_LOW * @return 0 in case of success, -1 otherwise. */ int32_t mpfs_gpio_set_value(struct no_os_gpio_desc *desc, uint8_t value) { if(desc) { xprintf( "mpfs_gpio_set_value number:%d,value=%d.\n", desc->number, value ); if( desc->number == AD9361_RESET_GPIO ) { bsp_ad9361_gpio_set(AD9361_RESET_GPIO,value); } } return 0; }
/** * @brief Write and read data to/from SPI. * @param desc - The SPI descriptor. * @param data - The buffer with the transmitted/received data. * @param bytes_number - Number of bytes to write/read. * @return 0 in case of success, -1 otherwise. */ int32_t mpfs_spi_write_and_read(struct no_os_spi_desc *desc, uint8_t *data, uint16_t tx_len, uint16_t rx_len) { MSS_SPI_set_slave_select(&g_mss_spi0_lo, MSS_SPI_SLAVE_1); MSS_SPI_transfer_block(&g_mss_spi0_lo, data, tx_len, &data[tx_len], rx_len); MSS_SPI_clear_slave_select(&g_mss_spi0_lo, MSS_SPI_SLAVE_1); // xprintf_hex( "mpfs_spi_tx_rx", data, tx_len+rx_len ); return 0; }
延迟接口,最小延迟 1ms , 因此 us 延迟 用 ms 延迟替代, 不足 1ms 用 1ms 替代
/* Kernel includes. */ #include "FreeRTOS.h" #include "task.h" #include "queue.h" /** * @brief Generate microseconds delay. * @param usecs - Delay in microseconds. */ void no_os_udelay(uint32_t usecs) { if(usecs<1000) vTaskDelay(1); else vTaskDelay((usecs/1000)+1); } /** * @brief Generate miliseconds delay. * @param msecs - Delay in miliseconds. */ void no_os_mdelay(uint32_t msecs) { vTaskDelay(msecs); }
内存分配和释放接口
/*****************************************/ /***************MALLOC/FREE***********************/ /*****************************************/ /** * @brief Allocate memory and return a pointer to it. * @param size - Size of the memory block, in bytes. * @return Pointer to the allocated memory, or NULL if the request fails. */ void *no_os_malloc(size_t size) { return pvPortMalloc(size); } /** * @brief Allocate memory and return a pointer to it, set memory to 0. * @param nitems - Number of elements to be allocated. * @param size - Size of elements. * @return Pointer to the allocated memory, or NULL if the request fails. */ void *no_os_calloc(size_t nitems, size_t size) { return pvPortCalloc(nitems, size); } /** * @brief Deallocate memory previously allocated by a call to no_os_calloc * or no_os_malloc. * @param ptr - Pointer to a memory block previously allocated by a call * to no_os_calloc or no_os_malloc. * @return None. */ void no_os_free(void *ptr) { vPortFree(ptr); }
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。