Nut/OS  5.0.5
API Reference
stm32_twi.c File Reference
#include <arch/cm3.h>
#include <dev/irqreg.h>
#include <sys/event.h>
#include <sys/atom.h>
#include <sys/timer.h>
#include <sys/thread.h>
#include <sys/heap.h>
#include <cfg/twi.h>
#include <dev/twif.h>
#include <stdlib.h>
#include <string.h>
#include <arch/cm3/stm/stm32xxxx.h>
Include dependency graph for stm32_twi.c:

Defines

#define TPRINTF(...)
#define DBGP1_INIT()
#define DBGP1(v)
#define DBGP2_INIT()
#define DBGP2(v)
#define MODE_FLAG_Mask   ((uint32_t)0x00FFFFFF)
#define CR1_CLEAR_Mask   ((uint16_t)0xFBF5)
#define CCR_CCR_Set   ((uint16_t)0x0FFF)
#define CCR_FS_Set   ((uint16_t)0x8000)
#define MODE_READ   1
#define MODE_WRITE   0
#define ENABLE   1
#define DISABLE   0
#define ERROR   0
#define SUCCESS   1
#define I2C_NACK_STOP(x)
#define I2C_ENA_ACK(x)   x->CR1 |= I2C_CR1_ACK
#define I2C_RESTART(x)   x->CR1 |= I2C_CR1_START
#define I2C_STOP(x)   x->CR1 |= I2C_CR1_STOP
#define I2C_DIS_EVT(x)   x->CR2 &= (uint16_t)~I2C_CR2_ITEVTEN
#define I2C_DIS_BUF(x)   x->CR2 &= (uint16_t)~I2C_CR2_ITBUFEN
#define I2C_ENA_BUF(x)   x->CR2 |= I2C_CR2_ITBUFEN

Functions

void I2C_DMA_Enable (I2C_TypeDef *I2Cx)
void I2C_DMA_Disable (I2C_TypeDef *I2Cx)
uint8_t I2C_Is_Busy (I2C_TypeDef *I2Cx)
void TwEventIrq (void *arg)
void TwErrorIrq (void *arg)
void NutTwiSoftReset (NUTTWIBUS *bus)
 Reset the I2C peripheral by issueing soft-reset.
int TwWaitForFlag (volatile uint16_t *reg, uint16_t mask, uint16_t flag)
int NutTwiStartRolling (NUTTWIBUS *bus, uint32_t tmo)
 Set START condition and wait for its appearance on the bus.
int NutTwiMasterTranceive (NUTTWIBUS *bus, uint8_t sla, const void *txdata, uint16_t txlen, void *rxdata, uint16_t rxsiz, uint32_t tmo)
 Transmit and/or receive data as a master.
int NutTwiMasterRegRead (NUTTWIBUS *bus, uint8_t sla, uint32_t iadr, uint8_t iadrlen, void *rxdata, uint16_t rxsiz, uint32_t tmo)
 Receive data as a master from a device having internal addressable registers.
int NutTwiMasterRegWrite (NUTTWIBUS *bus, uint8_t sla, uint32_t iadr, uint8_t iadrlen, const void *txdata, uint16_t txsiz, uint32_t tmo)
 Transmit data as a master to a device having internal addressable registers.
int NutTwiMasterError (NUTTWIBUS *bus)
 Get last master mode error.
int NutTwiSlaveListen (NUTTWIBUS *bus, uint8_t *sla, void *rxdata, uint16_t rxsiz, uint32_t tmo)
 Listen for incoming data from a master.
int NutTwiSlaveRespond (NUTTWIBUS *bus, void *txdata, uint16_t txlen, uint32_t tmo)
 Send response to a master.
int NutTwiSlaveError (NUTTWIBUS *bus)
 Get last slave mode error.
uint16_t NutTwiIndexes (NUTTWIBUS *bus, uint8_t idx)
 Get last transfer results.
int NutTwiSetSpeed (NUTTWIBUS *bus, uint32_t speed)
 Set Speed of I2C Interface.
int NutTwiGetSpeed (NUTTWIBUS *bus)
 Request Current Speed of I2C Interface.
int NutTwiIOCtl (NUTTWIBUS *bus, int req, void *conf)
 Perform TWI control functions.
int NutRegisterTwiBus (NUTTWIBUS *bus, uint8_t sla)
 Initialize TWI interface.

Define Documentation

#define TPRINTF (   ...)
#define DBGP1_INIT ( )

Referenced by NutRegisterTwiBus().

#define DBGP1 (   v)

Referenced by TwEventIrq().

#define DBGP2_INIT ( )

Referenced by NutRegisterTwiBus().

#define DBGP2 (   v)

Referenced by TwEventIrq().

#define MODE_FLAG_Mask   ((uint32_t)0x00FFFFFF)
#define CR1_CLEAR_Mask   ((uint16_t)0xFBF5)
#define CCR_CCR_Set   ((uint16_t)0x0FFF)
#define CCR_FS_Set   ((uint16_t)0x8000)
#define MODE_READ   1

Referenced by NutTwiMasterTranceive().

#define MODE_WRITE   0
#define ENABLE   1
#define DISABLE   0
#define ERROR   0
#define SUCCESS   1

Referenced by RCC_WaitForHSEStartUp().

#define I2C_NACK_STOP (   x)
Value:
{ \
        x->CR1 &= (uint16_t)~I2C_CR1_ACK; \
        x->CR1 |= I2C_CR1_STOP; \
    }
#define I2C_ENA_ACK (   x)    x->CR1 |= I2C_CR1_ACK
#define I2C_RESTART (   x)    x->CR1 |= I2C_CR1_START
#define I2C_STOP (   x)    x->CR1 |= I2C_CR1_STOP

Referenced by TwErrorIrq().

#define I2C_DIS_EVT (   x)    x->CR2 &= (uint16_t)~I2C_CR2_ITEVTEN
#define I2C_DIS_BUF (   x)    x->CR2 &= (uint16_t)~I2C_CR2_ITBUFEN
#define I2C_ENA_BUF (   x)    x->CR2 |= I2C_CR2_ITBUFEN

Function Documentation

void I2C_DMA_Enable ( I2C_TypeDef I2Cx) [inline]

References I2C_TypeDef::CR2, and I2C_CR2_DMAEN.

void I2C_DMA_Disable ( I2C_TypeDef I2Cx) [inline]

References I2C_TypeDef::CR2, and I2C_CR2_DMAEN.

uint8_t I2C_Is_Busy ( I2C_TypeDef I2Cx) [inline]

References I2C_SR2_BUSY, and I2C_TypeDef::SR2.

Referenced by NutTwiStartRolling().

void TwEventIrq ( void *  arg)
void NutTwiSoftReset ( NUTTWIBUS bus)

Reset the I2C peripheral by issueing soft-reset.

References _NUTTWIBUS::bus_base, I2C_TypeDef::CR1, and I2C_CR1_SWRST.

int TwWaitForFlag ( volatile uint16_t reg,
uint16_t  mask,
uint16_t  flag 
)

References TWERR_SPCTOUT.

Referenced by NutTwiStartRolling().

int NutTwiStartRolling ( NUTTWIBUS bus,
uint32_t  tmo 
)

Set START condition and wait for its appearance on the bus.

References _NUTTWIBUS::bus_base, I2C_TypeDef::CR1, I2C_TypeDef::CR2, I2C_CR1_ACK, I2C_CR1_PE, I2C_CR1_START, I2C_CR2_ITBUFEN, I2C_CR2_ITERREN, I2C_CR2_ITEVTEN, I2C_Is_Busy(), NutSleep(), TWERR_TIMEOUT, and TwWaitForFlag().

Referenced by NutTwiMasterRegRead(), NutTwiMasterRegWrite(), and NutTwiMasterTranceive().

Here is the call graph for this function:

int NutTwiSetSpeed ( NUTTWIBUS bus,
uint32_t  speed 
)

Set Speed of I2C Interface.

Setup Interface Speed

References _NUTTWIBUS::bus_base, I2C_TypeDef::CCR, I2C_TypeDef::CR1, I2C_CCR_CCR, I2C_CCR_DUTY, I2C_CCR_FS, I2C_CR1_PE, NutClockGet, rc, and I2C_TypeDef::TRISE.

int NutTwiGetSpeed ( NUTTWIBUS bus)

Request Current Speed of I2C Interface.

References _NUTTWIBUS::bus_base, I2C_TypeDef::CCR, I2C_CCR_CCR, I2C_CCR_FS, NutClockGet, and rc.