Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User/jl/hw refactor #125

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
/**
* @file HW_dma.h
* @brief Header file for DMA firmware
*/

#pragma once

/******************************************************************************
* I N C L U D E S
******************************************************************************/

// System Includes
#include "SystemConfig.h"


/******************************************************************************
* P U B L I C F U N C T I O N P R O T O T Y P E S
******************************************************************************/

void HW_DMA_init(void);
/**
* @file DRV_HIH_componentSpecific.c
* @brief Source code for HIH driver
*/

/******************************************************************************
* I N C L U D E S
******************************************************************************/

#include "DRV_HIH.h"
#include "HW_i2c.h"

/******************************************************************************
* P U B L I C V A R S
******************************************************************************/

HW_I2C_Device_S I2C_HIH = {
.addr = 0x27,
.handle = &i2c,
};

DRV_HIH_S hih_chip = {
.dev = &I2C_HIH,
};
91 changes: 0 additions & 91 deletions components/bms_boss/HW/HW.c

This file was deleted.

65 changes: 0 additions & 65 deletions components/bms_boss/HW/HW_HIH.c

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,20 @@
#include "string.h"

// Firmware Includes
#include "HW.h"
#include "HW_adc.h"

// Other Includes
#include "IO.h"
#include "SystemConfig.h"


/******************************************************************************
* D E F I N E S
******************************************************************************/

#define ADC_PRECALIBRATION_DELAY_ADCCLOCKCYCLES 2U
#define ADC_CALIBRATION_TIMEOUT 10U

#define ADC_MAX_COUNT 4095
#define ADC_REF_VOLTAGE 3.0F

#define ADC_N_CHANNEL ADC_CHANNEL_0
#define ADC_P_CHANNEL ADC_CHANNEL_1

Expand All @@ -43,13 +40,11 @@ ADC_HandleTypeDef hadc1;
ADC_HandleTypeDef hadc2;
DMA_HandleTypeDef hdma_adc1;


/******************************************************************************
* P R I V A T E F U N C T I O N P R O T O T Y P E S
******************************************************************************/

void HW_ADC_unpackBuffer(bufferHalf_E half);

void HW_ADC_unpackBuffer(HW_adc_bufferHalf_E half);

/******************************************************************************
* P U B L I C F U N C T I O N S
Expand All @@ -58,7 +53,7 @@ void HW_ADC_unpackBuffer(bufferHalf_E half);
/**
* @brief Init function for ADC firmware
*/
void HW_ADC_init(void)
HW_StatusTypeDef_E HW_ADC_init(void)
{
ADC_MultiModeTypeDef multimode = { 0 };
ADC_ChannelConfTypeDef sConfig = { 0 };
Expand Down Expand Up @@ -129,6 +124,8 @@ void HW_ADC_init(void)
}

HAL_ADC_Start(&hadc2);

return HW_OK;
}

/**
Expand Down Expand Up @@ -190,34 +187,3 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
__HAL_RCC_ADC2_CLK_DISABLE();
}
}


/******************************************************************************
* P U B L I C F U N C T I O N S
******************************************************************************/

/**
* @brief Firmware function to initiate ADC calibration.
*
* @param hadc Pointer to ADC peripheral
*
* @retval true = Success, false = Failure
*/
bool HW_ADC_calibrate(ADC_HandleTypeDef* hadc)
{
return HAL_ADCEx_Calibration_Start(hadc) == HAL_OK;
}

/**
* @brief Firmware function to start DMA transfer
*
* @param hadc Pointer to ADC peripheral
* @param data Pointer to memory start address
* @param size Size of buffer
*
* @retval true = Success, false = Failure
*/
bool HW_ADC_startDMA(ADC_HandleTypeDef* hadc, uint32_t* data, uint32_t size)
{
return HAL_ADCEx_MultiModeStart_DMA(hadc, data, size) == HAL_OK;
}
58 changes: 58 additions & 0 deletions components/bms_boss/HW/HW_i2c_componentSpecific.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @file HW_i2c_componentSpecific.c
* @brief Source code of I2C firmware/hardware interface
*/

/******************************************************************************
* I N C L U D E S
******************************************************************************/

// Firmware Includes
#include "HW_i2c.h"
#include "HW.h"

/******************************************************************************
* P U B L I C V A R S
******************************************************************************/

I2C_HandleTypeDef i2c;

/******************************************************************************
* P U B L I C F U N C T I O N S
******************************************************************************/

/**
* @brief Initializes the I2C1 bus
*/
void HW_I2C_init(void)
{
i2c.Instance = I2C1;
i2c.Init.ClockSpeed = 400000U; /**< Clocked at 100kHz */
i2c.Init.OwnAddress1 = 0; /**< Translates to 0x12*/
i2c.Init.DutyCycle = I2C_DUTYCYCLE_2;
i2c.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
i2c.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
i2c.Init.OwnAddress2 = 0;
i2c.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
i2c.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&i2c) == HAL_ERROR)
{
Error_Handler();
}
}

/**
* @brief Msp call back for I2C initialization
*
* @param hi2c i2c handle being initialized
*/
void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{
/**< Activate clocks */
__HAL_RCC_GPIOB_CLK_ENABLE();

if (hi2c->Instance == I2C1)
{
__HAL_RCC_I2C1_CLK_ENABLE();
}
}
4 changes: 2 additions & 2 deletions components/bms_boss/HW/HW_intc.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern ADC_HandleTypeDef hadc2;
extern DMA_HandleTypeDef hdma_adc1;
extern TIM_HandleTypeDef htim1;
extern TIM_HandleTypeDef htim4;
extern TIM_HandleTypeDef htim2;
extern TIM_HandleTypeDef htim_tick;
extern CAN_HandleTypeDef hcan[CAN_BUS_COUNT];


Expand Down Expand Up @@ -105,7 +105,7 @@ void ADC1_2_IRQHandler(void)

void TIM2_IRQHandler(void)
{
HAL_TIM_IRQHandler(&htim2);
HAL_TIM_IRQHandler(&htim_tick);
}

void TIM1_TRG_COM_IRQHandler(void)
Expand Down
Loading