added channel control and can communication (both are working)

This commit is contained in:
2025-03-12 19:56:15 +01:00
parent 35273b074c
commit f57eb4ccf4
151 changed files with 25182 additions and 124 deletions

View File

@ -0,0 +1,33 @@
/*
* can_communication.h
*
* Created on: Mar 12, 2025
* Author: janek
*/
#ifndef INC_CAN_COMMUNICATION_H_
#define INC_CAN_COMMUNICATION_H_
#include "channel_control.h"
#include "can_halal.h"
//#include "current_monitoring.h"
#define RX_STATUS_HEARTBEAT 0xC7 // IDs of all CAN-packages (may be other IDs next year)
#define RX_STATUS_MSG_ID 0xC8 // TODO: check new IDs
#define TX_STATUS_MSG_ID 0xC9
#define CUR_CHANNELS_1_ID 0xCA
#define CUR_CHANNELS_2_ID 0xCB
#define CUR_CHANNELS_3_ID 0xCC
#define CUR_CHANNELS_4_ID 0xCD
#define LV_SENS_ID 0xCE
typedef struct { // TODO: add error-codes
enable_gpios iostatus;
uint8_t checksum;
} rx_status_frame;
void can_init(CAN_HandleTypeDef* hcan);
void can_rxupdateFrame();
void can_sendloop();
#endif /* INC_CAN_COMMUNICATION_H_ */

View File

@ -0,0 +1,72 @@
#ifndef CAN_HALAL_H
#define CAN_HALAL_H
// Define family macros if none are defined and we recognize a chip macro
#if !defined(STM32F3) && !defined(STM32H7) && !defined(STM32F0)
#if defined(STM32F302x6) || defined(STM32F302x8) || defined(STM32F302xB) || \
defined(STM32F302xC)
#define STM32F3
#endif
#if defined(STM32H7A3xx) || defined(STM32H723xx)
#define STM32H7
#endif
#if defined(STM32F042x6)
#define STM32F0
#endif
#endif
#if defined(STM32F3)
#include "stm32f3xx_hal.h"
#define FTCAN_IS_BXCAN
#define FTCAN_NUM_FILTERS 13
#elif defined(STM32H7)
#include "stm32h7xx_hal.h"
#define FTCAN_IS_FDCAN
#ifndef FTCAN_NUM_FILTERS
#error "Please configure the number of filters in CubeMX, and then add a compiler define for FTCAN_NUM_FILTERS"
#endif
#elif defined(STM32F0)
#include "stm32f0xx_hal.h"
#define FTCAN_IS_BXCAN
#define FTCAN_NUM_FILTERS 13
#else
#error "Couldn't detect STM family"
#endif
#if defined(FTCAN_IS_BXCAN)
HAL_StatusTypeDef ftcan_init(CAN_HandleTypeDef *handle);
#elif defined(FTCAN_IS_FDCAN)
HAL_StatusTypeDef ftcan_init(FDCAN_HandleTypeDef *handle);
#else
#error "Unknown CAN peripheral"
#endif
HAL_StatusTypeDef ftcan_transmit(uint16_t id, const uint8_t *data,
size_t datalen);
HAL_StatusTypeDef ftcan_add_filter(uint16_t id, uint16_t mask);
/**
* Define this function to be notified of incoming CAN messages
*/
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data);
/**
* Read num_bytes bytes from a message (unmarshalled network byte order). The
* msg pointer is advanced by the corresponding number of bytes.
*
* Both methods return a 64-bit integer, but you can safely cast it to a smaller
* integer type.
*/
uint64_t ftcan_unmarshal_unsigned(const uint8_t **data, size_t num_bytes);
int64_t ftcan_unmarshal_signed(const uint8_t **data, size_t num_bytes);
/**
* Write num_bytes to a message (marshalled in network byte order). The pointer
* is advanced by the corresponding number of bytes and returned.
*/
uint8_t *ftcan_marshal_unsigned(uint8_t *data, uint64_t val, size_t num_bytes);
uint8_t *ftcan_marshal_signed(uint8_t *data, int64_t val, size_t num_bytes);
#endif // CAN_HALAL_H

View File

@ -0,0 +1,53 @@
/*
* channel_control.h
*
* Created on: Mar 10, 2025
* Author: janek
*/
#ifndef INC_CHANNEL_CONTROL_H_
#define INC_CHANNEL_CONTROL_H_
#include "stm32f3xx_hal.h"
typedef union {
struct {
uint8_t acc_cooling : 1;
uint8_t ts_cooling : 1;
uint8_t drs : 1;
uint8_t acu : 1;
uint8_t epsc : 1;
uint8_t inverter : 1;
uint8_t lidar : 1;
uint8_t misc : 1;
};
uint8_t porta;
} gpio_port_a;
typedef union {
struct {
uint8_t alwayson : 1;
uint8_t sdc : 1;
uint8_t ebs1 : 1;
uint8_t ebs2 : 1;
uint8_t ebs3 : 1;
uint8_t NC1 : 1; // not used
uint8_t NC2 : 1; // not used
uint8_t NC3 : 1; // not used
};
uint8_t portb;
} gpio_port_b;
typedef union {
struct {
gpio_port_a porta;
gpio_port_b portb;
};
uint16_t gpios_bitmask;
} enable_gpios;
void ChannelControl_init();
void ChannelControl_UpdateGPIOs(enable_gpios);
#endif /* INC_CHANNEL_CONTROL_H_ */

View File

@ -85,10 +85,10 @@ void Error_Handler(void);
#define IS5_GPIO_Port GPIOA
#define PC_Read_Pin GPIO_PIN_4
#define PC_Read_GPIO_Port GPIOC
#define IN11_Pin GPIO_PIN_0
#define IN11_GPIO_Port GPIOB
#define IN12_Pin GPIO_PIN_1
#define IN12_GPIO_Port GPIOB
#define IN11_Pin GPIO_PIN_2
#define IN11_GPIO_Port GPIOB
#define IN13_Pin GPIO_PIN_10
#define IN13_GPIO_Port GPIOB
#define IN9_Pin GPIO_PIN_11

View File

@ -57,6 +57,8 @@ void PendSV_Handler(void);
void SysTick_Handler(void);
void DMA1_Channel1_IRQHandler(void);
void ADC1_2_IRQHandler(void);
void USB_LP_CAN_RX0_IRQHandler(void);
void CAN_RX1_IRQHandler(void);
void TIM6_DAC_IRQHandler(void);
void DMA2_Channel1_IRQHandler(void);
/* USER CODE BEGIN EFP */