foxBMS - Unit Tests
1.5.0
The foxBMS Unit Tests API Documentation
|
Driver for the I2C module. More...
#include "i2c.h"
#include "HL_system.h"
#include "database.h"
#include "diag.h"
#include "dma.h"
#include "fstd_types.h"
#include "fsystem.h"
#include "mcu.h"
#include "os.h"
#include <stdbool.h>
#include <stdint.h>
Go to the source code of this file.
Functions | |
static uint32_t | I2C_GetWordTransmitTime (i2cBASE_t *pI2cInterface) |
Return transmit time of a word in microseconds. More... | |
static bool | I2C_WaitTransmit (i2cBASE_t *pI2cInterface, uint32_t timeout_us) |
Waits for the I2C Tx buffer to be empty. More... | |
static bool | I2C_WaitStop (i2cBASE_t *pI2cInterface, uint32_t timeout_us) |
Waits for a stop condition to be detected. More... | |
static uint32_t | I2C_WaitForTxCompletedNotification (void) |
Wait for the I2C transmit communication to complete, using notifications. More... | |
static uint32_t | I2C_WaitForRxCompletedNotification (void) |
Wait for the I2C receive communication to complete, using notifications. More... | |
static void | I2C_ClearNotifications (void) |
Clear pending notifications. More... | |
void | I2C_Initialize (void) |
Initialize the I2C hardware with dedicated HAL functions. Has to be called before any call to the rest of this API. More... | |
STD_RETURN_TYPE_e | I2C_Read (i2cBASE_t *pI2cInterface, uint32_t slaveAddress, uint32_t nrBytes, uint8_t *readData) |
reads from an I2C slave, no register address written first, blocking. More... | |
STD_RETURN_TYPE_e | I2C_Write (i2cBASE_t *pI2cInterface, uint32_t slaveAddress, uint32_t nrBytes, uint8_t *writeData) |
writes to an I2C slave, no register address written first, blocking. More... | |
STD_RETURN_TYPE_e | I2C_WriteRead (i2cBASE_t *pI2cInterface, uint32_t slaveAddress, uint32_t nrBytesWrite, uint8_t *writeData, uint32_t nrBytesRead, uint8_t *readData) |
reads from an I2C slave, blocking. More... | |
STD_RETURN_TYPE_e | I2C_ReadDma (i2cBASE_t *pI2cInterface, uint32_t slaveAddress, uint32_t nrBytes, uint8_t *readData) |
reads from an I2C slave, no register address written first, using DMA. More... | |
STD_RETURN_TYPE_e | I2C_WriteDma (i2cBASE_t *pI2cInterface, uint32_t slaveAddress, uint32_t nrBytes, uint8_t *writeData) |
writes to an I2C slave, no register address written first, using DMA. More... | |
STD_RETURN_TYPE_e | I2C_WriteReadDma (i2cBASE_t *pI2cInterface, uint32_t slaveAddress, uint32_t nrBytesWrite, uint8_t *writeData, uint32_t nrBytesRead, uint8_t *readData) |
reads from an I2C slave, using DMA. More... | |
uint8_t | I2C_ReadLastRxByte (i2cBASE_t *pI2cInterface) |
Used to read last byte received per I2C. More... | |
bool | I2C_WaitReceive (i2cBASE_t *pI2cInterface, uint32_t timeout_us) |
Waits for the I2C Rx buffer to be full. More... | |
Variables | |
uint8_t | i2c_rxLastByteInterface1 = 0u |
uint8_t | i2c_rxLastByteInterface2 = 0u |
Driver for the I2C module.
SPDX-License-Identifier: BSD-3-Clause
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
We kindly request you to use one or more of the following phrases to refer to foxBMS in your hardware, software, documentation or advertising materials:
Definition in file i2c.c.
|
static |
|
static |
Return transmit time of a word in microseconds.
The function uses the clock settings of the interface to determine the time needed to transmit one word. Word means one byte + the ACK bit.
pI2cInterface | I2C interface to use |
void I2C_Initialize | ( | void | ) |
STD_RETURN_TYPE_e I2C_Read | ( | i2cBASE_t * | pI2cInterface, |
uint32_t | slaveAddress, | ||
uint32_t | nrBytes, | ||
uint8_t * | readData | ||
) |
reads from an I2C slave, no register address written first, blocking.
pI2cInterface | I2C interface to use |
slaveAddress | address of slave to communicate with |
nrBytes | number of registers to read |
readData | buffer containing the read data |
Definition at line 226 of file i2c.c.
STD_RETURN_TYPE_e I2C_ReadDma | ( | i2cBASE_t * | pI2cInterface, |
uint32_t | slaveAddress, | ||
uint32_t | nrBytes, | ||
uint8_t * | readData | ||
) |
reads from an I2C slave, no register address written first, using DMA.
pI2cInterface | I2C interface to use |
slaveAddress | address of slave to communicate with |
nrBytes | number of registers to read |
readData | buffer containing the read data |
Definition at line 415 of file i2c.c.
uint8_t I2C_ReadLastRxByte | ( | i2cBASE_t * | pI2cInterface | ) |
|
static |
Wait for the I2C receive communication to complete, using notifications.
Suspend task and wait for I2C DMA RX finished notification, clear notification value on entry and exit
Definition at line 206 of file i2c.c.
|
static |
Wait for the I2C transmit communication to complete, using notifications.
Suspend task and wait for I2C DMA TX finished notification, clear notification value on entry and exit
Definition at line 196 of file i2c.c.
bool I2C_WaitReceive | ( | i2cBASE_t * | pI2cInterface, |
uint32_t | timeout_us | ||
) |
Waits for the I2C Rx buffer to be full.
When the buffer is full, the received byte can be read. If the buffer is full before timeout_us microseconds are elapsed, the function returns true, false otherwise. The function also returns false if a NACK condition is detected.
pI2cInterface | I2C interface to use |
timeout_us | time in microseconds to wait until the buffer is full |
Definition at line 772 of file i2c.c.
|
static |
Waits for a stop condition to be detected.
When a stop condition is issued, this function waits until the stop condition is detected on the bus. This means that that transmission is finished. If stop is detected before timeout_us microseconds are elapsed, the function returns true, false otherwise.
pI2cInterface | I2C interface to use |
timeout_us | time in microseconds to wait until stop is detected |
Definition at line 179 of file i2c.c.
|
static |
Waits for the I2C Tx buffer to be empty.
When the buffer is empty, the next byte can be sent. If the buffer is empty before timeout_us microseconds are elapsed, the function returns true, false otherwise. The function also returns false if a NACK condition is detected.
pI2cInterface | I2C interface to use |
timeout_us | time in microseconds to wait until the buffer is empty |
Definition at line 161 of file i2c.c.
STD_RETURN_TYPE_e I2C_Write | ( | i2cBASE_t * | pI2cInterface, |
uint32_t | slaveAddress, | ||
uint32_t | nrBytes, | ||
uint8_t * | writeData | ||
) |
writes to an I2C slave, no register address written first, blocking.
pI2cInterface | I2C interface to use |
slaveAddress | address of slave to communicate with |
nrBytes | number of registers to write |
writeData | buffer containing the data to write |
Definition at line 283 of file i2c.c.
STD_RETURN_TYPE_e I2C_WriteDma | ( | i2cBASE_t * | pI2cInterface, |
uint32_t | slaveAddress, | ||
uint32_t | nrBytes, | ||
uint8_t * | writeData | ||
) |
writes to an I2C slave, no register address written first, using DMA.
pI2cInterface | I2C interface to use |
slaveAddress | address of slave to communicate with |
nrBytes | number of registers to write |
writeData | buffer containing the data to write |
Definition at line 510 of file i2c.c.
STD_RETURN_TYPE_e I2C_WriteRead | ( | i2cBASE_t * | pI2cInterface, |
uint32_t | slaveAddress, | ||
uint32_t | nrBytesWrite, | ||
uint8_t * | writeData, | ||
uint32_t | nrBytesRead, | ||
uint8_t * | readData | ||
) |
reads from an I2C slave, blocking.
pI2cInterface | I2C interface to use |
slaveAddress | address of slave to communicate with |
nrBytesWrite | number of registers to read |
writeData | buffer containing the read data |
nrBytesRead | number of registers to read |
readData | buffer containing the read data |
Definition at line 335 of file i2c.c.
STD_RETURN_TYPE_e I2C_WriteReadDma | ( | i2cBASE_t * | pI2cInterface, |
uint32_t | slaveAddress, | ||
uint32_t | nrBytesWrite, | ||
uint8_t * | writeData, | ||
uint32_t | nrBytesRead, | ||
uint8_t * | readData | ||
) |
reads from an I2C slave, using DMA.
pI2cInterface | I2C interface to use |
slaveAddress | address of slave to communicate with |
nrBytesWrite | number of registers to read |
writeData | buffer containing the read data |
nrBytesRead | number of registers to read |
readData | buffer containing the read data |
Definition at line 599 of file i2c.c.