changed AMS_CAN.h -> can.h
This commit is contained in:
		@ -1,29 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * AMS_CAN.h
 | 
			
		||||
 *
 | 
			
		||||
 *  Created on: Mar 19, 2022
 | 
			
		||||
 *      Author: jasper
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef INC_AMS_CAN_H_
 | 
			
		||||
#define INC_AMS_CAN_H_
 | 
			
		||||
 | 
			
		||||
#include "main.h"
 | 
			
		||||
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
#include "stm32f3xx_hal_can.h"
 | 
			
		||||
#include "stm32f3xx_hal_def.h"
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
void ams_can_init(CAN_HandleTypeDef* hcan);
 | 
			
		||||
 | 
			
		||||
void ams_can_handle_ams_msg(CAN_RxHeaderTypeDef* header, uint8_t* data);
 | 
			
		||||
 | 
			
		||||
void ams_can_send_status();
 | 
			
		||||
 | 
			
		||||
HAL_StatusTypeDef ams_can_wait_for_free_mailboxes(CAN_HandleTypeDef* handle,
 | 
			
		||||
                                                  int num_mailboxes,
 | 
			
		||||
                                                  uint32_t timeout);
 | 
			
		||||
 | 
			
		||||
#endif /* INC_AMS_CAN_H_ */
 | 
			
		||||
@ -11,7 +11,7 @@
 | 
			
		||||
#include "ADBMS_Abstraction.h"
 | 
			
		||||
#include "ADBMS_CMD_MAKROS.h"
 | 
			
		||||
#include "ADBMS_LL_Driver.h"
 | 
			
		||||
#include "AMS_CAN.h"
 | 
			
		||||
#include "can.h"
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
  AMSDEACTIVE,
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
#ifndef INC_TMP1075_H_
 | 
			
		||||
#define INC_TMP1075_H_
 | 
			
		||||
 | 
			
		||||
#include "AMS_CAN.h"
 | 
			
		||||
#include "can.h"
 | 
			
		||||
#include "common_defs.h"
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
#include "stm32f3xx_hal_def.h"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										16
									
								
								Core/Inc/can.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								Core/Inc/can.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
#include "stm32f3xx_hal_can.h"
 | 
			
		||||
#include "stm32f3xx_hal_def.h"
 | 
			
		||||
#include "state_machine.h"
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#define CAN_ID_IN   0x501
 | 
			
		||||
#define CAN_ID_OUT  0x502
 | 
			
		||||
 | 
			
		||||
void can_init(CAN_HandleTypeDef* hcan);
 | 
			
		||||
 | 
			
		||||
void can_handle_send_status();
 | 
			
		||||
 | 
			
		||||
void can_handle_recieve_command(CAN_RxHeaderTypeDef* header, uint8_t* data);
 | 
			
		||||
 | 
			
		||||
@ -1,73 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * AMS_CAN.c
 | 
			
		||||
 *
 | 
			
		||||
 *  Created on: Mar 19, 2022
 | 
			
		||||
 *      Author: jasper
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "AMS_CAN.h"
 | 
			
		||||
 | 
			
		||||
#include "ADBMS_Abstraction.h"
 | 
			
		||||
 | 
			
		||||
#include "AMS_HighLevel.h"
 | 
			
		||||
#include "TMP1075.h"
 | 
			
		||||
#include "common_defs.h"
 | 
			
		||||
#include "eeprom.h"
 | 
			
		||||
#include "errors.h"
 | 
			
		||||
#include "main.h"
 | 
			
		||||
#include "stm32f3xx.h"
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
#include "stm32f3xx_hal_can.h"
 | 
			
		||||
 | 
			
		||||
#include "can-halal.h"
 | 
			
		||||
#include "stm32f3xx_hal_gpio.h"
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#define CAN_ID_MV_BMS 0x501
 | 
			
		||||
 | 
			
		||||
void ams_can_init(CAN_HandleTypeDef* hcan) { ftcan_init(hcan); }
 | 
			
		||||
 | 
			
		||||
#define ITER_COUNT 10
 | 
			
		||||
static uint8_t count = 0;
 | 
			
		||||
static bool isOn = false;
 | 
			
		||||
 | 
			
		||||
void ams_can_send_status() {
 | 
			
		||||
  if (count == ITER_COUNT) {
 | 
			
		||||
    HAL_GPIO_WritePin(STATUS_LED_G_GPIO_Port, STATUS_LED_G_Pin, isOn ? GPIO_PIN_SET : GPIO_PIN_RESET);
 | 
			
		||||
 | 
			
		||||
    count = 0;
 | 
			
		||||
    isOn = !isOn;
 | 
			
		||||
  } else {
 | 
			
		||||
    count++;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static uint8_t data[8];
 | 
			
		||||
  int error = error_data.error_sources != 0;
 | 
			
		||||
  data[0] = eeprom_config.id | (error << 7);
 | 
			
		||||
  data[1] = stateofcharge;
 | 
			
		||||
  uint8_t* ptr = &data[2];
 | 
			
		||||
  uint16_t min_volt = 0xFFFF;
 | 
			
		||||
  uint16_t max_volt = 0;
 | 
			
		||||
  for (size_t i = 0; i < numberofCells; i++) {
 | 
			
		||||
    if (module.cellVoltages[i] < min_volt) {
 | 
			
		||||
      min_volt = module.cellVoltages[i];
 | 
			
		||||
    }
 | 
			
		||||
    if (module.cellVoltages[i] > max_volt) {
 | 
			
		||||
      max_volt = module.cellVoltages[i];
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  ptr = ftcan_marshal_unsigned(ptr, min_volt, 2);
 | 
			
		||||
  ptr = ftcan_marshal_unsigned(ptr, max_volt, 2);
 | 
			
		||||
  int16_t max_temp = -0x8000;
 | 
			
		||||
  for (size_t i = 0; i < N_TEMP_SENSORS; i++) {
 | 
			
		||||
    if (tmp1075_temps[i] > max_temp &&
 | 
			
		||||
        (tmp1075_failed_sensors & (1 << i)) == 0) {
 | 
			
		||||
      max_temp = tmp1075_temps[i];
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  ftcan_marshal_unsigned(ptr, max_temp, 2);
 | 
			
		||||
  uint16_t id = CAN_ID_MV_BMS | eeprom_config.id;
 | 
			
		||||
  ftcan_transmit(id, data, sizeof(data));
 | 
			
		||||
}
 | 
			
		||||
@ -8,7 +8,7 @@
 | 
			
		||||
#include "AMS_HighLevel.h"
 | 
			
		||||
#include "ADBMS_Abstraction.h"
 | 
			
		||||
#include "ADBMS_LL_Driver.h"
 | 
			
		||||
#include "AMS_CAN.h"
 | 
			
		||||
#include "can.h"
 | 
			
		||||
#include "TMP1075.h"
 | 
			
		||||
#include "can-halal.h"
 | 
			
		||||
#include "errors.h"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										27
									
								
								Core/Src/can.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								Core/Src/can.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,27 @@
 | 
			
		||||
/*
 | 
			
		||||
 *          can.c
 | 
			
		||||
 *  Created on: Mai 23, 2024
 | 
			
		||||
 *      Author: Hamza
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "can.h"
 | 
			
		||||
 | 
			
		||||
#include "AMS_HighLevel.h"
 | 
			
		||||
#include "TMP1075.h"
 | 
			
		||||
#include "can-halal.h"
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
void can_init(CAN_HandleTypeDef* hcan) { ftcan_init(hcan); }
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
This function sends the status of the mvbms, the battery and of powerground.
 | 
			
		||||
once every 1s in states: INACTIVE, PRECHARGE, DISCHARGE, CHARGING, ERROR.
 | 
			
		||||
once every 0.5s in states: READY, ACTIVE.
 | 
			
		||||
with format of:
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
void can_handle_send_status() {
 | 
			
		||||
  static uint8_t data[8];
 | 
			
		||||
  data[0] =  state. (sm_get_state_code() << 5);       //save 5 bit since codes are from 0-6
 | 
			
		||||
  //ftcan_transmit(id, data, sizeof(data));
 | 
			
		||||
}
 | 
			
		||||
@ -23,7 +23,7 @@
 | 
			
		||||
/* USER CODE BEGIN Includes */
 | 
			
		||||
#include "ADBMS_Abstraction.h"
 | 
			
		||||
#include "ADBMS_CMD_MAKROS.h"
 | 
			
		||||
#include "AMS_CAN.h"
 | 
			
		||||
#include "can.h"
 | 
			
		||||
#include "AMS_HighLevel.h"
 | 
			
		||||
#include "TMP1075.h"
 | 
			
		||||
#include "eeprom.h"
 | 
			
		||||
@ -119,7 +119,7 @@ int main(void)
 | 
			
		||||
  /* USER CODE BEGIN 2 */
 | 
			
		||||
  tmp1075_init(&hi2c1);
 | 
			
		||||
  AMS_Init(&hspi1);
 | 
			
		||||
  ams_can_init(&hcan);
 | 
			
		||||
  can_init(&hcan);
 | 
			
		||||
 | 
			
		||||
  uint32_t target_time = HAL_GetTick() + 10000;
 | 
			
		||||
  /* USER CODE END 2 */
 | 
			
		||||
@ -133,7 +133,7 @@ int main(void)
 | 
			
		||||
    /* USER CODE BEGIN 3 */
 | 
			
		||||
    AMS_Loop();
 | 
			
		||||
 | 
			
		||||
    ams_can_send_status();
 | 
			
		||||
    can_handle_send_status();
 | 
			
		||||
  }
 | 
			
		||||
  /* USER CODE END 3 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user