NorthStar-Endurance-TestBench/EnduranceTestBench/nms_hal/map_hal.c

209 lines
4.4 KiB
C

/**
* @file map_hal.c
*
* @copyright Nehemis SARL reserves all rights even in the event of industrial
* property rights. We reserve all rights of disposal such as
* copying and passing on to third parties.
*
* @brief Mapping of the hardware interfaces.
*
*/
/******************************************************************************
* Include Header Files
******************************************************************************/
#include "nms_types.h"
#include "map_hal.h"
#include "stm32g4xx_hal_tim.h"
/******************************************************************************
* Macro constant declarations
******************************************************************************/
extern TIM_HandleTypeDef htim7;
/******************************************************************************
* Extern Function Declarations
******************************************************************************/
uint32 MapHalGpio( MapHalGpioPin_en pin_en, uint16* targetPin_pu16, GPIO_TypeDef** targetPort_ppst)
{
uint32 error_u32 = NMS_ERR_DEFAULT;
if(targetPin_pu16 == NULL || targetPort_ppst == NULL)
{
error_u32 = NMS_ERR_UNKNOWN;
}
else
{
switch (pin_en)
{
case MAP_HAL_PMP_ENABLE:
*targetPin_pu16 = GPIO_PIN_15;
*targetPort_ppst = GPIOB;
error_u32 = NMS_ERR_NONE;
break;
default:
error_u32 = NMS_ERR_UNKNOWN;
break;
}
}
return error_u32;
}
uint32 MapHalGpioCallback(uint16 targetPin_u16, MapHalGpioPin_en * pin_pen)
{
uint32 error_u32 = NMS_ERR_DEFAULT;
switch (targetPin_u16)
{
case GPIO_PIN_15:
*pin_pen = MAP_HAL_PMP_ENABLE;
error_u32 = NMS_ERR_NONE;
break;
default:
error_u32 = NMS_ERR_UNKNOWN;
break;
}
return error_u32;
}
uint32 MapHalTimerModule(MapHalTimerModule_en timer_en, TIM_HandleTypeDef ** targetModule_ppst)
{
uint32 error_u32 = NMS_ERR_DEFAULT;
if(targetModule_ppst != NULL)
{
switch(timer_en)
{
case MAP_HAL_TIMER_RTOS:
*targetModule_ppst = &htim7;
error_u32 = NMS_ERR_NONE;
break;
default:
error_u32 = NMS_ERR_UNKNOWN;
break;
}
}
else
{
error_u32 = NMS_ERR_UNKNOWN;
}
return error_u32;
}
uint32 MapHalTimerCallback(TIM_HandleTypeDef ** targetModule_ppst, MapHalTimerModule_en * timer_pen)
{
uint32 error_u32 = NMS_ERR_DEFAULT;
if(*targetModule_ppst != NULL)
{
if (*targetModule_ppst == &htim17)
{
*timer_pen = MAP_HAL_TIMER_RTOS;
error_u32 = NMS_ERR_NONE;
}
}
else
{
error_u32 = NMS_ERR_UNKNOWN;
}
return error_u32;
}
uint32 MapHalAdcModule(MapHalAdcModule_en adc_en, ADC_HandleTypeDef ** targetModule_ppst)
{
uint32 error_u32 = NMS_ERR_DEFAULT;
if(targetModule_ppst != NULL)
{
switch(adc_en)
{
case MAP_HAL_ADC_1:
*targetModule_ppst = &hadc1;
error_u32 = NMS_ERR_NONE;
break;
default:
error_u32 = NMS_ERR_UNKNOWN;
break;
}
}
else
{
error_u32 = NMS_ERR_UNKNOWN;
}
return error_u32;
}
extern uint32 MapHalAdcCallback(ADC_HandleTypeDef *targetModule_pst, MapHalAdcModule_en *adcModule_en)
{
uint32 error_u32 = NMS_ERR_DEFAULT;
if (targetModule_pst != NULL)
{
if (targetModule_pst == &hadc1)
{
*adcModule_en = MAP_HAL_ADC_1;
error_u32 = NMS_ERR_NONE;
}
else
{
error_u32 = NMS_ERR_UNKNOWN;
}
}
else
{
error_u32 = NMS_ERR_UNKNOWN;
}
return error_u32;
}
uint32 MapHalI2cModule(MapHalI2cModule_en module_en, I2C_HandleTypeDef ** targetModule_ppst)
{
uint32 error_u32 = NMS_ERR_DEFAULT;
if(targetModule_ppst != NULL)
{
switch(module_en)
{
case MAP_HAL_GRUNDFOS_PMP_I2C_HANDLE:
*targetModule_ppst = &hi2c4;
error_u32 = NMS_ERR_NONE;
break;
default:
error_u32 = NMS_ERR_UNKNOWN;
break;
}
}
else
{
error_u32 = NMS_ERR_UNKNOWN;
}
return error_u32;
}