libpynq (release 5EWC0-2023 version 0.2.5 of 2023-10-08 10:51)
Loading...
Searching...
No Matches
iic.c File Reference
#include "iic.h"
#include "arm_shared_memory_system.h"
#include "log.h"
#include <platform.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <xiic_l.h>
#include <unistd.h>
Include dependency graph for iic.c:

Go to the source code of this file.

Data Structures

struct  IICHandle
 

Macros

#define IIC_TIMEOUT   5
 
#define IIC_STOP   0x00
 
#define IIC_REPEATED_START   0x01
 
#define IIC_DGIER_OFFSET   0x1C
 
#define IIC_IISR_OFFSET   0x20
 
#define IIC_IIER_OFFSET   0x28
 
#define IIC_RESETR_OFFSET   0x40
 
#define IIC_CR_REG_OFFSET   0x100
 
#define IIC_SR_REG_OFFSET   0x104
 
#define IIC_DTR_REG_OFFSET   0x108
 
#define IIC_DRR_REG_OFFSET   0x10C
 
#define IIC_ADR_REG_OFFSET   0x110
 
#define IIC_TFO_REG_OFFSET   0x114
 
#define IIC_RFO_REG_OFFSET   0x118
 
#define IIC_TBA_REG_OFFSET   0x11C
 
#define IIC_RFD_REG_OFFSET   0x120
 
#define IIC_GPO_REG_OFFSET   0x124
 
#define IIC_CR_ENABLE_DEVICE_MASK   0x00000001
 
#define IIC_CR_TX_FIFO_RESET_MASK   0x00000002
 
#define IIC_CR_MSMS_MASK   0x00000004
 
#define IIC_CR_DIR_IS_TX_MASK   0x00000008
 
#define IIC_CR_NO_ACK_MASK   0x00000010
 
#define IIC_CR_REPEATED_START_MASK   0x00000020
 
#define IIC_CR_GENERAL_CALL_MASK   0x00000040
 
#define IIC_INTR_ARB_LOST_MASK   0x00000001
 
#define IIC_INTR_TX_ERROR_MASK   0x00000002
 
#define IIC_INTR_TX_EMPTY_MASK   0x00000004
 
#define IIC_INTR_RX_FULL_MASK   0x00000008
 
#define IIC_INTR_BNB_MASK   0x00000010
 
#define IIC_INTR_AAS_MASK   0x00000020
 
#define IIC_INTR_NAAS_MASK   0x00000040
 
#define IIC_INTR_TX_HALF_MASK   0x00000080
 
#define IIC_SR_BUS_BUSY_MASK   0x00000004
 
#define IIC_SR_RX_FIFO_EMPTY   0x00000040
 
#define IIC_REG_SOFT_RESET   (0x40)
 
#define IIC_SR_MSTR_RDING_SLAVE_MASK   0x00000008
 

Typedefs

typedef struct IICHandle IICHandle
 

Enumerations

enum  IICState { IIC_IDLE = 0 , IIC_ADDRESS = 1 , IIC_READ = 2 , IIC_WRITE = 3 }
 

Functions

void iic_init (const iic_index_t iic)
 
void iic_destroy (const iic_index_t iic)
 
bool iic_set_slave_mode (const iic_index_t iic, const uint8_t addr, uint32_t *register_map, const uint32_t rm_length)
 
void iic_slave_mode_handler (const iic_index_t iic)
 
void iic_reset (const iic_index_t iic)
 
bool iic_read_register (const iic_index_t iic, const uint8_t addr, const uint8_t reg, uint8_t *data, uint16_t data_length)
 
bool iic_write_register (const iic_index_t iic, const uint8_t addr, const uint8_t reg, uint8_t *data, uint16_t data_length)
 

Macro Definition Documentation

◆ IIC_ADR_REG_OFFSET

#define IIC_ADR_REG_OFFSET   0x110

Address Register

Definition at line 80 of file iic.c.

◆ IIC_CR_DIR_IS_TX_MASK

#define IIC_CR_DIR_IS_TX_MASK   0x00000008

Dir of Tx. Txing=1

Definition at line 90 of file iic.c.

◆ IIC_CR_ENABLE_DEVICE_MASK

#define IIC_CR_ENABLE_DEVICE_MASK   0x00000001

Device enable = 1

Definition at line 87 of file iic.c.

◆ IIC_CR_GENERAL_CALL_MASK

#define IIC_CR_GENERAL_CALL_MASK   0x00000040

Gen Call enabled = 1

Definition at line 93 of file iic.c.

◆ IIC_CR_MSMS_MASK

#define IIC_CR_MSMS_MASK   0x00000004

Master starts Txing=1

Definition at line 89 of file iic.c.

◆ IIC_CR_NO_ACK_MASK

#define IIC_CR_NO_ACK_MASK   0x00000010

Tx Ack. NO ack = 1

Definition at line 91 of file iic.c.

◆ IIC_CR_REG_OFFSET

#define IIC_CR_REG_OFFSET   0x100

Control Register

Definition at line 76 of file iic.c.

◆ IIC_CR_REPEATED_START_MASK

#define IIC_CR_REPEATED_START_MASK   0x00000020

Repeated start = 1

Definition at line 92 of file iic.c.

◆ IIC_CR_TX_FIFO_RESET_MASK

#define IIC_CR_TX_FIFO_RESET_MASK   0x00000002

Transmit FIFO reset=1

Definition at line 88 of file iic.c.

◆ IIC_DGIER_OFFSET

#define IIC_DGIER_OFFSET   0x1C

Global Interrupt Enable Register

Definition at line 72 of file iic.c.

◆ IIC_DRR_REG_OFFSET

#define IIC_DRR_REG_OFFSET   0x10C

Data Rx Register

Definition at line 79 of file iic.c.

◆ IIC_DTR_REG_OFFSET

#define IIC_DTR_REG_OFFSET   0x108

Data Tx Register

Definition at line 78 of file iic.c.

◆ IIC_GPO_REG_OFFSET

#define IIC_GPO_REG_OFFSET   0x124

Output Register

Definition at line 85 of file iic.c.

◆ IIC_IIER_OFFSET

#define IIC_IIER_OFFSET   0x28

Interrupt Enable Register

Definition at line 74 of file iic.c.

◆ IIC_IISR_OFFSET

#define IIC_IISR_OFFSET   0x20

Interrupt Status Register

Definition at line 73 of file iic.c.

◆ IIC_INTR_AAS_MASK

#define IIC_INTR_AAS_MASK   0x00000020

1 = When addr as slave

Definition at line 100 of file iic.c.

◆ IIC_INTR_ARB_LOST_MASK

#define IIC_INTR_ARB_LOST_MASK   0x00000001

1 = Arbitration lost

Definition at line 95 of file iic.c.

◆ IIC_INTR_BNB_MASK

#define IIC_INTR_BNB_MASK   0x00000010

1 = Bus not busy

Definition at line 99 of file iic.c.

◆ IIC_INTR_NAAS_MASK

#define IIC_INTR_NAAS_MASK   0x00000040

1 = Not addr as slave

Definition at line 101 of file iic.c.

◆ IIC_INTR_RX_FULL_MASK

#define IIC_INTR_RX_FULL_MASK   0x00000008

1 = Rx FIFO/reg=OCY level

Definition at line 98 of file iic.c.

◆ IIC_INTR_TX_EMPTY_MASK

#define IIC_INTR_TX_EMPTY_MASK   0x00000004

1 = Tx FIFO/reg empty

Definition at line 97 of file iic.c.

◆ IIC_INTR_TX_ERROR_MASK

#define IIC_INTR_TX_ERROR_MASK   0x00000002

1 = Tx error/msg complete

Definition at line 96 of file iic.c.

◆ IIC_INTR_TX_HALF_MASK

#define IIC_INTR_TX_HALF_MASK   0x00000080

1 = Tx FIFO half empty

Definition at line 102 of file iic.c.

◆ IIC_REG_SOFT_RESET

#define IIC_REG_SOFT_RESET   (0x40)

Definition at line 105 of file iic.c.

◆ IIC_REPEATED_START

#define IIC_REPEATED_START   0x01

Definition at line 70 of file iic.c.

◆ IIC_RESETR_OFFSET

#define IIC_RESETR_OFFSET   0x40

Reset Register

Definition at line 75 of file iic.c.

◆ IIC_RFD_REG_OFFSET

#define IIC_RFD_REG_OFFSET   0x120

Rx FIFO Depth reg

Definition at line 84 of file iic.c.

◆ IIC_RFO_REG_OFFSET

#define IIC_RFO_REG_OFFSET   0x118

Rx FIFO Occupancy

Definition at line 82 of file iic.c.

◆ IIC_SR_BUS_BUSY_MASK

#define IIC_SR_BUS_BUSY_MASK   0x00000004

1 = Bus is busy

Definition at line 103 of file iic.c.

◆ IIC_SR_MSTR_RDING_SLAVE_MASK

#define IIC_SR_MSTR_RDING_SLAVE_MASK   0x00000008

Definition at line 106 of file iic.c.

◆ IIC_SR_REG_OFFSET

#define IIC_SR_REG_OFFSET   0x104

Status Register

Definition at line 77 of file iic.c.

◆ IIC_SR_RX_FIFO_EMPTY

#define IIC_SR_RX_FIFO_EMPTY   0x00000040

Definition at line 104 of file iic.c.

◆ IIC_STOP

#define IIC_STOP   0x00

Definition at line 69 of file iic.c.

◆ IIC_TBA_REG_OFFSET

#define IIC_TBA_REG_OFFSET   0x11C

10 Bit Address reg

Definition at line 83 of file iic.c.

◆ IIC_TFO_REG_OFFSET

#define IIC_TFO_REG_OFFSET   0x114

Tx FIFO Occupancy

Definition at line 81 of file iic.c.

◆ IIC_TIMEOUT

#define IIC_TIMEOUT   5

Definition at line 33 of file iic.c.

Typedef Documentation

◆ IICHandle

typedef struct IICHandle IICHandle

Enumeration Type Documentation

◆ IICState

enum IICState
Enumerator
IIC_IDLE 
IIC_ADDRESS 
IIC_READ 
IIC_WRITE 

Definition at line 34 of file iic.c.