From 9e92b9a9b8a7b04a95da9f20e15f9ab6ab3a07c1 Mon Sep 17 00:00:00 2001 From: Alessandro Conforti Date: Mon, 11 Dec 2023 14:23:54 +0100 Subject: [PATCH 1/3] feat(can-manager): added tests minor: clang format --- can-manager/can_manager.c | 64 +++++++++++++++++++++++++++++++++------ can-manager/can_manager.h | 14 ++++++++- can-manager/test/test.c | 43 ++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 11 deletions(-) create mode 100644 can-manager/test/test.c diff --git a/can-manager/can_manager.c b/can-manager/can_manager.c index 2105f85..ef33a5a 100644 --- a/can-manager/can_manager.c +++ b/can-manager/can_manager.c @@ -82,15 +82,30 @@ #include "can_manager.h" -int _n_active_can = 0; -int can_manager_error_code = 0; +int _n_active_can = 0; +int can_manager_error_code = 0; +#ifndef TEST HAL_StatusTypeDef can_manager_hal_status_retval = HAL_OK; +#endif generic_queue_t _rx_queues[CAN_MGR_MAX_CAN_BUSES]; generic_queue_t _tx_queues[CAN_MGR_MAX_CAN_BUSES]; uint8_t _rx_queues_data[CAN_MGR_MAX_QUEUE_ELEMENTS * sizeof(can_manager_message_t) * CAN_MGR_MAX_CAN_BUSES]; uint8_t _tx_queues_data[CAN_MGR_MAX_QUEUE_ELEMENTS * sizeof(can_manager_message_t) * CAN_MGR_MAX_CAN_BUSES]; void (*can_rx_msg_handlers[CAN_MGR_MAX_CAN_BUSES])(can_manager_message_t *); +#ifdef TEST +void print_message(can_manager_message_t *msg) { + printf("id: %d, size: %d, data: [", msg->id, msg->size); + if (msg->size > 0) { + printf("%d", msg->data[0]); + for (int i = 1; i < msg->size && i < 8; ++i) { + printf(", %d", msg->data[i]); + } + } + printf("]\n"); +} +#endif + #if FDCAN_MGR_ENABLED == 1 FDCAN_HandleTypeDef *fdcan_buses[MAX_CAN_BUSES]; @@ -106,14 +121,17 @@ int fdcan_init( can_rx_msg_handlers[assigned_id] = can_rx_msg_handler; GENQ_init( - &_rx_queues[assigned_id], sizeof(can_manager_message_t), CAN_MGR_MAX_QUEUE_ELEMENTS, &_rx_queues_data[assigned_id]); + &_rx_queues[assigned_id], sizeof(can_manager_message_t), CAN_MGR_MAX_QUEUE_ELEMENTS, + &_rx_queues_data[assigned_id]); GENQ_init( - &_tx_queues[assigned_id], sizeof(can_manager_message_t), CAN_MGR_MAX_QUEUE_ELEMENTS, &_tx_queues_data[assigned_id]); + &_tx_queues[assigned_id], sizeof(can_manager_message_t), CAN_MGR_MAX_QUEUE_ELEMENTS, + &_tx_queues_data[assigned_id]); fdcan_buses[assigned_id] = hcan; _n_active_can++; +#ifndef TEST if ((can_manager_hal_status_retval = HAL_FDCAN_ConfigFilter(hcan, filter)) != HAL_OK) { can_manager_hal_status_retval = CAN_MGR_FILTER_ERROR_CODE; return -1; @@ -126,9 +144,11 @@ int fdcan_init( can_manager_hal_status_retval = CAN_MGR_CAN_START_ERROR_CODE; return -1; } +#endif return assigned_id; } +#ifndef TEST void _fdcan_wait(FDCAN_HandleTypeDef *hcan) { uint32_t start_timestamp = HAL_GetTick(); while (HAL_FDCAN_GetTxFifoFreeLevel(hcan) == 0) { @@ -137,11 +157,13 @@ void _fdcan_wait(FDCAN_HandleTypeDef *hcan) { } } } +#endif int _fdcan_send(int can_id, can_manager_message_t *msg) { CAN_MGR_ID_CHECK(can_id); FDCAN_HandleTypeDef *hcan = fdcan_buses[can_id]; +#ifndef TEST uint32_t dlc_len = 0; switch (msg->size) { case 0: @@ -192,6 +214,10 @@ int _fdcan_send(int can_id, can_manager_message_t *msg) { if ((can_manager_hal_status_retval = HAL_FDCAN_AddMessageToTxFifoQ(hcan, &header, msg->data)) != HAL_OK) { return 0; } +#else + printf("SENDING fdcan: %s, ", hcan->name); + print_message(msg); +#endif return 1; } @@ -210,13 +236,16 @@ int can_init( can_rx_msg_handlers[assigned_id] = can_rx_msg_handler; GENQ_init( - &_rx_queues[assigned_id], CAN_MGR_MAX_QUEUE_ELEMENTS * sizeof(can_manager_message_t), sizeof(can_manager_message_t), &_rx_queues_data[assigned_id]); + &_rx_queues[assigned_id], CAN_MGR_MAX_QUEUE_ELEMENTS * sizeof(can_manager_message_t), + sizeof(can_manager_message_t), &_rx_queues_data[assigned_id]); GENQ_init( - &_tx_queues[assigned_id], CAN_MGR_MAX_QUEUE_ELEMENTS * sizeof(can_manager_message_t), sizeof(can_manager_message_t), &_tx_queues_data[assigned_id]); + &_tx_queues[assigned_id], CAN_MGR_MAX_QUEUE_ELEMENTS * sizeof(can_manager_message_t), + sizeof(can_manager_message_t), &_tx_queues_data[assigned_id]); can_buses[assigned_id] = hcan; _n_active_can++; +#ifndef TEST if ((can_manager_hal_status_retval = HAL_CAN_ConfigFilter(hcan, filter)) != HAL_OK) { can_manager_error_code = CAN_MGR_FILTER_ERROR_CODE; return -1; @@ -229,29 +258,38 @@ int can_init( can_manager_error_code = CAN_MGR_CAN_START_ERROR_CODE; return -1; } +#endif return assigned_id; } +#ifndef TEST void _can_wait(CAN_HandleTypeDef *hcan) { uint32_t start_timestamp = HAL_GetTick(); while (HAL_CAN_GetTxMailboxesFreeLevel(hcan) == 0) if (HAL_GetTick() > start_timestamp + 5) return; } +#endif int _can_send(int can_id, can_manager_message_t *msg) { CAN_MGR_ID_CHECK(can_id); - CAN_HandleTypeDef *hcan = can_buses[can_id]; + CAN_HandleTypeDef *hcan = can_buses[can_id]; +#ifndef TEST CAN_TxHeaderTypeDef header = { .StdId = msg->id, .IDE = CAN_ID_STD, .RTR = CAN_RTR_DATA, .DLC = msg->size, .TransmitGlobalTime = DISABLE}; #if CAN_WAIT_ENABLED == 1 _can_wait(hcan); #endif + uint32_t mlb = CAN_TX_MAILBOX0; if (HAL_CAN_AddTxMessage(hcan, &header, msg->data, &mlb) != HAL_OK) { return 0; } +#else + printf("SENDING can: %s, ", hcan->name); + print_message(msg); +#endif return 1; } #endif @@ -279,12 +317,18 @@ int consume_rx_queue(int can_id) { int flush_tx_queue(int can_id) { CAN_MGR_ID_CHECK(can_id); can_manager_message_t msg; + int sent_messages = 0; while (GENQ_pop(&_tx_queues[can_id], (uint8_t *)&msg)) { #ifdef FDCAN_MGR - return _fdcan_send(can_id, &msg); + if (!_fdcan_send(can_id, &msg)) { + return -1; + } #else - return _can_send(can_id, &msg); + if (!_can_send(can_id, &msg)) { + return -1; + } #endif + ++sent_messages; } - return 0; + return sent_messages; } diff --git a/can-manager/can_manager.h b/can-manager/can_manager.h index 3a7b6f6..f1ce1ec 100644 --- a/can-manager/can_manager.h +++ b/can-manager/can_manager.h @@ -3,9 +3,21 @@ #include "can_types.h" #include "generic_queue.h" -#include "main.h" #include "stdbool.h" +#ifndef TEST +#include "main.h" +#else +#include "stdio.h" +#include "string.h" +typedef struct { + char *name; +} CAN_HandleTypeDef; +typedef struct { +} CAN_FilterTypeDef; +void print_message(can_manager_message_t *msg); +#endif + #define CAN_MGR_MAX_CAN_BUSES 2 #define CAN_MGR_MAX_QUEUE_ELEMENTS 10 #define CAN_MGR_CAN_WAIT_ENABLED 1 diff --git a/can-manager/test/test.c b/can-manager/test/test.c new file mode 100644 index 0000000..2868e3e --- /dev/null +++ b/can-manager/test/test.c @@ -0,0 +1,43 @@ +#include "../can_manager.h" + +void consume_primary_rx_queue(can_manager_message_t *msg) { + printf("RECEIVED can: primary, "); + print_message(msg); +} + +void consume_secondary_rx_queue(can_manager_message_t *msg) { + printf("RECEIVED can: secondary, "); + print_message(msg); +} + +int main() { + CAN_HandleTypeDef primary_can_handle; + CAN_HandleTypeDef secondary_can_handle; + primary_can_handle.name = "primary"; + secondary_can_handle.name = "secondary"; + + int can_primary_id = can_init(&primary_can_handle, consume_primary_rx_queue, 0, 0); + int can_secondary_id = can_init(&secondary_can_handle, consume_secondary_rx_queue, 0, 0); + + can_manager_message_t msg1 = {.id = 1, .size = 8, .data = {4, 6, 2, 8, 2, 4, 8, 6}}; + can_manager_message_t msg2 = {.id = 2, .size = 3, .data = {9, 1, 0, 0, 3, 2, 5, 4}}; + can_manager_message_t msg3 = {.id = 3, .size = 7, .data = {8, 2, 3, 4, 5, 6, 7, 1}}; + can_manager_message_t msg4 = {.id = 4, .size = 5, .data = {3, 7, 3, 6, 9, 5, 8, 5}}; + + add_to_tx_queue(can_primary_id, &msg1); + add_to_rx_queue(can_secondary_id, &msg2); + add_to_tx_queue(can_primary_id, &msg3); + add_to_rx_queue(can_secondary_id, &msg4); + + while (consume_rx_queue(can_primary_id)) + ; + + printf("sent %d messages primary\n", flush_tx_queue(can_primary_id)); + + while (consume_rx_queue(can_secondary_id)) + ; + + printf("sent %d messages secondary\n", flush_tx_queue(can_secondary_id)); + + return 0; +} \ No newline at end of file From 43ea4b62235f6eb8f63ea4f7f8a21ce55cbc42a0 Mon Sep 17 00:00:00 2001 From: tzarjakob Date: Tue, 12 Dec 2023 17:12:27 +0100 Subject: [PATCH 2/3] added candump to serial module --- candump-to-serial/README.md | 7 + candump-to-serial/candump_to_serial.py | 82 ++++++ candump-to-serial/candump_to_serial_example.c | 278 ++++++++++++++++++ 3 files changed, 367 insertions(+) create mode 100644 candump-to-serial/README.md create mode 100644 candump-to-serial/candump_to_serial.py create mode 100644 candump-to-serial/candump_to_serial_example.c diff --git a/candump-to-serial/README.md b/candump-to-serial/README.md new file mode 100644 index 0000000..92476aa --- /dev/null +++ b/candump-to-serial/README.md @@ -0,0 +1,7 @@ +# Candump to Serial + +Simple tool to replay old candump log files on mcu via uart. Run [candump_to_serial.py](./candump_to_serial.py) to send data via serial. Regarding the MCU part, please refer to the [example](./candump_to_serial_example.c). Remember only to activate the UART interrupt in CubeMX. + +Authors: +Giacomo Mazzucchi +Antonio Gelain diff --git a/candump-to-serial/candump_to_serial.py b/candump-to-serial/candump_to_serial.py new file mode 100644 index 0000000..290ee5c --- /dev/null +++ b/candump-to-serial/candump_to_serial.py @@ -0,0 +1,82 @@ +""" +# PSEUDOCODE IDEA + +producer +open file and serial +for line + parse line + timestamp interface id#content + (0.000000) secondary 4EC#00140000FFFF0000 + send interface, id and content + +consumer +while(true) { + riceve interface, id and content +} +""" + +import sys +import serial +import datetime +import time + +DEFAULT_DELAY = 0.1 + + +def delta_us(ctime, ptime): + delta = ctime - ptime + return delta.total_seconds() * 1e6 + + +def send_message(si, mint, mid, mdata): + smsg = 0 if (mint == "primary") else 1 + msg = f"{smsg}&{mid}&{mdata}$".ljust(23, "0") + si.write(str.encode(msg)) + sys.stdout.write(f"Sent message: {str.encode(msg)}\n") + + +if __name__ == "__main__": + argc = len(sys.argv) + if argc < 3: + sys.stderr.write( + "Usage: python3 candump_to_serial.py \n" + ) + exit(1) + candump_file_path = sys.argv[1] + serial_port = sys.argv[2] + try: + serial_interface = serial.Serial( + port=serial_port, + baudrate=115200, + parity=serial.PARITY_NONE, + stopbits=serial.STOPBITS_ONE, + bytesize=serial.EIGHTBITS, + ) + except OSError: + sys.stderr.write(f"Usage: could not open the serial port {serial_port}\n") + exit(1) + try: + candump_file = open(candump_file_path, "r") + except OSError: + sys.stderr.write(f"Could not open/read file: {candump_file_path}\n") + exit(1) + + ptime = datetime.datetime.now() + ploggingtime = datetime.datetime.now() + pdelta = 0 + + with candump_file: + for row in candump_file.readlines(): + message_contents = row.split() + message_delta = float(str.strip(message_contents[0].strip("()"))) + message_interface = message_contents[1] + msg_tmp = str.split(message_contents[2], "#") + message_id = msg_tmp[0] + message_data = msg_tmp[1] + while delta_us(datetime.datetime.now(), ptime) < (message_delta - pdelta): + pass + send_message(serial_interface, message_interface, message_id, message_data) + ptime = datetime.datetime.now() + pdelta += message_delta + time.sleep(DEFAULT_DELAY) + diff --git a/candump-to-serial/candump_to_serial_example.c b/candump-to-serial/candump_to_serial_example.c new file mode 100644 index 0000000..bddd18e --- /dev/null +++ b/candump-to-serial/candump_to_serial_example.c @@ -0,0 +1,278 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.c + * @brief : Main program body + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "eth.h" +#include "gpio.h" +#include "main.h" +#include "usart.h" +#include "usb_otg.h" + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ +#include +#include +#include +#include +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN PTD */ + +/* USER CODE END PTD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN PD */ + +/* USER CODE END PD */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN PM */ + +/* USER CODE END PM */ + +/* Private variables ---------------------------------------------------------*/ + +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +void SystemClock_Config(void); +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* Private user code ---------------------------------------------------------*/ +/* USER CODE BEGIN 0 */ +#define RCV_SIZ 23 +uint8_t rcv_data[RCV_SIZ]; +uint8_t msg_buf[BUFSIZ]; +uint32_t msg_buf_size = 0; +int serial_received = 0; +int activated_its = 0; + +void start_uart_interrupt() { HAL_UART_Receive_IT(&huart3, rcv_data, RCV_SIZ); } + +void HAL_UART_RxCpltCallback(UART_HandleTypeDef *uart_handle) { + if (uart_handle == &huart3) + serial_received = 1; +} + +void print(const char *fmt, ...) { + char buff[256]; + va_list args; + va_start(args, fmt); + vsnprintf(buff, sizeof(buff), fmt, args); + va_end(args); + HAL_UART_Transmit(&huart3, (uint8_t *)buff, strlen(buff), 250); +} + +uint32_t led_activated[2] = {0}; +void turn_led_on(int led) { + led_activated[led] = HAL_GetTick(); + if (led == 0) { + HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET); + } + if (led == 1) { + HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET); + } +} + +void led_timeout_check() { + uint32_t currtime = HAL_GetTick(); + if (led_activated[0] + 50 < currtime) { + HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET); + } + if (led_activated[1] + 50 < currtime) { + HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_RESET); + } +} + +void message_parser(uint8_t *msg, size_t msg_siz) { + msg[msg_siz] = 0; + uint32_t msgi = 0, msgl = 0; + uint8_t msg_data[8] = {0}; + msgi = strtol(msg, NULL, 16); + msgl = strtol(msg + 2, NULL, 16); + for (size_t i = 0; i < 8; ++i) { + char m[3] = {msg[6 + i * 2], msg[6 + i * 2 + 1], 0}; + msg_data[i] = strtol(m, NULL, 16); + } + if (msgi == 0) { + turn_led_on(0); + } else if (msgi == 1) { + turn_led_on(1); + } +} + +void can_over_serial_routine(void) { + led_timeout_check(); + if (serial_received) { + for (size_t ic = 0; ic < RCV_SIZ; ic++) { + msg_buf[msg_buf_size] = rcv_data[ic]; + msg_buf_size++; + if (rcv_data[ic] == '$') { + message_parser(msg_buf, msg_buf_size); + msg_buf_size = 0; + break; + } + } + memset(rcv_data, 0, RCV_SIZ); + serial_received = 0; + start_uart_interrupt(); + } +} + +/* USER CODE END 0 */ + +/** + * @brief The application entry point. + * @retval int + */ +int main(void) { + /* USER CODE BEGIN 1 */ + + /* USER CODE END 1 */ + + /* MCU Configuration--------------------------------------------------------*/ + + /* Reset of all peripherals, Initializes the Flash interface and the Systick. + */ + HAL_Init(); + + /* USER CODE BEGIN Init */ + + /* USER CODE END Init */ + + /* Configure the system clock */ + SystemClock_Config(); + + /* USER CODE BEGIN SysInit */ + + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_USART3_UART_Init(); + MX_ETH_Init(); + MX_USB_OTG_FS_PCD_Init(); + /* USER CODE BEGIN 2 */ + uint32_t currtime = HAL_GetTick(); + led_activated[0] = currtime; + led_activated[1] = currtime; + start_uart_interrupt(); + /* USER CODE END 2 */ + + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + while (1) { + can_over_serial_routine(); + /* USER CODE END WHILE */ + + /* USER CODE BEGIN 3 */ + } + /* USER CODE END 3 */ +} + +/** + * @brief System Clock Configuration + * @retval None + */ +void SystemClock_Config(void) { + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + + /** Configure LSE Drive Capability + */ + HAL_PWR_EnableBkUpAccess(); + + /** Configure the main internal regulator output voltage + */ + __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = 4; + RCC_OscInitStruct.PLL.PLLN = 216; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; + RCC_OscInitStruct.PLL.PLLQ = 9; + RCC_OscInitStruct.PLL.PLLR = 2; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + Error_Handler(); + } + + /** Activate the Over-Drive mode + */ + if (HAL_PWREx_EnableOverDrive() != HAL_OK) { + Error_Handler(); + } + + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | + RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK) { + Error_Handler(); + } +} + +/* USER CODE BEGIN 4 */ + +/* USER CODE END 4 */ + +/** + * @brief This function is executed in case of error occurrence. + * @retval None + */ +void Error_Handler(void) { + /* USER CODE BEGIN Error_Handler_Debug */ + /* User can add his own implementation to report the HAL error return state */ + __disable_irq(); + while (1) { + } + /* USER CODE END Error_Handler_Debug */ +} + +#ifdef USE_FULL_ASSERT +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ +void assert_failed(uint8_t *file, uint32_t line) { + /* USER CODE BEGIN 6 */ + /* User can add his own implementation to report the file name and line + number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, + line) */ + /* USER CODE END 6 */ +} +#endif /* USE_FULL_ASSERT */ From 2fd08b85a69fdd97742dcda310e3fe8b485261c8 Mon Sep 17 00:00:00 2001 From: tzarjakob Date: Wed, 24 Jan 2024 10:16:03 +0100 Subject: [PATCH 3/3] can manager: exposed can send api --- can-manager/can_manager.c | 10 +++++----- can-manager/can_types.h | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/can-manager/can_manager.c b/can-manager/can_manager.c index ef33a5a..a5cd960 100644 --- a/can-manager/can_manager.c +++ b/can-manager/can_manager.c @@ -53,7 +53,7 @@ * ++++++++++++++++++++++++ * * int primary_can_id = -1; - * int secondary_can_id = -2; + * int secondary_can_id = -1; * * void f() { * can_manager_message_t msg = { @@ -159,7 +159,7 @@ void _fdcan_wait(FDCAN_HandleTypeDef *hcan) { } #endif -int _fdcan_send(int can_id, can_manager_message_t *msg) { +int fdcan_send(int can_id, can_manager_message_t *msg) { CAN_MGR_ID_CHECK(can_id); FDCAN_HandleTypeDef *hcan = fdcan_buses[can_id]; @@ -271,7 +271,7 @@ void _can_wait(CAN_HandleTypeDef *hcan) { } #endif -int _can_send(int can_id, can_manager_message_t *msg) { +int can_send(int can_id, can_manager_message_t *msg) { CAN_MGR_ID_CHECK(can_id); CAN_HandleTypeDef *hcan = can_buses[can_id]; #ifndef TEST @@ -320,11 +320,11 @@ int flush_tx_queue(int can_id) { int sent_messages = 0; while (GENQ_pop(&_tx_queues[can_id], (uint8_t *)&msg)) { #ifdef FDCAN_MGR - if (!_fdcan_send(can_id, &msg)) { + if (!fdcan_send(can_id, &msg)) { return -1; } #else - if (!_can_send(can_id, &msg)) { + if (!can_send(can_id, &msg)) { return -1; } #endif diff --git a/can-manager/can_types.h b/can-manager/can_types.h index 355f118..ff5e4ac 100644 --- a/can-manager/can_types.h +++ b/can-manager/can_types.h @@ -9,6 +9,11 @@ typedef struct { uint8_t data[8]; } can_manager_message_t; +#ifdef FDCAN_MGR +int fdcan_send(int can_id, can_manager_message_t *msg); +#else +int can_send(int can_id, can_manager_message_t *msg); +#endif int consume_rx_queue(int can_id); int flush_tx_queue(int can_id); int add_to_rx_queue(int can_id, can_manager_message_t *msg);