hal_com/prg/HAL_COM_prg.c

107 lines
4.4 KiB
C

/******************************************************************************
* File: HAL_COM_prg.c
* Component: HAL_COM
* Description: Program (implementation) file for the HAL_COM abstraction.
* Dispatches send operations to the MCU-level driver wired to
* each channel via function pointers in HAL_COM_astrChannelConfig.
*
* The dispatch is a single indirect call — no if/else chains,
* no transport-specific code. Adding a new transport (SPI, I2C,
* etc.) requires zero changes here — only a new config entry.
*
* Layer: HAL
*****************************************************************************/
#include "HAL_COM.h"
#include "HAL_COM_priv.h"
#include "HAL_COM_cfg.h"
/* ========================================================================= */
/* INIT */
/* ========================================================================= */
STD_tenuResult HAL_COM_enuInit(void)
{
STD_tenuResult enuResultLoc = STD_OK;
/* HAL_COM has no internal state to set up yet. The underlying MCU
* drivers are already initialized by SYS_ECU before this function
* is called. When internal queuing or channel-level state is added,
* initialize it here. */
return enuResultLoc;
}
/* ========================================================================= */
/* SEND BYTE */
/* ========================================================================= */
STD_tenuResult HAL_COM_enuSendByte(u8 u8Channel, u8 u8Byte)
{
STD_tenuResult enuResultLoc = STD_OK;
const HAL_COM_tstrChannelConfig *pstrCfgLoc = &HAL_COM_astrChannelConfig[u8Channel];
/* Dispatch through the function pointer configured for this channel.
* The driver's instance index is passed through transparently — the
* caller never sees it. */
enuResultLoc = pstrCfgLoc->pfSendByte(pstrCfgLoc->u8Instance, u8Byte);
return enuResultLoc;
}
/* ========================================================================= */
/* SEND BUFFER */
/* ========================================================================= */
STD_tenuResult HAL_COM_enuSendBuffer(u8 u8Channel, const u8 *pu8Data, u16 u16Length)
{
STD_tenuResult enuResultLoc = STD_OK;
const HAL_COM_tstrChannelConfig *pstrCfgLoc = &HAL_COM_astrChannelConfig[u8Channel];
/* Dispatch through the function pointer configured for this channel.
* Null-pointer validation is handled inside the MCU driver, so we
* don't duplicate the check here. */
enuResultLoc = pstrCfgLoc->pfSendBuffer(pstrCfgLoc->u8Instance, pu8Data, u16Length);
return enuResultLoc;
}
/* ========================================================================= */
/* RECEIVE BYTE (BLOCKING) */
/* ========================================================================= */
STD_tenuResult HAL_COM_enuReadByte(u8 u8Channel, u8 *pu8Byte)
{
STD_tenuResult enuResultLoc = STD_OK;
const HAL_COM_tstrChannelConfig *pstrCfgLoc = &HAL_COM_astrChannelConfig[u8Channel];
enuResultLoc = pstrCfgLoc->pfReadByte(pstrCfgLoc->u8Instance, pu8Byte);
return enuResultLoc;
}
/* ========================================================================= */
/* READ BUFFER (NON-BLOCKING) */
/* ========================================================================= */
STD_tenuResult HAL_COM_enuReadBuffer(u8 u8Channel, u8 *pu8Data, u16 u16MaxLength, u16 *pu16Read)
{
STD_tenuResult enuResultLoc = STD_OK;
const HAL_COM_tstrChannelConfig *pstrCfgLoc = &HAL_COM_astrChannelConfig[u8Channel];
enuResultLoc = pstrCfgLoc->pfReadBuffer(pstrCfgLoc->u8Instance, pu8Data, u16MaxLength, pu16Read);
return enuResultLoc;
}
/* ========================================================================= */
/* RX DATA AVAILABLE CHECK */
/* ========================================================================= */
STD_tBool HAL_COM_bIsRxDataAvailable(u8 u8Channel)
{
const HAL_COM_tstrChannelConfig *pstrCfgLoc = &HAL_COM_astrChannelConfig[u8Channel];
return pstrCfgLoc->pfIsRxDataAvailable(pstrCfgLoc->u8Instance);
}