enable streaming for testing, route FC messages to isotp stack
This commit is contained in:
parent
354b6dc453
commit
765f1e5ee1
@ -22,6 +22,9 @@
|
|||||||
#define CAN_ID_SHUNT_CURRENT_COUNTER 0x527
|
#define CAN_ID_SHUNT_CURRENT_COUNTER 0x527
|
||||||
#define CAN_ID_SHUNT_ENERGY_COUNTER 0x528
|
#define CAN_ID_SHUNT_ENERGY_COUNTER 0x528
|
||||||
|
|
||||||
|
//TEMP until final IDs are defined
|
||||||
|
#define CAN_ID_LOG_FC 0x132
|
||||||
|
|
||||||
void can_init(FDCAN_HandleTypeDef *handle);
|
void can_init(FDCAN_HandleTypeDef *handle);
|
||||||
HAL_StatusTypeDef can_send_status();
|
HAL_StatusTypeDef can_send_status();
|
||||||
HAL_StatusTypeDef can_send_error(TSErrorKind kind, uint8_t arg);
|
HAL_StatusTypeDef can_send_error(TSErrorKind kind, uint8_t arg);
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 4e3bb026f88a7ee5a89ec48dc10281e8e0a3175a
|
Subproject commit 887f92167d58e551abac18f4f899c74bddc13d46
|
@ -3,13 +3,15 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
/* ISO-TP Backend Configuration */
|
/* ISO-TP Backend Configuration */
|
||||||
#define ISOTP_LOG_BUFFER_MIN_LEVEL LOG_LEVEL_WARNING // log level where messages are buffered before streaming mode is enabled
|
#define ISOTP_LOG_BUFFER_MIN_LEVEL LOG_LEVEL_INFO // log level where messages are buffered before streaming mode is enabled
|
||||||
#define ISOTP_LOG_BUFFER_1_BYTES 1024 // Primary buffer, used when streaming is disabled
|
#define ISOTP_LOG_BUFFER_1_BYTES 1024 // Primary buffer, used when streaming is disabled
|
||||||
#define ISOTP_LOG_BUFFER_2_BYTES 256 // Secondary buffer, used for double-buffering during streaming, can be smaller
|
#define ISOTP_LOG_BUFFER_2_BYTES 256 // Secondary buffer, used for double-buffering during streaming, can be smaller
|
||||||
|
|
||||||
|
|
||||||
/* ISO-TP CAN ID configuration */
|
/* ISO-TP CAN ID configuration */
|
||||||
|
#ifndef ISOTP_LOG_CAN_ID
|
||||||
#define ISOTP_LOG_CAN_ID 0x123 // CAN ID to use for ISO-TP log messages
|
#define ISOTP_LOG_CAN_ID 0x123 // CAN ID to use for ISO-TP log messages
|
||||||
|
#endif
|
||||||
|
|
||||||
/* ISO-TP backend API */
|
/* ISO-TP backend API */
|
||||||
void isotp_log_backend_init(void);
|
void isotp_log_backend_init(void);
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#include "can.h"
|
#include "can.h"
|
||||||
|
|
||||||
#include "imd_monitoring.h"
|
#include "imd_monitoring.h"
|
||||||
|
#include "isotp.h"
|
||||||
|
#include "isotp_log_backend.h"
|
||||||
|
#include "log.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "shunt_monitoring.h"
|
#include "shunt_monitoring.h"
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
@ -33,7 +36,7 @@ HAL_StatusTypeDef can_send_status() {
|
|||||||
uint8_t data[8];
|
uint8_t data[8];
|
||||||
data[0] = ts_state.current_state | (sdc_closed << 7);
|
data[0] = ts_state.current_state | (sdc_closed << 7);
|
||||||
data[1] = roundf(current_soc);
|
data[1] = roundf(current_soc);
|
||||||
ftcan_marshal_unsigned(&data[2], min_voltage, 2); //was declared in slave_monitoring.c
|
ftcan_marshal_unsigned(&data[2], min_voltage, 2);
|
||||||
ftcan_marshal_signed(&data[4], max_temp, 2);
|
ftcan_marshal_signed(&data[4], max_temp, 2);
|
||||||
data[6] = imd_data.state | (imd_data.ok << 7);
|
data[6] = imd_data.state | (imd_data.ok << 7);
|
||||||
if (imd_data.r_iso < 0xFFF) {
|
if (imd_data.r_iso < 0xFFF) {
|
||||||
@ -58,24 +61,21 @@ HAL_StatusTypeDef can_send_error(TSErrorKind kind, uint8_t arg) {
|
|||||||
return ftcan_transmit(CAN_ID_AMS_ERROR, data, sizeof(data));
|
return ftcan_transmit(CAN_ID_AMS_ERROR, data, sizeof(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ftcan_msg_received_cb(uint16_t id, size_t, const uint8_t *data) {
|
void ftcan_msg_received_cb(uint16_t id, size_t len, const uint8_t *data) {
|
||||||
if ((id & 0xFF0) == CAN_ID_SHUNT_BASE) {
|
if ((id & 0xFF0) == CAN_ID_SHUNT_BASE) {
|
||||||
shunt_handle_can_msg(id, data);
|
shunt_handle_can_msg(id, data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// else if ((id & 0xFF0) == CAN_ID_SLAVE_STATUS_BASE) {
|
|
||||||
// slaves_handle_status(data);
|
switch (id) {
|
||||||
// return;
|
case CAN_ID_LOG_FC:
|
||||||
// }
|
auto status = isotp_handle_flow_control(ISOTP_LOG_CAN_ID, data, len);
|
||||||
// switch (id) {
|
if (status != ISOTP_OK) {
|
||||||
// case CAN_ID_SLAVE_PANIC:
|
log_debug("Error when handling flow control: %s", isotp_status_to_string(status));
|
||||||
// slaves_handle_panic(data);
|
}
|
||||||
// break;
|
break;
|
||||||
// case CAN_ID_SLAVE_LOG:
|
case CAN_ID_AMS_IN:
|
||||||
// slaves_handle_log(data);
|
ts_sm_handle_ams_in(data);
|
||||||
// break;
|
break;
|
||||||
// case CAN_ID_AMS_IN:
|
}
|
||||||
// ts_sm_handle_ams_in(data);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
|
#include "isotp.h"
|
||||||
|
#include "isotp_log_backend.h"
|
||||||
#define SWO_LOG_PREFIX "[MAIN] "
|
#define SWO_LOG_PREFIX "[MAIN] "
|
||||||
#include "swo_log.h"
|
#include "swo_log.h"
|
||||||
|
|
||||||
@ -93,15 +95,15 @@ void init_logging(void);
|
|||||||
/* USER CODE BEGIN 0 */
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
#define MAIN_LOOP_PERIOD 50
|
#define MAIN_LOOP_PERIOD 50
|
||||||
|
#define ISO_TP_UPDATE_PERIOD 1
|
||||||
|
|
||||||
static void loop_delay() {
|
static void loop_delay() {
|
||||||
static uint32_t last_loop = 0;
|
static uint32_t last_loop = 0;
|
||||||
uint32_t dt = HAL_GetTick() - last_loop;
|
uint32_t dt = HAL_GetTick() - last_loop;
|
||||||
if (dt < MAIN_LOOP_PERIOD) {
|
while (dt < MAIN_LOOP_PERIOD) {
|
||||||
HAL_Delay(MAIN_LOOP_PERIOD - dt);
|
HAL_Delay(ISO_TP_UPDATE_PERIOD);
|
||||||
//HAL_GPIO_WritePin(STATUS2_GPIO_Port, STATUS2_Pin, GPIO_PIN_RESET);
|
isotp_update(); // make sure isotp messages are processed reasonably quickly
|
||||||
} else {
|
dt = HAL_GetTick() - last_loop;
|
||||||
//HAL_GPIO_WritePin(STATUS2_GPIO_Port, STATUS2_Pin, GPIO_PIN_SET);
|
|
||||||
}
|
}
|
||||||
last_loop = HAL_GetTick();
|
last_loop = HAL_GetTick();
|
||||||
}
|
}
|
||||||
@ -132,6 +134,8 @@ void init_logging(void) {
|
|||||||
/* Register and initialize SWO backend */
|
/* Register and initialize SWO backend */
|
||||||
swo_log_backend_init();
|
swo_log_backend_init();
|
||||||
|
|
||||||
|
isotp_log_backend_init();
|
||||||
|
|
||||||
/* Initialize all registered backends */
|
/* Initialize all registered backends */
|
||||||
log_init_all_backends();
|
log_init_all_backends();
|
||||||
|
|
||||||
@ -194,6 +198,10 @@ int main(void)
|
|||||||
|
|
||||||
// init for master functions
|
// init for master functions
|
||||||
can_init(&hfdcan1);
|
can_init(&hfdcan1);
|
||||||
|
|
||||||
|
// for testing. in the final code can log streaming will be enabled by can message
|
||||||
|
isotp_log_enable_streaming(LOG_LEVEL_INFO);
|
||||||
|
|
||||||
shunt_init();
|
shunt_init();
|
||||||
ts_sm_init();
|
ts_sm_init();
|
||||||
soc_init();
|
soc_init();
|
||||||
@ -208,6 +216,7 @@ int main(void)
|
|||||||
int error_count = 0;
|
int error_count = 0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
isotp_update();
|
||||||
//left over from slave communication test, could be nicer and in an additional function !!
|
//left over from slave communication test, could be nicer and in an additional function !!
|
||||||
if (error_count > 25) {
|
if (error_count > 25) {
|
||||||
debug_log(LOG_LEVEL_ERROR, "Too many errors, restarting BMS...");
|
debug_log(LOG_LEVEL_ERROR, "Too many errors, restarting BMS...");
|
||||||
@ -221,7 +230,6 @@ int main(void)
|
|||||||
}
|
}
|
||||||
error_count = 0;
|
error_count = 0;
|
||||||
}
|
}
|
||||||
uint32_t lastTimestamp = HAL_GetTick();
|
|
||||||
|
|
||||||
update_sdc();
|
update_sdc();
|
||||||
update_tsal_signals();
|
update_tsal_signals();
|
||||||
@ -238,6 +246,7 @@ int main(void)
|
|||||||
soc_update();
|
soc_update();
|
||||||
imd_update();
|
imd_update();
|
||||||
can_send_status();
|
can_send_status();
|
||||||
|
isotp_update();
|
||||||
|
|
||||||
loop_delay();
|
loop_delay();
|
||||||
/* USER CODE END WHILE */
|
/* USER CODE END WHILE */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user