/*! * \copyright * COPYRIGHT(C) 2021 Honeywell Inc. All rights reserved. * This software is a copyrighted work and/or information protected as a * trade secret. Legal rights of Honeywell Inc in this software is distinct * from ownership of any medium in which the software is embodied. Copyright * or trade secret notices included must be reproduced in any copy autorized * by Honeywell Inc. The information in this software is subject to change * without notice and should not be considered as a commitment by Honeywell. * * \file hal_i2c.c * \brief Hardware functions for I2C * \ingroup hal_i2c * \details Handles both master and slave functions for I2C interfaces. * The slave interface to the end user is interrupt enabled and * triggers the command handler and state machine transitions. * The master interface may be interrupt enabled or polling, and * it is used to interface to the on-board HON5000 ASIC. * * \author Mrikank Srivastava * * \date 08/Aug/2022 * */ /* ------------------------------------------------------------------------------- Includes ------------------------------------------------------------------------------- */ #include "hal_i2c.h" #include "liquidflow_data.h" /* ------------------------------------------------------------------------------- Globals ------------------------------------------------------------------------------- */ /*! \var g_reset_cmd * \ingroup hal_i2c * \brief set when reset cmd needs to issued to ASIC */ bool gb_reset_cmd = false; /* ------------------------------------------------------------------------------- Local Functions ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- Functions ------------------------------------------------------------------------------- */ /*! \fn I2C_init(void) * \ingroup hal_i2c * \brief Configures i2c peripherals * \details Configure I2C peripheral for I2C0 and I2C1 * \param void * \return void */ void I2C_init(void) { //configure i2c0 //I2C0_init(); //configure i2c1 as Master //I2C1_Master_init(); return; } /*! \fn master_slave_write(uint8_t u8_data_length) * \ingroup hal_i2c * \brief Initiate the Master I2C write Transfer * \details -Gets the transfer data byte length * -sets the master bus status and enables interrupt if not busy * \param[in] uint8_t u8_data_length The number of data bytes for transfer * \return void */ bool master_slave_write(const uint8_t * cmdBuff, uint32_t cmdSize, uint32_t txSize) { uint32_t bytesRemaining; I2C_DRV_MasterSendData(BOARD_I2C_MASTER_INSTANCE, &slaveASIC, (const uint8_t*)cmdBuff, cmdSize, (const uint8_t*)(gu8_master_tx_data + 1), txSize); // Wait until finish send while(I2C_DRV_MasterGetSendStatus(BOARD_I2C_MASTER_INSTANCE, &bytesRemaining) != kStatus_I2C_Success) {} return true; } /*! \fn master_slave_read(uint8_t u8_data_length) * \ingroup hal_i2c * \brief Initiate the Master I2C read Transfer * \details gets the receive data byte length * sets the master bus status and enables interrupt if not busy * \param[in] uint8_t u8_data_length The number of data bytes to receive * \return void */ i2c_status_t master_transmit_receive_timeout(const uint8_t * cmdBuff, uint32_t cmdSize, uint32_t rxSize, uint32_t timeout_ms) { i2c_status_t status = I2C_DRV_MasterReceiveDataBlocking(BOARD_I2C_MASTER_INSTANCE, &slaveASIC, cmdBuff, cmdSize, gu8_master_rx_data, rxSize, timeout_ms); return status; } /*! \fn master_transmit_receive(void) * \ingroup hal_i2c * \brief Initiate the Master I2C WriteRead Transfer * \details gets the transfer and receive data byte length * sets the master bus status and enables interrupt if not busy * \return void */ bool master_transmit_receive(const uint8_t * cmdBuff, uint32_t cmdSize, uint32_t rxSize) { uint32_t bytesRemaining; // Master receive count byte data from slave I2C_DRV_MasterReceiveData(BOARD_I2C_MASTER_INSTANCE, &slaveASIC, cmdBuff, cmdSize, gu8_master_rx_data, rxSize); while(I2C_DRV_MasterGetReceiveStatus(BOARD_I2C_MASTER_INSTANCE, &bytesRemaining) != kStatus_I2C_Success) {} return true; } /*! \fn I2C1_Master_init(void) * \ingroup hal_i2c * \brief Configures i2c peripherals as Master * \details Configure I2C peripheral for I2C1 * \param void * \return void */ void I2C1_Master_init(void) { // Initialize i2c master I2C_DRV_MasterInit(BOARD_I2C_MASTER_INSTANCE, &masterASIC); return; }