ESOS32
ESOSOn32-bitProcessors
Files | Macros | Functions | Variables
ESOS_I2C_Service

Files

file  esos_i2c.c
 Hardware independent support for ESOS32 I2C services.
 
file  esos_hwxxx_i2c.c
 Template for creating hardware-specific support for ESOS32 I2C services.
 
file  esos_hwxxx_i2c.c
 Template for creating hardware-specific support for ESOS32 I2C services.
 
file  esos_stm32l4_i2c.c
 Hardware-specific support for ESOS32 I2C services on the STM32L4xx MCUs (tested on STM32L452RE)
 
file  esos_stm32l4_i2c.c
 Hardware-specific support for ESOS32 I2C services on the STM32L4xx MCUs (tested on STM32L452RE)
 
file  esos_i2c.h
 
file  esos_hwxxx_i2c.h
 This file contains template routines which define, configure and allow use of the I2C service on some specific hardware.
 
file  esos_stm32l4_i2c.h
 This file contains routines which define, configure and allow use of the I2C service on the ST Microelectronics STM32L452RE MCU.
 

Macros

#define DEBUG(str)   __esos_unsafe_PutString(str)
 
#define ESOS_I2C_ACK   0
 
#define ESOS_I2C_NAK   1
 
#define I2C_WADDR(x)   (x & 0xFE)
 
#define I2C_RADDR(x)   (x | 0x01)
 
#define ESOS_TASK_WAIT_ON_AVAILABLE_I2C()
 
#define ESOS_SIGNAL_AVAILABLE_I2C()
 
#define ESOS_IS_I2C_AVAILABLE()
 
#define ESOS_TASK_WAIT_ON_WRITE1I2C(u8_addr, u8_d1)
 
#define ESOS_TASK_WAIT_ON_WRITE2I2C(u8_addr, u8_d1, u8_d2)
 
#define ESOS_TASK_WAIT_ON_WRITENI2C(u8_addr, pu8_d, u8_cnt)
 
#define ESOS_TASK_WAIT_ON_READ1I2C(u8_addr, u8_d1)
 
#define ESOS_TASK_WAIT_ON_READ2I2C(u8_addr, u8_d1, u8_d2)
 
#define ESOS_TASK_WAIT_ON_READNI2C(u8_addr, pu8_d, u8_cnt)
 
#define CLEAR_REGISTER_BITS(reg, mask)   reg &= (~(mask))
 
#define SET_REGISTER_BITS(reg, mask)   reg |= (mask)
 
#define MAKE_I2C_WR_ADDR(bits)   bits &= 0xFFE
 
#define MAKE_I2C_RD_ADDR(bits)   bits &= 0x001
 
#define CLEAR_REGISTER_BITS(reg, mask)   reg &= (~(mask))
 
#define SET_REGISTER_BITS(reg, mask)   reg |= (mask)
 
#define MAKE_I2C_WR_ADDR(bits)   bits &= 0xFFF
 
#define MAKE_I2C_RD_ADDR(bits)   bits &= 0x001
 
#define __ESOS_I2C_STM32L4_SET_WRITE_DIR()   I2C1_CR2 &= (~I2C_CR2_RD_WRN)
 
#define __ESOS_I2C_STM32L4_SET_READ_DIR()   I2C1_CR2 |= I2C_CR2_RD_WRN
 
#define __ESOS_I2C_STM32L4_SET_NUM_BYTES(x)   I2C1_CR2 = (I2C1_CR2 & ~I2C_CR2_NBYTES_MASK) | (x << I2C_CR2_NBYTES_SHIFT)
 
#define __ESOS_I2C_STM32L4_SET_ADDR7_MODE()   I2C1_CR2 &= (~I2C_CR2_ADD10)
 
#define __ESOS_I2C_STM32L4_SET_ADDR10_MODE()   I2C1_CR2 |= I2C_CR2_ADD10
 
#define __ESOS_I2C_STM32L4_SET_ADDR7(x)   I2C1_CR2 = (I2C1_CR2 & ~I2C_CR2_SADD_7BIT_MASK) | ((x & 0x7F) << I2C_CR2_SADD_7BIT_SHIFT)
 
#define __ESOS_I2C_STM32L4_SET_AUTOEND()   I2C1_CR2 |= I2C_CR2_AUTOEND
 
#define __ESOS_I2C_STM32L4_CLEAR_AUTOEND()   I2C1_CR2 &= (~I2C_CR2_AUTOEND)
 
#define __ESOS_I2C_STM32L4_SET_RELOAD()   I2C1_CR2 |= I2C_CR2_RELOAD
 
#define __ESOS_I2C_STM32L4_CLEAR_RELOAD()   I2C1_CR2 &= (~I2C_CR2_RELOAD)
 
#define __ESOS_I2C_STM32L4_IS_NACK_RECEIVED()   (I2C1_ISR & I2C_ISR_NACKF)
 
#define __ESOS_I2C_STM32L4_CLEAR_STOP_FLAG()   I2C1_ICR |= I2C_ICR_STOPCF
 
#define __ESOS_I2C_STM32L4_RESET_CR2()   I2C1_CR2 &= (uint32_t)~((uint32_t)(I2C_CR2_SADD_7BIT_MASK | I2C_CR2_HEAD10R | I2C_CR2_NBYTES_MASK | I2C_CR2_RELOAD | I2C_CR2_RD_WRN))
 
#define __ESOS_I2C_STM32L4_IS_BUSY()   (I2C1_ISR & I2C_ISR_BUSY)
 
#define __ESOS_I2C_STM32L4_IS_TX_EMPTY()   (I2C1_ISR & I2C_ISR_TXIS)
 
#define __ESOS_I2C_STM32L4_IS_RX_NOT_EMPTY()   (I2C1_ISR & I2C_ISR_RXNE)
 
#define __ESOS_I2C_HW_START()
 
#define __ESOS_I2C_HW_RSTART()
 
#define __ESOS_I2C_HW_STOP()
 
#define __ESOS_I2C_HW_PUT(byte)
 

Functions

void __esos_i2c_config (uint32_t u32_i2cbps)
 
void __esos_i2c_hw_config (uint32_t u32_i2cbps)
 
 ESOS_CHILD_TASK (__esos_i2c_hw_writeN, uint8_t u8_addr, uint8_t *pu8_d, uint8_t u8_cnt)
 
 ESOS_CHILD_TASK (__esos_i2c_hw_readN, uint8_t u8_addr, uint8_t *pu8_d, uint8_t u8_cnt)
 
 ESOS_CHILD_TASK (__esos_i2c_hw_writeNReadM, uint8_t u8_addr, uint8_t *pu8_wd, uint8_t u8_wcnt, uint8_t *pu8_rd, uint8_t u8_rcnt)
 
 ESOS_CHILD_TASK (__esos_hw_getI2C, uint8_t *pu8_x, uint8_t u8_ack2Send)
 
 ESOS_CHILD_TASK (__esos_i2c_hw_writeN, uint8_t u8_addr, uint8_t *pu8_d, uint_t u8_cnt)
 
 ESOS_CHILD_TASK (__esos_hw_getI2C1, uint8_t *pu8_x, uint8_t u8_ack2Send)
 
 ESOS_CHILD_TASK (__esos_hw_writeNI2C1, uint8_t u8_addr, uint8_t *pu8_d, uint16_t u16_cnt)
 
 ESOS_CHILD_TASK (__esos_hw_readNI2C1, uint8_t u8_addr, uint8_t *pu8_d, uint16_t u16_cnt)
 

Variables

struct stTask __stChildTaskI2C
 
uint8_t __esos_i2c_dataBytes [2]
 
struct stTask __stChildTaskI2C __stGrandChildTaskI2C
 
uint8_t __esos_i2c_dataBytes [2]
 
struct stTask __stChildTaskI2C __stGrandChildTaskI2C
 
uint8_t __esos_i2c_dataBytes [2]
 
struct stTask __stChildTaskI2C __stGrandChildTaskI2C
 
uint8_t __esos_i2c_dataBytes [2]
 
struct stTask __stChildTaskI2C __stGrandChildTaskI2C
 
uint8_t __esos_i2c_dataBytes [2]
 

Detailed Description

Macro Definition Documentation

◆ __ESOS_I2C_HW_PUT

#define __ESOS_I2C_HW_PUT (   byte)
Value:
do{ \
I2C1_TXDR = (byte); \
ESOS_TASK_WAIT_UNTIL( __esos_i2c_hw_IsTransferComplete() ); \
}while(0)

Definition at line 112 of file esos_stm32l4_i2c.h.

◆ __ESOS_I2C_HW_RSTART

#define __ESOS_I2C_HW_RSTART ( )
Value:
do{ \
I2C1CONbits.RSEN = 1; \
ESOS_TASK_WAIT_WHILE( I2C1CONbits.RSEN); \
}while(0)

Definition at line 100 of file esos_stm32l4_i2c.h.

◆ __ESOS_I2C_HW_START

#define __ESOS_I2C_HW_START ( )
Value:
do{ \
I2C1_CR2 |= I2C_CR2_START; \
ESOS_TASK_WAIT_WHILE( I2C1_CR2 & I2C_CR2_START); \
}while(0)

Definition at line 94 of file esos_stm32l4_i2c.h.

◆ __ESOS_I2C_HW_STOP

#define __ESOS_I2C_HW_STOP ( )
Value:
do{ \
I2C1_CR2 |= I2C_CR2_STOP; \
ESOS_TASK_WAIT_WHILE( I2C1_CR2 & I2C_CR2_STOP); \
}while(0)

Definition at line 106 of file esos_stm32l4_i2c.h.

◆ ESOS_IS_I2C_AVAILABLE

#define ESOS_IS_I2C_AVAILABLE ( )

Returns TRUE if the ESOS I2C resource is available, else returns FALSE.

Return values
TRUEESOS I2C is not in use; available
See also
ESOS_TASK_WAIT_ON_AVAILABLE_I2C
ESOS_SIGNAL_AVAILABLE_I2C
ESOS_TASK_WAIT_ON_WRITE2I2C
ESOS_TASK_WAIT_ON_WRITENI2C
__esos_i2c_hw_config

Definition at line 95 of file esos_i2c.h.

◆ ESOS_SIGNAL_AVAILABLE_I2C

#define ESOS_SIGNAL_AVAILABLE_I2C ( )

Release ESOS I2C resource for use by other task.

See also
ESOS_TASK_WAIT_ON_AVAILABLE_I2C
ESOS_IS_I2C_AVAILABLE
ESOS_TASK_WAIT_ON_WRITE2I2C
ESOS_TASK_WAIT_ON_WRITENI2C
__esos_i2c_hw_config

Definition at line 83 of file esos_i2c.h.

◆ ESOS_TASK_WAIT_ON_AVAILABLE_I2C

#define ESOS_TASK_WAIT_ON_AVAILABLE_I2C ( )

Current task waits until the ESOS I2C resource becomes available for use.

See also
ESOS_SIGNAL_AVAILABLE_I2C
ESOS_IS_I2C_AVAILABLE
ESOS_TASK_WAIT_ON_WRITE2I2C
ESOS_TASK_WAIT_ON_WRITENI2C
__esos_i2c_hw_config

Definition at line 67 of file esos_i2c.h.

◆ ESOS_TASK_WAIT_ON_READ1I2C

#define ESOS_TASK_WAIT_ON_READ1I2C (   u8_addr,
  u8_d1 
)

Transaction: Read 1 (ONE) byte from I2C slave at address u8_addr, and save to variable u8_d1 As per the I2C standard, a NAK is returned for the last byte read from the slave, ACKs are returned for the other bytes.

Parameters
u8_addrSlave I2C address
u8_d1variable to hold the read byte
See also
ESOS_TASK_WAIT_ON_AVAILABLE_I2C
ESOS_SIGNAL_AVAILABLE_I2C
ESOS_IS_I2C_AVAILABLE
ESOS_TASK_WAIT_ON_READ2I2C
ESOS_TASK_WAIT_ON_READNI2C
__esos_i2c_hw_config

Definition at line 177 of file esos_i2c.h.

◆ ESOS_TASK_WAIT_ON_READ2I2C

#define ESOS_TASK_WAIT_ON_READ2I2C (   u8_addr,
  u8_d1,
  u8_d2 
)

Transaction: Read 2 (TWO) bytes from I2C slave at address u8_addr, save to variables u8_d1 and u8_d2 As per the I2C standard, a NAK is returned for the last byte read from the slave, ACKs are returned for the other bytes.

Parameters
u8_addrSlave I2C address
u8_d1variable to hold first read byte
u8_d2variable to hold second read byte
See also
ESOS_TASK_WAIT_ON_AVAILABLE_I2C
ESOS_SIGNAL_AVAILABLE_I2C
ESOS_IS_I2C_AVAILABLE
ESOS_TASK_WAIT_ON_READ1I2C
ESOS_TASK_WAIT_ON_READNI2C
__esos_i2c_hw_config

Definition at line 198 of file esos_i2c.h.

◆ ESOS_TASK_WAIT_ON_READNI2C

#define ESOS_TASK_WAIT_ON_READNI2C (   u8_addr,
  pu8_d,
  u8_cnt 
)

Transaction: Read u16_cnt bytes from I2C slave at address u8_addr, save to buffer *pu8_d. As per the I2C standard, a NAK is returned for the last byte read from the slave, ACKs are returned for the other bytes.

Parameters
u8_addrSlave I2C address
pu8_dPointer to buffer for storing bytes read from slave
u16_cntNumber of bytes read from slave.
See also
ESOS_TASK_WAIT_ON_AVIALABLE_I2C
ESOS_SIGNAL_AVIALABLE_I2C
ESOS_TASK_WAIT_ON_READ1I2C
ESOS_TASK_WAIT_ON_READ2I2C
__esos_i2c_hw_config

Definition at line 218 of file esos_i2c.h.

◆ ESOS_TASK_WAIT_ON_WRITE1I2C

#define ESOS_TASK_WAIT_ON_WRITE1I2C (   u8_addr,
  u8_d1 
)
Todo:
Should this be deprecated? #define ESOS_TASK_WAIT_ON_GETI2C( pu8_get, u8_ack2Send ) \ ESOS_TASK_SPAWN_AND_WAIT( (ESOS_TASK_HANDLE)&__stGrandChildTaskI2C, __esos_hw_getI2C, (pu8_get), (u8_ack2Send) )

Transaction: Write 1 (ONE) byte stored in variable u8_d1 to I2C slave at address u8_addr.

Parameters
u8_addrSlave I2C address
u8_d1Variable containing first byte to write
See also
ESOS_TASK_WAIT_ON_AVAILABLE_I2C
ESOS_SIGNAL_AVAILABLE_I2C
ESOS_IS_I2C_AVAILABLE
ESOS_TASK_WAIT_ON_WRITE2I2C
ESOS_TASK_WAIT_ON_WRITENI2C
__esos_i2c_hw_config

Definition at line 116 of file esos_i2c.h.

◆ ESOS_TASK_WAIT_ON_WRITE2I2C

#define ESOS_TASK_WAIT_ON_WRITE2I2C (   u8_addr,
  u8_d1,
  u8_d2 
)

Transaction: Write 2 (TWO) bytes stored in variables u8_d1 and u8_d2 to I2C slave at address u8_addr.

Parameters
u8_addrSlave I2C address
u8_d1Variable containing first byte to write
u8_d2Variable containing second byte to write
See also
ESOS_TASK_WAIT_ON_AVAILABLE_I2C
ESOS_SIGNAL_AVAILABLE_I2C
ESOS_IS_I2C_AVAILABLE
ESOS_TASK_WAIT_ON_WRITE1I2C
ESOS_TASK_WAIT_ON_WRITENI2C
__esos_i2c_hw_config

Definition at line 139 of file esos_i2c.h.

◆ ESOS_TASK_WAIT_ON_WRITENI2C

#define ESOS_TASK_WAIT_ON_WRITENI2C (   u8_addr,
  pu8_d,
  u8_cnt 
)

Transaction: Write u16_cnt bytes stored in buffer *pu8_d to I2C slave at address u8_addr.

Parameters
u8_addrSlave I2C address
pu8_dPointer to buffer containing bytes to send
u16_cntNumber of bytes to send
See also
ESOS_TASK_WAIT_ON_AVAILABLE_I2C
ESOS_SIGNAL_AVAILABLE_I2C
ESOS_IS_I2C_AVAILABLE
ESOS_TASK_WAIT_ON_WRITE1I2C
ESOS_TASK_WAIT_ON_WRITE2I2C
__esos_i2c_hw_config

Definition at line 159 of file esos_i2c.h.

Function Documentation

◆ __esos_i2c_config()

void __esos_i2c_config ( uint32_t  u32_i2cbps)

Configure and enable the ESOS I2C service for operation at u32_i2cbbps bits per second clock speed.

Parameters
u32_i2cbpsspecifies clock speed in bits per second
See also
ESOS_TASK_WAIT_ON_WRITENI2C
ESOS_TASK_WAIT_ON_READNI2C

Definition at line 65 of file esos_i2c.c.

◆ __esos_i2c_hw_config()

void __esos_i2c_hw_config ( uint32_t  u32_i2cbps)

Configure and enable the I2C1 module for operation at u32_i2cbps.

Parameters
u32_i2cbpsspecifies clock speed in bits per second
See also
ESOS_TASK_WAIT_ON_WRITENI2C1
ESOS_TASK_WAIT_ON_READNI2C1

Configure and enable the I2C1 module for operation at u16_fKHz KHz clock speed.

Parameters
u16_fKHzspecifies clock speed in KHz
See also
ESOS_TASK_WAIT_ON_WRITENI2C1
ESOS_TASK_WAIT_ON_READNI2C1

Definition at line 74 of file esos_hwxxx_i2c.c.

◆ ESOS_CHILD_TASK() [1/3]

ESOS_CHILD_TASK ( __esos_i2c_hw_readN  ,
uint8_t  u8_addr,
uint8_t *  pu8_d,
uint8_t  u8_cnt 
)

Transaction: Read u8_cnt bytes from I2C slave at address u8_addr, save to buffer *pu8_d. As per the I2C standard, a NAK is returned for the last byte read from the slave, ACKs are returned for the other bytes.

Parameters
u8_addrSlave I2C address
pu8_dPointer to buffer for storing bytes read from slave
u8_cntNumber of bytes read from slave.

Definition at line 108 of file esos_hwxxx_i2c.c.

◆ ESOS_CHILD_TASK() [2/3]

ESOS_CHILD_TASK ( __esos_i2c_hw_writeN  ,
uint8_t  u8_addr,
uint8_t *  pu8_d,
uint8_t  u8_cnt 
)

Transaction: Write u8_cnt bytes stored in buffer *pu8_d to I2C slave, I2C slave is located at I2C address u8_addr.

Parameters
u8_addrSlave I2C address
pu8_dPointer to buffer containing bytes to send
u8_cntNumber of bytes to send

ESOS_CHILD_TASK( __esos_i2c_hw_writeMReadN, uint8_t u8_addr, uint8_t* pu8_wd, uint8_t u8_wcnt, uint8_t* pu8_rd, uint8_t u8_rcnt)

Transaction: Write u8_wcnt bytes stored in buffer *pu8_wd to I2C slave, then read u8_rcnt bytes into buffer *pu8_rd from I2C slave. I2C slave is located at I2C address u8_addr.

Parameters
u8_addrSlave I2C address
pu8_dPointer to buffer containing bytes to send
u16_cntNumber of bytes to send

/note Once written, the writeN() and readN() routines can call this routine to do their dirty work Transaction: Write u16_cnt bytes stored in buffer *pu8_d to I2C slave at address u8_addr.

Parameters
u8_addrSlave I2C address
pu8_dPointer to buffer containing bytes to send
u16_cntNumber of bytes to send

Definition at line 90 of file esos_hwxxx_i2c.c.

◆ ESOS_CHILD_TASK() [3/3]

ESOS_CHILD_TASK ( __esos_i2c_hw_writeNReadM  ,
uint8_t  u8_addr,
uint8_t *  pu8_wd,
uint8_t  u8_wcnt,
uint8_t *  pu8_rd,
uint8_t  u8_rcnt 
)

ESOS_CHILD_TASK( __esos_i2c_hw_writeMReadN, uint8_t u8_addr, uint8_t* pu8_wd, uint8_t u8_wcnt, uint8_t* pu8_rd, uint8_t u8_rcnt)

Transaction: Write u8_wcnt bytes stored in buffer *pu8_wd to I2C slave, then read u8_rcnt bytes into buffer *pu8_rd from I2C slave. I2C slave is located at I2C address u8_addr.

Parameters
u8_addrSlave I2C address
pu8_dPointer to buffer containing bytes to send
u16_cntNumber of bytes to send

\TODO WRITE THIS CHILD TASK __esos_i2c_hw_WriteMReadN

ESOS_CHILD_TASK( __esos_i2c_hw_writeMReadN, uint8_t u8_addr, uint8_t* pu8_wd, uint8_t u8_wcnt, uint8_t* pu8_rd, uint8_t u8_rcnt)

Transaction: Write u8_wcnt bytes stored in buffer *pu8_wd to I2C slave, then read u8_rcnt bytes into buffer *pu8_rd from I2C slave. I2C slave is located at I2C address u8_addr.

Parameters
u8_addrSlave I2C address
pu8_dPointer to buffer containing bytes to send
u16_cntNumber of bytes to send

/note Once written, the writeN() and readN() routines can call this routine to do their dirty work Transaction: Write u8_wcnt bytes stored in buffer *pu8_wd to I2C slave at address u8_addr, followed by a read of u8_rcnt bytes into the buffer *pu8_rd

Parameters
u8_addrSlave I2C address
pu8_wdPointer to buffer containing bytes to send
u8_wcntNumber of bytes to send
pu8_rdPointer to buffer to "catch" bytes read from device
u8_rcntNumber of bytes to read

Definition at line 128 of file esos_hwxxx_i2c.c.