44 volatile uint32_t *
ptr;
63 .register_map_length = 0,
64 .selected_register = 0,
70#define IIC_REPEATED_START 0x01
72#define IIC_DGIER_OFFSET 0x1C
73#define IIC_IISR_OFFSET 0x20
74#define IIC_IIER_OFFSET 0x28
75#define IIC_RESETR_OFFSET 0x40
76#define IIC_CR_REG_OFFSET 0x100
77#define IIC_SR_REG_OFFSET 0x104
78#define IIC_DTR_REG_OFFSET 0x108
79#define IIC_DRR_REG_OFFSET 0x10C
80#define IIC_ADR_REG_OFFSET 0x110
81#define IIC_TFO_REG_OFFSET 0x114
82#define IIC_RFO_REG_OFFSET 0x118
83#define IIC_TBA_REG_OFFSET 0x11C
84#define IIC_RFD_REG_OFFSET 0x120
85#define IIC_GPO_REG_OFFSET 0x124
87#define IIC_CR_ENABLE_DEVICE_MASK 0x00000001
88#define IIC_CR_TX_FIFO_RESET_MASK 0x00000002
89#define IIC_CR_MSMS_MASK 0x00000004
90#define IIC_CR_DIR_IS_TX_MASK 0x00000008
91#define IIC_CR_NO_ACK_MASK 0x00000010
92#define IIC_CR_REPEATED_START_MASK 0x00000020
93#define IIC_CR_GENERAL_CALL_MASK 0x00000040
95#define IIC_INTR_ARB_LOST_MASK 0x00000001
96#define IIC_INTR_TX_ERROR_MASK 0x00000002
97#define IIC_INTR_TX_EMPTY_MASK 0x00000004
98#define IIC_INTR_RX_FULL_MASK 0x00000008
99#define IIC_INTR_BNB_MASK 0x00000010
100#define IIC_INTR_AAS_MASK 0x00000020
101#define IIC_INTR_NAAS_MASK 0x00000040
102#define IIC_INTR_TX_HALF_MASK 0x00000080
103#define IIC_SR_BUS_BUSY_MASK 0x00000004
104#define IIC_SR_RX_FIFO_EMPTY 0x00000040
105#define IIC_REG_SOFT_RESET (0x40)
106#define IIC_SR_MSTR_RDING_SLAVE_MASK 0x00000008
113 iic_handles[iic].
ptr =
115 }
else if (iic ==
IIC1) {
116 iic_handles[iic].
ptr =
128 if (iic_handles[iic].ptr == NULL) {
129 pynq_error(
"IIC%d has not been initialized.\n", iic);
132 iic_handles[iic].
ptr = NULL;
136 uint32_t *register_map,
const uint32_t rm_length) {
140 if (iic_handles[iic].ptr == NULL) {
141 pynq_error(
"IIC%d has not been initialized.\n", iic);
143 (iic_handles[iic].
saddr) = addr;
160static inline void iic_clear_isr_mask(
const iic_index_t iic, uint32_t mask) {
166static void iic_flush_tx_fifo(
const iic_index_t iic) {
173static void iic_tx_error_handler(
const iic_index_t iic) {
175 iic_flush_tx_fifo(iic);
182static void iic_slave_master_write(
const iic_index_t iic,
const uint32_t c) {
184 uint32_t v = (c << (handle->
recv_cnt) * 8);
196static void iic_slave_master_read(
const iic_index_t iic) {
204 uint8_t c = (r >> ((handle->
recv_cnt) * 8)) & 0xFF;
215static void iic_interrupt_handle(
const iic_index_t iic) {
216 time_t start = time(NULL);
221 time_t now = time(NULL);
230 iic_tx_error_handler(iic);
238 reg &= ~IIC_CR_NO_ACK_MASK;
240 switch (handle->
state) {
251 iic_slave_master_write(iic, d);
275 iic_slave_master_read(iic);
285 iic_clear_isr_mask(iic, 0xFF);
297 iic_clear_isr_mask(iic, clear);
307 if (iic_handles[iic].ptr == NULL) {
308 pynq_error(
"IIC%d has not been initialized.\n", iic);
310 iic_interrupt_handle(iic);
318 if (iic_handles[iic].ptr == NULL) {
319 pynq_error(
"IIC%d has not been initialized.\n", iic);
324 reg & ~IIC_CR_REPEATED_START_MASK;
328 const uint8_t reg, uint8_t *data, uint16_t data_length) {
332 if (iic_handles[iic].ptr == NULL) {
333 pynq_error(
"IIC%d has not been initialized.\n", iic);
335 if (
XIic_Send((UINTPTR)iic_handles[iic].ptr, addr, (u8 *)®, 1,
339 uint8_t ByteCount =
XIic_Recv((UINTPTR)iic_handles[iic].ptr, addr, data,
341 return (ByteCount == data_length) ? 0 : 1;
345 const uint8_t reg, uint8_t *data,
346 uint16_t data_length) {
350 if (iic_handles[iic].ptr == NULL) {
351 pynq_error(
"IIC%d has not been initialized.\n", iic);
353 uint8_t buffer[1 + data_length];
355 memcpy(&(buffer[1]), data, data_length);
356 uint8_t ByteCount =
XIic_Send((UINTPTR)iic_handles[iic].ptr, addr,
357 &(buffer[0]), 1 + data_length,
XIIC_STOP);
358 return (ByteCount == (data_length + 1)) ? 0 : 1;
void arm_shared_close(arm_shared *handle)
void * arm_shared_init(arm_shared *handle, const uint32_t address, const uint32_t length)
iic_index_t
Enum of IICs. Functions use a switch numbered from 0..NUM_IICS-1.
void iic_destroy(const iic_index_t iic)
Close the shared memory handle for the specified IIC index.
bool iic_set_slave_mode(const iic_index_t iic, const uint8_t addr, uint32_t *register_map, const uint32_t rm_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)
bool iic_read_register(const iic_index_t iic, const uint8_t addr, const uint8_t reg, uint8_t *data, uint16_t data_length)
void iic_reset(const iic_index_t iic)
void iic_slave_mode_handler(const iic_index_t iic)
void iic_init(const iic_index_t iic)
Initialize the IIC specified by the index with a shared memory handle and a buffer size of 4096 bytes...
#define pynq_warning(...)
#define IIC_INTR_TX_HALF_MASK
#define IIC_INTR_ARB_LOST_MASK
#define IIC_CR_TX_FIFO_RESET_MASK
#define IIC_DTR_REG_OFFSET
#define IIC_INTR_AAS_MASK
#define IIC_ADR_REG_OFFSET
#define IIC_SR_REG_OFFSET
#define IIC_INTR_TX_ERROR_MASK
#define IIC_SR_MSTR_RDING_SLAVE_MASK
#define IIC_DRR_REG_OFFSET
#define IIC_INTR_BNB_MASK
#define IIC_SR_BUS_BUSY_MASK
#define IIC_CR_REG_OFFSET
#define IIC_INTR_NAAS_MASK
#define IIC_RFD_REG_OFFSET
#define IIC_INTR_TX_EMPTY_MASK
#define IIC_CR_ENABLE_DEVICE_MASK
#define IIC_REG_SOFT_RESET
#define IIC_INTR_RX_FULL_MASK
uint32_t selected_register
uint32_t register_map_length
unsigned XIic_Recv(UINTPTR BaseAddress, u8 Address, u8 *BufferPtr, unsigned ByteCount, u8 Option)
unsigned XIic_Send(UINTPTR BaseAddress, u8 Address, u8 *BufferPtr, unsigned ByteCount, u8 Option)
#define XIIC_REPEATED_START