RTEMS  5.1
Macros | Functions | Variables
twi.c File Reference
#include "chip.h"
#include <assert.h>

Macros

#define TWIHS_IT
 

Functions

void TWI_ConfigureMaster (Twihs *pTwi, uint32_t dwTwCk, uint32_t dwMCk)
 Configures a TWI peripheral to operate in master mode, at the given frequency (in Hz). The duty cycle of the TWI clock is set to 50%. More...
 
void TWI_ConfigureSlave (Twihs *pTwi, uint8_t slaveAddress)
 Configures a TWI peripheral to operate in slave mode. More...
 
void TWI_Stop (Twihs *pTwi)
 Sends a STOP condition on the TWI. More...
 
void TWI_StartRead (Twihs *pTwi, uint8_t address, uint32_t iaddress, uint8_t isize)
 Starts a read operation on the TWI bus with the specified slave, it returns immediately. Data must then be read using TWI_ReadByte() whenever a byte is available (poll using TWI_ByteReceived()). More...
 
uint8_t TWI_ReadByte (Twihs *pTwi)
 Reads a byte from the TWI bus. The read operation must have been started using TWI_StartRead() and a byte must be available (check with TWI_ByteReceived()). More...
 
void TWI_WriteByte (Twihs *pTwi, uint8_t byte)
 Sends a byte of data to one of the TWI slaves on the bus. More...
 
void TWI_StartWrite (Twihs *pTwi, uint8_t address, uint32_t iaddress, uint8_t isize, uint8_t byte)
 Starts a write operation on the TWI to access the selected slave, then returns immediately. A byte of data must be provided to start the write; other bytes are written next. after that to send the remaining bytes. More...
 
uint8_t TWI_ByteReceived (Twihs *pTwi)
 Check if a byte have been received from TWI. More...
 
uint8_t TWI_ByteSent (Twihs *pTwi)
 Check if a byte have been sent to TWI. More...
 
uint8_t TWI_TransferComplete (Twihs *pTwi)
 Check if current transmission is completed. More...
 
void TWI_EnableIt (Twihs *pTwi, uint32_t sources)
 Enables the selected interrupts sources on a TWI peripheral. More...
 
void TWI_DisableIt (Twihs *pTwi, uint32_t sources)
 Disables the selected interrupts sources on a TWI peripheral. More...
 
uint32_t TWI_GetStatus (Twihs *pTwi)
 Get the current status register of the given TWI peripheral. More...
 
uint32_t TWI_GetMaskedStatus (Twihs *pTwi)
 Returns the current status register of the given TWI peripheral, but masking interrupt sources which are not currently enabled. More...
 
void TWI_SendSTOPCondition (Twihs *pTwi)
 Sends a STOP condition. STOP Condition is sent just after completing the current byte transmission in master read mode. More...
 

Variables

uint32_t twi_send_stop = 0
 

Detailed Description

Implementation of Two Wire Interface (TWI).

Macro Definition Documentation

◆ TWIHS_IT

#define TWIHS_IT
Value:
TWIHS_IER_OVRE | TWIHS_IER_UNRE | TWIHS_IER_NACK | \
TWIHS_IER_ARBLST | TWIHS_IER_SCL_WS | TWIHS_IER_EOSACC | \
TWIHS_IER_MCACK | TWIHS_IER_TOUT | TWIHS_IER_PECERR |\
TWIHS_IER_SMBDAM | TWIHS_IER_SMBHHM)
#define TWIHS_IER_RXRDY
(TWIHS_IER) Receive Holding Register Ready Interrupt Enable
Definition: component_twihs.h:147
#define TWIHS_IER_PECERR
(TWIHS_IER) PEC Error Interrupt Enable
Definition: component_twihs.h:159
#define TWIHS_IER_TOUT
(TWIHS_IER) Timeout Error Interrupt Enable
Definition: component_twihs.h:158
#define TWIHS_IER_SVACC
(TWIHS_IER) Slave Access Interrupt Enable
Definition: component_twihs.h:149
#define TWIHS_IER_NACK
(TWIHS_IER) Not Acknowledge Interrupt Enable
Definition: component_twihs.h:153
#define TWIHS_IER_SCL_WS
(TWIHS_IER) Clock Wait State Interrupt Enable
Definition: component_twihs.h:155
#define TWIHS_IER_SMBHHM
(TWIHS_IER) SMBus Host Header Address Match Interrupt Enable
Definition: component_twihs.h:161
#define TWIHS_IER_TXRDY
(TWIHS_IER) Transmit Holding Register Ready Interrupt Enable
Definition: component_twihs.h:148
#define TWIHS_IER_UNRE
(TWIHS_IER) Underrun Error Interrupt Enable
Definition: component_twihs.h:152
#define TWIHS_IER_TXCOMP
(TWIHS_IER) Transmission Completed Interrupt Enable
Definition: component_twihs.h:146
#define TWIHS_IER_EOSACC
(TWIHS_IER) End Of Slave Access Interrupt Enable
Definition: component_twihs.h:156
#define TWIHS_IER_GACC
(TWIHS_IER) General Call Access Interrupt Enable
Definition: component_twihs.h:150

Function Documentation

◆ TWI_ByteReceived()

uint8_t TWI_ByteReceived ( Twihs pTwi)

Check if a byte have been received from TWI.

Parameters
pTwiPointer to an Twihs instance.
Returns
1 if a byte has been received and can be read on the given TWI peripheral; otherwise, returns 0. This function resets the status register.

◆ TWI_ByteSent()

uint8_t TWI_ByteSent ( Twihs pTwi)

Check if a byte have been sent to TWI.

Parameters
pTwiPointer to an Twihs instance.
Returns
1 if a byte has been sent so another one can be stored for transmission; otherwise returns 0. This function clears the status register.

◆ TWI_ConfigureMaster()

void TWI_ConfigureMaster ( Twihs pTwi,
uint32_t  dwTwCk,
uint32_t  dwMCk 
)

Configures a TWI peripheral to operate in master mode, at the given frequency (in Hz). The duty cycle of the TWI clock is set to 50%.

Parameters
pTwiPointer to an Twihs instance.
twckDesired TWI clock frequency.
mckMaster clock frequency.

◆ TWI_ConfigureSlave()

void TWI_ConfigureSlave ( Twihs pTwi,
uint8_t  slaveAddress 
)

Configures a TWI peripheral to operate in slave mode.

Parameters
pTwiPointer to an Twihs instance.
slaveAddressSlave address.

◆ TWI_DisableIt()

void TWI_DisableIt ( Twihs pTwi,
uint32_t  sources 
)

Disables the selected interrupts sources on a TWI peripheral.

Parameters
pTwiPointer to an Twihs instance.
sourcesBitwise OR of selected interrupt sources.

◆ TWI_EnableIt()

void TWI_EnableIt ( Twihs pTwi,
uint32_t  sources 
)

Enables the selected interrupts sources on a TWI peripheral.

Parameters
pTwiPointer to an Twihs instance.
sourcesBitwise OR of selected interrupt sources.

◆ TWI_GetMaskedStatus()

uint32_t TWI_GetMaskedStatus ( Twihs pTwi)

Returns the current status register of the given TWI peripheral, but masking interrupt sources which are not currently enabled.

Note
This resets the internal value of the status register, so further read may yield different values.
Parameters
pTwiPointer to an Twihs instance.

◆ TWI_GetStatus()

uint32_t TWI_GetStatus ( Twihs pTwi)

Get the current status register of the given TWI peripheral.

Note
This resets the internal value of the status register, so further read may yield different values.
Parameters
pTwiPointer to an Twihs instance.
Returns
TWI status register.

◆ TWI_ReadByte()

uint8_t TWI_ReadByte ( Twihs pTwi)

Reads a byte from the TWI bus. The read operation must have been started using TWI_StartRead() and a byte must be available (check with TWI_ByteReceived()).

Parameters
pTwiPointer to an Twihs instance.
Returns
byte read.

◆ TWI_SendSTOPCondition()

void TWI_SendSTOPCondition ( Twihs pTwi)

Sends a STOP condition. STOP Condition is sent just after completing the current byte transmission in master read mode.

Parameters
pTwiPointer to an Twihs instance.

◆ TWI_StartRead()

void TWI_StartRead ( Twihs pTwi,
uint8_t  address,
uint32_t  iaddress,
uint8_t  isize 
)

Starts a read operation on the TWI bus with the specified slave, it returns immediately. Data must then be read using TWI_ReadByte() whenever a byte is available (poll using TWI_ByteReceived()).

Parameters
pTwiPointer to an Twihs instance.
addressSlave address on the bus.
iaddressOptional internal address bytes.
isizeNumber of internal address bytes.

◆ TWI_StartWrite()

void TWI_StartWrite ( Twihs pTwi,
uint8_t  address,
uint32_t  iaddress,
uint8_t  isize,
uint8_t  byte 
)

Starts a write operation on the TWI to access the selected slave, then returns immediately. A byte of data must be provided to start the write; other bytes are written next. after that to send the remaining bytes.

Parameters
pTwiPointer to an Twihs instance.
addressAddress of slave to acccess on the bus.
iaddressOptional slave internal address.
isizeNumber of internal address bytes.
byteFirst byte to send.

◆ TWI_Stop()

void TWI_Stop ( Twihs pTwi)

Sends a STOP condition on the TWI.

Parameters
pTwiPointer to an Twihs instance.

◆ TWI_TransferComplete()

uint8_t TWI_TransferComplete ( Twihs pTwi)

Check if current transmission is completed.

Parameters
pTwiPointer to an Twihs instance.
Returns
1 if the current transmission is complete (the STOP has been sent); otherwise returns 0.

◆ TWI_WriteByte()

void TWI_WriteByte ( Twihs pTwi,
uint8_t  byte 
)

Sends a byte of data to one of the TWI slaves on the bus.

Note
This function must be called once before TWI_StartWrite() with the first byte of data to send, then it shall be called repeatedly after that to send the remaining bytes.
Parameters
pTwiPointer to an Twihs instance.
byteByte to send.

Variable Documentation

◆ twi_send_stop

uint32_t twi_send_stop = 0

variable for control thether or not to set both START and STOP In single data byte master read, the START and STOP must both be set