refactor(freertos): 更新 TCA6416 任务创建代码
- 移除 TCA6416 任务创建的注释 - 更新任务名称从 start_tca6416_task 到 test_tca6416_task - 删除多余的空行 fix(ad7124): 重构 AD7124 SPI 通信函数 - 移除冗余的接收缓冲区声明 - 新增 AD7124_OUT_spi_transmit_receive 函数用于 AD7124 的 SPI 通信 - 更新函数调用以使用新的 AD7124 通信函数 - 在头文件中添加新函数的声明
This commit is contained in:
parent
af35522a99
commit
c451e7d754
|
@ -204,9 +204,9 @@ void MX_FREERTOS_Init(void)
|
|||
usart6_test_taskHandle = osThreadCreate(osThread(usart6_test_task), NULL);
|
||||
|
||||
/* TCA6416任务 */
|
||||
//osThreadDef(tca6416_task, start_tca6416_task, osPriorityNormal, 0, 128);
|
||||
// tca6416_taskHandle = osThreadCreate(osThread(tca6416_task), NULL);
|
||||
/* TCA6416测试任务 */
|
||||
osThreadDef(tca6416_task, test_tca6416_task, osPriorityNormal, 0, 128);
|
||||
tca6416_taskHandle = osThreadCreate(osThread(tca6416_task), NULL);
|
||||
|
||||
|
||||
|
||||
/* DAC161S997测试任务 */
|
||||
|
|
|
@ -415,10 +415,10 @@ int32_t ad7124_setup(void)
|
|||
int32_t ad7124_read_write_spi(uint8_t *buff, uint8_t length)
|
||||
{
|
||||
int32_t ret;
|
||||
uint8_t rx_buff[8] = {0}; // Add receive buffer
|
||||
board_spi_init(AD7124); // 初始化SPI,因为DAC161的SPI要和AD7124共用,并且时序不一样,所以要先初始化SPI接口。
|
||||
board_spi_init(AD7124);
|
||||
board_spi_cs_on(AD7124);
|
||||
ret = spi_transmit_receive(&hspi1, buff, rx_buff, length);
|
||||
ret = AD7124_OUT_spi_transmit_receive(buff, length);
|
||||
board_spi_cs_off(AD7124);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,10 @@ typedef volatile uint32_t __IO;
|
|||
#define SUCCESS 0
|
||||
#define FAILURE -1
|
||||
|
||||
#define SPI_BUFFER_SIZE 255
|
||||
// 定义SPI缓冲区
|
||||
static uint8_t spi_rx_buffer[256]; // 接收缓冲区
|
||||
|
||||
static uint8_t ad7124_spi_rx_buffer[SPI_BUFFER_SIZE] = {0};
|
||||
// SPI句柄声明
|
||||
extern SPI_HandleTypeDef hspi1; // 在spi.c中定义
|
||||
extern SPI_HandleTypeDef hspi2; // 在main.c中定义
|
||||
|
@ -58,7 +59,7 @@ extern SPI_HandleTypeDef hspi3; // 在main.c中定义
|
|||
/***************************** #defines ***************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
#define SPI_BUFFER_SIZE 255
|
||||
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -71,6 +72,20 @@ extern SPI_HandleTypeDef hspi1; // 在spi.c中定义
|
|||
/******************************************************************************/
|
||||
/************************ Functions Definitions *******************************/
|
||||
/******************************************************************************/
|
||||
//AD7124重要通信函数
|
||||
int32_t AD7124_OUT_spi_transmit_receive(uint8_t *data_write, uint8_t bytes_number)
|
||||
{
|
||||
// 使用 HAL_SPI_TransmitReceive 函数进行 SPI 通信
|
||||
if (HAL_SPI_TransmitReceive(&hspi2, data_write, (uint8_t *)ad7124_spi_rx_buffer, bytes_number, 1000) != HAL_OK)
|
||||
{
|
||||
// 如果通信失败,返回 FAILURE
|
||||
return FAILURE;
|
||||
}
|
||||
/* 将 SPI 接收缓冲区复制到提供的数据缓冲区,以便返回给调用者 */
|
||||
memcpy(data_write, ad7124_spi_rx_buffer, bytes_number);
|
||||
// 返回 SUCCESS 表示通信成功
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t spi_transmit_receive(SPI_HandleTypeDef *hspi, uint8_t *data_write, uint8_t *data_read, uint8_t bytes_number)
|
||||
{
|
||||
|
|
|
@ -13,6 +13,7 @@ typedef enum
|
|||
} chip_type_e; // 芯片类型
|
||||
|
||||
extern int32_t spi_transmit_receive(SPI_HandleTypeDef *hspi, uint8_t *data_write, uint8_t *data_read, uint8_t bytes_number);
|
||||
extern int32_t AD7124_OUT_spi_transmit_receive(uint8_t *data_write, uint8_t bytes_number);
|
||||
extern SPI_HandleTypeDef hspi1;
|
||||
extern SPI_HandleTypeDef hspi2;
|
||||
extern SPI_HandleTypeDef hspi3;
|
||||
|
|
Loading…
Reference in New Issue